Example #1
0
 /**
  * @param $groupId
  * @throws \Exception
  */
 public function changeGroup($groupId)
 {
     $group = PowerGroup::find($groupId);
     if ($group == null) {
         throw new \Exception("Unknown power group ID " . $groupId);
     }
     $this->group = $groupId;
     $this->save();
 }
 public function groupHasPower($groupId, $power)
 {
     $hasPower = false;
     if (array_key_exists($groupId, $this->groups) && array_key_exists($power->id, $this->groups[$groupId])) {
         return $this->groups[$groupId][$power->id];
     }
     if ($power->group == $groupId) {
         $hasPower = true;
     } else {
         $group = PowerGroup::find($groupId);
         if ($group == null) {
             throw new \Exception("Unknown power group ID " . $groupId);
         }
         if ($group->group != null) {
             $hasPower = $this->groupHasPower($group->group, $power);
         }
     }
     if (!array_key_exists($groupId, $this->groups)) {
         $this->groups[$groupId] = [];
     }
     $this->groups[$groupId][$power->id] = $hasPower;
     return $hasPower;
 }