00001 <?php
00002
00003 lt_include( PLOG_CLASS_PATH."class/dao/model.class.php" );
00004 lt_include( PLOG_CLASS_PATH."class/dao/mylinkscategory.class.php" );
00005 lt_include( PLOG_CLASS_PATH."class/dao/mylinks.class.php" );
00006 lt_include( PLOG_CLASS_PATH."class/dao/daocacheconstants.properties.php" );
00007
00008 define( "MYLINKS_CATEGORIES_NO_ORDER", 0 );
00009 define( "MYLINKS_CATEGORIES_ALPHABETICAL_ORDER", 1 );
00010 define( "MYLINKS_CATEGORIES_REVERSE_ALPHABETICAL_ORDER", 2 );
00011 define( "MYLINKS_CATEGORIES_MOST_LINKS_FIRST", 3 );
00012 define( "MYLINKS_CATEGORIES_LESS_LINKS_FIRST", 4 );
00013 define( "MYLINKS_CATEGORIES_LAST_UPDATED_FIRST", 5 );
00014 define( "MYLINKS_CATEGORIES_LAST_UPDATED_LAST", 6 );
00015
00021 class MyLinksCategories extends Model
00022 {
00023
00024 function MyLinksCategories()
00025 {
00026 $this->Model();
00027
00028 $this->table = $this->getPrefix()."mylinks_categories";
00029 }
00030
00040 function getMyLinksCategories( $blogId,
00041 $order = MYLINKS_CATEGORIES_NO_ORDER,
00042 $searchTerms = "",
00043 $page = -1,
00044 $itemsPerPage = DEFAULT_ITEMS_PER_PAGE )
00045 {
00046
00047
00048
00049
00050 if( $order == MYLINKS_CATEGORIES_ALPHABETICAL_ORDER )
00051 $order = Array( "name" => "ASC" );
00052 elseif( $order == MYLINKS_CATEGORIES_REVERSE_ALPHABETICAL_ORDER )
00053 $order = Array( "name" => "DESC" );
00054 elseif( $order == MYLINKS_CATEGORIES_MOST_LINKS_FIRST )
00055 $order = Array( "num_links" => "DESC" );
00056 elseif( $order == MYLINKS_CATEGORIES_LESS_LINKS_FIRST )
00057 $order = Array( "num_links" => "ASC" );
00058 elseif( $order == MYLINKS_CATEGORIES_LAST_UPDATED_FIRST )
00059 $order = Array( "last_modification" => "ASC" );
00060 elseif( $order == MYLINKS_CATEGORIES_LAST_UPDATED_LAST )
00061 $order = Array( "last_modification" => "ASC" );
00062 else
00063 $order = Array();
00064
00065 $blogCategories = $this->getMany( "blog_id",
00066 $blogId,
00067 CACHE_MYLINKCATEGORIES_ALL,
00068 Array( CACHE_MYLINKCATEGORIES => "getId" ),
00069 $order,
00070 $searchTerms );
00071
00072 if( !$blogCategories )
00073 $blogCategories = Array();
00074
00075
00076 if( $page > -1 ) {
00077
00078 $start = (($page - 1) * $itemsPerPage );
00079 $blogCategories = array_slice( $blogCategories, $start, $itemsPerPage );
00080 }
00081
00082 return( $blogCategories );
00083 }
00084
00091 function addMyLinksCategory( &$myLinksCategory )
00092 {
00093 if(( $result = $this->add( $myLinksCategory, Array( CACHE_MYLINKCATEGORIES => "getId" )))) {
00094 $this->_cache->removeData( $myLinksCategory->getBlogId(), CACHE_MYLINKCATEGORIES_ALL );
00095 }
00096
00097 return( $result );
00098 }
00099
00107 function deleteMyLinksCategory( $categoryId, $blogId )
00108 {
00109
00110 $category = $this->getMyLinksCategory( $categoryId, $blogId );
00111 if( $category ) {
00112 if( $this->delete( "id", $categoryId )) {
00113 $this->_cache->removeData( $category->getId(), CACHE_MYLINKCATEGORIES );
00114 $this->_cache->removeData( $blogId, CACHE_MYLINKCATEGORIES_ALL );
00115 }
00116 }
00117 else
00118 return false;
00119
00120 return( true );
00121 }
00122
00128 function deleteBlogMyLinksCategories( $blogId )
00129 {
00130 $res = false;
00131 $categories = $this->getMyLinksCategories( $blogId );
00132 if(( $res = $this->delete( "blog_id", $blogId ))) {
00133 $this->_cache->removeData( $blogId, CACHE_MYLINKCATEGORIES_ALL );
00134
00135 foreach( $categories as $category ) {
00136 $this->_cache->removeData( $category->getId(), CACHE_MYLINKCATEGORIES );
00137 }
00138 }
00139
00140 return( $res );
00141 }
00142
00150 function getMyLinksCategory( $categoryId, $blogId = 0 )
00151 {
00152 $myLinksCategory = $this->get( "id", $categoryId, CACHE_MYLINKCATEGORIES );
00153
00154 if( !$myLinksCategory )
00155 return false;
00156
00157 if( $blogId > 0 && $myLinksCategory->getBlogId() != $blogId )
00158 return false;
00159
00160 return $myLinksCategory;
00161 }
00162
00169 function updateMyLinksCategory( $category )
00170 {
00171 if( ($result = $this->update( $category ))) {
00172 $this->_cache->removeData( $category->getId(), CACHE_MYLINKCATEGORIES );
00173 $this->_cache->removeData( $category->getBlogId(), CACHE_MYLINKCATEGORIES_ALL );
00174 }
00175
00176 return( $result );
00177 }
00178
00186 function getNumMyLinksCategories( $blogId, $searchTerms = "" )
00187 {
00188 return( count( $this->getMyLinksCategories( $blogId, MYLINKS_CATEGORIES_NO_ORDER, $searchTerms )));
00189 }
00190
00198 function updateCategoryModificationDate( $categoryId )
00199 {
00200 lt_include( PLOG_CLASS_PATH."class/data/timestamp.class.php" );
00201 $category = $this->getMyLinksCategory( $categoryId );
00202 if( $category ) {
00203 $category->setLastModification( Timestamp::getNowTimestamp());
00204 return( $this->update( $category ));
00205 }
00206 else
00207 return false;
00208 }
00209
00213 function updateLastModification( $categoryId , $lastModification)
00214 {
00215 lt_include( PLOG_CLASS_PATH."class/data/timestamp.class.php" );
00216 $category = $this->getMyLinksCategory( $categoryId );
00217 if( $category ) {
00218 $category->setLastModification( Timestamp::getNowTimestamp());
00219 return( $this->update( $category ));
00220 }
00221 else
00222 return false;
00223 }
00224
00228 function getSearchConditions( $searchTerms )
00229 {
00230 return( "name LIKE '%".$searchTerms."%'" );
00231 }
00232
00236 function mapRow( $row )
00237 {
00238 $myLinksCategory = new MyLinksCategory( $row["name"],
00239 $row["blog_id"],
00240 $row["num_links"],
00241 unserialize($row["properties"]),
00242 $row["id"] );
00243
00244 $myLinksCategory->setLastModification( new Timestamp( $row["last_modification"] ));
00245 $myLinksCategory->setNumLinks( $row["num_links"] );
00246
00247 return $myLinksCategory;
00248 }
00249 }
00250 ?>