/** * @param \Secretary\Entity\Key $key * @param \Secretary\Entity\User $user * @return \Secretary\Entity\Key */ public function saveKey(KeyEntity $key, UserEntity $user, $pubKey) { $key->setPubKey($pubKey); $key->setUserId($user->getId()); $key->setUser($user); $this->em->persist($key); $this->em->flush(); return $key; }
/** * @param \Secretary\Entity\User $user * @param string $action */ public function __construct(\Secretary\Entity\User $user, $action = '#') { parent::__construct('userForm'); $this->setAttribute('method', 'post')->setAttribute('action', $action)->setAttribute('class', 'form-horizontal'); $displayName = new \Zend\Form\Element\Text('display_name'); $displayName->setAttribute('required', 'required')->setAttribute('label', 'Display Name')->setValue($user->getDisplayName()); $this->add($displayName); $select = new \Zend\Form\Element\Select('language'); $select->setAttribute('required', 'required')->setAttribute('label', 'Select Language')->setValueOptions(array('de_DE' => 'german', 'en_US' => 'english'))->setValue($user->getLanguage()); $this->add($select); $notifications = new \Zend\Form\Element\Select('notifications'); $notifications->setAttribute('required', 'required')->setAttribute('label', 'Enable notifications')->setValueOptions(array('0' => 'no', '1' => 'yes'))->setValue($user->getNotifications()); $this->add($notifications); $submit = new \Zend\Form\Element\Submit('submit'); $submit->setAttribute('class', 'btn btn-primary')->setAttribute('value', 'save'); $this->add($submit); }
/** * @param Entity\User $user * @param Entity\Group $group * @return User */ public function removeUserFromGroup(Entity\User $user, Entity\Group $group) { $user->getGroups()->removeElement($group); $this->em->persist($user); $this->em->flush(); return $user; }
/** * @param Entity\User $user * @return void * @throws \LogicException If needed role can not be found */ public function updateUserToKeyRole(Entity\User $user) { /** @var \Secretary\Entity\Role $roleRecord */ $roleRecord = $this->getRoleRepository()->findOneBy(array('roleId' => 'keyuser')); if (empty($roleRecord)) { throw new \LogicException('Roles are missing, please configure them'); } $user->getRoles()->clear(); $user->addRole($roleRecord); $this->em->persist($user); $this->em->flush(); return; }
/** * {@inheritDoc} */ public function getArrayCopy() { $this->__initializer__ && $this->__initializer__->__invoke($this, 'getArrayCopy', array()); return parent::getArrayCopy(); }
/** * @param array $users * @param Entity\Note $note * @param Entity\User $owner * @param array $encryptData * @return Entity\Note */ public function saveUser2NoteRelations(array $users, Entity\Note $note, Entity\User $owner, array $encryptData) { $i = 0; // Save User2Note entries /** @var Entity\User $user */ foreach ($users as $user) { $ownerCheck = false; if ($owner->getId() == $user->getId()) { $ownerCheck = true; } $user2Note = new Entity\User2Note(); $user2Note->setUser($user)->setUserId($user->getId())->setNote($note)->setNoteId($note->getId())->setEKey($encryptData['ekeys'][$i])->setOwner($ownerCheck)->setReadPermission(true)->setWritePermission($ownerCheck); $note->addUser2Note($user2Note); $this->em->persist($note); $i++; } $this->em->flush(); return $note; }
/** * @param Entity\Note $note * @param array $users * @param Entity\User $owner * @param string $subject * @param string $title * @return void */ protected function sendNoteGroupMail(Entity\Note $note, array $users, Entity\User $owner, $subject, $title) { /** @var Entity\User $user */ foreach ($users as $user) { if ($user->getId() != $owner->getId() && true === $user->getNotifications()) { $this->translator->setLocale($user->getLanguage()); $subject = $this->translator->translate($subject); $content = new ViewModel(); $content->setTemplate('mail/note.phtml')->setVariable('title', $title)->setVariable('note', $note)->setVariable('host', $this->host); $message = $this->SxMail->compose($content); $message->addTo($user->getEmail()); $message->addFrom($this->defaultFrom); $message->setSubject($subject); $this->SxMail->send($message); } } // @todo this will only work, as long owner is the only one with edit permissions $this->translator->setLocale($owner->getLanguage()); return; }