Пример #1
0
 /**
  * Is the user in a group.
  * @param  string|\vakata\user\GroupInterface  $group the group to check for
  * @return boolean        is the user in the group
  */
 public function inGroup($group) : bool
 {
     $id = $group instanceof GroupInterface ? $group->getID() : $group;
     return isset($this->groups[$id]);
 }
Пример #2
0
 /**
  * Remove a user form a group
  * @param  vakata\user\GroupInterface      $group the group to remove the user from
  * @return  self
  */
 public function deleteGroup(GroupInterface $group) : UserInterface
 {
     if (isset($this->groups[$group->getID()])) {
         unset($this->groups[$group->getID()]);
         if ($this->primary->getID() === $group->getID()) {
             $this->primary = null;
         }
     }
     return $this;
 }
Пример #3
0
 /**
  * Save a group.
  * @param  \vakata\user\GroupInterface $group the group to save
  * @return self
  */
 public function saveGroup(GroupInterface $group) : UserManagementInterface
 {
     $trans = $this->db->begin();
     try {
         if (!$this->db->one("SELECT 1 FROM " . $this->options['tableGroups'] . " WHERE grp = ?", [$group->getID()])) {
             $this->db->query("INSERT INTO " . $this->options['tableGroups'] . " (grp, created) VALUES (?, ?)", [$group->getID(), date('Y-m-d H:i:s')]);
         }
         foreach ($group->getPermissions() as $permission) {
             if (!$this->db->one("SELECT 1 FROM " . $this->options['tablePermissions'] . " WHERE perm = ?", [$permission])) {
                 $this->db->query("INSERT INTO " . $this->options['tablePermissions'] . " (perm, created) VALUES (?, ?)\n                        ON DUPLICATE KEY UPDATE perm = perm", [$permission, date('Y-m-d H:i:s')]);
             }
             if (!$this->db->one("SELECT 1 FROM " . $this->options['tableGroupsPermissions'] . " WHERE grp = ? AND perm = ?", [$group->getID(), $permission])) {
                 $this->db->query("INSERT INTO " . $this->options['tableGroupsPermissions'] . " (grp, perm, created) VALUES (?, ?, ?)", [$group->getID(), $permission, date('Y-m-d H:i:s')]);
             }
         }
         $this->db->commit();
         parent::saveGroup($group);
         return $this;
     } catch (\Exception $e) {
         $this->db->rollback($trans);
         throw $e;
     }
 }