[ Index ]
 

Code source de LifeType 1.2.4

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/class/dao/ -> mylinkscategories.class.php (source)

   1  <?php
   2  
   3      lt_include( PLOG_CLASS_PATH."class/dao/model.class.php" );
   4      lt_include( PLOG_CLASS_PATH."class/dao/mylinkscategory.class.php" );
   5      lt_include( PLOG_CLASS_PATH."class/dao/mylinks.class.php" );
   6      lt_include( PLOG_CLASS_PATH."class/dao/daocacheconstants.properties.php" );    
   7      
   8      define( "MYLINKS_CATEGORIES_NO_ORDER", 0 );
   9      define( "MYLINKS_CATEGORIES_ALPHABETICAL_ORDER", 1 );
  10      define( "MYLINKS_CATEGORIES_REVERSE_ALPHABETICAL_ORDER", 2 );
  11      define( "MYLINKS_CATEGORIES_MOST_LINKS_FIRST", 3 );
  12      define( "MYLINKS_CATEGORIES_LESS_LINKS_FIRST", 4 );
  13      define( "MYLINKS_CATEGORIES_LAST_UPDATED_FIRST", 5 );
  14      define( "MYLINKS_CATEGORIES_LAST_UPDATED_LAST", 6 );
  15      
  16      /**
  17       * \ingroup DAO
  18       *
  19       * Model for retrieving MyLinksCategory objects from the database
  20       */
  21      class MyLinksCategories extends Model 
  22      {
  23      
  24  		function MyLinksCategories()
  25          {
  26              $this->Model();
  27              
  28              $this->table = $this->getPrefix()."mylinks_categories";
  29          }
  30  
  31          /**
  32           * Returns the categories for my_links for a given blog
  33           *
  34           * @param blogId Identifier of the blog.
  35           * @param order
  36           * @param searchTerms
  37           * @param page
  38           * @param itemsPerPage
  39           */
  40          function getMyLinksCategories( $blogId,
  41                                         $order = MYLINKS_CATEGORIES_NO_ORDER, 
  42                                         $searchTerms = "",
  43                                         $page = -1, 
  44                                         $itemsPerPage = DEFAULT_ITEMS_PER_PAGE )
  45          {
  46              /*
  47               * :TODO:
  48               * Implement sorting here!!!
  49               */
  50              if( $order == MYLINKS_CATEGORIES_ALPHABETICAL_ORDER )
  51                  $order = Array( "name" => "ASC" );
  52              elseif( $order == MYLINKS_CATEGORIES_REVERSE_ALPHABETICAL_ORDER )
  53                  $order = Array( "name" => "DESC" );
  54              elseif( $order == MYLINKS_CATEGORIES_MOST_LINKS_FIRST )
  55                  $order = Array( "num_links" => "DESC" );
  56              elseif( $order == MYLINKS_CATEGORIES_LESS_LINKS_FIRST )
  57                  $order = Array( "num_links" => "ASC" );
  58              elseif( $order == MYLINKS_CATEGORIES_LAST_UPDATED_FIRST ) 
  59                  $order = Array( "last_modification" => "ASC" );
  60              elseif( $order == MYLINKS_CATEGORIES_LAST_UPDATED_LAST )
  61                  $order = Array( "last_modification" => "ASC" );
  62              else
  63                  $order = Array();
  64              
  65              $blogCategories = $this->getMany( "blog_id", 
  66                                               $blogId,
  67                                               CACHE_MYLINKCATEGORIES_ALL, 
  68                                               Array( CACHE_MYLINKCATEGORIES => "getId" ),
  69                                               $order,
  70                                               $searchTerms );
  71                                               
  72              if( !$blogCategories )
  73                  $blogCategories = Array();
  74                  
  75              // apply the slicing
  76              if( $page > -1 ) {
  77                  // return only a subset of the items
  78                  $start = (($page - 1) * $itemsPerPage );
  79                  $blogCategories = array_slice( $blogCategories, $start, $itemsPerPage );                
  80              }                        
  81                                               
  82              return( $blogCategories );
  83          }
  84  
  85          /**
  86           * Adds a category to the database of link categories.
  87           *
  88           * @param linkCategory A MyLinkCategory object with the information we need.
  89           * @return Returns true if successful or false otherwise.
  90           */
  91          function addMyLinksCategory( &$myLinksCategory )
  92          {
  93              if(( $result = $this->add( $myLinksCategory, Array( CACHE_MYLINKCATEGORIES => "getId" )))) {
  94                  $this->_cache->removeData( $myLinksCategory->getBlogId(), CACHE_MYLINKCATEGORIES_ALL );
  95              }
  96              
  97              return( $result );
  98          }
  99  
 100          /**
 101           * Removes a link category from the database.
 102           *
 103           * @param categoryId Category identifier.
 104           * @param blogId Blog identifier.
 105           * @return True if successful or false otherwise.
 106           */
 107          function deleteMyLinksCategory( $categoryId, $blogId )
 108          {
 109      
 110              $category = $this->getMyLinksCategory( $categoryId, $blogId );
 111              if( $category ) {
 112                  if( $this->delete( "id", $categoryId )) {
 113                      $this->_cache->removeData( $category->getId(), CACHE_MYLINKCATEGORIES );
 114                      $this->_cache->removeData( $blogId, CACHE_MYLINKCATEGORIES_ALL );
 115                  }
 116              }
 117              else
 118                  return false;
 119  
 120              return( true );
 121          }
 122  
 123          /**
 124           * Removes all the links categories from the given blog
 125           *
 126           * @param blogId The blog identifier
 127           */
 128          function deleteBlogMyLinksCategories( $blogId )
 129          {    
 130              $res = false;
 131              $categories = $this->getMyLinksCategories( $blogId );
 132              if(( $res = $this->delete( "blog_id", $blogId ))) {
 133                  $this->_cache->removeData( $blogId, CACHE_MYLINKCATEGORIES_ALL );    
 134                  // remove all other categories
 135                  foreach( $categories as $category  ) {
 136                      $this->_cache->removeData( $category->getId(), CACHE_MYLINKCATEGORIES );
 137                  }
 138              }
 139              
 140              return( $res );
 141          }        
 142  
 143          /**
 144           * Retrieves a single link category from the database
 145           *
 146           * @param categoryId Category identifier.
 147           * @param blogId Blog identifier.
 148           * @return The MyLinksCategory object containing the information.
 149           */
 150          function getMyLinksCategory( $categoryId, $blogId = 0 )
 151          {
 152              $myLinksCategory = $this->get( "id", $categoryId, CACHE_MYLINKCATEGORIES );
 153  
 154              if( !$myLinksCategory )
 155                  return false;
 156  
 157              if( $blogId > 0 && $myLinksCategory->getBlogId() != $blogId )
 158                  return false;
 159  
 160              return $myLinksCategory;
 161          }
 162  
 163          /**
 164           * Updates a category.
 165           *
 166           * @param category The MyLinkCategory object we're trying to update.
 167           * @return True if successful or false otherwise.
 168           */
 169          function updateMyLinksCategory( $category )
 170          {
 171              if( ($result = $this->update( $category ))) {
 172                  $this->_cache->removeData( $category->getId(), CACHE_MYLINKCATEGORIES );
 173                  $this->_cache->removeData( $category->getBlogId(), CACHE_MYLINKCATEGORIES_ALL );
 174              }
 175              
 176              return( $result );
 177          }
 178  
 179          /**
 180           * returns how many link categories a blog has
 181           *
 182           * @param blogId
 183           * @param searchTerms
 184           * @return an integer
 185           */        
 186  		function getNumMyLinksCategories( $blogId, $searchTerms = "" )
 187          {
 188              return( count( $this->getMyLinksCategories( $blogId, MYLINKS_CATEGORIES_NO_ORDER, $searchTerms )));
 189          }
 190  
 191          /**
 192           * marks a category as updated now, changing the last_modfication field to
 193           * NOW()
 194           *
 195           * @param categoryId the id of the category we're trying to update
 196           * @return true if successful or false otherwise
 197           */
 198  		function updateCategoryModificationDate( $categoryId )
 199          {
 200              lt_include( PLOG_CLASS_PATH."class/data/timestamp.class.php" );
 201              $category = $this->getMyLinksCategory( $categoryId );
 202              if( $category ) {
 203                  $category->setLastModification( Timestamp::getNowTimestamp());
 204                  return( $this->update( $category ));
 205              }
 206              else
 207                  return false;
 208          }
 209  
 210          /**
 211           * update last modification field
 212           */
 213  		function updateLastModification( $categoryId , $lastModification)
 214          {
 215              lt_include( PLOG_CLASS_PATH."class/data/timestamp.class.php" );
 216              $category = $this->getMyLinksCategory( $categoryId );
 217              if( $category ) {
 218                  $category->setLastModification( Timestamp::getNowTimestamp());
 219                  return( $this->update( $category ));
 220              }
 221              else
 222                  return false;
 223          }
 224          
 225          /**
 226           * @see Model::getSearchConditions
 227           */
 228  		function getSearchConditions( $searchTerms ) 
 229          {
 230              return( "name LIKE '%".$searchTerms."%'" );
 231          }
 232          
 233          /**
 234           * @private
 235           */
 236  		function mapRow( $row )
 237          {
 238              $myLinksCategory = new MyLinksCategory( $row["name"],
 239                                                      $row["blog_id"],
 240                                                      $row["num_links"],
 241                                                      unserialize($row["properties"]),
 242                                                      $row["id"] );
 243  
 244              $myLinksCategory->setLastModification( new Timestamp( $row["last_modification"] ));
 245              $myLinksCategory->setNumLinks( $row["num_links"] );
 246  
 247              return $myLinksCategory;
 248          }
 249      }
 250  ?>


Généré le : Mon Nov 26 21:04:15 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics