public function getUsersApplication(User $u, Season $s)
 {
     try {
         $id = "{$this->getEntityClassName()}/{$u->getId()}-{$s->getId()}";
         $cache = $this->getEntityCache();
         $data = $cache->load($id);
         if ($data === null) {
             $data = $this->seasonApplicationDao->createQueryBuilder("a")->where("a.owner = :owner")->setParameter("owner", $u->getId())->andWhere("a.season = :season")->setParameter("season", $s->getId())->getQuery()->getSingleResult();
             $opts = [Cache::TAGS => [self::ENTITY_COLLECTION, $id]];
             $cache->save($id, $data, $opts);
         }
         return $data;
     } catch (\Exception $ex) {
         $this->logError($ex->getMessage());
         throw new Exceptions\DataErrorException($ex->getMessage(), $ex->getCode(), $ex->getPrevious());
     }
 }
示例#2
0
 public function getUserRoles(User $user, $useCache = true)
 {
     if ($user === null) {
         throw new NullPointerException("Argument User cannot be null");
     }
     try {
         if (!$useCache) {
             return $this->positionDao->findBy(array("owner" => $user->getId()));
         }
         $id = User::getClassName() . "-" . $user->getId();
         $cache = $this->getEntityCache();
         $data = $cache->load($id);
         if ($data === null) {
             $coll = $this->positionDao->findBy(array("owner" => $user->getId()));
             foreach ($coll as $p) {
                 $data[] = $p->getRole()->getName();
             }
             $opts = [Cache::TAGS => [self::ENTITY_COLLECTION, $id], Cache::SLIDING => true];
             $cache->save($id, $data, $opts);
         }
         return $data;
     } catch (\Exception $e) {
         $this->logError($e);
         throw new Exceptions\DataErrorException($e->getMessage(), $e->getCode(), $e->getPrevious());
     }
 }
示例#3
0
 public function changeWebProfile(User $u)
 {
     try {
         $wp = $u->getWebProfile();
         $user = $this->userDao->find($u->getId());
         if ($wp->getPicture() instanceof \Nette\Http\FileUpload && $wp->getPicture()->isOk()) {
             $oldImgId = $wp->provideOldImgId();
             $this->imageService->removeResource($oldImgId);
             $identifier = $this->imageService->storeNetteFile($wp->getPicture());
             $wp->setPicture($identifier);
         }
         $this->entityManager->flush();
     } catch (\Exception $ex) {
         $this->logError($ex->getMessage());
         throw new Exceptions\DataErrorException($ex->getMessage(), $ex->getCode(), $ex->getPrevious());
     }
 }
示例#4
0
 public function getUserEventsDatasource(User $u)
 {
     $model = new Doctrine($this->participationDao->createQueryBuilder()->select("ep, ev.title AS title, ev.takePlaceSince as takePlaceSince, ev.takePlaceTill AS takePlaceTill, ev.eventType AS eventType")->add("from", EventParticipation::getClassName() . " ep LEFT JOIN ep.event ev")->where("ep.owner = :owner")->setParameter("owner", $u->getId()));
     return $model;
 }
示例#5
0
 /**
  * Checks if specified email is free
  *
  * @param User $user
  * @param string $email
  *
  * @return boolean
  */
 public function isEmailFree(User $user, $email)
 {
     return $this->createQuery('SELECT COUNT(u) FROM ' . User::class . ' u WHERE u.id != ?0 AND u.email = ?1')->setParameters([(string) $user->getId(), $email])->getSingleScalarResult() == 0;
 }
示例#6
0
 /**
  * @param User $user
  * @return array Vychozi hodnoty pro formular
  */
 protected function getDefaults($user)
 {
     $result = [];
     $result['id'] = $user->getId();
     $result['user']['login'] = $user->getLogin();
     $result['user']['role'] = $user->getRole();
     $person = $user->person;
     if ($person) {
         $result['person']['name'] = $person->name;
         $result['person']['surname'] = $person->surname;
     }
     return $result;
 }
示例#7
0
 public function getPaymentsDatasource(User $u = null)
 {
     $model = $this->paymentDao->createQueryBuilder('pa');
     if ($u !== null) {
         $model->where("pa.owner = :id")->setParameter("id", $u->getId());
     }
     return new Doctrine($model);
 }