[ 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/ -> blogcategories.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/blogcategory.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 BlogCategory objects
  11       */        
  12      class BlogCategories extends Model
  13      {
  14      
  15  		function BlogCategories()
  16          {
  17              $this->Model();            
  18              $this->table = $this->getPrefix()."blog_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 getBlogCategory( $id )
  28          {
  29              return( $this->get( "id", $id, CACHE_BLOGCATEGORIES ));
  30          }
  31          
  32          /**
  33           * adds a new blog category
  34           *
  35           * @param category A BlogCategory 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 addBlogCategory( &$category )
  40          {
  41              if( ($result = $this->add( $category, Array( CACHE_BLOGCATEGORIES => "getId" )))) {
  42                  $this->_cache->removeData( "_all_", CACHE_BLOGCATEGORIES_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 deleteBlogCategory( $id )
  57          {
  58              if( ($result = $this->delete( "id", $id ))) {
  59                  $this->_cache->removeData( $id, CACHE_BLOGCATEGORIES );
  60                  $this->_cache->removeData( "_all_", CACHE_BLOGCATEGORIES_ALL );
  61              }
  62              
  63              return( $result );
  64          }
  65          
  66          /**
  67           * update a given blog category
  68           *
  69           * @param category A BlogCategory object
  70           * @return True if successful or false otherwise
  71           */
  72  		function updateBlogCategory( $category )
  73          {
  74              if( ($result = $this->update( $category ))) {
  75                  $this->_cache->removeData( $category->getId(), CACHE_BLOGCATEGORIES );
  76                  $this->_cache->removeData( "_all_", CACHE_BLOGCATEGORIES_ALL );                
  77              }
  78              
  79              return( $result );
  80          }
  81          
  82          /**
  83           * returns the total amount of blog categories in the database
  84           *
  85           * @return an integer
  86           */
  87  		function getNumBlogCategories( $searchTerms = "" )
  88          {
  89              return( count( $this->getBlogCategories( $searchTerms )));
  90          }
  91          
  92          /**
  93           * returns all blog categories
  94           *
  95           * @param searchTerms         
  96           * @param page
  97           * @param itemsPerPage
  98           * @return An array of BlogCategory objects or false in case of error
  99           */
 100  		function getBlogCategories( $searchTerms = "", $page = -1, $itemsPerPage = DEFAULT_ITEMS_PER_PAGE )
 101          {
 102              $categories = $this->getAll( "all", 
 103                                           CACHE_BLOGCATEGORIES_ALL, 
 104                                           Array( CACHE_BLOGCATEGORIES => "getId" ),
 105                                           Array( "name" => "ASC" ),
 106                                           $searchTerms,
 107                                           $page,
 108                                           $itemsPerPage );
 109                                           
 110              if( !$categories )
 111                  return( Array());
 112                                                                                    
 113              return( $categories );
 114          }
 115          
 116          /**
 117           * returns how many blogs have been categorized under this category
 118           *
 119           * @param categoryId
 120           * @param blogStatus
 121           * @return an integer
 122           */
 123  		function getNumBlogsCategory( $categoryId, $status = BLOG_STATUS_ALL )
 124          {
 125              $cond = "b.blog_category_id = '".Db::qstr( $categoryId )."'";            
 126              if( $status != BLOG_STATUS_ALL )
 127                  $cond .= " AND status = '".Db::qstr( $status )."'";
 128              
 129              return( $this->getNumItems( $this->getPrefix()."blogs", $cond ));
 130                        
 131          }
 132  
 133          /**
 134           * @see Model::getSearchConditions()
 135           */
 136  		function getSearchConditions( $searchTerms )
 137          {
 138              return( "name LIKE '%".Db::qstr( $searchTerms )."%' OR description LIKE '%".Db::qstr( $searchTerms )."%'" );
 139          }
 140          
 141          /**
 142           * @private
 143           */
 144  		function mapRow( $row )
 145          {
 146              $category = new BlogCategory( $row["name"],
 147                                            $row["description"],
 148                                            unserialize($row["properties"]),
 149                                            $row["id"] );
 150              $category->setNumBlogs( $row["num_blogs"] );
 151              $category->setNumActiveBlogs( $row["num_active_blogs"] );
 152                  
 153              return( $category );
 154          }
 155      }
 156  ?>


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