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
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • PHP
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob

Classes

  • cApiAction
  • cApiActionCollection
  • cApiActionlog
  • cApiActionlogCollection
  • cApiArea
  • cApiAreaCollection
  • cApiArticle
  • cApiArticleCollection
  • cApiArticleLanguage
  • cApiArticleLanguageCollection
  • cApiArticleLanguageVersion
  • cApiArticleLanguageVersionCollection
  • cApiArticleSpecification
  • cApiArticleSpecificationCollection
  • cApiCategory
  • cApiCategoryArticle
  • cApiCategoryArticleCollection
  • cApiCategoryCollection
  • cApiCategoryLanguage
  • cApiCategoryLanguageCollection
  • cApiCategoryTree
  • cApiCategoryTreeCollection
  • cApiClient
  • cApiClientCollection
  • cApiClientLanguage
  • cApiClientLanguageCollection
  • cApiCommunication
  • cApiCommunicationCollection
  • cApiContainer
  • cApiContainerCollection
  • cApiContainerConfiguration
  • cApiContainerConfigurationCollection
  • cApiContent
  • cApiContentCollection
  • cApiContentVersion
  • cApiContentVersionCollection
  • cApiDbfs
  • cApiDbfsCollection
  • cApiFile
  • cApiFileCollection
  • cApiFileInformation
  • cApiFileInformationCollection
  • cApiFrameFile
  • cApiFrameFileCollection
  • cApiFrontendGroup
  • cApiFrontendGroupCollection
  • cApiFrontendGroupMember
  • cApiFrontendGroupMemberCollection
  • cApiFrontendPermission
  • cApiFrontendPermissionCollection
  • cApiFrontendUser
  • cApiFrontendUserCollection
  • cApiGroup
  • cApiGroupCollection
  • cApiGroupMember
  • cApiGroupMemberCollection
  • cApiGroupProperty
  • cApiGroupPropertyCollection
  • cApiInUse
  • cApiInUseCollection
  • cApiIso3166
  • cApiIso3166Collection
  • cApiIso6392
  • cApiIso6392Collection
  • cApiKeyword
  • cApiKeywordCollection
  • cApiLanguage
  • cApiLanguageCollection
  • cApiLayout
  • cApiLayoutCollection
  • cApiMailLog
  • cApiMailLogCollection
  • cApiMailLogSuccess
  • cApiMailLogSuccessCollection
  • cApiMetaTag
  • cApiMetaTagCollection
  • cApiMetaTagVersion
  • cApiMetaTagVersionCollection
  • cApiMetaType
  • cApiMetaTypeCollection
  • cApiModule
  • cApiModuleCollection
  • cApiNavMain
  • cApiNavMainCollection
  • cApiNavSub
  • cApiNavSubCollection
  • cApiOnlineUser
  • cApiOnlineUserCollection
  • cApiPathresolveCache
  • cApiPathresolveCacheCollection
  • cApiProperty
  • cApiPropertyCollection
  • cApiRight
  • cApiRightCollection
  • cApiSearchTracking
  • cApiSearchTrackingCollection
  • cApiStat
  • cApiStatCollection
  • cApiSystemProperty
  • cApiSystemPropertyCollection
  • cApiTemplate
  • cApiTemplateCollection
  • cApiTemplateConfiguration
  • cApiTemplateConfigurationCollection
  • cApiType
  • cApiTypeCollection
  • cApiUpload
  • cApiUploadCollection
  • cApiUploadMeta
  • cApiUploadMetaCollection
  • cApiUser
  • cApiUserCollection
  • cApiUserPasswordRequest
  • cApiUserPasswordRequestCollection
  • cApiUserProperty
  • cApiUserPropertyCollection
  • NoteCollection
  • NoteItem
  • TODOCollection
  • TODOItem
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: 
  3: /**
  4:  * This file contains the system property collection and item class.
  5:  *
  6:  * @package          Core
  7:  * @subpackage       GenericDB_Model
  8:  * @author           Murat Purc <murat@purc.de>
  9:  * @copyright        four for business AG <www.4fb.de>
 10:  * @license          http://www.contenido.org/license/LIZENZ.txt
 11:  * @link             http://www.4fb.de
 12:  * @link             http://www.contenido.org
 13:  */
 14: 
 15: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 16: 
 17: /**
 18:  * System property collection
 19:  *
 20:  * The cApiSystemPropertyCollection class keeps also track of changed and
 21:  * deleted
 22:  * properties and synchronizes them with cached values, as long as you use the
 23:  * interface of cApiSystemPropertyCollection to manage the properties.
 24:  *
 25:  * @package Core
 26:  * @subpackage GenericDB_Model
 27:  */
 28: class cApiSystemPropertyCollection extends ItemCollection {
 29: 
 30:     /**
 31:      * List of cached entries
 32:      *
 33:      * @var array
 34:      */
 35:     protected static $_entries;
 36: 
 37:     /**
 38:      * Flag to enable caching.
 39:      *
 40:      * @var bool
 41:      */
 42:     protected static $_enableCache;
 43: 
 44:     /**
 45:      * Constructor to create an instance of this class.
 46:      *
 47:      * @throws cDbException
 48:      * @throws cException
 49:      * @throws cInvalidArgumentException
 50:      */
 51:     public function __construct() {
 52:         global $cfg;
 53:         parent::__construct($cfg['tab']['system_prop'], 'idsystemprop');
 54:         $this->_setItemClass('cApiSystemProperty');
 55: 
 56:         if (!isset(self::$_enableCache)) {
 57:             if (isset($cfg['properties']) && isset($cfg['properties']['system_prop']) && isset($cfg['properties']['system_prop']['enable_cache'])) {
 58:                 self::$_enableCache = (bool) $cfg['properties']['system_prop']['enable_cache'];
 59:             } else {
 60:                 self::$_enableCache = false;
 61:             }
 62:         }
 63: 
 64:         if (self::$_enableCache && !isset(self::$_entries)) {
 65:             $this->_loadFromCache();
 66:         }
 67:     }
 68: 
 69:     /**
 70:      * Resets the states of static properties.
 71:      */
 72:     public static function reset() {
 73:         self::$_enableCache = null;
 74:         self::$_entries = null;
 75:     }
 76: 
 77:     /**
 78:      * Updatess a existing system property entry by it's id.
 79:      *
 80:      * @param string $type
 81:      * @param string $name
 82:      * @param string $value
 83:      * @param int    $id
 84:      *
 85:      * @return cApiSystemProperty|NULL
 86:      * @throws cDbException
 87:      * @throws cException
 88:      * @throws cInvalidArgumentException
 89:      */
 90:     public function setTypeNameValueById($type, $name, $value, $id) {
 91:         $item = $this->fetchById($id);
 92:         if (!$item) {
 93:             return NULL;
 94:         }
 95: 
 96:         $item->set('type', $type);
 97:         $item->set('name', $name);
 98:         $item->set('value', $value);
 99:         $item->store();
100: 
101:         if (self::$_enableCache) {
102:             $this->_addToCache($item);
103:         }
104: 
105:         return $item;
106:     }
107: 
108:     /**
109:      * Updatess a existing system property entry or creates it.
110:      *
111:      * @param string $type
112:      * @param string $name
113:      * @param string $value
114:      * 
115:      * @return cApiSystemProperty
116:      * 
117:      * @throws cDbException
118:      * @throws cException
119:      * @throws cInvalidArgumentException
120:      */
121:     public function setValueByTypeName($type, $name, $value) {
122:         $item = $this->fetchByTypeName($type, $name);
123:         if ($item) {
124:             $item->set('value', $value);
125:             $item->store();
126:         } else {
127:             $item = $this->create($type, $name, $value);
128:         }
129: 
130:         if (self::$_enableCache) {
131:             $this->_addToCache($item);
132:         }
133: 
134:         return $item;
135:     }
136: 
137:     /**
138:      * Creates a system property entry.
139:      *
140:      * @param string $type
141:      * @param string $name
142:      * @param string $value
143:      * @return cApiSystemProperty
144:      * @throws cDbException
145:      * @throws cException
146:      * @throws cInvalidArgumentException
147:      */
148:     public function create($type, $name, $value) {
149:         $item = $this->createNewItem();
150: 
151:         $item->set('type', $type);
152:         $item->set('name', $name);
153:         $item->set('value', $value);
154:         $item->store();
155: 
156:         if (self::$_enableCache) {
157:             $this->_addToCache($item);
158:         }
159: 
160:         return $item;
161:     }
162: 
163:     /**
164:      * Returns all system properties.
165:      *
166:      * @param string $orderBy [optional]
167:      *                        Order by clause like "value ASC"
168:      * @return array
169:      * @throws cDbException
170:      * @throws cException
171:      */
172:     public function fetchAll($orderBy = '') {
173:         if (self::$_enableCache) {
174:             // no order for cached results
175:             return $this->_fetchAllFromCache();
176:         }
177: 
178:         $this->select('', '', $this->escape($orderBy));
179:         $props = array();
180:         while (($property = $this->next()) !== false) {
181:             $props[] = clone $property;
182:         }
183:         return $props;
184:     }
185: 
186:     /**
187:      * Returns system property by it's id.
188:      *
189:      * @param int $id
190:      * @return cApiSystemProperty NULL
191:      * @throws cException
192:      */
193:     public function fetchById($id) {
194:         if (self::$_enableCache) {
195:             return $this->_fetchByIdFromCache($id);
196:         }
197: 
198:         $item = parent::fetchById($id);
199:         return ($item && $item->isLoaded()) ? $item : NULL;
200:     }
201: 
202:     /**
203:      * Returns all system properties by type and name.
204:      *
205:      * @param string $type
206:      * @param string $name
207:      *
208:      * @return cApiSystemProperty NULL
209:      *
210:      * @throws cDbException
211:      * @throws cException
212:      */
213:     public function fetchByTypeName($type, $name) {
214:         if (self::$_enableCache) {
215:             return $this->_fetchByTypeNameFromCache($type, $name);
216:         }
217: 
218:         $sql = $this->db->prepare("type = '%s' AND name = '%s'", $type, $name);
219:         $this->select($sql);
220:         if (($property = $this->next()) !== false) {
221:             return $property;
222:         }
223:         return NULL;
224:     }
225: 
226:     /**
227:      * Returns all system properties by type.
228:      *
229:      * @param string $type
230:      *
231:      * @return array
232:      * 
233:      * @throws cDbException
234:      * @throws cException
235:      */
236:     public function fetchByType($type) {
237:         if (self::$_enableCache) {
238:             return $this->_fetchByTypeFromCache($type);
239:         }
240: 
241:         $sql = $this->db->prepare("type = '%s'", $type);
242:         $this->select($sql);
243:         $props = array();
244:         while (($property = $this->next()) !== false) {
245:             $props[] = clone $property;
246:         }
247:         return $props;
248:     }
249: 
250:     /**
251:      * Deletes system property by type and name.
252:      *
253:      * @param string $type
254:      * @param string $name
255:      *
256:      * @return bool
257:      * 
258:      * @throws cDbException
259:      * @throws cException
260:      * @throws cInvalidArgumentException
261:      */
262:     public function deleteByTypeName($type, $name) {
263:         $sql = $this->db->prepare("type = '%s' AND name = '%s'", $type, $name);
264:         $this->select($sql);
265:         return $this->_deleteSelected();
266:     }
267: 
268:     /**
269:      * Deletes system properties by type.
270:      *
271:      * @param string $type
272:      *
273:      * @return bool
274:      * 
275:      * @throws cDbException
276:      * @throws cException
277:      * @throws cInvalidArgumentException
278:      */
279:     public function deleteByType($type) {
280:         $sql = $this->db->prepare("type = '%s'", $type);
281:         $this->select($sql);
282:         return $this->_deleteSelected();
283:     }
284: 
285:     /**
286:      * Deletes selected system properties.
287:      *
288:      * @return bool
289:      * 
290:      * @throws cDbException
291:      * @throws cException
292:      * @throws cInvalidArgumentException
293:      */
294:     protected function _deleteSelected() {
295:         $result = false;
296:         while (($system = $this->next()) !== false) {
297:             $id = $system->get('idsystemprop');
298:             if (self::$_enableCache) {
299:                 $this->_deleteFromCache($id);
300:             }
301:             $result = $this->delete($id);
302:         }
303:         return $result;
304:     }
305: 
306:     /**
307:      * Loads/Caches all system properties.
308:      *
309:      * @throws cDbException
310:      * @throws cException
311:      */
312:     protected function _loadFromCache() {
313:         self::$_entries = array();
314:         $this->select();
315:         while (($property = $this->next()) !== false) {
316:             $data = $property->toArray();
317:             self::$_entries[$data['idsystemprop']] = $data;
318:         }
319:     }
320: 
321:     /**
322:      * Adds a entry to the cache.
323:      *
324:      * @param cApiSystemProperty $entry
325:      */
326:     protected function _addToCache($entry) {
327:         $data = $entry->toArray();
328:         self::$_entries[$data['idsystemprop']] = $data;
329:     }
330: 
331:     /**
332:      * Fetches all entries from cache.
333:      *
334:      * @return array
335:      */
336:     protected function _fetchAllFromCache() {
337:         $props = array();
338:         $obj = new cApiSystemProperty();
339:         foreach (self::$_entries as $entry) {
340:             $obj->loadByRecordSet($entry);
341:             $props[] = clone $obj;
342:         }
343:         return $props;
344:     }
345: 
346:     /**
347:      * Fetches entry by id from cache.
348:      *
349:      * @param int $id
350:      * @return cApiSystemProperty|NULL
351:      */
352:     protected function _fetchByIdFromCache($id) {
353:         $obj = new cApiSystemProperty();
354:         foreach (self::$_entries as $_id => $entry) {
355:             if ($_id == $id) {
356:                 $obj->loadByRecordSet($entry);
357:                 return $obj;
358:             }
359:         }
360:         return NULL;
361:     }
362: 
363:     /**
364:      * Fetches entry by type and name from cache.
365:      *
366:      * @param string $type
367:      * @param string $name
368:      * @return cApiSystemProperty|NULL
369:      */
370:     protected function _fetchByTypeNameFromCache($type, $name) {
371:         $obj = new cApiSystemProperty();
372:         foreach (self::$_entries as $entry) {
373:             if ($entry['type'] == $type && $entry['name'] == $name) {
374:                 $obj->loadByRecordSet($entry);
375:                 return $obj;
376:             }
377:         }
378:         return NULL;
379:     }
380: 
381:     /**
382:      * Fetches entries by type from cache.
383:      *
384:      * @param string $type
385:      * @return array
386:      */
387:     protected function _fetchByTypeFromCache($type) {
388:         $props = array();
389:         $obj = new cApiSystemProperty();
390:         foreach (self::$_entries as $entry) {
391:             if ($entry['type'] == $type) {
392:                 $obj->loadByRecordSet($entry);
393:                 $props[] = clone $obj;
394:             }
395:         }
396:         return $props;
397:     }
398: 
399:     /**
400:      * Removes a entry from cache.
401:      *
402:      * @param int $id
403:      */
404:     protected function _deleteFromCache($id) {
405:         if (isset(self::$_entries[$id])) {
406:             unset(self::$_entries[$id]);
407:         }
408:     }
409: 
410: }
411: 
412: /**
413:  * System property item
414:  *
415:  * cApiSystemProperty instance contains following class properties:
416:  * - idsystemprop (int)
417:  * - type (string)
418:  * - name (string)
419:  * - value (string)
420:  *
421:  * If caching is enabled, see $cfg['properties']['system_prop']['enable_cache'],
422:  * all entries will be loaded at first time.
423:  * If enabled, each call of cApiSystemPropertyCollection functions to retrieve
424:  * properties
425:  * will return the cached entries without stressing the database.
426:  *
427:  * @package Core
428:  * @subpackage GenericDB_Model
429:  */
430: class cApiSystemProperty extends Item
431: {
432:     /**
433:      * Constructor to create an instance of this class.
434:      *
435:      * @param mixed $mId [optional]
436:      *                   Specifies the ID of item to load
437:      *
438:      * @throws cDbException
439:      * @throws cException
440:      */
441:     public function __construct($mId = false) {
442:         global $cfg;
443:         parent::__construct($cfg['tab']['system_prop'], 'idsystemprop');
444:         $this->setFilters(array(), array());
445:         if ($mId !== false) {
446:             $this->loadByPrimaryKey($mId);
447:         }
448:     }
449: 
450:     /**
451:      * Updates a system property value.
452:      *
453:      * @param string $value
454:      * @return bool
455:      * @throws cDbException
456:      * @throws cInvalidArgumentException
457:      */
458:     public function updateValue($value) {
459:         $this->set('value', $value);
460:         return $this->store();
461:     }
462: 
463: }
464: 
CMS CONTENIDO 4.10.0 API documentation generated by ApiGen 2.8.0