private static function roleIsUsed($oRole) { if ($oRole->isNew()) { return false; } $iCountRolesUsed = UserRoleQuery::create()->filterByRole($oRole)->joinUserRelatedByUserId()->count(); $iCountRolesInGroupsUsed = UserGroupQuery::create()->filterByRole($oRole)->joinUserRelatedByUserId()->count(); return $iCountRolesUsed + $iCountRolesInGroupsUsed > 0; }
/** * Get user form. * * @param User $user * @return Curry_Form_ModelForm */ protected function getUserForm(User $user) { $createHomeFolder = $user->isNew() || self::getUserHome($user) !== null; $validRoles = $this->getValidRoles(); $invalidRoles = UserRoleQuery::create()->filterByUserRoleId(array_keys($validRoles), Criteria::NOT_IN)->select('UserRoleId')->find()->getArrayCopy(); $validLanguages = UserLanguageQuery::create()->_if(!$user->hasAccess('*'))->filterByUser(User::getUser())->_endif()->select('langcode')->find()->getArrayCopy(); $invalidLanguages = LanguageQuery::create()->filterByLangcode($validLanguages, Criteria::NOT_IN)->select('langcode')->find()->getArrayCopy(); $form = new Curry_Form_ModelForm('User', array('method' => 'post', 'action' => url('', $_GET), 'columnElements' => array('password' => array('password', array('required' => $user->isNew())), 'relation__userrole' => array('select', array('label' => 'Role', 'disable' => $invalidRoles, 'validators' => array(array('InArray', true, array(array_keys($validRoles)))))), 'relation__language' => array('multiselect', array('class' => 'chosen', 'disable' => $invalidLanguages, 'validators' => array(array('InArray', true, array($validLanguages)))))))); $form->addElements(array('verify_password' => array('password', array('label' => 'Verify password', 'required' => $user->isNew(), 'validators' => array(array('identical', false, array('token' => 'password'))))), 'create_home_folder' => array('checkbox', array('label' => 'Create home folder', 'description' => 'Creates a folder in /user-content/ for the user and adds file permission for it.', 'value' => $createHomeFolder, 'order' => 5)))); $form->withRelation('UserRole'); $form->withRelation('Language'); $form->addElement('submit', 'save', array('label' => 'Save')); return $form; }
protected static function createRole($name, array $access = array()) { $role = UserRoleQuery::create()->filterByName($name)->findOneOrCreate(); if ($role->isNew()) { foreach ($access as $module) { $roleAccess = new UserRoleAccess(); $roleAccess->setUserRole($role); $roleAccess->setModule($module); } } return $role; }
/** * Removes this object from datastore and sets delete attribute. * * @param PropelPDO $con * @return void * @throws PropelException * @throws Exception * @see BaseObject::setDeleted() * @see BaseObject::isDeleted() */ public function delete(PropelPDO $con = null) { if ($this->isDeleted()) { throw new PropelException("This object has already been deleted."); } if ($con === null) { $con = Propel::getConnection(UserRolePeer::DATABASE_NAME, Propel::CONNECTION_WRITE); } $con->beginTransaction(); try { $deleteQuery = UserRoleQuery::create()->filterByPrimaryKey($this->getPrimaryKey()); $ret = $this->preDelete($con); // denyable behavior if (!(UserRolePeer::isIgnoringRights() || $this->mayOperate("delete"))) { throw new PropelException(new NotPermittedException("delete.by_role", array("role_key" => "users"))); } if ($ret) { $deleteQuery->delete($con); $this->postDelete($con); $con->commit(); $this->setDeleted(true); } else { $con->commit(); } } catch (Exception $e) { $con->rollBack(); throw $e; } }
/** * If this collection has already been initialized with * an identical criteria, it returns the collection. * Otherwise if this Role is new, it will return * an empty collection; or if this Role has previously * been saved, it will retrieve related UserRoles from storage. * * This method is protected by default in order to keep the public * api reasonable. You can provide public methods for those you * actually need in Role. * * @param Criteria $criteria optional Criteria object to narrow the query * @param PropelPDO $con optional connection object * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN) * @return PropelObjectCollection|UserRole[] List of UserRole objects */ public function getUserRolesJoinUserRelatedByUpdatedBy($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN) { $query = UserRoleQuery::create(null, $criteria); $query->joinWith('UserRelatedByUpdatedBy', $join_behavior); return $this->getUserRoles($query, $con); }
/** * Save page permissions * * @param Page $page * @param array $values */ public static function savePagePermission(Page $page, array $values) { self::savePagePermissionEntry($page, null, null, (array) $values['everyone']); foreach ((array) $values['user'] as $userId => $permissions) { self::savePagePermissionEntry($page, UserQuery::create()->findPk($userId), null, $permissions); } foreach ((array) $values['role'] as $roleId => $permissions) { self::savePagePermissionEntry($page, null, UserRoleQuery::create()->findPk($roleId), $permissions); } }
public function addRole($sRoleName) { $aRoles = func_get_args(); foreach ($aRoles as $mRole) { if (!$mRole instanceof Role) { $mRole = RoleQuery::create()->createOrFindPk($mRole); } UserRoleQuery::create()->createOrFind($this, $mRole); } }