[ 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/ -> globalarticlecategories.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/globalarticlecategory.class.php" );
   5      lt_include( PLOG_CLASS_PATH."class/dao/daocacheconstants.properties.php" );    
   6      
   7      /**
   8       * \ingroup DAO
   9       *
  10       * Provides an interface for working with GlobalArticleCategory objects
  11       */
  12      class GlobalArticleCategories extends Model
  13      {
  14      
  15  		function GlobalArticleCategories()
  16          {
  17              $this->Model();            
  18              $this->table = $this->getPrefix()."global_articles_categories";
  19          }
  20          
  21          /**
  22           * loads the given blog category
  23           *
  24           * @param id
  25           * @return false if there was an error loading or a BlogCategory object if it was found
  26           */
  27  		function getGlobalArticleCategory( $id )
  28          {
  29              return( $this->get( "id", $id, CACHE_GLOBALCATEGORIES ));
  30          }
  31          
  32          /**
  33           * adds a new global article category
  34           *
  35           * @param category A GlobalArticleCategory object
  36           * @return true if successful or false otherwise. Upon success, $category->getId() will
  37           * return the new id assigned to the object in the db.
  38           */
  39  		function addGlobalArticleCategory( &$category )
  40          {
  41              if( ($result = $this->add( $category, Array( CACHE_GLOBALCATEGORIES => "getId" )))) {
  42                  $this->_cache->removeData( "_all_", CACHE_GLOBALCATEGORIES_ALL );
  43              }
  44                  
  45              return( $result );
  46          }
  47          
  48          /**
  49           * deletes a blog category. Warning: the upper layers must have already made sure that there
  50           * are no blogs that point to this blog categories *before* removing it, or else we could have
  51           * problems with data integrity.         
  52           *
  53           * @param id
  54           * @return True if successful, false otherwise
  55           */
  56  		function deleteGlobalArticleCategory( $id )
  57          {
  58              if( ($result = $this->delete( "id", $id ))) {
  59                  $this->_cache->removeData( $id, CACHE_GLOBALCATEGORIES );
  60                  $this->_cache->removeData( "_all_", CACHE_GLOBALCATEGORIES_ALL );
  61              }
  62              
  63              return( $result );
  64          }
  65          
  66          /**
  67           * update a given global article category
  68           *
  69           * @param category A GlobalArticleCategory object
  70           * @return True if successful or false otherwise
  71           */
  72  		function updateGlobalArticleCategory( $category )
  73          {
  74              if(( $result = $this->update( $category ))) {
  75                  $this->_cache->removeData( $category->getId(), CACHE_GLOBALCATEGORIES );
  76                  $this->_cache->removeData( "_all_", CACHE_GLOBALCATEGORIES_ALL );
  77              }
  78              
  79              return( $result );
  80          }
  81          
  82          /**
  83           * returns the total amount of global article categories in the database
  84           *
  85           * @param searchTerms
  86           * @return an integer
  87           */
  88  		function getNumGlobalArticleCategories( $searchTerms = "" )
  89          {
  90              return( count( $this->getGlobalArticleCategories( $searchTerms )));
  91          }
  92          
  93          /**
  94           * returns all blog categories
  95           *
  96           * @param searchTerms
  97           * @param page
  98           * @param itemsPerPage
  99           * @return An array of BlogCategory objects or false in case of error
 100           */
 101  		function getGlobalArticleCategories( $searchTerms = "", $page = -1, $itemsPerPage = DEFAULT_ITEMS_PER_PAGE )
 102          {
 103              $categories = $this->getAll( "all", 
 104                                           CACHE_GLOBALCATEGORIES_ALL, 
 105                                           Array( CACHE_GLOBALCATEGORIES => "getId" ),
 106                                           Array( "name" => "ASC" ),
 107                                           $searchTerms,
 108                                           $page,
 109                                           $itemsPerPage );
 110                                   
 111              if( !$categories )
 112                  return( Array());
 113                                                                                    
 114              return( $categories );
 115          }
 116          
 117          /**
 118           * returns how many blogs have been categorized under this category
 119           *
 120           * @param categoryId
 121           * @param status
 122           * @return an integer
 123           */
 124  		function getNumArticlesGlobalCategory( $categoryId, $status = ARTICLE_STATUS_ALL )
 125          {
 126              $cond = "a.global_category_id = '".Db::qstr( $categoryId )."'";            
 127              if( $status != BLOG_STATUS_ALL )
 128                  $cond .= " AND status = '".Db::qstr( $status )."'";
 129              
 130              return( $this->getNumItems( $this->getPrefix()."articles", $cond ));
 131                        
 132          }
 133  
 134          /**
 135           * @see Model::getSearchConditions()
 136           */
 137  		function getSearchConditions( $searchTerms ) 
 138          {
 139              return( "name LIKE '%".Db::qstr( $searchTerms )."%' OR description LIKE '%".Db::qstr( $searchTerms )."%'" );
 140          }
 141          
 142          /**
 143           * @private
 144           */
 145  		function mapRow( $row )
 146          {
 147              $category = new GlobalArticleCategory( $row["name"],
 148                                            $row["description"],
 149                                            unserialize($row["properties"]),
 150                                            $row["id"] );
 151              $category->setNumArticles( $row["num_articles"] );
 152              $category->setNumActiveArticles( $row["num_active_articles"] );
 153                  
 154              return( $category );
 155          }
 156      }
 157  ?>


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