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 group collection and item class.
  5:  *
  6:  * @package Core
  7:  * @subpackage GenericDB_Model
  8:  * @author Dominik Ziegler
  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:  * Group collection
 19:  *
 20:  * @package Core
 21:  * @subpackage GenericDB_Model
 22:  */
 23: class cApiGroupCollection extends ItemCollection {
 24:     /**
 25:      * Constructor to create an instance of this class.
 26:      *
 27:      * @throws cInvalidArgumentException
 28:      */
 29:     public function __construct() {
 30:         global $cfg;
 31:         parent::__construct($cfg['tab']['groups'], 'group_id');
 32:         $this->_setItemClass('cApiGroup');
 33:     }
 34: 
 35:     /**
 36:      * Creates a group entry.
 37:      *
 38:      * @param string $groupname
 39:      * @param string $perms
 40:      * @param string $description
 41:      *
 42:      * @return cApiGroup|false
 43:      * @throws cDbException
 44:      * @throws cException
 45:      * @throws cInvalidArgumentException
 46:      */
 47:     public function create($groupname, $perms, $description) {
 48:         $primaryKeyValue = md5($groupname . time());
 49: 
 50:         /** @var cApiGroup $item */
 51:         $item = $this->createNewItem($primaryKeyValue);
 52:         if (!is_object($item)) {
 53:             return false;
 54:         }
 55: 
 56:         $groupname = cApiGroup::prefixedGroupName($groupname);
 57: 
 58:         $item->set('groupname', $groupname);
 59:         $item->set('perms', $perms);
 60:         $item->set('description', $description);
 61:         $item->store();
 62: 
 63:         return $item;
 64:     }
 65: 
 66:     /**
 67:      * Returns the groups a user is in
 68:      *
 69:      * @param string $userid
 70:      * @return cApiGroup[]
 71:      *         List of groups
 72:      * @throws cDbException
 73:      * @throws cException
 74:      */
 75:     public function fetchByUserID($userid) {
 76:         global $cfg;
 77: 
 78:         $aIds = array();
 79:         $aGroups = array();
 80: 
 81:         $sql = "SELECT a.group_id FROM `%s` AS a, `%s` AS b " . "WHERE (a.group_id  = b.group_id) AND (b.user_id = '%s')";
 82: 
 83:         $this->db->query($sql, $this->table, $cfg['tab']['groupmembers'], $userid);
 84:         $this->_lastSQL = $sql;
 85: 
 86:         while ($this->db->nextRecord()) {
 87:             $aIds[] = $this->db->f('group_id');
 88:         }
 89: 
 90:         if (0 === count($aIds)) {
 91:             return $aGroups;
 92:         }
 93: 
 94:         $where = "group_id IN ('" . implode("', '", $aIds) . "')";
 95:         $this->select($where);
 96:         while (($oItem = $this->next()) !== false) {
 97:             $aGroups[] = clone $oItem;
 98:         }
 99: 
100:         return $aGroups;
101:     }
102: 
103:     /**
104:      * Removes the specified group from the database.
105:      *
106:      * @param string $groupname
107:      *         Specifies the groupname
108:      *
109:      * @return bool
110:      *         True if the delete was successful
111:      *
112:      * @throws cDbException
113:      * @throws cInvalidArgumentException
114:      */
115:     public function deleteGroupByGroupname($groupname) {
116:         $groupname = cApiGroup::prefixedGroupName($groupname);
117:         $result = $this->deleteBy('groupname', $groupname);
118:         return ($result > 0) ? true : false;
119:     }
120: 
121:     /**
122:      * Returns all groups which are accessible by the current group.
123:      *
124:      * @param array $perms
125:      * @return array Array of group objects*         Array of group objects
126:      * @throws cDbException
127:      * @throws cException
128:      */
129:     public function fetchAccessibleGroups($perms) {
130:         $groups = array();
131:         $limit = array();
132:         $where = '';
133: 
134:         if (!in_array('sysadmin', $perms)) {
135:             // not sysadmin, compose where rules
136:             $oClientColl = new cApiClientCollection();
137:             $allClients = $oClientColl->getAvailableClients();
138:             foreach ($allClients as $key => $value) {
139:                 if (in_array('client[' . $key . ']', $perms) || in_array('admin[' . $key . ']', $perms)) {
140:                     $limit[] = 'perms LIKE "%client[' . $this->escape($key) . ']%"';
141:                 }
142:                 if (in_array('admin[' . $key . ']', $perms)) {
143:                     $limit[] = 'perms LIKE "%admin[' . $this->escape($key) . ']%"';
144:                 }
145:             }
146: 
147:             if (count($limit) > 0) {
148:                 $where = '1 AND ' . implode(' OR ', $limit);
149:             }
150:         }
151: 
152:         $this->select($where);
153:         while (($oItem = $this->next()) !== false) {
154:             $groups[] = clone $oItem;
155:         }
156: 
157:         return $groups;
158:     }
159: 
160:     /**
161:      * Returns all groups which are accessible by the current group.
162:      * Is a wrapper of fetchAccessibleGroups() and returns contrary to that
163:      * function
164:      * a multidimensional array instead of a list of objects.
165:      *
166:      * @param array $perms
167:      *
168:      * @return array
169:      *         Array of user like
170:      *         $arr[user_id][groupname],
171:      *         $arr[user_id][description]
172:      *         Note: Value of $arr[user_id][groupname] is cleaned from prefix
173:      *         "grp_"
174:      * @throws cDbException
175:      * @throws cException
176:      */
177:     public function getAccessibleGroups($perms) {
178:         $groups = array();
179:         $oGroups = $this->fetchAccessibleGroups($perms);
180:         foreach ($oGroups as $oItem) {
181:             $groups[$oItem->get('group_id')] = array(
182:                 'groupname' => $oItem->getGroupName(true),
183:                 'description' => $oItem->get('description')
184:             );
185:         }
186:         return $groups;
187:     }
188: }
189: 
190: /**
191:  * Group item
192:  *
193:  * @package Core
194:  * @subpackage GenericDB_Model
195:  */
196: class cApiGroup extends Item {
197: 
198:     /**
199:      * Prefix to be used for group names.
200:      *
201:      * @var string
202:      */
203:     const PREFIX = 'grp_';
204: 
205:     /**
206:      * Constructor to create an instance of this class.
207:      *
208:      * @param mixed $mId [optional]
209:      *                   Specifies the ID of item to load
210:      *                   
211:      * @throws cDbException
212:      * @throws cException
213:      */
214:     public function __construct($mId = false) {
215:         global $cfg;
216:         parent::__construct($cfg['tab']['groups'], 'group_id');
217:         $this->setFilters(array(), array());
218:         if ($mId !== false) {
219:             $this->loadByPrimaryKey($mId);
220:         }
221:     }
222: 
223:     /**
224:      * Loads a group from the database by its groupId.
225:      *
226:      * @param string $groupId
227:      *         Specifies the groupId
228:      * 
229:      * @return bool
230:      *         True if the load was successful
231:      * 
232:      * @throws cDbException
233:      * @throws cException
234:      */
235:     public function loadGroupByGroupID($groupId) {
236:         return $this->loadByPrimaryKey($groupId);
237:     }
238: 
239:     /**
240:      * Loads a group entry by its groupname.
241:      *
242:      * @param string $groupname
243:      *         Specifies the groupname
244:      *
245:      * @return bool
246:      *         True if the load was successful
247:      * 
248:      * @throws cDbException
249:      * @throws cException
250:      */
251:     public function loadGroupByGroupname($groupname) {
252:         $groupname = cApiGroup::prefixedGroupName($groupname);
253:         return $this->loadBy('groupname', $groupname);
254:     }
255: 
256:     /**
257:      * User defined field value setter.
258:      *
259:      * @see Item::setField()
260:      * @param string $sField
261:      *         Field name
262:      * @param string $mValue
263:      *         Value to set
264:      * @param bool $bSafe [optional]
265:      *         Flag to run defined inFilter on passed value
266:      * @return bool
267:      */
268:     public function setField($sField, $mValue, $bSafe = true) {
269:         if ('perms' === $sField) {
270:             if (is_array($mValue)) {
271:                 $mValue = implode(',', $mValue);
272:             }
273:         }
274: 
275:         return parent::setField($sField, $mValue, $bSafe);
276:     }
277: 
278:     /**
279:      * Returns list of group permissions.
280:      *
281:      * @return array
282:      */
283:     public function getPermsArray() {
284:         return explode(',', $this->get('perms'));
285:     }
286: 
287:     /**
288:      * Returns group id, currently set.
289:      *
290:      * @return string
291:      */
292:     public function getGroupId() {
293:         return $this->get('group_id');
294:     }
295: 
296:     /**
297:      * Returns name of group.
298:      *
299:      * @param bool $removePrefix [optional]
300:      *         Flag to remove "grp_" prefix from group name
301:      * @return string
302:      */
303:     public function getGroupName($removePrefix = false) {
304:         $groupname = $this->get('groupname');
305:         return (false === $removePrefix) ? $groupname : self::getUnprefixedGroupName($groupname);
306:     }
307: 
308:     /**
309:      * Returns name of a group cleaned from prefix "grp_".
310:      *
311:      * @param string $groupname
312:      * @return string
313:      */
314:     public static function getUnprefixedGroupName($groupname) {
315:         return cString::getPartOfString($groupname, cString::getStringLength(self::PREFIX));
316:     }
317: 
318:     /**
319:      * Returns the passed groupname prefixed with "grp_", if not exists.
320:      *
321:      * @param string $groupname
322:      * @return string
323:      */
324:     public static function prefixedGroupName($groupname) {
325:         if (cString::getPartOfString($groupname, 0, cString::getStringLength(cApiGroup::PREFIX)) != cApiGroup::PREFIX) {
326:             return cApiGroup::PREFIX . $groupname;
327:         }
328:         return $groupname;
329:     }
330: 
331:     /**
332:      * Returns group property by its type and name
333:      *
334:      * @param string $type
335:      * @param string $name
336:      *
337:      * @return string|bool
338:      *         value or false
339:      *
340:      * @throws cDbException
341:      * @throws cException
342:      */
343:     public function getGroupProperty($type, $name) {
344:         $groupPropColl = new cApiGroupPropertyCollection($this->values['group_id']);
345:         $groupProp = $groupPropColl->fetchByGroupIdTypeName($type, $name);
346:         return ($groupProp) ? $groupProp->get('value') : false;
347:     }
348: 
349:     /**
350:      * Retrieves all available properties of the group.
351:      *
352:      * @return array
353:      *         Returns assoziative properties array as follows:
354:      *         - $arr[idgroupprop][name]
355:      *         - $arr[idgroupprop][type]
356:      *         - $arr[idgroupprop][value]
357:      *
358:      * @throws cDbException
359:      * @throws cException
360:      */
361:     public function getGroupProperties() {
362:         $props = array();
363: 
364:         $groupPropColl = new cApiGroupPropertyCollection($this->values['group_id']);
365:         $groupProps = $groupPropColl->fetchByGroupId();
366:         foreach ($groupProps as $groupProp) {
367:             $props[$groupProp->get('idgroupprop')] = array(
368:                 'name' => $groupProp->get('name'),
369:                 'type' => $groupProp->get('type'),
370:                 'value' => $groupProp->get('value')
371:             );
372:         }
373: 
374:         return $props;
375:     }
376: 
377:     /**
378:      * Stores a property to the database.
379:      *
380:      * @param string $type
381:      *         Type (class, category etc) for the property to retrieve
382:      * @param string $name
383:      *         Name of the property to retrieve
384:      * @param string $value
385:      *         Value to insert
386:      * 
387:      * @return cApiGroupProperty
388:      * 
389:      * @throws cDbException
390:      * @throws cException
391:      * @throws cInvalidArgumentException
392:      */
393:     public function setGroupProperty($type, $name, $value) {
394:         $groupPropColl = new cApiGroupPropertyCollection($this->values['group_id']);
395:         return $groupPropColl->setValueByTypeName($type, $name, $value);
396:     }
397: 
398:     /**
399:      * Deletes a group property from the table.
400:      *
401:      * @param string $type
402:      *         Type (class, category etc) for the property to delete
403:      * @param string $name
404:      *         Name of the property to delete
405:      *
406:      * @return bool
407:      *
408:      * @throws cDbException
409:      * @throws cException
410:      * @throws cInvalidArgumentException
411:      */
412:     public function deleteGroupProperty($type, $name) {
413:         $groupPropColl = new cApiGroupPropertyCollection($this->values['group_id']);
414:         return $groupPropColl->deleteByGroupIdTypeName($type, $name);
415:     }
416: }
417: 
CMS CONTENIDO 4.10.0 API documentation generated by ApiGen 2.8.0