Overview

Packages

  • CONTENIDO
  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentRssCreator
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SearchSolr
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob
  • Smarty
    • Cacher
    • Compiler
    • Config
    • Debug
    • PluginsBlock
    • PluginsFilter
    • PluginsFunction
    • PluginsInternal
    • PluginsModifier
    • PluginsModifierCompiler
    • PluginsShared
    • Security
    • Template
    • TemplateResources
  • Swift
    • ByteStream
    • CharacterStream
    • Encoder
    • Events
    • KeyCache
    • Mailer
    • Mime
    • Plugins
    • Transport

Classes

  • Swift_FailoverTransport
  • Swift_LoadBalancedTransport
  • Swift_MailTransport
  • Swift_Plugins_Loggers_ArrayLogger
  • Swift_Plugins_Loggers_EchoLogger
  • Swift_SendmailTransport
  • Swift_SmtpTransport
  • Swift_Transport_AbstractSmtpTransport
  • Swift_Transport_Esmtp_Auth_CramMd5Authenticator
  • Swift_Transport_Esmtp_Auth_LoginAuthenticator
  • Swift_Transport_Esmtp_Auth_PlainAuthenticator
  • Swift_Transport_Esmtp_AuthHandler
  • Swift_Transport_EsmtpTransport
  • Swift_Transport_FailoverTransport
  • Swift_Transport_LoadBalancedTransport
  • Swift_Transport_MailTransport
  • Swift_Transport_SendmailTransport
  • Swift_Transport_SimpleMailInvoker
  • Swift_Transport_StreamBuffer

Interfaces

  • Swift_Plugins_Logger
  • Swift_Plugins_Pop_Pop3Exception
  • Swift_Transport
  • Swift_Transport_Esmtp_Authenticator
  • Swift_Transport_EsmtpHandler
  • Swift_Transport_IoBuffer
  • Swift_Transport_MailInvoker
  • Swift_Transport_SmtpAgent
  • Swift_TransportException
  • Overview
  • Package
  • Function
  • Todo
  • Download
  1: <?php
  2: /**
  3:  * This file contains the category article collection and item class.
  4:  *
  5:  * @package Core
  6:  * @subpackage GenericDB_Model
  7:  * @version SVN Revision $Rev:$
  8:  *
  9:  * @author Timo Hummel
 10:  * @copyright four for business AG <www.4fb.de>
 11:  * @license http://www.contenido.org/license/LIZENZ.txt
 12:  * @link http://www.4fb.de
 13:  * @link http://www.contenido.org
 14:  */
 15: 
 16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 17: 
 18: /**
 19:  * Category article collection
 20:  *
 21:  * @package Core
 22:  * @subpackage GenericDB_Model
 23:  */
 24: class cApiCategoryArticleCollection extends ItemCollection {
 25: 
 26:     /**
 27:      * Create a new collection of items.
 28:      *
 29:      * @param string $select where clause to use for selection (see
 30:      *            ItemCollection::select())
 31:      */
 32:     public function __construct($select = false) {
 33:         global $cfg;
 34:         parent::__construct($cfg['tab']['cat_art'], 'idcatart');
 35:         $this->_setItemClass('cApiCategoryArticle');
 36: 
 37:         // set the join partners so that joins can be used via link() method
 38:         $this->_setJoinPartner('cApiCategoryCollection');
 39:         $this->_setJoinPartner('cApiArticleCollection');
 40: 
 41:         if ($select !== false) {
 42:             $this->select($select);
 43:         }
 44:     }
 45: 
 46:     /**
 47:      * Creates an article item entry
 48:      *
 49:      * @param int $idcat
 50:      * @param int $idart
 51:      * @param int $status
 52:      * @param string $author
 53:      * @param string $created
 54:      * @param string $lastmodified
 55:      * @param int $createcode
 56:      * @return cApiCategoryArticle
 57:      */
 58:     public function create($idcat, $idart, $status = 0, $author = "", $created = "", $lastmodified = "", $createcode = 1) {
 59:         global $auth;
 60: 
 61:         if (empty($author)) {
 62:             $author = $auth->auth['uname'];
 63:         }
 64:         if (empty($created)) {
 65:             $created = date('Y-m-d H:i:s');
 66:         }
 67:         if (empty($lastmodified)) {
 68:             $lastmodified = date('Y-m-d H:i:s');
 69:         }
 70: 
 71:         $item = $this->createNewItem();
 72: 
 73:         $item->set('idcat', $idcat);
 74:         $item->set('idart', $idart);
 75:         $item->set('status', $status);
 76:         $item->set('author', $author);
 77:         $item->set('created', $created);
 78:         $item->set('lastmodified', $lastmodified);
 79:         $item->set('createcode', $createcode);
 80: 
 81:         $item->store();
 82:         return $item;
 83:     }
 84: 
 85:     /**
 86:      * Returns the first category article available entry from category tree by
 87:      * client id and language id.
 88:      * Build a complex query trough several tables to get a ordered tree
 89:      * structure
 90:      * and returns first available category article item.
 91:      *
 92:      * @param int $client
 93:      * @param int $lang
 94:      * @return cApiCategoryArticle NULL
 95:      */
 96:     public function fetchFirstFromTreeByClientIdAndLangId($client, $lang) {
 97:         global $cfg;
 98: 
 99:         $sql = "SELECT A.* FROM `:cat_art` AS A, `:cat_tree` AS B, `:cat` AS C, `:cat_lang` AS D, `:art_lang` AS E " . "WHERE A.idcat = B.idcat AND B.idcat = C.idcat AND D.startidartlang = E.idartlang AND D.idlang = :lang AND E.idart = A.idart AND E.idlang = :lang AND idclient = :client " . "ORDER BY idtree ASC LIMIT 1";
100: 
101:         $params = array(
102:             'cat_art' => $this->table,
103:             'cat_tree' => $cfg['tab']['cat_tree'],
104:             'cat' => $cfg['tab']['cat'],
105:             'cat_lang' => $cfg['tab']['cat_lang'],
106:             'art_lang' => $cfg['tab']['art_lang'],
107:             'lang' => (int) $lang,
108:             'client' => (int) $client
109:         );
110: 
111:         $sql = $this->db->prepare($sql, $params);
112:         $this->db->query($sql);
113:         if ($this->db->nextRecord()) {
114:             $oItem = new cApiCategoryArticle();
115:             $oItem->loadByRecordSet($this->db->toArray());
116:             return $oItem;
117:         }
118:         return NULL;
119:     }
120: 
121:     /**
122:      * Returns a category article entry by category id and article id.
123:      *
124:      * @param int $idcat
125:      * @param int $idart
126:      * @return cApiCategoryArticle NULL
127:      */
128:     public function fetchByCategoryIdAndArticleId($idcat, $idart) {
129:         $aProps = array(
130:             'idcat' => $idcat,
131:             'idart' => $idart
132:         );
133:         $aRecordSet = $this->_oCache->getItemByProperties($aProps);
134:         if ($aRecordSet) {
135:             // entry in cache found, load entry from cache
136:             $oItem = new cApiCategoryArticle();
137:             $oItem->loadByRecordSet($aRecordSet);
138:             return $oItem;
139:         } else {
140:             $this->select('idcat = ' . (int) $idcat . ' AND idart = ' . (int) $idart);
141:             return $this->next();
142:         }
143:     }
144: 
145:     /**
146:      * Returns a category article id by category id and article id.
147:      *
148:      * @param int $idcat
149:      * @param int $idart
150:      * @return int NULL
151:      */
152:     public function getIdByCategoryIdAndArticleId($idcat, $idart) {
153:         $where = "idcat = %d AND idart = %d";
154:         $where = $this->db->prepare("idcat = %d AND idart = %d", $idcat, $idart);
155:         $aIds = $this->getIdsByWhereClause($where);
156:         return (count($aIds) > 0) ? $aIds[0] : NULL;
157:     }
158: 
159:     /**
160:      * Returns all category article ids by client id.
161:      *
162:      * @param int $idclient
163:      * @return array
164:      */
165:     public function getAllIdsByClientId($idclient) {
166:         global $cfg;
167: 
168:         $aIds = array();
169: 
170:         $sql = "SELECT A.idcatart FROM `%s` as A, `%s` as B WHERE B.idclient = %d AND B.idcat = A.idcat";
171:         $this->db->query($sql, $this->table, $cfg['tab']['cat'], $idclient);
172:         while ($this->db->nextRecord()) {
173:             $aIds[] = $this->db->f('idcatart');
174:         }
175: 
176:         return $aIds;
177:     }
178: 
179:     /**
180:      * Returns all available category ids of entries having a secific article id
181:      *
182:      * @param int $idart
183:      * @return array
184:      */
185:     public function getCategoryIdsByArticleId($idart) {
186:         $aIdCats = array();
187: 
188:         $sql = "SELECT idcat FROM `:cat_art` WHERE idart=:idart";
189:         $sql = $this->db->prepare($sql, array(
190:             'cat_art' => $this->table,
191:             'idart' => (int) $idart
192:         ));
193:         $this->db->query($sql);
194: 
195:         while ($this->db->nextRecord()) {
196:             $aIdCats[] = $this->db->f('idcat');
197:         }
198: 
199:         return $aIdCats;
200:     }
201: 
202:     /**
203:      * Checks, if passed category contains any articles in specified language.
204:      *
205:      * @param int $idcat Category id
206:      * @param int $idlang Language id
207:      * @return bool
208:      */
209:     public function getHasArticles($idcat, $idlang) {
210:         global $cfg;
211: 
212:         $sql = "SELECT b.idartlang AS idartlang FROM `:cat_art` AS a, `:art_lang` AS b " . "WHERE a.idcat = :idcat AND a.idart = b.idart AND b.idlang = :idlang";
213:         $sql = $this->db->prepare($sql, array(
214:             'cat_art' => $this->table,
215:             'art_lang' => $cfg['tab']['art_lang'],
216:             'idcat' => $idcat,
217:             'idlang' => $idlang
218:         ));
219:         $this->db->query($sql);
220: 
221:         return ($this->db->nextRecord()) ? true : false;
222:     }
223: 
224:     /**
225:      * Sets 'createcode' flag for one or more category articles.
226:      *
227:      * @param int|array $idcatart One category article id or list of category
228:      *        article ids
229:      * @param int $createcode Create code state, either 1 or 0.
230:      * @return int Number of updated entries
231:      */
232:     public function setCreateCodeFlag($idcatart, $createcode = 1) {
233:         $createcode = ($createcode == 1) ? 1 : 0;
234:         if (is_array($idcatart)) {
235:             // Multiple ids
236:             if (count($idcatart) == 0) {
237:                 return;
238:             }
239:             foreach ($idcatart as $pos => $id) {
240:                 $idcatart[$pos] = (int) $id;
241:             }
242:             $inSql = implode(', ', $idcatart);
243:             $sql = "UPDATE `%s` SET createcode = %d WHERE idcatart IN (" . $inSql . ")";
244:             $sql = $this->db->prepare($sql, $this->table, $createcode);
245:         } else {
246:             // Single id
247:             $sql = "UPDATE `%s` SET createcode = %d WHERE idcatart = %d";
248:             $sql = $this->db->prepare($sql, $this->table, $createcode, $idcatart);
249:         }
250:         $this->db->query($sql);
251:         return $this->db->affectedRows();
252:     }
253: }
254: 
255: /**
256:  * Category article item
257:  *
258:  * @package Core
259:  * @subpackage GenericDB_Model
260:  */
261: class cApiCategoryArticle extends Item {
262: 
263:     /**
264:      * Constructor Function
265:      *
266:      * @param mixed $mId Specifies the ID of item to load
267:      */
268:     public function __construct($mId = false) {
269:         global $cfg;
270:         parent::__construct($cfg['tab']['cat_art'], 'idcatart');
271:         $this->setFilters(array(), array());
272:         if ($mId !== false) {
273:             $this->loadByPrimaryKey($mId);
274:         }
275:     }
276: 
277:     /**
278:      * Userdefined setter for category article fields.
279:      *
280:      * @param string $name
281:      * @param mixed $value
282:      * @param bool $bSafe Flag to run defined inFilter on passed value
283:      */
284:     public function setField($name, $value, $bSafe = true) {
285:         switch ($name) {
286:             case 'idcat':
287:                 $value = cSecurity::toInteger($value);
288:                 break;
289:             case 'idart':
290:                 $value = cSecurity::toInteger($value);
291:                 break;
292:             case 'status':
293:                 $value = cSecurity::toInteger($value);
294:                 break;
295:             case 'createcode':
296:                 $value = ($value == 1) ? 1 : 0;
297:                 break;
298:         }
299: 
300:         return parent::setField($name, $value, $bSafe);
301:     }
302: 
303: }
304: 
CMS CONTENIDO 4.9.7 API documentation generated by ApiGen