1 <?php 2 /* Copyright (c) 2012, Geert Bergman (geert@scrivo.nl) 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, 9 * this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright notice, 11 * this list of conditions and the following disclaimer in the documentation 12 * and/or other materials provided with the distribution. 13 * 3. Neither the name of "Scrivo" nor the names of its contributors may be 14 * used to endorse or promote products derived from this software without 15 * specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 * POSSIBILITY OF SUCH DAMAGE. 28 * 29 * $Id: ListItemProperty.php 866 2013-08-25 16:22:35Z geert $ 30 */ 31 32 /** 33 * Implementation of the \Scrivo\ListItemProperty class. 34 */ 35 36 namespace Scrivo; 37 38 /** 39 * The ListItemProperty class is the base class for all list item properties. 40 * Page properties are a part of the list item. 41 * 42 */ 43 class ListItemProperty { 44 45 /** 46 * The property type: one out of the TemplateProperty::TYPE_* constants. 47 * @var \Scrivo\String 48 */ 49 // protected $type; 50 51 /** 52 * An textual identification/key for this property. 53 * @var \Scrivo\String 54 */ 55 protected $phpSelector; 56 57 /** 58 * The property data. 59 * @var \Scrivo\String 60 */ 61 protected $data; 62 63 /** 64 * Id of the property defintion. 65 * @var int 66 */ 67 private $definitionId; 68 69 /** 70 * The id of the list item where this property belongs to. 71 * @var int 72 */ 73 private $listItemId; 74 75 /** 76 * The id of the page where this property belongs to. 77 * @var int 78 */ 79 private $pageId; 80 81 /** 82 * Create an empty list item property object or select a list item property 83 * from the database. 84 * 85 * @param array $rd An array (result set row) containing inital data. 86 */ 87 protected function __construct(array $rd) { 88 $this->listItemId = intval($rd["list_item_id"]); 89 // $this->type = new \Scrivo\String($rd["type"]); 90 $this->phpSelector = new \Scrivo\String($rd["php_key"]); 91 $this->setData(new \Scrivo\String($rd["value"])); 92 $this->definitionId = intval($rd["ID_DEF"]); 93 $this->pageId = intval($rd["page_id"]); 94 } 95 96 /** 97 * Factory method for creating a list item property. This method will 98 * return a list item property of the proper specialized type. 99 * 100 * @param array $rd An array (result set row) containing inital data. 101 */ 102 public static function create(array $rd) { 103 \Scrivo\ArgumentCheck::assertArgs(func_get_args(), array(null)); 104 105 switch ($rd["type"]) { 106 case \Scrivo\ListItemPropertyDefinition::TYPE_IMAGE: 107 return new \Scrivo\ListItemProperty\ImageAltTitle($rd); 108 109 case \Scrivo\ListItemPropertyDefinition::TYPE_SELECT: 110 return new \Scrivo\ListItemProperty\SelectList($rd); 111 112 case \Scrivo\ListItemPropertyDefinition::TYPE_COLOR: 113 return new \Scrivo\ListItemProperty\Color($rd); 114 115 case \Scrivo\ListItemPropertyDefinition::TYPE_URL: 116 return new \Scrivo\ListItemProperty\Url($rd); 117 118 case \Scrivo\ListItemPropertyDefinition::TYPE_CHECKBOX: 119 return new \Scrivo\ListItemProperty\CheckBox($rd); 120 121 case \Scrivo\ListItemPropertyDefinition::TYPE_INPUT: 122 return new \Scrivo\ListItemProperty\Input($rd); 123 124 case \Scrivo\ListItemPropertyDefinition::TYPE_TEXT: 125 return new \Scrivo\ListItemProperty\Text($rd); 126 127 case \Scrivo\ListItemPropertyDefinition::TYPE_HTML_TEXT: 128 return new \Scrivo\ListItemProperty\HtmlText($rd); 129 130 case \Scrivo\ListItemPropertyDefinition::TYPE_DATE_TIME: 131 return new \Scrivo\ListItemProperty\DateTime($rd); 132 133 case \Scrivo\ListItemPropertyDefinition::TYPE_TAB: 134 return null; 135 136 case \Scrivo\ListItemPropertyDefinition::TYPE_INFO: 137 return null; 138 } 139 140 throw new \Scrivo\SystemException( 141 "Invalid property type {$rd["type"]}"); 142 } 143 144 /** 145 * Implementation of the readable properties using the PHP magic 146 * method __get(). 147 * 148 * @param string $name The name of the property to get. 149 * 150 * @return mixed The value of the requested property. 151 */ 152 public function __get($name) { 153 switch ($name) { 154 // case "type": return $this->type; 155 case "phpSelector": return $this->phpSelector; 156 case "data": return $this->data; 157 case "definitionId": return $this->definitionId; 158 case "listItemId": return $this->listItemId; 159 case "pageId": return $this->pageId; 160 } 161 throw new \Scrivo\SystemException("No such get-property '$name'."); 162 } 163 164 /** 165 * Implementation of the writable properties using the PHP magic 166 * method __set(). 167 * 168 * @param string $name The name of the property to set. 169 * @param mixed $value The value of the property to set. 170 */ 171 public function __set($name, $value) { 172 switch ($name) { 173 case "data": $this->setData($value); return; 174 } 175 throw new \Scrivo\SystemException("No such set-property '$name'."); 176 } 177 178 /** 179 * Set The property data. 180 * 181 * @param \Scrivo\String $data The property data. 182 */ 183 protected function setData(\Scrivo\String $data) { 184 $this->data = $data; 185 } 186 187 } 188 189 ?>
Documentation generated by phpDocumentor 2.0.0a12 and ScrivoDocumentor on August 29, 2013