Ejemplo n.º 1
0
 public function __construct()
 {
     parent::__construct();
     $this->user_model = \models\User::getInstance();
     $groups = \models\UserGroup::getInstance()->getAllGroups();
     foreach ($groups as $g) {
         $this->groups[$g->id] = $g;
     }
 }
Ejemplo n.º 2
0
 public function beforeroute()
 {
     $this->model = \models\UserGroup::getInstance();
     parent::beforeroute();
     $this->table = 'groups';
     $this->fw->mset(['ctrl_base' => $this->fw->get('backend_base.group'), 'core_ctrl_base' => $this->fw->get('backend_base.group_core')]);
     $default_group = $this->model->getDefaultGroup();
     $this->fw->set('default_group', $default_group);
     $this->fw->set('no_bulk', 'true');
 }
Ejemplo n.º 3
0
 public function addUsersFromArray($users = array())
 {
     foreach ($users as $user) {
         $u = UserQuery::create()->findOneByUsername($user["username"]);
         if ($u) {
             if ($u == $this->data["loggedUser"]) {
                 $response["messages"][] = "You can not add yourself to group.";
                 continue;
             }
             $userGroup = UserGroupQuery::create()->filterByUser($u)->filterByGroup($this->data["group"])->findOne();
             if ($userGroup) {
                 $response["messages"][] = "User " . $user["username"] . " is already in this group.";
                 continue;
             }
             $userGroup = new UserGroup();
             $userGroup->setUser($u);
             $userGroup->setGroup($this->data["group"]);
             $userGroup->save();
         } else {
             $response["messages"][] = "User " . $user["username"] . " does not exist.";
         }
     }
 }
Ejemplo n.º 4
0
 /**
  * Remove user of this object
  * through the user_group cross reference table.
  *
  * @param ChildUser $user
  * @return ChildGroup The current object (for fluent API support)
  */
 public function removeUser(ChildUser $user)
 {
     if ($this->getUsers()->contains($user)) {
         $userGroup = new ChildUserGroup();
         $userGroup->setUser($user);
         if ($user->isGroupsLoaded()) {
             //remove the back reference if available
             $user->getGroups()->removeObject($this);
         }
         $userGroup->setGroup($this);
         $this->removeUserGroup(clone $userGroup);
         $userGroup->clear();
         $this->collUsers->remove($this->collUsers->search($user));
         if (null === $this->usersScheduledForDeletion) {
             $this->usersScheduledForDeletion = clone $this->collUsers;
             $this->usersScheduledForDeletion->clear();
         }
         $this->usersScheduledForDeletion->push($user);
     }
     return $this;
 }
Ejemplo n.º 5
0
 /**
  * Filter the query by a related \Models\UserGroup object
  *
  * @param \Models\UserGroup|ObjectCollection $userGroup the related object to use as filter
  * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return ChildUserQuery The current query, for fluid interface
  */
 public function filterByUserGroup($userGroup, $comparison = null)
 {
     if ($userGroup instanceof \Models\UserGroup) {
         return $this->addUsingAlias(UserTableMap::COL_ID, $userGroup->getUserId(), $comparison);
     } elseif ($userGroup instanceof ObjectCollection) {
         return $this->useUserGroupQuery()->filterByPrimaryKeys($userGroup->getPrimaryKeys())->endUse();
     } else {
         throw new PropelException('filterByUserGroup() only accepts arguments of type \\Models\\UserGroup or Collection');
     }
 }
Ejemplo n.º 6
0
 /**
  * Exclude object from result
  *
  * @param   ChildUserGroup $userGroup Object to remove from the list of results
  *
  * @return $this|ChildUserGroupQuery The current query, for fluid interface
  */
 public function prune($userGroup = null)
 {
     if ($userGroup) {
         $this->addCond('pruneCond0', $this->getAliasedColName(UserGroupTableMap::COL_USER_ID), $userGroup->getUserId(), Criteria::NOT_EQUAL);
         $this->addCond('pruneCond1', $this->getAliasedColName(UserGroupTableMap::COL_GROUP_ID), $userGroup->getGroupId(), Criteria::NOT_EQUAL);
         $this->combine(array('pruneCond0', 'pruneCond1'), Criteria::LOGICAL_OR);
     }
     return $this;
 }
Ejemplo n.º 7
0
 /**
  * Проверяет данные перед добавлением на корректность
  * Полe 'actions' могут быть заданы как массивами, так и строками, в которых действия/связи разделены запятыми
  */
 private function isValid($post)
 {
     if (is_array($post) && count($post) > 0) {
         $isValid = true;
         /* Действия */
         if (isset($post['actions'])) {
             $actions = $post['actions'];
             if (!is_array($actions)) {
                 $actions = explode(',', $actions);
             }
             foreach ($actions as $a) {
                 if (!in_array(trim($a), self::$actions)) {
                     \helpers\Msg::error('acl.action_incorrect');
                     $isValid = false;
                 }
             }
             if ($isValid) {
                 $post['actions'] = implode($actions, ',');
             }
         }
         /* Группы */
         if (isset($post['group_id'])) {
             $group = \models\UserGroup::getInstance()->get($post['group_id']);
             if (!$group) {
                 \helpers\Msg::error('acl.group_incorrect');
                 $isValid = false;
             }
         }
         /* Связи */
         if (isset($post['relation'])) {
             $relation = $post['relation'];
             if (!in_array(trim($relation), self::$relations)) {
                 \helpers\Msg::error('acl.relation_incorrect');
                 $isValid = false;
             } else {
                 /*	$relation = self::$relations[trim($relation)];
                 			}
                 			if ($isValid)
                 			{*/
                 $post['relation'] = $relation;
             }
         }
         /* Объекты */
         if (isset($post['object'])) {
             $objects = $this->getObjectNamesList();
             if (!in_array(trim($post['object']), $objects)) {
                 \helpers\Msg::error('acl.object_incorrect');
                 $isValid = false;
             }
             if ($isValid) {
                 $post['object'] = trim($post['object']);
             }
         }
     }
     return $isValid ? $post : false;
 }
Ejemplo n.º 8
0
 /**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database. In some cases you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by find*()
  * and findPk*() calls.
  *
  * @param \Models\UserGroup $obj A \Models\UserGroup object.
  * @param string $key             (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool($obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if (null === $key) {
             $key = serialize(array((string) $obj->getUserId(), (string) $obj->getGroupId()));
         }
         // if key === null
         self::$instances[$key] = $obj;
     }
 }
Ejemplo n.º 9
0
 private function clearGroupId($post, $f3)
 {
     $group_id = false;
     if (!isset($post['group_id'])) {
         if ($f3->exists('account.default_group_id')) {
             $group_id = $f3->get('account.default_group_id');
         } else {
             $group_id = 0;
         }
     } else {
         $group_id = $post['group_id'];
     }
     $group = \models\UserGroup::getInstance()->get($group_id);
     if (!$group) {
         \helpers\Msg::error('acl.group_incorrect');
         $isValid = false;
     }
     return $group_id;
 }
Ejemplo n.º 10
0
 /**
  * Устанавливает массив с данными для генерации AJAX-полей
  * @param type $this->fw
  */
 private function setAJAXFields()
 {
     $object_options = $this->model->getObjectSelectOptions();
     $this->fw->set('ajax_fields', [['name' => 'group_id', 'options' => \models\UserGroup::getInstance()->getSelectOptions(), 'type' => 'select_list', 'multiselect' => false, 'selected_id' => $this->fw->get('account.default_group_id') * 1, 'placeHolder' => $this->fw->get('i18n.acl.group.placeholder'), 'label' => $this->fw->get('i18n.acl.group.label')], ['name' => 'object', 'options' => $object_options, 'type' => 'select_list', 'multiselect' => false, 'selected_id' => $object_options[0], 'placeHolder' => $this->fw->get('i18n.acl.object.placeholder'), 'label' => $this->fw->get('i18n.acl.object.label')], ['name' => 'relation', 'options' => $this->model->getRelationSelectOptions(), 'type' => 'select_list', 'multiselect' => false, 'selected_id' => $this->model->RELATION_NO, 'placeHolder' => $this->fw->get('i18n.acl.relation.placeholder'), 'label' => $this->fw->get('i18n.acl.relation.label')], ['name' => 'actions', 'options' => $this->model->getActionsSelectOptions(), 'type' => 'select_list', 'multiselect' => true, 'selected_id' => ['create', 'read', 'update', 'delete'], 'placeHolder' => $this->fw->get('i18n.acl.action.placeholder'), 'label' => $this->fw->get('i18n.acl.action.label')]]);
     $this->setAjaxFieldsPost();
 }
Ejemplo n.º 11
0
 /**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database. In some cases you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by find*()
  * and findPk*() calls.
  *
  * @param \Models\UserGroup $obj A \Models\UserGroup object.
  * @param string $key             (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool($obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if (null === $key) {
             $key = serialize([null === $obj->getUserId() || is_scalar($obj->getUserId()) || is_callable([$obj->getUserId(), '__toString']) ? (string) $obj->getUserId() : $obj->getUserId(), null === $obj->getGroupId() || is_scalar($obj->getGroupId()) || is_callable([$obj->getGroupId(), '__toString']) ? (string) $obj->getGroupId() : $obj->getGroupId()]);
         }
         // if key === null
         self::$instances[$key] = $obj;
     }
 }