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