1 <?php 2 /* Copyright (c) 2013, 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: ListItem.php 866 2013-08-25 16:22:35Z geert $ 30 */ 31 32 /** 33 * Implementation of the \Scrivo\ListItem class. 34 */ 35 36 namespace Scrivo; 37 38 /** 39 * A Scrivo list item is a simple data structure for list item data. List items 40 * contain a fixed set of properties and a variable set of properties as 41 * definded in its list item property definition. 42 * 43 * Instances of this class are created through objects of the \Scrivo\ItemList 44 * class. Either by retrieving them as items that were previously added to the 45 * list or by using the \Scrivo\ItemList::newItem(\Scrivo\String $type) method. 46 * 47 * @property-read \DateTime $dateCreated The date/time that this list item was created. 48 * @property-read \DateTime $dateModified The last date/time that this list item was modified. 49 * @property-read int $definitionId The id of the defintion of the list item. 50 * @property-read int $id The list item's id (DB key). 51 * @property-read int $linkedPageId An optional id of a linked page. 52 * @property-read int $listId The id of the list where this list item belongs to. 53 * @property-read int $pageId The id of the page where this list item belongs to. 54 * @property \DateTime $dateOffline The date/time this list item need to go offline. 55 * @property \DateTime $dateOnline The date/time this list item need to go online. 56 * @property int $parentId The id of the parent list item. 57 * @property \Scrivo\String $title The list item title. 58 */ 59 class ListItem { 60 61 /** 62 * The list items id (DB key). 63 * @var int 64 */ 65 private $id = 0; 66 67 /** 68 * The id of the list where this list item belongs to. 69 * @var int 70 */ 71 private $listId = 0; 72 73 /** 74 * The id of the page where this list item belongs to. 75 * @var int 76 */ 77 private $pageId = 0; 78 79 /** 80 * The current version of the page: -1: scratch version, 0 live version, 1 and up versions. 81 * @var int 82 */ 83 private $version = 0; 84 85 /** 86 * The id of the parent list item. 87 * @var int 88 */ 89 private $parentId = 0; 90 91 /** 92 * The id of the defintion of the list item. 93 * @var int 94 */ 95 private $definitionId = 0; 96 97 /** 98 * An optional id of a linked page. 99 * @var int 100 */ 101 private $linkedPageId = 0; 102 103 /** 104 * The list item title. 105 * @var \Scrivo\String 106 */ 107 protected $title = null; 108 109 /** 110 * The date/time that this list item was created. 111 * @var \DateTime 112 */ 113 protected $dateCreated = null; 114 115 /** 116 * The last date/time that this list item was modified. 117 * @var \DateTime 118 */ 119 protected $dateModified = null; 120 121 /** 122 * The date/time this list item need to go online. 123 * @var \DateTime 124 */ 125 protected $dateOnline = null; 126 127 /** 128 * The date/time this list item need to go offline. 129 * @var \DateTime 130 */ 131 protected $dateOffline = null; 132 133 /** 134 * The list item properties 135 * @var object 136 */ 137 protected $properties = null; 138 139 /** 140 * Create an and initalize a list item object. 141 * 142 * @param array $rd An array containing the field data using the database 143 * field names as keys. 144 * @param \Scrivo\PropertySet $properties An array containing the list 145 * item properties. 146 */ 147 public function __construct(array $rd, \Scrivo\PropertySet $properties) { 148 \Scrivo\ArgumentCheck::assertArgs(func_get_args(), array(null, null)); 149 150 $this->id = intval($rd["list_item_id"]); 151 $this->listId = intval($rd["item_list_id"]); 152 $this->pageId = intval($rd["page_id"]); 153 $this->version = intval($rd["version"]); 154 $this->parentId = intval($rd["parent_id"]); 155 $this->definitionId = intval($rd["list_item_definition_id"]); 156 $this->linkedPageId = intval($rd["link_id"]); 157 $this->title = new \Scrivo\String($rd["title"]); 158 $this->dateCreated = new \DateTime($rd["date_created"]); 159 $this->dateModified = new \DateTime($rd["date_modified"]); 160 $this->dateOnline = new \DateTime($rd["date_online"]); 161 $this->dateOffline = $rd["date_offline"] == null 162 ? null : new \DateTime($rd["date_offline"]); 163 $this->properties = $properties; 164 } 165 166 /** 167 * Implementation of the readable properties using the PHP magic 168 * method __get(). 169 * 170 * @param string $name The name of the property to get. 171 * 172 * @return mixed The value of the requested property. 173 */ 174 public function __get($name) { 175 switch($name) { 176 case "id": return $this->id; 177 case "listId": return $this->listId; 178 case "pageId": return $this->pageId; 179 case "version": return $this->version; 180 case "parentId": return $this->parentId; 181 case "definitionId": return $this->definitionId; 182 case "linkedPageId": return $this->linkedPageId; 183 case "title": return $this->title; 184 case "dateCreated": return $this->dateCreated; 185 case "dateModified": return $this->dateModified; 186 case "dateOnline": return $this->dateOnline; 187 case "dateOffline": return $this->dateOffline; 188 case "properties": return $this->properties; 189 } 190 throw new \Scrivo\SystemException("No such get-property '$name'."); 191 } 192 193 /** 194 * Implementation of the writable properties using the PHP magic 195 * method __set(). 196 * 197 * @param string $name The name of the property to set. 198 * @param mixed $value The value of the property to set. 199 */ 200 public function __set($name, $value) { 201 switch($name) { 202 case "parentId": $this->setParentId($value); return; 203 case "title": $this->setTitle($value); return; 204 case "dateOnline": $this->setDateOnline($value); return; 205 case "dateOffline": $this->setDateOffline($value); return; 206 } 207 throw new \Scrivo\SystemException("No such set-property '$name'."); 208 } 209 210 /** 211 * Set The id of the parent list item. 212 * 213 * @param int $parentId The id of the parent list item. 214 */ 215 public function setParentId($parentId) { 216 \Scrivo\ArgumentCheck::assertArgs(func_get_args(), array( 217 array(\Scrivo\ArgumentCheck::TYPE_INTEGER) 218 )); 219 220 \Scrivo\ArgumentCheck::assert( 221 $parentId, \Scrivo\ArgumentCheck::TYPE_INTEGER); 222 $this->parentId = $parentId; 223 } 224 225 /** 226 * Set The page title (<title>). 227 * 228 * @param \Scrivo\String $title The page title (<title>). 229 */ 230 public function setTitle(\Scrivo\String $title) { 231 $this->title = $title; 232 } 233 234 /** 235 * Set The date/time this page need to go online. 236 * 237 * @param \DateTime $dateOnline The date/time this page need to go online. 238 */ 239 public function setDateOnline(\DateTime $dateOnline) { 240 $this->dateOnline = $dateOnline; 241 } 242 243 /** 244 * Set The date/time this page need to go offline. 245 * 246 * @param \DateTime $dateOffline The date/time this page need to go offline. 247 */ 248 public function setDateOffline(\DateTime $dateOffline=null) { 249 $this->dateOffline = $dateOffline; 250 } 251 252 } 253 254 ?>
Documentation generated by phpDocumentor 2.0.0a12 and ScrivoDocumentor on August 29, 2013