protected function createGroupTree() { foreach ($this->database->table($this->config['groups']['table']) as $v) { $this->groups[$v->{$this->getTableInfo()["id"]}] = $group = new Group($v, $this->getTableInfo()); foreach ($v->related($this->config['group_email']['table'], $this->config['group_email']['groupId']) as $v2) { $group->registerEmail($this->emails->getEmailById($v2->{$this->config['group_email']['emailId']})); } } foreach ($this->groups as $v) { $v->connectToParent($this->groups); if (!$v->hasParent()) { $this->rootGroups[$v->getId()] = $v; } } return $this->rootGroups; }
public function addEmailToGroup(Email $email, Group $group) { $groups = $this->getGroups(); if (!$group->containEmail($email)) { $this->database->table($this->config['group_email']['table'])->insert([$this->config['group_email']['groupId'] => $group->getId(), $this->config['group_email']['emailId'] => $email->getId()]); } else { throw new \Exception("Email '" . $email->getEmail() . "' is already in group '" . $group->getName() . "'"); } $group->registerEmail($email); $groups->invalidateCache(); }