Exemplo n.º 1
0
 public function saveData($aGroupData)
 {
     if ($this->iGroupId === null) {
         $oGroup = new Group();
     } else {
         $oGroup = GroupQuery::create()->findPk($this->iGroupId);
     }
     $oGroup->setName($aGroupData['name']);
     if ($oGroup->isNew() && count(self::$ROLES) > 0) {
         foreach (self::$ROLES as $sRoleKey) {
             $oGroupRole = new GroupRole();
             $oGroupRole->setRoleKey($sRoleKey);
             $oGroup->addGroupRole($oGroupRole);
         }
     } else {
         foreach ($oGroup->getGroupRoles() as $oGroupRole) {
             $oGroupRole->delete();
         }
         foreach ($aGroupData['roles'] as $sRoleKey) {
             $oGroupRole = new GroupRole();
             $oGroupRole->setRoleKey($sRoleKey);
             $oGroup->addGroupRole($oGroupRole);
         }
     }
     return $oGroup->save();
 }
Exemplo n.º 2
0
 /**
  * Return all groups, converted it names to role names.
  *
  * @return string[]
  * @throws \Propel\Runtime\Exception\PropelException
  */
 public function getGroupRoles()
 {
     $names = GroupQuery::create()->select('Name')->filterByUser($this)->find();
     $result = [];
     foreach ($names as $name) {
         $result[] = preg_replace('/[^a-zA-Z0-9]+/', '_', strtoupper($name));
     }
     return $result;
 }
Exemplo n.º 3
0
 public function getGroupName()
 {
     if ($this->oDelegateProxy->getGroupId() !== CriteriaListWidgetDelegate::SELECT_ALL) {
         $oGroup = GroupQuery::create()->findPk($this->oDelegateProxy->getGroupId());
         if ($oGroup) {
             return $oGroup->getName();
         }
     }
     return $this->oDelegateProxy->getGroupId();
 }
Exemplo n.º 4
0
 public function getGroupName()
 {
     $oGroup = GroupQuery::create()->findPk($this->oDelegateProxy->getGroupId());
     if ($oGroup) {
         return $oGroup->getName();
     }
     if ($this->oDelegateProxy->getGroupId() === CriteriaListWidgetDelegate::SELECT_WITHOUT) {
         return TranslationPeer::getString('wns.users.without_category');
     }
     return $this->oDelegateProxy->getGroupId();
 }
 /**
  * Get the associated Group object
  *
  * @param      PropelPDO Optional Connection object.
  * @return     Group The associated Group object.
  * @throws     PropelException
  */
 public function getGroup(PropelPDO $con = null)
 {
     if ($this->aGroup === null && $this->group_id !== null) {
         $this->aGroup = GroupQuery::create()->findPk($this->group_id);
         /* The following can be used additionally to
         		   guarantee the related object contains a reference
         		   to this object.  This level of coupling may, however, be
         		   undesirable since it could result in an only partially populated collection
         		   in the referenced object.
         		   $this->aGroup->addDirectoryPermissions($this);
         		 */
     }
     return $this->aGroup;
 }
Exemplo n.º 6
0
 public function allGroups()
 {
     return WidgetJsonFileModule::jsonBaseObjects(GroupQuery::create()->orderByName()->find(), array('id', 'name'));
 }
Exemplo n.º 7
0
 /**
  * Returns a new GroupQuery object.
  *
  * @param     string $modelAlias The alias of a model in the query
  * @param   GroupQuery|Criteria $criteria Optional Criteria to build the query from
  *
  * @return GroupQuery
  */
 public static function create($modelAlias = null, $criteria = null)
 {
     if ($criteria instanceof GroupQuery) {
         return $criteria;
     }
     $query = new GroupQuery(null, null, $modelAlias);
     if ($criteria instanceof Criteria) {
         $query->mergeWith($criteria);
     }
     return $query;
 }
Exemplo n.º 8
0
 /**
  * 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(GroupPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = GroupQuery::create()->filterByPrimaryKey($this->getPrimaryKey());
         $ret = $this->preDelete($con);
         // denyable behavior
         if (!(GroupPeer::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;
     }
 }
Exemplo n.º 9
0
 /**
  * Returns the number of related Group objects.
  *
  * @param Criteria $criteria
  * @param boolean $distinct
  * @param PropelPDO $con
  * @return int             Count of related Group objects.
  * @throws PropelException
  */
 public function countGroupsRelatedByUpdatedBy(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
 {
     $partial = $this->collGroupsRelatedByUpdatedByPartial && !$this->isNew();
     if (null === $this->collGroupsRelatedByUpdatedBy || null !== $criteria || $partial) {
         if ($this->isNew() && null === $this->collGroupsRelatedByUpdatedBy) {
             return 0;
         }
         if ($partial && !$criteria) {
             return count($this->getGroupsRelatedByUpdatedBy());
         }
         $query = GroupQuery::create(null, $criteria);
         if ($distinct) {
             $query->distinct();
         }
         return $query->filterByUserRelatedByUpdatedBy($this)->count($con);
     }
     return count($this->collGroupsRelatedByUpdatedBy);
 }
Exemplo n.º 10
0
 public function addGroup($mGroup)
 {
     if (!$mGroup instanceof Group) {
         $mGroup = GroupQuery::create()->createOrFindByName($mGroup);
     }
     if (!$this->hasGroup($mGroup)) {
         $oUserGroup = new UserGroup();
         $oUserGroup->setUserRelatedByUserId($this);
         $oUserGroup->setGroup($mGroup);
     }
     return $mGroup;
 }