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

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:     public function __construct() {
 48:         global $cfg;
 49:         parent::__construct($cfg['tab']['system_prop'], 'idsystemprop');
 50:         $this->_setItemClass('cApiSystemProperty');
 51: 
 52:         if (!isset(self::$_enableCache)) {
 53:             if (isset($cfg['properties']) && isset($cfg['properties']['system_prop']) && isset($cfg['properties']['system_prop']['enable_cache'])) {
 54:                 self::$_enableCache = (bool) $cfg['properties']['system_prop']['enable_cache'];
 55:             } else {
 56:                 self::$_enableCache = false;
 57:             }
 58:         }
 59: 
 60:         if (self::$_enableCache && !isset(self::$_entries)) {
 61:             $this->_loadFromCache();
 62:         }
 63:     }
 64: 
 65:     /**
 66:      * Resets the states of static properties.
 67:      */
 68:     public static function reset() {
 69:         unset(self::$_enableCache, self::$_entries);
 70:     }
 71: 
 72:     /**
 73:      * Updatess a existing system property entry by it's id.
 74:      *
 75:      * @param string $type
 76:      * @param string $name
 77:      * @param string $value
 78:      * @param int $id
 79:      * @return cApiSystemProperty|NULL
 80:      */
 81:     public function setTypeNameValueById($type, $name, $value, $id) {
 82:         $item = $this->fetchById($id);
 83:         if (!$item) {
 84:             return NULL;
 85:         }
 86: 
 87:         $item->set('type', $type);
 88:         $item->set('name', $name);
 89:         $item->set('value', $value);
 90:         $item->store();
 91: 
 92:         if (self::$_enableCache) {
 93:             $this->_addToCache($item);
 94:         }
 95: 
 96:         return $item;
 97:     }
 98: 
 99:     /**
100:      * Updatess a existing system property entry or creates it.
101:      *
102:      * @param string $type
103:      * @param string $name
104:      * @param string $value
105:      * @return cApiSystemProperty
106:      */
107:     public function setValueByTypeName($type, $name, $value) {
108:         $item = $this->fetchByTypeName($type, $name);
109:         if ($item) {
110:             $item->set('value', $value);
111:             $item->store();
112:         } else {
113:             $item = $this->create($type, $name, $value);
114:         }
115: 
116:         if (self::$_enableCache) {
117:             $this->_addToCache($item);
118:         }
119: 
120:         return $item;
121:     }
122: 
123:     /**
124:      * Creates a system property entry.
125:      *
126:      * @param string $type
127:      * @param string $name
128:      * @param string $value
129:      * @return cApiSystemProperty
130:      */
131:     public function create($type, $name, $value) {
132:         $item = $this->createNewItem();
133: 
134:         $item->set('type', $type);
135:         $item->set('name', $name);
136:         $item->set('value', $value);
137:         $item->store();
138: 
139:         if (self::$_enableCache) {
140:             $this->_addToCache($item);
141:         }
142: 
143:         return $item;
144:     }
145: 
146:     /**
147:      * Returns all system properties.
148:      *
149:      * @param string $orderBy [optional]
150:      *         Order by clause like "value ASC"
151:      * @return array
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:         $sql = $this->db->prepare("type = '%s' AND name = '%s'", $type, $name);
195:         $this->select($sql);
196:         if (($property = $this->next()) !== false) {
197:             return $property;
198:         }
199:         return NULL;
200:     }
201: 
202:     /**
203:      * Returns all system properties by type.
204:      *
205:      * @param string $type
206:      * @return array
207:      */
208:     public function fetchByType($type) {
209:         if (self::$_enableCache) {
210:             return $this->_fetchByTypeFromCache($type);
211:         }
212: 
213:         $sql = $this->db->prepare("type = '%s'", $type);
214:         $this->select($sql);
215:         $props = array();
216:         while (($property = $this->next()) !== false) {
217:             $props[] = clone $property;
218:         }
219:         return $props;
220:     }
221: 
222:     /**
223:      * Deletes system property by type and name.
224:      *
225:      * @param string $type
226:      * @param string $name
227:      * @return bool
228:      */
229:     public function deleteByTypeName($type, $name) {
230:         $sql = $this->db->prepare("type = '%s' AND name = '%s'", $type, $name);
231:         $this->select($sql);
232:         return $this->_deleteSelected();
233:     }
234: 
235:     /**
236:      * Deletes system properties by type.
237:      *
238:      * @param string $type
239:      * @return bool
240:      */
241:     public function deleteByType($type) {
242:         $sql = $this->db->prepare("type = '%s'", $type);
243:         $this->select($sql);
244:         return $this->_deleteSelected();
245:     }
246: 
247:     /**
248:      * Deletes selected system properties.
249:      *
250:      * @return bool
251:      */
252:     protected function _deleteSelected() {
253:         $result = false;
254:         while (($system = $this->next()) !== false) {
255:             $id = $system->get('idsystemprop');
256:             if (self::$_enableCache) {
257:                 $this->_deleteFromCache($id);
258:             }
259:             $result = $this->delete($id);
260:         }
261:         return $result;
262:     }
263: 
264:     /**
265:      * Loads/Caches all system properties.
266:      */
267:     protected function _loadFromCache() {
268:         self::$_entries = array();
269:         $this->select();
270:         while (($property = $this->next()) !== false) {
271:             $data = $property->toArray();
272:             self::$_entries[$data['idsystemprop']] = $data;
273:         }
274:     }
275: 
276:     /**
277:      * Adds a entry to the cache.
278:      *
279:      * @param cApiSystemProperty $entry
280:      */
281:     protected function _addToCache($entry) {
282:         $data = $entry->toArray();
283:         self::$_entries[$data['idsystemprop']] = $data;
284:     }
285: 
286:     /**
287:      * Fetches all entries from cache.
288:      *
289:      * @return array
290:      */
291:     protected function _fetchAllFromCache() {
292:         $props = array();
293:         $obj = new cApiSystemProperty();
294:         foreach (self::$_entries as $entry) {
295:             $obj->loadByRecordSet($entry);
296:             $props[] = clone $obj;
297:         }
298:         return $props;
299:     }
300: 
301:     /**
302:      * Fetches entry by id from cache.
303:      *
304:      * @param int $id
305:      * @return cApiSystemProperty|NULL
306:      */
307:     protected function _fetchByIdFromCache($id) {
308:         $obj = new cApiSystemProperty();
309:         foreach (self::$_entries as $_id => $entry) {
310:             if ($_id == $id) {
311:                 $obj->loadByRecordSet($entry);
312:                 return $obj;
313:             }
314:         }
315:         return NULL;
316:     }
317: 
318:     /**
319:      * Fetches entry by type and name from cache.
320:      *
321:      * @param string $type
322:      * @param string $name
323:      * @return cApiSystemProperty|NULL
324:      */
325:     protected function _fetchByTypeNameFromCache($type, $name) {
326:         $obj = new cApiSystemProperty();
327:         foreach (self::$_entries as $entry) {
328:             if ($entry['type'] == $type && $entry['name'] == $name) {
329:                 $obj->loadByRecordSet($entry);
330:                 return $obj;
331:             }
332:         }
333:         return NULL;
334:     }
335: 
336:     /**
337:      * Fetches entries by type from cache.
338:      *
339:      * @param string $type
340:      * @return array
341:      */
342:     protected function _fetchByTypeFromCache($type) {
343:         $props = array();
344:         $obj = new cApiSystemProperty();
345:         foreach (self::$_entries as $entry) {
346:             if ($entry['type'] == $type) {
347:                 $obj->loadByRecordSet($entry);
348:                 $props[] = clone $obj;
349:             }
350:         }
351:         return $props;
352:     }
353: 
354:     /**
355:      * Removes a entry from cache.
356:      *
357:      * @param int $id
358:      */
359:     protected function _deleteFromCache($id) {
360:         if (isset(self::$_entries[$id])) {
361:             unset(self::$_entries[$id]);
362:         }
363:     }
364: 
365: }
366: 
367: /**
368:  * System property item
369:  *
370:  * cApiSystemProperty instance contains following class properties:
371:  * - idsystemprop (int)
372:  * - type (string)
373:  * - name (string)
374:  * - value (string)
375:  *
376:  * If caching is enabled, see $cfg['properties']['system_prop']['enable_cache'],
377:  * all entries will be loaded at first time.
378:  * If enabled, each call of cApiSystemPropertyCollection functions to retrieve
379:  * properties
380:  * will return the cached entries without stressing the database.
381:  *
382:  * @package Core
383:  * @subpackage GenericDB_Model
384:  */
385: class cApiSystemProperty extends Item {
386: 
387:     /**
388:      * Constructor to create an instance of this class.
389:      *
390:      * @param mixed $mId [optional]
391:      *         Specifies the ID of item to load
392:      */
393:     public function __construct($mId = false) {
394:         global $cfg;
395:         parent::__construct($cfg['tab']['system_prop'], 'idsystemprop');
396:         $this->setFilters(array(), array());
397:         if ($mId !== false) {
398:             $this->loadByPrimaryKey($mId);
399:         }
400:     }
401: 
402:     /**
403:      * Updates a system property value.
404:      *
405:      * @param string $value
406:      * @return bool
407:      */
408:     public function updateValue($value) {
409:         $this->set('value', $value);
410:         return $this->store();
411:     }
412: 
413: }
414: 
CMS CONTENIDO 4.9.11 API documentation generated by ApiGen 2.8.0