예제 #1
0
 /**
  * @param \Venne\Queue\Job $job
  * @param integer $priority
  */
 public function run(Job $job, $priority)
 {
     /** @var Notification $notificationEntity */
     $notificationEntity = $this->notificationRepository->find($job->arguments[0]);
     if ($notificationEntity === null) {
         return;
     }
     $qb = $this->notificationSettingRepository->createQueryBuilder('a')->andWhere('a.type IS NULL OR a.type = :type')->setParameter('type', $notificationEntity->type->id);
     if ($notificationEntity->user) {
         $qb = $qb->andWhere('a.targetUser IS NULL OR a.targetUser = :targetUser')->setParameter('targetUser', $notificationEntity->user->id);
     }
     if ($notificationEntity->target) {
         $qb = $qb->andWhere('a.target IS NULL OR a.target = :target')->setParameter('target', $notificationEntity->target);
     }
     if ($notificationEntity->targetKey) {
         $qb = $qb->andWhere('a.targetKey IS NULL OR a.targetKey = :targetKey')->setParameter('targetKey', $notificationEntity->targetKey);
     }
     $users = array();
     foreach ($qb->getQuery()->getResult() as $setting) {
         $user = $setting->user !== null ? $setting->user : $notificationEntity->user;
         if (isset($users[$user->id]) && !$users[$user->id]['email']) {
             $users[$user->id]['email'] = $setting->email;
         } else {
             $users[$user->id] = array('user' => $user, 'email' => $setting->user !== null ? $setting->email : $notificationEntity->user->getEmail());
         }
     }
     foreach ($users as $user) {
         $notificationUser = new NotificationUser($notificationEntity, $user['user']);
         $this->entityManager->persist($notificationUser);
         $this->entityManager->flush($notificationUser);
         if ($user['email']) {
             $this->jobManager->scheduleJob(new Job(EmailJob::getName(), null, array('user' => $user['user'] instanceof User ? $user['user']->id : $user['user'], 'notification' => $notificationUser->id)), $priority);
         }
     }
 }
예제 #2
0
 public function find($id = null)
 {
     if (!$id) {
         $id = 0;
     }
     return $this->repository->find($id);
 }
예제 #3
0
파일: JobControl.php 프로젝트: venne/venne
 public function render()
 {
     $this->template->job = $this->dataTransferManager->createQuery(JobDto::class, function () {
         return $this->jobRepository->find($this->id);
     })->enableCache()->fetch();
     $this->template->render();
 }
예제 #4
0
 /**
  * @return \Venne\System\Components\AdminGrid\AdminGrid
  */
 protected function createComponentTable()
 {
     $admin = $this->adminGridFactory->create($this->jobRepository);
     $table = $admin->getTable();
     $table->addColumnText('type', 'Type')->getCellPrototype()->width = '35%';
     $table->addColumnText('state', 'State')->getCellPrototype()->width = '15%';
     $table->addColumnText('priority', 'Priority')->getCellPrototype()->width = '10%';
     $table->addColumnDate('date', 'Date')->getCellPrototype()->width = '15%';
     $table->addColumnDate('dateInterval', 'Interval')->getCellPrototype()->width = '15%';
     $table->addColumnDate('round', 'Round')->getCellPrototype()->width = '10%';
     // actions
     $table->addActionEvent('run', 'Run')->onClick[] = function ($id) {
         $job = $this->jobRepository->find($id);
         try {
             $this->jobManager->scheduleJob($job, JobManager::PRIORITY_REALTIME);
             $this->flashMessage($this->getTranslator()->translate('Job has been done.'), 'success');
         } catch (JobFailedException $e) {
             $this->flashMessage($this->getTranslator()->translate('Job failed.'), 'warning');
         }
         $this->redirect('this');
     };
     $table->addActionEvent('edit', 'Edit')->getElementPrototype()->class[] = 'ajax';
     $form = $admin->addForm('job', 'Job', function (Job $job = null) {
         return $this->jobFormService->getFormFactory($job !== null ? $job->getId() : null);
     });
     $admin->connectFormWithAction($form, $table->getAction('edit'));
     $table->addActionEvent('delete', 'Delete')->getElementPrototype()->class[] = 'ajax';
     $admin->connectActionAsDelete($table->getAction('delete'));
     return $admin;
 }
예제 #5
0
파일: EmailJob.php 프로젝트: venne/venne
 /**
  * @param \Venne\Queue\Job $job
  * @param integer $priority
  */
 public function run(Job $job, $priority)
 {
     $user = $this->userRepository->find($job->arguments['user']);
     $notificationUser = $this->notificationUserRepository->find($job->arguments['notification']);
     $notification = $notificationUser->getNotification();
     $this->emailManager->send($user->email, $user->name, NotificationEvent::getName(), 'userNotification', array('type' => $notification->type->type, 'action' => $notification->type->action, 'message' => $notification->type->message, 'user' => $notification->user, 'notification' => $notification, 'notificationManager' => $this));
 }
예제 #6
0
 /**
  * Vraci clanek podle Id (article_id)
  * @param int $id article_id pkey
  * @return object|null
  */
 public function getById($id)
 {
     if (empty($id)) {
         return NULL;
     }
     return $this->myArticleRepository->find($id);
 }
예제 #7
0
 public function getById($id)
 {
     $x = $this->repository->find($id);
     if ($x == NULL) {
         throw new RecordNotFoundException("Record with id {$id} not found!");
     }
     return $x;
 }
예제 #8
0
 /**
  * @param integer|null $primaryKey
  * @param integer|null $parentId
  * @return \Venne\Files\File
  */
 protected function getEntity($primaryKey, $parentId = null)
 {
     $entity = parent::getEntity($primaryKey);
     if ($parentId !== null) {
         $entity->setParent($this->dirRepository->find($parentId));
     }
     return $entity;
 }
예제 #9
0
 public function render()
 {
     if ($this->id !== null) {
         $this->template->notification = $this->dataTransferManager->createQuery(NotificationDto::class, function () {
             return $this->notificationUserRepository->find($this->id);
         })->enableCache()->fetch();
     }
     $this->template->render();
 }
예제 #10
0
 public function getText($ident)
 {
     if ($this->authorizator->canRead($ident)) {
         $et = $this->editableTextRepository->find($ident);
         if ($et === NULL) {
             return NULL;
         } else {
             return $et->getText();
         }
     } else {
         throw new AuthenticationException("You have no authorization to get text");
     }
 }
예제 #11
0
 /**
  * Finds an entity by id.
  * @param mixed $id
  * @param int $lockMode
  * @param null $lockVersion
  * @return object
  * @throws IOException
  */
 public function find($id, $lockMode = null, $lockVersion = null)
 {
     $result = parent::find($id, $lockMode, $lockVersion);
     if ($result === NULL) {
         throw new IOException('Not found', 404);
     }
     return $result;
 }
예제 #12
0
 /**
  * @param AMQPMessage $message
  * @return bool
  */
 public function process(AMQPMessage $message)
 {
     $ids = Json::decode((string) $message->body, Json::FORCE_ARRAY);
     /** @var Screenplay[] $documents */
     $documents = [];
     foreach ($ids as $id) {
         /** @var Screenplay|NULL $screenplay */
         $screenplay = $this->scenariosRepository->find($id);
         if ($screenplay === NULL) {
             $this->onError("Screenplay with ID #{$id} not found!");
             return FALSE;
         }
         $documents[] = $this->createDocument($screenplay);
     }
     /** @var Index $indexEntity */
     $indexEntity = $this->indicesRepository->findOneBy([], ['createdAt' => 'DESC']);
     $index = $this->client->getIndex($indexEntity->getName());
     $type = $index->getType('screenplay');
     $type->addDocuments($documents);
     return TRUE;
 }
예제 #13
0
 /**
  * @return \Nette\Forms\Form
  */
 protected function createComponentAccountForm()
 {
     $user = $this->userRepository->find($this->getUser()->getIdentity()->getId());
     $formService = $this->securityManager->getUserTypeByClass($user->getClass())->getFrontFormService();
     $form = $formService->getFormFactory($user->getId())->create();
     $form->onSuccess[] = function () {
         $this->flashMessage($this->translator->translate('Account settings has been updated.'), 'success');
         $this->redirect('this');
         $this->redrawControl('content');
     };
     return $form;
 }
예제 #14
0
 public function loadState(array $params)
 {
     if (isset($params['dirId'])) {
         $this->dir = $this->dirRepository->find($params['dirId']);
     } elseif ($this->root) {
         $this->dir = $this->root;
     }
     if (isset($params['fileId'])) {
         $this->file = $this->fileRepository->find($params['fileId']);
         $this->dir = $this->file->getParent();
     }
     parent::loadState($params);
 }
예제 #15
0
파일: TagRemover.php 프로젝트: blitzik/CMS
 /**
  * @param $tagID
  * @throws \Exception
  */
 public function remove($tagID)
 {
     try {
         $this->em->beginTransaction();
         /** @var Tag $tag */
         $tag = $this->tagRepository->find($tagID);
         if ($tag === null) {
             $this->em->commit();
             return;
         }
         $tagSearchUrl = $this->urlFacade->getUrl('Pages:Front:Search', 'tag', $tag->getId());
         $this->em->remove($tag);
         $this->em->remove($tagSearchUrl);
         $this->em->flush();
         $this->em->commit();
         $this->onSuccessTagRemoval($tag, $tagID);
     } catch (\Exception $e) {
         $this->em->rollback();
         $this->em->close();
         throw $e;
     }
 }
예제 #16
0
 /**
  * @param string $from
  * @param string $to
  * @param string $dropMode
  */
 public function setFileParent($from, $to, $dropMode)
 {
     $fromType = substr($from, 0, 1);
     $from = substr($from, 2);
     $toType = substr($to, 0, 1);
     $to = substr($to, 2);
     $entity = $fromType == 'd' ? $this->dirRepository->find($from) : $this->fileRepository->find($from);
     $target = $toType == 'd' ? $this->dirRepository->find($to) : $this->fileRepository->find($to);
     if ($dropMode === 'before' || $dropMode === 'after') {
         $entity->setParent($target->parent);
     } else {
         $entity->setParent($target);
     }
     $this->entityManager->flush($entity);
 }
예제 #17
0
파일: AdminGrid.php 프로젝트: venne/venne
 /**
  * @param integer $id
  * @param integer[] $action
  */
 public function tableDelete($id, $action)
 {
     if (is_array($action)) {
         foreach ($action as $item) {
             $this->tableDelete($item, null);
         }
     } else {
         try {
             $this->repository->getEntityManager()->remove($this->repository->find($id));
             $this->repository->getEntityManager()->flush();
         } catch (\Exception $e) {
             $this->onError($this, $e);
         }
     }
     $this->redirect('this');
     $this->redrawControl('table');
 }
예제 #18
0
 /**
  * @param string $songId
  * @return \string[]
  */
 public function getSongPathAndName(string $songId) : array
 {
     /** @var Song $song */
     $song = $this->songRepository->find($songId);
     return [$this->getSongPath($songId), $song->getName()];
 }
예제 #19
0
 /**
  * @param number $id
  * @return Entity\TaskGroup|null
  */
 public function getById($id)
 {
     return $this->taskGroup->find($id);
 }
예제 #20
0
 /**
  * @param $id
  *
  * @return null|Entity\Performance
  */
 public function findPerformanceById($id)
 {
     return $this->performanceRepository->find($id);
 }
예제 #21
0
 /**
  * @return \Kdyby\Doctrine\Entities\BaseEntity
  */
 protected function createEntity()
 {
     $user = $this->userRepository->find($this->netteUser->getIdentity()->getId());
     $class = new \ReflectionClass($this->getEntityClassName());
     return $class->newInstanceArgs(array($user));
 }
예제 #22
0
 public function renderDefault()
 {
     $this->template->userDto = $this->dataTransferManager->createQuery(UserDto::class, function () {
         return $this->userRepository->find($this->getUser()->getIdentity()->getId());
     })->enableCache(sprintf('#%s', $this->getUser()->getIdentity()->getId()))->fetch();
 }
예제 #23
0
 /**
  * Vraci tag podle Id (tag_id)
  * @param int $id tag_id pkey
  * @return object|null
  */
 public function getById($id)
 {
     return $this->repository->find($id);
 }
예제 #24
0
파일: Child.php 프로젝트: Kotys/eventor.io
 /**
  * @param $id
  *
  * @return null|object
  */
 public function findChildById($id)
 {
     return $this->childRepository->find($id);
 }
예제 #25
0
파일: UrlFacade.php 프로젝트: blitzik/CMS
 /**
  * @param int $urlId
  * @return Url|null
  */
 public function getById($urlId)
 {
     return $this->urlRepository->find($urlId);
 }
예제 #26
0
파일: Event.php 프로젝트: Kotys/eventor.io
 /**
  * @param $id
  * @return null|Entity\Event
  */
 public function findEventById($id)
 {
     return $this->eventRepository->find($id);
 }
 public function getGenre(int $id) : Genre
 {
     return $this->genreRepository->find($id);
 }
예제 #28
0
 /**
  * @return \Venne\Security\User|null
  */
 private function getUser()
 {
     return $this->netteUser->isLoggedIn() ? $this->userRepository->find($this->netteUser->getIdentity()->getId()) : null;
 }
예제 #29
0
 /**
  * @param $id
  * @return Season|NULL
  */
 public function find($id)
 {
     return $this->seasonsRepository->find($id);
 }