[ Index ] |
|
Code source de LifeType 1.2.4 |
1 <?php 2 3 lt_include( PLOG_CLASS_PATH."class/database/dbobject.class.php" ); 4 lt_include( PLOG_CLASS_PATH."class/dao/articlestatus.class.php" ); 5 6 /** 7 * \ingroup DAO 8 * 9 * Represents an article category. 10 */ 11 class ArticleCategory extends DbObject 12 { 13 14 var $_id; 15 var $_name; 16 var $_url; 17 var $_blogId; 18 var $_numArticles; 19 var $_inMainPage; 20 var $_parentId; 21 var $_parentCategory; 22 var $_description; 23 var $_lastModification; 24 var $_blog; 25 var $_mangledName; 26 var $_articles; 27 28 /** 29 * Creates an article category. 30 * 31 * @param name The name given to the new category 32 * @param url Not used. 33 * @param blogId The id of the blog to which this category id assigned. 34 * @param inMainPage Whether posts belonging to this category should be shown in the front page of the blog or not. 35 * @param description Description of the category, defaults to nothing. 36 * @param numArticles Number of articles in this category, defaults to '0'. 37 * @param properties Not used. 38 * @param id Id assigned to this category in the database, defaults to '-1' and it is ignored for new categories. 39 * @param lastModification Date when this category was last modified. 40 * @param parentId Id of the parent category, not used as of LifeType 1.1. 41 */ 42 function ArticleCategory( $name, $url, $blogId, $inMainPage, $description = "", $numArticles = 0, $properties = Array(), $id = -1, $lastModification=null, $parentId = 0) 43 { 44 lt_include( PLOG_CLASS_PATH."class/data/timestamp.class.php" ); 45 46 $this->DbObject(); 47 48 $this->_name = $name; 49 $this->_url = $url; 50 $this->_id = $id; 51 $this->_blogId = $blogId; 52 $this->setInMainPage( $inMainPage ); 53 $this->_numArticles = $numArticles; 54 $this->setProperties( $properties ); 55 $this->_parentId = $parentId; 56 $this->_description = $description; 57 $this->_lastModification = new Timestamp($lastModification); 58 $this->_articles = Array(); 59 $this->_numArticles = 0; 60 $this->_numPublishedArticles = 0; 61 $this->_blog = null; 62 $this->_mangledName = ""; 63 64 $this->_pk = "id"; 65 $this->_fields = Array( "name" => "getName", 66 "url" => "getUrl", 67 "blog_id" => "getBlogId", 68 "parent_id" => "getParentId", 69 "description" => "getDescription", 70 "in_main_page" => "isInMainPage", 71 "last_modification" => "getLastModification", 72 "properties" => "getProperties", 73 "num_articles" => "getNumAllArticles", 74 "num_published_articles" => "getNumPublishedArticles", 75 "mangled_name" => "getMangledName" ); 76 } 77 78 /** 79 * @private 80 */ 81 function setId( $newId ) 82 { 83 $this->_id = $newId; 84 } 85 86 /** 87 * @private 88 */ 89 function setName( $newName ) 90 { 91 $this->_name = $newName; 92 } 93 94 /** 95 * @private 96 */ 97 function setURL( $newURL ) 98 { 99 $this->_url = $newURL; 100 } 101 102 /** 103 * @private 104 */ 105 function setBlogId( $blogId ) 106 { 107 $this->_blogId = $blogId; 108 } 109 110 /** 111 * sets the parent category id 112 * 113 * @param parentId The id of the parent category 114 */ 115 function setParentId( $parentId ) 116 { 117 $this->_parentId = $parentId; 118 } 119 120 /** 121 * sets the parent ArticleCategory object 122 * 123 * @param An ArticleCategory object representing the parent category 124 */ 125 function setParentCategory( $parentCategory ) 126 { 127 $this->_parentCategory = $parentCategory; 128 } 129 130 /** 131 * sets the description 132 * 133 * @param description 134 */ 135 function setDescription( $desc ) 136 { 137 $this->_description = $desc; 138 } 139 140 /** 141 * Returns the identifier assigned to this category. 142 * 143 * @return An integer value with the category number. 144 */ 145 function getId() 146 { 147 return $this->_id; 148 } 149 150 /** 151 * Returns the name assigned to the category. 152 * 153 * @return A string value with the name assigned to the category. 154 */ 155 function getName() 156 { 157 return $this->_name; 158 } 159 160 /** 161 * @private 162 */ 163 function getURL() 164 { 165 return $this->_url; 166 } 167 168 /** 169 * Returns the identifier of the blog to which this category belongs. 170 * 171 * @return An integer value containing the identifier to which this category belongs. 172 */ 173 function getBlogId() 174 { 175 return $this->_blogId; 176 } 177 178 /** 179 * Returns how many articles have been categorized under this category. 180 * 181 * @param status A valid post status 182 * @return An integer value 183 */ 184 function getNumArticles( $status = POST_STATUS_PUBLISHED ) 185 { 186 if( $status == POST_STATUS_ALL ) 187 return( $this->_numArticles ); 188 elseif( $status == POST_STATUS_PUBLISHED ) 189 return( $this->_numPublishedArticles ); 190 else { 191 $origStatus = $status; 192 if( !is_array( $this->_numArticles[$status] ) || $this->_numArticles[$status] == null ) { 193 $categories = new ArticleCategories(); 194 $this->_numArticles[$status] = $categories->getNumArticlesCategory( $this->getId(), $origStatus ); 195 } 196 197 return( $this->_numArticles[$status] ); 198 } 199 } 200 201 /** 202 * shorthand method for getting the total number of articles in the category, regardless of the 203 * status 204 * 205 * @return the total number of posts 206 */ 207 function getNumAllArticles() 208 { 209 return( $this->getNumArticles( POST_STATUS_ALL )); 210 } 211 212 /** 213 * Returns the number of articles that have a published status in this category 214 * 215 * @return Number of published articles 216 */ 217 function getNumPublishedArticles() 218 { 219 return( $this->_numPublishedArticles ); 220 } 221 222 /** 223 * Sets the number of articles that have a published status in this category. This method 224 * should usually not be called unless we want to mess up counters. 225 * 226 * @private. 227 */ 228 function setNumPublishedArticles( $num ) 229 { 230 $this->_numPublishedArticles = $num; 231 } 232 233 /** 234 * Sets the number of articles in this category. This method 235 * should usually not be called unless we want to mess up counters. 236 * 237 * @private. 238 */ 239 function setNumArticles( $num ) 240 { 241 $this->_numArticles = $num; 242 } 243 244 /** 245 * returns the articles categorized here 246 * 247 * @param an array of Article obejcts 248 */ 249 function getArticles( $status = POST_STATUS_PUBLISHED ) 250 { 251 lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" ); 252 253 if( !is_array( $this->_articles[$status] ) || $this->_articles[$status] == null ) { 254 $articles = new Articles(); 255 // you've got to love these huge method calls... 256 $this->_articles[$status] = $articles->getBlogArticles( $this->getBlogId(), 257 -1, 258 -1, 259 $this->getId(), 260 $status ); 261 } 262 263 return( $this->_articles[$status] ); 264 } 265 266 /** 267 * returns the id of the parent category 268 * 269 * @return The id of the parent category 270 */ 271 function getParentId() 272 { 273 return $this->_parentId; 274 } 275 276 /** 277 * returns the parent ArticleCategory object 278 * 279 * @return An ArticleCategory object representing the parent category 280 */ 281 function getParentCategory() 282 { 283 return $this->_parentCategory; 284 } 285 286 /** 287 * Returns true if the category has been configured to be shown in the main 288 * page or not. 289 * 290 * @return True wether the category is shown in main page, or false otherwise. 291 */ 292 function isInMainPage() 293 { 294 return $this->_inMainPage; 295 } 296 297 /** 298 * If set to true, enables the category to be shown in the main page, or false 299 * otherwise. 300 * 301 * @param show True or false, depending wether we'd like to show the category in 302 * the main page or not. 303 */ 304 function setInMainPage( $show ) 305 { 306 if( $show ) 307 $this->_inMainPage = 1; 308 else 309 $this->_inMainPage = 0; 310 } 311 312 /** 313 * returns the description 314 * 315 * @return The description 316 */ 317 function getDescription() 318 { 319 return $this->_description; 320 } 321 322 /** 323 * returns the last modification date 324 * 325 * @return A Timestamp object 326 */ 327 function getLastModification() 328 { 329 return $this->_lastModification; 330 } 331 332 /** 333 * Sets the date in which this category was last modified 334 * 335 * @param newDate a Timestamp object containing the date in which this category was last modified 336 */ 337 function setLastModification( $newDate ) 338 { 339 $this->_lastModification = $newDate; 340 } 341 342 /** 343 * Returns the 'mangled' version of the name of this category, used for generating nicer 344 * links when custom URLs are enabled. It may not work with double-byte languages. 345 * 346 * @return A string containing a 'url-ified' version of the category name 347 */ 348 function getMangledName() 349 { 350 if( $this->_mangledName == "" ) { 351 lt_include( PLOG_CLASS_PATH."class/data/textfilter.class.php" ); 352 $this->_mangledName = Textfilter::urlize( $this->getName()); 353 } 354 355 return( $this->_mangledName ); 356 } 357 358 /** 359 * Sets the 'mangled' version of the name of this category, used for generating nicer 360 * links when custom URLs are enabled. 361 * 362 * @param mangledName A string containing a 'url-ified' version of the category name 363 */ 364 function setMangledName( $mangledName ) 365 { 366 $this->_mangledName = $mangledName; 367 } 368 369 /** 370 * Returns the BlogInfo object to which this category belongs 371 * 372 * @return A BlogInfo object 373 */ 374 function getBlog() 375 { 376 if( $this->_blog == null ) { 377 lt_include( PLOG_CLASS_PATH."class/dao/bloginfo.class.php" ); 378 $blogs = new Blogs(); 379 $this->_blog = $blogs->getBlogInfoById( $this->getBlogId()); 380 } 381 382 return( $this->_blog ); 383 } 384 385 /** 386 * @private 387 * Those attributes that should not be serialized (not cached) are set to 388 * null. 389 */ 390 function __sleep() 391 { 392 $this->_parentCategory = null; 393 $this->_blog = null; 394 $this->_articles = null; 395 return( parent::__sleep()); 396 } 397 } 398 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 21:04:15 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |