Overview

Packages

  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Datatype
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
  • 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

Classes

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