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: /**
  4:  * This file contains the property collection and item class.
  5:  *
  6:  * Custom properties
  7:  * -----------------
  8:  * Custom properties are properties which can be assigned to virtually any element
  9:  * in CONTENIDO and underlaying websites.
 10:  *
 11:  * Table structure
 12:  * ---------------
 13:  *
 14:  * Field       Size         Description
 15:  * -----       ----         -----------
 16:  * idproperty  int(10)      idproperty (automatically handled by this class)
 17:  * idclient    int(10)      Id of client
 18:  * itemtype    varchar(32)  Custom item type (e.g. idcat, idart, idartlang, custom)
 19:  * itemid      varchar(32)  ID of the item
 20:  * type        varchar(32)  Property type
 21:  * name        varchar(32)  Property name value text Property value
 22:  * author      varchar(32)  Author (md5-hash of the username)
 23:  * created     datetime     Created date and time
 24:  * modified    datetime     Modified date and time
 25:  * modifiedby  varchar(32)  Modified by (md5-hash of the username)
 26:  *
 27:  * Example:
 28:  * --------
 29:  * A module needs to store custom properties for categories. Modifying the database
 30:  * would be a bad thing, since the changes might get lost during an upgrade or
 31:  * reinstall. If the custom property for a category would be the path to a category
 32:  * image, we would fill a row as follows:
 33:  *
 34:  * itemtype: idcat
 35:  * itemid:   <number of your category>
 36:  * type:     category
 37:  * name:     image
 38:  * value:    images/category01.gif
 39:  *
 40:  * idproperty, author, created, modified and modifiedby are automatically handled
 41:  * by the class. If caching is enabled, see $cfg['properties']['properties']['enable_cache'],
 42:  * configured entries will be loaded at first time. If enabled, each call of
 43:  * cApiPropertyCollection functions to retrieve cacheable properties will return
 44:  * the cached entries without stressing the database. The cApiPropertyCollection
 45:  * class keeps also track of changed and deleted properties and synchronizes
 46:  * them with cached values, as long as you use the interface of
 47:  * cApiPropertyCollection to manage the properties.
 48:  *
 49:  * @package          Core
 50:  * @subpackage       GenericDB_Model
 51:  * @version          SVN Revision $Rev:$
 52:  *
 53:  * @author           Murat Purc <murat@purc.de>
 54:  * @copyright        four for business AG <www.4fb.de>
 55:  * @license          http://www.contenido.org/license/LIZENZ.txt
 56:  * @link             http://www.4fb.de
 57:  * @link             http://www.contenido.org
 58:  */
 59: 
 60: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 61: 
 62: 
 63: /**
 64:  * Property collection
 65:  *
 66:  * @package Core
 67:  * @subpackage GenericDB_Model
 68:  */
 69: class cApiPropertyCollection extends ItemCollection {
 70: 
 71:     /**
 72:      * Client id
 73:      *
 74:      * @var int
 75:      */
 76:     public $client;
 77: 
 78:     /**
 79:      * List of cached entries
 80:      *
 81:      * @var array
 82:      */
 83:     protected static $_entries;
 84: 
 85:     /**
 86:      * Flag to enable caching.
 87:      *
 88:      * @var bool
 89:      */
 90:     protected static $_enableCache;
 91: 
 92:     /**
 93:      * Itemtypes and itemids array
 94:      *
 95:      * @var array
 96:      */
 97:     protected static $_cacheItemtypes;
 98: 
 99:     /**
100:      * Constructor function
101:      * @param int $idclient  Client id
102:      */
103:     public function __construct($idclient = 0) {
104:         global $cfg, $client, $lang;
105: 
106:         if (0 === $idclient) {
107:             // @todo Make client id parameter mandatory, otherwhise using the global variable
108:             // may lead to unwanted issues!
109:             $idclient = $client;
110:         }
111: 
112:         $this->client = cSecurity::toInteger($idclient);
113:         parent::__construct($cfg['tab']['properties'], 'idproperty');
114:         $this->_setItemClass('cApiProperty');
115: 
116:         // set the join partners so that joins can be used via link() method
117:         $this->_setJoinPartner('cApiClientCollection');
118: 
119:         if (!isset(self::$_enableCache)) {
120:             if (isset($cfg['properties']) && isset($cfg['properties']['properties']) && isset($cfg['properties']['properties']['enable_cache'])) {
121:                 self::$_enableCache = (bool) $cfg['properties']['properties']['enable_cache'];
122: 
123:                 if (isset($cfg['properties']['properties']['itemtypes']) && is_array($cfg['properties']['properties']['itemtypes'])) {
124:                     self::$_cacheItemtypes = $cfg['properties']['properties']['itemtypes'];
125:                     foreach (self::$_cacheItemtypes as $name => $value) {
126:                         if ('%client%' == $value) {
127:                             self::$_cacheItemtypes[$name] = (int) $idclient;
128:                         } elseif ('%lang%' == $value) {
129:                             self::$_cacheItemtypes[$name] = (int) $lang;
130:                         } else {
131:                             unset(self::$_cacheItemtypes[$name]);
132:                         }
133:                     }
134:                 }
135:             } else {
136:                 self::$_enableCache = false;
137:             }
138:         }
139: 
140:         if (self::$_enableCache && !isset(self::$_entries)) {
141:             $this->_loadFromCache();
142:         }
143:     }
144: 
145:     /**
146:      * Resets the states of static properties.
147:      */
148:     public static function reset() {
149:         self::$_enableCache = false;
150:         self::$_entries = array();
151:         self::$_cacheItemtypes = array();
152:     }
153: 
154:     /**
155:      * Creates a new property item.
156:      *
157:      * Example:
158:      * <pre>
159:      * $properties = new cApiPropertyCollection($clientid);
160:      * $property = $properties->create('idcat', 27, 'visual', 'image', 'images/tool.gif');
161:      * </pre>
162:      *
163:      * @param mixed $itemtype Type of the item (example: idcat)
164:      * @param mixed $itemid ID of the item (example: 31)
165:      * @param mixed $type Type of the data to store (arbitary data)
166:      * @param mixed $name Entry name
167:      * @param mixed $value Value
168:      * @param bool $bDontEscape Optionally default false (on internal call do
169:      *        not escape parameters again
170:      *        NOTE: This parameter is deprecated since 2013-11-26
171:      * @return cApiProperty
172:      */
173:     public function create($itemtype, $itemid, $type, $name, $value, $bDontEscape = false) {
174:         global $auth;
175: 
176:         $item = $this->createNewItem();
177: 
178:         $item->set('idclient', $this->client);
179:         $item->set('itemtype', $itemtype, false);
180:         $item->set('itemid', $itemid, false);
181:         $item->set('type', $type);
182:         $item->set('name', $name);
183:         $item->set('value', $value);
184: 
185:         $item->set('created', date('Y-m-d H:i:s'), false);
186:         $item->set('author', $auth->auth['uid']);
187:         $item->store();
188: 
189:         if ($this->_useCache($itemtype, $itemid)) {
190:             $this->_addToCache($item);
191:         }
192: 
193:         return $item;
194:     }
195: 
196:     /**
197:      * Returns the value for a given item.
198:      *
199:      * Example:
200:      * <pre>
201:      * $properties = new cApiPropertyCollection($clientid);
202:      * $value = $properties->getValue('idcat', 27, 'visual', 'image');
203:      * </pre>
204:      *
205:      * @param mixed $itemtype Type of the item (example: idcat)
206:      * @param mixed $itemid ID of the item (example: 31)
207:      * @param mixed $type Type of the data to store (arbitary data)
208:      * @param mixed $name Entry name
209:      * @param mixed $default to be returned if no item was found
210:      * @return mixed Value
211:      */
212:     public function getValue($itemtype, $itemid, $type, $name, $default = false) {
213:         if ($this->_useCache($itemtype, $itemid)) {
214:             return $this->_getValueFromCache($itemtype, $itemid, $type, $name, $default);
215:         }
216: 
217:         if (isset($this->client)) {
218:             $sql = $this->db->prepare("idclient = %d AND itemtype = '%s' AND itemid = '%s' AND type = '%s' AND name = '%s'", $this->client, $itemtype, $itemid, $type, $name);
219:         } else {
220:             // @todo We never get here, since this class will always have a set client property!
221:             $sql = $this->db->prepare("itemtype = '%s' AND itemid = '%s' AND type = '%s' AND name = '%s'", $itemtype, $itemid, $type, $name);
222:         }
223:         $this->select($sql);
224: 
225:         if (false !== $item = $this->next()) {
226:             return cSecurity::unescapeDB($item->get('value'));
227:         }
228: 
229:         return $default;
230:     }
231: 
232:     /**
233:      * Returns the value for a given item.
234:      *
235:      * Example:
236:      * <pre>
237:      * $properties = new cApiPropertyCollection($clientid);
238:      * $values = $properties->getValuesByType('idcat', 27, 'visual');
239:      * </pre>
240:      *
241:      * @param mixed $itemtype Type of the item (example: idcat)
242:      * @param mixed $itemid ID of the item (example: 31)
243:      * @param mixed $type Type of the data to store (arbitary data)
244:      * @return array Value
245:      *
246:      */
247:     public function getValuesByType($itemtype, $itemid, $type) {
248:         if ($this->_useCache($itemtype, $itemid)) {
249:             return $this->_getValuesByTypeFromCache($itemtype, $itemid, $type);
250:         }
251: 
252:         $aResult = array();
253: 
254:         if (isset($this->client)) {
255:             $sql = $this->db->prepare("idclient = %d AND itemtype = '%s' AND itemid = '%s' AND type = '%s'", $this->client, $itemtype, $itemid, $type);
256:         } else {
257:             // @fixme We never get here, since this class will always have a set client property!
258:             $sql = $this->db->prepare("itemtype = '%s' AND itemid = '%s' AND type = '%s'", $itemtype, $itemid, $type);
259:         }
260:         $this->select($sql);
261: 
262:         while (($item = $this->next()) !== false) {
263:             $aResult[$item->get('name')] = cSecurity::unescapeDB($item->get('value'));
264:         }
265: 
266:         return $aResult;
267:     }
268: 
269:     /**
270:      * Returns the values only by type and name.
271:      *
272:      * Example:
273:      * <pre>
274:      * $properties = new cApiPropertyCollection($clientid);
275:      * $values = $properties->getValuesOnlyByTypeName('note', 'category');
276:      * </pre>
277:      *
278:      * @param mixed $itemtype Type of the item (example: idcat)
279:      * @param mixed $name Type of the data to store (arbitary data)
280:      * @return array Value
281:      *
282:      */
283:     public function getValuesOnlyByTypeName($type, $name) {
284:         $aResult = array();
285: 
286:         $sql = $this->db->prepare("type = '%s' AND name = '%s'", $type, $name);
287: 
288:         while (($item = $this->next()) !== false) {
289:             $aResult[] = cSecurity::unescapeDB($item->get('value'));
290:         }
291: 
292:         return $aResult;
293:     }
294: 
295:     /**
296:      * Sets a property item.
297:      * Handles creation and updating.
298:      * Existing item will be updated, not existing item will be created.
299:      *
300:      * Example:
301:      * <pre>
302:      * $properties = new cApiPropertyCollection($clientid);
303:      * $properties->setValue('idcat', 27, 'visual', 'image', 'images/tool.gif');
304:      * </pre>
305:      *
306:      * @param mixed $itemtype Type of the item (example: idcat)
307:      * @param mixed $itemid ID of the item (example: 31)
308:      * @param mixed $type Type of the data to store (arbitary data)
309:      * @param mixed $name Entry name
310:      * @param mixed $value Value
311:      * @param int $idProp Id of database record (if set, update on this basis
312:      *        (possiblity to update name value and type))
313:      */
314:     public function setValue($itemtype, $itemid, $type, $name, $value, $idProp = 0) {
315:         $idProp = (int) $idProp;
316: 
317:         if ($idProp == 0) {
318:             $sql = $this->db->prepare("idclient = %d AND itemtype = '%s' AND itemid = '%s' AND type = '%s' AND name = '%s'", $this->client, $itemtype, $itemid, $type, $name);
319:         } else {
320:             $sql = $this->db->prepare("idclient = %d AND itemtype = '%s' AND itemid = '%s' AND idproperty = %d", $this->client, $itemtype, $itemid, $idProp);
321:         }
322:         $this->select($sql);
323: 
324:         if (($item = $this->next()) !== false) {
325:             $item->set('value', $value);
326:             $item->set('name', $name);
327:             $item->set('type', $type);
328:             $item->store();
329: 
330:             if ($this->_useCache($itemtype, $itemid)) {
331:                 $this->_addToCache($item);
332:             }
333:         } else {
334:             $this->create($itemtype, $itemid, $type, $name, $value, true);
335:         }
336:     }
337: 
338:     /**
339:      * Delete a property item.
340:      *
341:      * Example:
342:      * <pre>
343:      * $properties = new cApiPropertyCollection($clientid);
344:      * $properties->deleteValue('idcat', 27, 'visual', 'image');
345:      * </pre>
346:      *
347:      * @param mixed $itemtype Type of the item (example: idcat)
348:      * @param mixed $itemid ID of the item (example: 31)
349:      * @param mixed $type Type of the data to store (arbitary data)
350:      * @param mixed $name Entry name
351:      */
352:     public function deleteValue($itemtype, $itemid, $type, $name) {
353:         if (isset($this->client)) {
354:             $where = $this->db->prepare("idclient = %d AND itemtype = '%s' AND itemid = '%s' AND type = '%s' AND name = '%s'", $this->client, $itemtype, $itemid, $type, $name);
355:         } else {
356:             // @fixme We never get here, since this class will always have a set client property!
357:             $where = $this->db->prepare("itemtype = '%s' AND itemid = '%s' AND type = '%s' AND name = '%s'", $itemtype, $itemid, $type, $name);
358:         }
359: 
360:         $idproperties = $this->getIdsByWhereClause($where);
361: 
362:         $this->_deleteMultiple($idproperties);
363:         if ($this->_useCache()) {
364:             $this->_deleteFromCacheMultiple($idproperties);
365:         }
366:     }
367: 
368:     /**
369:      * Checks if values for a given item are available.
370:      *
371:      * @param mixed $itemtype Type of the item (example: idcat)
372:      * @param mixed $itemid ID of the item (example: 31)
373:      * @return array For each given item
374:      */
375:     public function getProperties($itemtype, $itemid) {
376:         if ($this->_useCache($itemtype, $itemid)) {
377:             return $this->_getPropertiesFromCache($itemtype, $itemid);
378:         }
379: 
380:         if (isset($this->client)) {
381:             $sql = $this->db->prepare("idclient = %d AND itemtype = '%s' AND itemid = '%s'", $this->client, $itemtype, $itemid);
382:         } else {
383:             // @fixme We never get here, since this class will always have a set client property!
384:             $sql = $this->db->prepare("itemtype = '%s' AND itemid = '%s'", $itemtype, $itemid);
385:         }
386:         $this->select($sql);
387: 
388:         $result[$itemid] = false;
389: 
390:         while (($item = $this->next()) !== false) {
391:             // enable accessing property values per number and field name
392:             $result[$item->get('itemid')][$item->get('idproperty')] = array(
393:                 0 => $item->get('type'),
394:                 'type' => $item->get('type'),
395:                 1 => $item->get('name'),
396:                 'name' => $item->get('name'),
397:                 2 => $item->get('value'),
398:                 'value' => $item->get('value')
399:             );
400:         }
401:         return $result;
402:     }
403: 
404:     /**
405:      * Returns all datasets selected by given field and value combination
406:      *
407:      * @param mixed $field Field to search in
408:      * @param mixed $fieldValue Value to search for
409:      * @param cAuth $auth Narrow result down to user in auth objext
410:      * @return array For each given item
411:      */
412:     public function getAllValues($field, $fieldValue, $auth = NULL) {
413:         $authString = '';
414:         if (!is_null($auth) && sizeof($auth) > 0) {
415:             $authString .= " AND author = '" . $this->db->escape($auth->auth["uid"]) . "'";
416:         }
417: 
418:         $field = $this->db->escape($field);
419:         $fieldValue = $this->db->escape($fieldValue);
420: 
421:         if (isset($this->client)) {
422:             $this->select("idclient = " . (int) $this->client . " AND " . $field . " = '" . $fieldValue . "'" . $authString, '', 'itemid');
423:         } else {
424:             // @fixme We never get here, since this class will always have a set client property!
425:             $this->select($field . " = '" . $fieldValue . "'" . $authString);
426:         }
427: 
428:         $retValue = array();
429:         while (($item = $this->next()) !== false) {
430:             $dbLine = array(
431:                 'idproperty' => $item->get('idproperty'),
432:                 'idclient' => $item->get('idclient'),
433:                 'itemtype' => $item->get('itemtype'),
434:                 'itemid' => $item->get('itemid'),
435:                 'type' => $item->get('type'),
436:                 'name' => $item->get('name'),
437:                 'value' => $item->get('value'),
438:                 'author' => $item->get('author'),
439:                 'created' => $item->get('created'),
440:                 'modified' => $item->get('modified'),
441:                 'modifiedby' => $item->get('modifiedby')
442:             );
443:             $retValue[] = $dbLine;
444:         }
445:         return $retValue;
446:     }
447: 
448:     /**
449:      * Delete all properties which match itemtype and itemid
450:      *
451:      * @param mixed $itemtype Type of the item (example: idcat)
452:      * @param mixed $itemid ID of the item (example: 31)
453:      */
454:     public function deleteProperties($itemtype, $itemid) {
455:         if (isset($this->client)) {
456:             $where = $this->db->prepare("idclient = %d AND itemtype = '%s' AND itemid = '%s'", $this->client, $itemtype, $itemid);
457:         } else {
458:             // @fixme We never get here, since this class will always have a set client property!
459:             $where = $this->db->prepare("itemtype = '%s' AND itemid = '%s'", $itemtype, $itemid);
460:         }
461: 
462:         $idproperties = $this->getIdsByWhereClause($where);
463: 
464:         $this->_deletePropertiesByIds($idproperties);
465:     }
466: 
467:     /**
468:      * Delete all properties which match itemtype and multiple itemids.
469:      *
470:      * @param mixed $itemtype Type of the item (example: idcat)
471:      * @param array $itemids Ids of multiple items (example: array(31,12,22))
472:      */
473:     public function deletePropertiesMultiple($itemtype, array $itemids) {
474:         $itemtype = $this->db->escape($itemtype);
475:         $itemids = array_map(array($this, 'escape'), $itemids);
476:         $in = "'" . implode("', '", $itemids) . "'";
477: 
478:         if (isset($this->client)) {
479:             $where = "idclient = " . (int) $this->client . " AND itemtype = '" . $itemtype . "' AND itemid IN (" . $in . ")";
480:         } else {
481:             // @fixme We never get here, since this class will always have a set client property!
482:             $where = "itemtype = '" . $itemtype . "' AND itemid IN (" . $in . ")";
483:         }
484: 
485:         $idproperties = $this->getIdsByWhereClause($where);
486: 
487:         $this->_deletePropertiesByIds($idproperties);
488:     }
489: 
490:     /**
491:      * Changes the client
492:      *
493:      * @param int $idclient
494:      */
495:     public function changeClient($idclient) {
496:         $this->client = (int) $idclient;
497:     }
498: 
499:     /**
500:      * Loads/Caches configured properties, but only for current client!
501:      * NOTE: It loads properties for global set client, not for the client set
502:      * in this instance!
503:      */
504:     protected function _loadFromCache() {
505:         global $client;
506:         if (!isset(self::$_entries)) {
507:             self::$_entries = array();
508:         }
509: 
510:         $where = array();
511:         foreach (self::$_cacheItemtypes as $itemtype => $itemid) {
512:             if (is_numeric($itemid)) {
513:                 $where[] = "(itemtype = '" . $itemtype . "' AND itemid = " . $itemid . ")";
514:             } else {
515:                 $where[] = "(itemtype = '" . $itemtype . "' AND itemid = '" . $itemid . "')";
516:             }
517:         }
518: 
519:         if (count($where) == 0) {
520:             return;
521:         }
522: 
523:         $where = "idclient = " . (int) $client . ' AND ' . implode(' OR ', $where);
524:         $this->select($where);
525:         while (($property = $this->next()) !== false) {
526:             $this->_addToCache($property);
527:         }
528:     }
529: 
530:     /**
531:      *
532:      * @param string $itemtype
533:      * @param int $itemid
534:      * @return bool
535:      */
536:     protected function _useCache($itemtype = NULL, $itemid = NULL) {
537:         global $client;
538:         $ok = (self::$_enableCache && $this->client == $client);
539:         if (!$ok) {
540:             return $ok;
541:         } elseif ($itemtype == NULL || $itemid == NULL) {
542:             return $ok;
543:         }
544: 
545:         foreach (self::$_cacheItemtypes as $name => $value) {
546:             if ($itemtype == $value['itemtype'] || $itemid == $value['itemid']) {
547:                 return true;
548:             }
549:         }
550:     }
551: 
552:     /**
553:      * Deletes multiple property entries by their ids.
554:      * Deletes them also from internal cache.
555:      *
556:      * @param array $ids
557:      */
558:     protected function _deletePropertiesByIds(array $ids) {
559:         if (count($ids) > 0) {
560:             $this->_deleteMultiple($ids);
561:             if ($this->_useCache()) {
562:                 $this->_deleteFromCacheMultiple($ids);
563:             }
564:         }
565:     }
566: 
567:     /**
568:      * Adds a entry to the cache.
569:      *
570:      * @param cApiUserProperty $entry
571:      */
572:     protected function _addToCache($entry) {
573:         $data = $entry->toArray();
574:         self::$_entries[$data['idproperty']] = $data;
575:     }
576: 
577:     /**
578:      * Removes a entry from cache.
579:      *
580:      * @param int $id
581:      */
582:     protected function _deleteFromCache($id) {
583:         if (isset(self::$_entries[$id])) {
584:             unset(self::$_entries[$id]);
585:         }
586:     }
587: 
588:     /**
589:      * Removes multiple entries from cache.
590:      *
591:      * @param array $ids
592:      */
593:     protected function _deleteFromCacheMultiple(array $ids) {
594:         foreach ($ids as $id) {
595:             if (isset(self::$_entries[$id])) {
596:                 unset(self::$_entries[$id]);
597:             }
598:         }
599:     }
600: 
601:     /**
602:      * Returns the value for a given item from cache.
603:      *
604:      * @param mixed $itemtype Type of the item (example: idcat)
605:      * @param mixed $itemid ID of the item (example: 31)
606:      * @param mixed $type Type of the data to store (arbitary data)
607:      * @param mixed $name Entry name
608:      * @param mixed $default to be returned if no item was found
609:      * @return mixed Value
610:      */
611:     protected function _getValueFromCache($itemtype, $itemid, $type, $name, $default = false) {
612:         foreach (self::$_entries as $id => $entry) {
613:             if ($entry['itemtype'] == $itemtype && $entry['itemid'] == $itemid && $entry['type'] == $type && $entry['name'] == $name) {
614:                 return cSecurity::unescapeDB($entry['value']);
615:             }
616:         }
617: 
618:         return $default;
619:     }
620: 
621:     /**
622:      * Returns the values for a given item by its type from cache.
623:      *
624:      * @param mixed $itemtype Type of the item (example: idcat)
625:      * @param mixed $itemid ID of the item (example: 31)
626:      * @param mixed $type Type of the data to store (arbitary data)
627:      * @return array Value
628:      *
629:      */
630:     protected function _getValuesByTypeFromCache($itemtype, $itemid, $type) {
631:         $result = array();
632: 
633:         foreach (self::$_entries as $id => $entry) {
634:             if ($entry['itemtype'] == $itemtype && $entry['itemid'] == $itemid && $entry['type'] == $type) {
635:                 $result[$entry['name']] = cSecurity::unescapeDB($entry['value']);
636:             }
637:         }
638: 
639:         return $result;
640:     }
641: 
642:     /**
643:      * Returns poperties for given item are available.
644:      *
645:      * @param mixed $itemtype Type of the item (example: idcat)
646:      * @param mixed $itemid ID of the item (example: 31)
647:      * @return array For each given item
648:      */
649:     public function _getPropertiesFromCache($itemtype, $itemid) {
650:         $result = array();
651:         $result[$itemid] = false;
652: 
653:         foreach (self::$_entries as $id => $entry) {
654:             if ($entry['itemtype'] == $itemtype && $entry['itemid'] == $itemid) {
655:                 // enable accessing property values per number and field name
656:                 $result[$entry['itemid']][$entry['idproperty']] = array(
657:                     0 => $entry['type'],
658:                     'type' => $entry['type'],
659:                     1 => $entry['name'],
660:                     'name' => $entry['name'],
661:                     2 => $entry['value'],
662:                     'value' => $entry['value']
663:                 );
664:             }
665:         }
666: 
667:         return $result;
668:     }
669: 
670: }
671: 
672: /**
673:  * Property item
674:  *
675:  * @package Core
676:  * @subpackage GenericDB_Model
677:  */
678: class cApiProperty extends Item {
679: 
680:     /**
681:      * Array which stores the maximum string length of each field
682:      *
683:      * @var array
684:      */
685:     public $maximumLength;
686: 
687:     /**
688:      * Constructor Function
689:      *
690:      * @param mixed $mId Specifies the ID of item to load
691:      */
692:     public function __construct($mId = false) {
693:         global $cfg;
694:         parent::__construct($cfg['tab']['properties'], 'idproperty');
695: 
696:         // Initialize maximum lengths for each column
697:         $this->maximumLength = array(
698:             'itemtype' => 64,
699:             'itemid' => 255,
700:             'type' => 96,
701:             'name' => 96
702:         );
703: 
704:         if ($mId !== false) {
705:             $this->loadByPrimaryKey($mId);
706:         }
707:     }
708: 
709:     /**
710:      * Stores changed cApiProperty
711:      *
712:      * @return bool
713:      */
714:     public function store() {
715:         global $auth;
716: 
717:         $this->set('modified', date('Y-m-d H:i:s'), false);
718:         $this->set('modifiedby', $auth->auth['uid']);
719: 
720:         return parent::store();
721:     }
722: 
723:     /**
724:      * Sets value of a field
725:      *
726:      * @param string $field
727:      * @param string $value
728:      * @param bool $safe Flag to run filter on passed value
729:      * @throws cInvalidArgumentException if the field is too small for the given
730:      *         value
731:      */
732:     public function setField($field, $value, $safe = true) {
733:         if (array_key_exists($field, $this->maximumLength)) {
734:             if (strlen($value) > $this->maximumLength[$field]) {
735:                 throw new cInvalidArgumentException("Tried to set field $field to value $value, but the field is too small. Truncated.");
736:             }
737:         }
738: 
739:         return parent::setField($field, $value, $safe);
740:     }
741: 
742: }
743: 
CMS CONTENIDO 4.9.7 API documentation generated by ApiGen