articles
[ class tree: articles ] [ index: articles ] [ all elements ]

Source for file BitArticleType.php

Documentation is available at BitArticleType.php

  1. <?php
  2. /**
  3.  * @version $Header$
  4.  * @package articles
  5.  *
  6.  * @copyright Copyright (c) 2004-2006, bitweaver.org
  7.  *  All Rights Reserved. See below for details and a complete list of authors.
  8.  *  Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See http://www.gnu.org/copyleft/lesser.html for details.
  9.  */
  10.  
  11. /**
  12.  * Required setup
  13.  */
  14. require_once (KERNEL_PKG_PATH."BitBase.php");
  15. require_once(ARTICLES_PKG_PATH.'BitArticle.php');
  16.  
  17. /**
  18.  * @package articles
  19.  */
  20. class BitArticleType extends BitBase
  21. {
  22.     public $mTypeId;
  23.  
  24.     public function __construct($iTypeId = NULL)
  25.     {
  26.         $this->mTypeId = NULL;
  27.         parent::__construct();
  28.         if ($iTypeId) {
  29.             $this->loadType($iTypeId);
  30.         }
  31.     }
  32.  
  33.     public function isValid()
  34.     {
  35.         return (@BitBase::verifyId($this->mTypeId));
  36.     }
  37.  
  38.     public function loadType($iTypeId)
  39.     {
  40.         $ret = NULL;
  41.  
  42.         if (!$this->mTypeId) {
  43.             $this->mTypeId = $iTypeId;
  44.         }
  45.  
  46.         if ($this->mTypeId) {
  47.             $sql = "SELECT * FROM `".BIT_DB_PREFIX."article_types` WHERE `article_type_id` = ?";
  48.  
  49.             if( $ret = $this->mDb->getRow( $sql, array( $this->mTypeId ) ) ) {
  50.                 $ret['num_articles'] = $this->mDb->getOne('SELECT COUNT(*) FROM `'.BIT_DB_PREFIX.'articles` WHERE `article_type_id` = ?', array($ret['article_type_id']));
  51.             }
  52.         }
  53.         $this->mInfo = $ret;
  54.  
  55.         return $ret;
  56.     }
  57.  
  58.     public function verify(&$iParamHash)
  59.     {
  60.         $isNewType = FALSE;
  61.  
  62.         // Validate the (optional) topic_id parameter
  63.         if (@BitBase::verifyId($iParamHash['article_type_id'])) {
  64.             $cleanHash['article_type_id'] = (int) $iParamHash['article_type_id'];
  65.         } else {
  66.             $isNewType = TRUE;
  67.             $cleanHash['article_type_id'] = NULL;
  68.         }
  69.  
  70.         if (!$isNewType) {
  71.             $cleanHash['use_ratings']              = (!empty($iParamHash['use_ratings'])              ? ($iParamHash['use_ratings'])              : 'n');
  72.             $cleanHash['show_pre_publ']            = (!empty($iParamHash['show_pre_publ'])            ? ($iParamHash['show_pre_publ'])            : 'n');
  73.             $cleanHash['show_post_expire']         = (!empty($iParamHash['show_post_expire'])         ? ($iParamHash['show_post_expire'])         : 'n');
  74.             $cleanHash['heading_only']             = (!empty($iParamHash['heading_only'])             ? ($iParamHash['heading_only'])             : 'n');
  75.             $cleanHash['allow_comments']           = (!empty($iParamHash['allow_comments'])           ? ($iParamHash['allow_comments'])           : 'n');
  76.             $cleanHash['comment_can_rate_article'] = (!empty($iParamHash['comment_can_rate_article']) ? ($iParamHash['comment_can_rate_article']) : 'n');
  77.             $cleanHash['show_image']               = (!empty($iParamHash['show_image'])               ? ($iParamHash['show_image'])               : 'n');
  78.             $cleanHash['show_avatar']              = (!empty($iParamHash['show_avatar'])              ? ($iParamHash['show_avatar'])              : 'n');
  79.             $cleanHash['show_author']              = (!empty($iParamHash['show_author'])              ? ($iParamHash['show_author'])              : 'n');
  80.             $cleanHash['show_pubdate']             = (!empty($iParamHash['show_pubdate'])             ? ($iParamHash['show_pubdate'])             : 'n');
  81.             $cleanHash['show_expdate']             = (!empty($iParamHash['show_expdate'])             ? ($iParamHash['show_expdate'])             : 'n');
  82.             $cleanHash['show_reads']               = (!empty($iParamHash['show_reads'])               ? ($iParamHash['show_reads'])               : 'n');
  83.             $cleanHash['show_size']                = (!empty($iParamHash['show_size'])                ? ($iParamHash['show_size'])                : 'n');
  84.             $cleanHash['creator_edit']             = (!empty($iParamHash['creator_edit'])             ? ($iParamHash['creator_edit'])             : 'n');
  85.             $cleanHash['type_name']                = (!empty($iParamHash['type_name'])                ? ($iParamHash['type_name'])                : NULL);
  86.         } else {
  87.             // Was an acceptable name given?
  88.             if (empty($iParamHash['type_name']) || ($iParamHash['type_name'] == '')) {
  89.                 $this->mErrors['type_name'] = tra("Invalid or blank article type name supplied");
  90.             } else {
  91.                 $cleanHash['type_name'] = $iParamHash['type_name'];
  92.             }
  93.         }
  94.  
  95.         $iParamHash = $cleanHash;
  96.         return(count($this->mErrors) == 0);
  97.     }
  98.  
  99.     public function storeType(&$iParamHash)
  100.     {
  101.         global $gLibertySystem;
  102.         global $gBitUser;
  103.  
  104.         if ($this->verify($iParamHash)) {
  105.             if (!$iParamHash['article_type_id']) {
  106.                 if (empty($this->mTopicId)) {
  107.                     $typeId = $this->mDb->GenID('article_types_id_seq');
  108.                 } else {
  109.                     $typeId = $this->mTopicId;
  110.                 }
  111.             } else {
  112.                 $typeId = $iParamHash['article_type_id'];
  113.             }
  114.  
  115.             if ($iParamHash['article_type_id']) {
  116.                 $this->mDb->associateUpdate(BIT_DB_PREFIX."article_types", $iParamHash, array( 'article_type_id'=> $iParamHash['article_type_id']));
  117.             } else {
  118.                 $iParamHash['article_type_id'] = $typeId;
  119.                 $this->mDb->associateInsert(BIT_DB_PREFIX."article_types", $iParamHash);
  120.             }
  121.         }
  122.         $this->mTypeId = $iParamHash['article_type_id'];
  123.     }
  124.  
  125.     public function removeType($iTypeId = NULL)
  126.     {
  127.         if (!$iTypeId) {
  128.              if (!$this->mTypeId) {
  129.                 $this->mErrors[] = tra("Invalid type id given");
  130.                 return NULL;
  131.             } else {
  132.                 $iTypeId = $this->mTypeId;
  133.             }
  134.         } else {
  135.             $iTypeId = (int)($iTypeId);
  136.         }
  137.  
  138.         $sql = "DELETE FROM `".BIT_DB_PREFIX."article_types` WHERE `article_type_id` = ?";
  139.         $rs = $this->mDb->query($sql, array($iTypeId));
  140.     }
  141.  
  142.     public static function getTypeList()
  143.     {
  144.         global $gBitSystem;
  145.  
  146.         $query = "SELECT * FROM `" . BIT_DB_PREFIX . "article_types`";
  147.         $result = $gBitSystem->mDb->query( $query, array() );
  148.         $ret = array();
  149.  
  150.         while ( $res = $result->fetchRow() ) {
  151.             $res['article_cnt'] = $gBitSystem->mDb->getOne( "select count(*) from `" . BIT_DB_PREFIX . "articles` where `article_type_id` = ?", array( $res['article_type_id'] ) );
  152.             $ret[] = $res;
  153.         }
  154.  
  155.         return $ret;
  156.     }
  157. }

Documentation generated on Wed, 29 Jul 2015 13:55:39 +0000 by phpDocumentor 1.5.0-lsces