[ Index ] |
|
Code source de LifeType 1.2.4 |
1 <?php 2 3 lt_include( PLOG_CLASS_PATH."class/dao/model.class.php" ); 4 lt_include( PLOG_CLASS_PATH."class/dao/mylink.class.php" ); 5 lt_include( PLOG_CLASS_PATH."class/dao/mylinkscategories.class.php" ); 6 lt_include( PLOG_CLASS_PATH."class/dao/daocacheconstants.properties.php" ); 7 8 /** 9 * \ingroup DAO 10 * 11 * Model for the myLinks feature 12 */ 13 class MyLinks extends Model 14 { 15 16 function MyLinks() 17 { 18 $this->Model(); 19 20 $this->table = $this->getPrefix()."mylinks"; 21 } 22 23 /** 24 * Retrieves the links of the given blog. 25 * 26 * @param blogId Identifier of the blog 27 * @param categoryId Category of the links 28 * @param searchTerms 29 * @param page 30 * @param itemsPerPage 31 */ 32 function getLinks( $blogId, $categoryId = 0, $searchTerms = "", $page = -1, $itemsPerPage = 15 ) 33 { 34 $blogLinks = $this->getMany( "blog_id", 35 $blogId, 36 CACHE_MYLINKS_ALL, 37 Array( CACHE_MYLINKS => "getId" ), 38 Array( "date" => "DESC" ), 39 $searchTerms, 40 $page, 41 $itemsPerPage ); 42 43 if( !$blogLinks ) 44 return Array(); 45 46 $result = Array(); 47 if( $categoryId > 0 ) { 48 foreach( $blogLinks as $link ) { 49 if( $link->getCategoryId() == $categoryId ) 50 $result[] = $link; 51 } 52 } 53 else 54 $result = $blogLinks; 55 56 return( $result ); 57 } 58 59 /** 60 * returns how many links a blog has 61 * 62 * @param blogId 63 * @param categoryId 64 * @param searchTerms 65 * @return an integer 66 */ 67 function getNumLinks( $blogId, $categoryId = 0, $searchTerms = "" ) 68 { 69 return( count( $this->getLinks( $blogId, $categoryId, $searchTerms ))); 70 } 71 72 /** 73 * Adds a link to the database 74 * 75 * @param myLink a MyLink object 76 * @param blogId The blog id 77 * @return True if successful or false otherwise. 78 */ 79 function addMyLink( &$myLink ) 80 { 81 $result = $this->add( $myLink ); 82 83 if( $result ) { 84 // clean the cache 85 $this->_cache->removeData( $myLink->getId(), CACHE_MYLINKS ); 86 $this->_cache->removeData( $myLink->getBlogId(), CACHE_MYLINKS_ALL ); 87 // mark the corresponding link categories as modified now 88 $linkCategories = new MyLinksCategories(); 89 $category = $myLink->getMyLinkCategory(); 90 $category->setLastModification( Timestamp::getNowTimestamp()); 91 $category->setNumLinks( $category->getNumLinks() + 1 ); 92 $linkCategories->updateMyLinksCategory( $category ); 93 } 94 95 return $result; 96 } 97 98 /** 99 * Removes a MyLink object from the database. 100 * 101 * @param linkId The link identifier. 102 * @param blogId The blog identifier. 103 * @return True if successful or false otherwise. 104 */ 105 function deleteMyLink( $linkId, $blogId ) 106 { 107 $link = $this->getMyLink( $linkId, $blogId ); 108 if( $link ) { 109 $this->delete( "id", $linkId ); 110 $this->_cache->removeData( $blogId, CACHE_MYLINKS_ALL ); 111 $this->_cache->removeData( $linkId, CACHE_MYLINKS ); 112 $linkCategories = new MyLinksCategories(); 113 $linkCategory = $link->getMyLinkCategory(); 114 $linkCategory->setLastModification( Timestamp::getNowTimestamp()); 115 $linkCategory->setNumLinks( $linkCategory->getNumLinks() - 1 ); 116 $linkCategories->updateMyLinksCategory( $linkCategory ); 117 return( true ); 118 } 119 else 120 return false; 121 } 122 123 /** 124 * Removes all the posts from the given blog 125 * 126 * @param blogId The blog identifier 127 */ 128 function deleteBlogMyLinks( $blogId ) 129 { 130 if( $this->delete( "blog_id", $blogId )) { 131 return( $this->_cache->removeData( $blogId, CACHE_MYLINKS_ALL )); 132 } 133 else 134 return false; 135 } 136 137 /** 138 * Retrieves a single link from disk. 139 * 140 * @param linkId The link identifier 141 * @param blogId The blog identifier 142 * @return The MyLink object containing information or false if it didn't exist 143 */ 144 function getMyLink( $linkId, $blogId = -1 ) 145 { 146 $blogLink = $this->get( "id", $linkId, CACHE_MYLINKS ); 147 if( !$blogLink ) 148 return false; 149 150 if( $blogId == -1 ) 151 return $blogLink; 152 153 if( $blogLink->getBlogId() == $blogId ) 154 return $blogLink; 155 else 156 return false; 157 } 158 159 /** 160 * Updates a link in the database. 161 * 162 * @param myLink A MyLink object with the information we'd like to update. 163 * @return True if successful or false otherwise. 164 */ 165 function updateMyLink( &$myLink ) 166 { 167 // get the previous version of this link before saving it 168 $prevVersion = $this->getMyLink( $myLink->getId()); 169 170 $result = $this->update( $myLink ); 171 172 if( !$result ) { 173 return false; 174 } 175 176 // mark the corresponding link categories as modified now 177 $linkCategories = new MyLinksCategories(); 178 $linkCategories->updateCategoryModificationDate( $myLink->getCategoryId()); 179 // clean the cache 180 $this->_cache->removeData( $myLink->getId(), CACHE_MYLINKS ); 181 $this->_cache->removeData( $myLink->getBlogId(), CACHE_MYLINKS_ALL ); 182 // and update the link category counters 183 lt_include( PLOG_CLASS_PATH."class/dao/mylinkscategories.class.php" ); 184 $linkCategories = new MyLinksCategories(); 185 if( $prevVersion->getCategoryId() != $myLink->getCategoryId()) { 186 // add one to the new category 187 $newCategory = $myLink->getMyLinkCategory(); 188 $newCategory->setNumLinks( $newCategory->getNumLinks() + 1 ); 189 // remove one from the old category 190 $oldCategory = $prevVersion->getMyLinkCategory(); 191 $oldCategory->setNumLinks( $oldCategory->getNumLinks() - 1 ); 192 // update the categories 193 $linkCategories->updateMyLinksCategory( $newCategory ); 194 $linkCategories->updateMyLinksCategory( $oldCategory ); 195 } 196 197 return true; 198 } 199 200 /** 201 * @see Model::getSearchConditions 202 */ 203 function getSearchConditions( $searchTerms ) 204 { 205 return( "(name LIKE '%".Db::qstr( $searchTerms )."%' OR description LIKE'%".Db::qstr( $searchTerms )."%'". 206 " OR url LIKE '%".Db::qstr( $searchTerms )."%')" ); 207 } 208 209 /** 210 * @private 211 */ 212 function mapRow( $row ) 213 { 214 $blogLink = new MyLink( $row["name"], 215 $row["description"], 216 $row["url"], 217 $row["blog_id"], 218 $row["category_id"], 219 $row["date"], 220 $row["rss_feed"], 221 unserialize($row["properties"]), 222 $row["id"] ); 223 224 return $blogLink; 225 226 } 227 } 228 ?>
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 |
![]() |