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
    • NavigationMain
    • 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 user 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:  * User property collection
 20:  *
 21:  * @package Core
 22:  * @subpackage GenericDB_Model
 23:  */
 24: class cApiUserPropertyCollection extends ItemCollection {
 25: 
 26:     /**
 27:      * User id (usually the current logged in user)
 28:      *
 29:      * @var string
 30:      */
 31:     protected $_userId = '';
 32: 
 33:     /**
 34:      * List of cached entries
 35:      *
 36:      * @var array
 37:      */
 38:     protected static $_entries;
 39: 
 40:     /**
 41:      * Flag to enable caching.
 42:      *
 43:      * @var bool
 44:      */
 45:     protected static $_enableCache;
 46: 
 47:     /**
 48:      * Constructor
 49:      *
 50:      * @param string $userId
 51:      */
 52:     public function __construct($userId) {
 53:         $cfg = cRegistry::getConfig();
 54:         parent::__construct($cfg['tab']['user_prop'], 'iduserprop');
 55:         $this->_setItemClass('cApiUserProperty');
 56: 
 57:         // set the join partners so that joins can be used via link() method
 58:         $this->_setJoinPartner('cApiUserCollection');
 59: 
 60:         if (!isset(self::$_enableCache)) {
 61:             if (isset($cfg['properties']) && isset($cfg['properties']['user_prop']) && isset($cfg['properties']['user_prop']['enable_cache'])) {
 62:                 self::$_enableCache = (bool) $cfg['properties']['user_prop']['enable_cache'];
 63:             } else {
 64:                 self::$_enableCache = false;
 65:             }
 66:         }
 67: 
 68:         $this->setUserId($userId);
 69:     }
 70: 
 71:     /**
 72:      * Resets the states of static properties.
 73:      */
 74:     public static function reset() {
 75:         unset(self::$_enableCache, self::$_entries);
 76:     }
 77: 
 78:     /**
 79:      * User id setter
 80:      *
 81:      * @param string $userId
 82:      * @throws cInvalidArgumentException If passed user id is empty
 83:      */
 84:     public function setUserId($userId) {
 85:         if (empty($userId)) {
 86:             throw new cInvalidArgumentException("Empty user id");
 87:         }
 88:         $this->_userId = $userId;
 89:         if (self::$_enableCache) {
 90:             $this->_loadFromCache();
 91:         }
 92:     }
 93: 
 94:     /**
 95:      * Updatess a existing user property entry or creates it.
 96:      *
 97:      * @param string $type
 98:      * @param string $name
 99:      * @param string $value
100:      * @param int $idcatlang
101:      * @return cApiUserProperty
102:      */
103:     public function setValueByTypeName($type, $name, $value, $idcatlang = 0) {
104:         $item = $this->fetchByUserIdTypeName($type, $name);
105:         if ($item) {
106:             $item->set('value', $value);
107:             $item->store();
108:         } else {
109:             $item = $this->create($type, $name, $value, $idcatlang);
110:         }
111: 
112:         if (self::$_enableCache) {
113:             $this->_addToCache($item);
114:         }
115: 
116:         return $item;
117:     }
118: 
119:     /**
120:      * Creates a user property entry.
121:      *
122:      * @param string $type
123:      * @param string $name
124:      * @param string $value
125:      * @param int $idcatlang
126:      * @return cApiUserProperty
127:      */
128:     public function create($type, $name, $value, $idcatlang = 0) {
129:         $item = parent::createNewItem();
130: 
131:         $item->set('user_id', $this->_userId);
132:         $item->set('type', $type);
133:         $item->set('name', $name);
134:         $item->set('value', $value);
135:         $item->set('idcatlang', (int) $idcatlang);
136:         $item->store();
137: 
138:         if (self::$_enableCache) {
139:             $this->_addToCache($item);
140:         }
141: 
142:         return $item;
143:     }
144: 
145:     /**
146:      * Returns all user properties by userid.
147:      *
148:      * @return cApiUserProperty[]
149:      */
150:     public function fetchByUserId() {
151:         if (self::$_enableCache) {
152:             return $this->_fetchByUserIdFromCache();
153:         }
154: 
155:         $this->select("user_id = '" . $this->escape($this->_userId) . "'");
156:         $props = array();
157:         while (($property = $this->next()) !== false) {
158:             $props[] = clone $property;
159:         }
160:         return $props;
161:     }
162: 
163:     /**
164:      * Returns all user properties of all users by type and name. NOTE: Enabled
165:      * caching will be skipped in this case!
166:      *
167:      * @param string $type
168:      * @param string $name
169:      * @return cApiUserProperty[]
170:      */
171:     public function fetchByTypeName($type, $name) {
172:         $this->select("type ='" . $this->escape($type) . "' AND name = '" . $this->escape($name) . "'");
173:         $props = array();
174:         while (($property = $this->next()) !== false) {
175:             $props[] = clone $property;
176:         }
177:         return $props;
178:     }
179: 
180:     /**
181:      * Returns all user properties by userid, type and name.
182:      *
183:      * @param string $type
184:      * @param string $name
185:      * @return cApiUserProperty|null
186:      */
187:     public function fetchByUserIdTypeName($type, $name) {
188:         if (self::$_enableCache) {
189:             return $this->_fetchByUserIdTypeNameFromCache($type, $name);
190:         }
191: 
192:         $this->select("user_id = '" . $this->escape($this->_userId) . "' AND type = '" . $this->escape($type) . "' AND name = '" . $this->escape($name) . "'");
193:         if (($property = $this->next()) !== false) {
194:             return $property;
195:         }
196:         return null;
197:     }
198: 
199:     /**
200:      * Returns all user properties by userid and type.
201:      *
202:      * @param string $type
203:      * @return cApiUserProperty[]
204:      */
205:     public function fetchByUserIdType($type) {
206:         if (self::$_enableCache) {
207:             return $this->_fetchByUserIdTypeFromCache($type);
208:         }
209: 
210:         $this->select("user_id = '" . $this->escape($this->_userId) . "' AND type = '" . $this->escape($type) . "'");
211:         $props = array();
212:         while (($property = $this->next()) !== false) {
213:             $props[] = clone $property;
214:         }
215:         return $props;
216:     }
217: 
218:     /**
219:      * Deletes user property by userid, type and name.
220:      *
221:      * @param string $type
222:      * @param string $name
223:      * @return bool
224:      */
225:     public function deleteByUserIdTypeName($type, $name) {
226:         $this->select("user_id = '" . $this->escape($this->_userId) . "' AND type = '" . $this->escape($type) . "' AND name = '" . $this->escape($name) . "'");
227:         return $this->_deleteSelected();
228:     }
229: 
230:     /**
231:      * Deletes user properties by userid and type.
232:      *
233:      * @param string $type
234:      * @return bool
235:      */
236:     public function deleteByUserIdType($type) {
237:         $this->select("user_id = '" . $this->escape($this->_userId) . "' AND type = '" . $this->escape($type) . "'");
238:         return $this->_deleteSelected();
239:     }
240: 
241:     /**
242:      * Deletes all user properties by userid.
243:      *
244:      * @return bool
245:      */
246:     public function deleteByUserId() {
247:         $this->select("user_id = '" . $this->escape($this->_userId) . "'");
248:         return $this->_deleteSelected();
249:     }
250: 
251:     /**
252:      * Deletes selected user properties.
253:      *
254:      * @return bool
255:      */
256:     protected function _deleteSelected() {
257:         $result = false;
258:         while (($prop = $this->next()) !== false) {
259:             $id = $prop->get('iduserprop');
260:             if (self::$_enableCache) {
261:                 $this->_deleteFromCache($id);
262:             }
263:             $result = $this->delete($id);
264:         }
265:         return $result;
266:     }
267: 
268:     /**
269:      * Loads/Caches all user properties.
270:      */
271:     protected function _loadFromCache() {
272:         self::$_entries = array();
273:         $this->select("user_id='" . $this->escape($this->_userId) . "'");
274:         while (($property = $this->next()) !== false) {
275:             $data = $property->toArray();
276:             self::$_entries[$data['iduserprop']] = $data;
277:         }
278:     }
279: 
280:     /**
281:      * Adds a entry to the cache.
282:      *
283:      * @param cApiUserProperty $entry
284:      */
285:     protected function _addToCache($entry) {
286:         $data = $entry->toArray();
287:         self::$_entries[$data['iduserprop']] = $data;
288:     }
289: 
290:     /**
291:      * Fetches all user properties by userid from cache.
292:      *
293:      * @return cApiUserProperty[]
294:      */
295:     protected function _fetchByUserIdFromCache() {
296:         $props = array();
297:         $obj = new cApiUserProperty();
298:         foreach (self::$_entries as $entry) {
299:             $obj->loadByRecordSet($entry);
300:             $props[] = clone $obj;
301:         }
302:         return $props;
303:     }
304: 
305:     /**
306:      * Fetches user properties by userid, type and name from cache.
307:      *
308:      * @param string $type
309:      * @param string $name
310:      * @return cApiUserProperty|null
311:      */
312:     public function _fetchByUserIdTypeNameFromCache($type, $name) {
313:         $props = array();
314:         $obj = new cApiUserProperty();
315:         foreach (self::$_entries as $entry) {
316:             if ($entry['type'] == $type && $entry['name'] == $name) {
317:                 $obj->loadByRecordSet($entry);
318:                 return $obj;
319:             }
320:         }
321:         return null;
322:     }
323: 
324:     /**
325:      * Fetches user properties by userid and type from cache.
326:      *
327:      * @param string $type
328:      * @return cApiUserProperty[]
329:      */
330:     public function _fetchByUserIdTypeFromCache($type) {
331:         $props = array();
332:         $obj = new cApiUserProperty();
333:         foreach (self::$_entries as $entry) {
334:             if ($entry['type'] == $type) {
335:                 $obj->loadByRecordSet($entry);
336:                 $props[] = clone $obj;
337:             }
338:         }
339:         return $props;
340:     }
341: 
342:     /**
343:      * Removes a entry from cache.
344:      *
345:      * @param int $id
346:      */
347:     protected function _deleteFromCache($id) {
348:         if (isset(self::$_entries[$id])) {
349:             unset(self::$_entries[$id]);
350:         }
351:     }
352: 
353: }
354: 
355: /**
356:  * User property item
357:  *
358:  * @package Core
359:  * @subpackage GenericDB_Model
360:  */
361: class cApiUserProperty extends Item {
362: 
363:     /**
364:      * Constructor Function
365:      *
366:      * @param mixed $mId Specifies the ID of item to load
367:      */
368:     public function __construct($mId = false) {
369:         $cfg = cRegistry::getConfig();
370:         parent::__construct($cfg['tab']['user_prop'], 'iduserprop');
371:         $this->setFilters(array(), array());
372:         if ($mId !== false) {
373:             $this->loadByPrimaryKey($mId);
374:         }
375:     }
376: 
377:     /**
378:      * Updates a user property value.
379:      *
380:      * @param string $value
381:      * @return bool
382:      */
383:     public function updateValue($value) {
384:         $this->set('value', $this->escape($value));
385:         return $this->store();
386:     }
387: 
388: }
389: 
CMS CONTENIDO 4.9.0 API documentation generated by ApiGen 2.8.0