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