コード例 #1
0
 /**
  * @param string $entityType
  * @param integer $entityId
  * @param User $user
  * @return bool
  */
 public function unsubscribe(User $user, $entityType, $entityId)
 {
     /** @var $em EntityManager */
     $em = $this->doctrine->getManager();
     $em->createQueryBuilder()->delete('EtuCoreBundle:Subscription', 's')->andWhere('s.entityId = :entityId')->andWhere('s.entityType = :entityType')->andWhere('s.user = :user')->setParameter('entityType', $entityType)->setParameter('entityId', $entityId)->setParameter('user', $user->getId())->getQuery()->execute();
     return true;
 }
コード例 #2
0
ファイル: HomeBuilder.php プロジェクト: ChrisdAutume/EtuUTT
 /**
  * @return User[]
  */
 public function getBirthdays()
 {
     if ($this->stopwatch) {
         $this->stopwatch->start('block_birthdays', 'home_blocks');
     }
     $query = $this->manager->createQueryBuilder()->select('u, m, o')->from('EtuUserBundle:User', 'u')->leftJoin('u.memberships', 'm')->leftJoin('m.organization', 'o')->where('DAY(u.birthday) = DAY(CURRENT_TIMESTAMP())')->andWhere('MONTH(u.birthday) = MONTH(CURRENT_TIMESTAMP())')->andWhere('u.birthday IS NOT NULL')->andWhere('u.birthdayPrivacy = :privacy')->setParameter('privacy', User::PRIVACY_PUBLIC)->andWhere('u.id != :me')->setParameter('me', $this->user->getId())->getQuery();
     $query->useResultCache(true, 3600);
     /** @var User[] $users */
     $users = $query->getResult();
     // Find more interesting birthdays : same promotion (SRT4), same branch (SRT), others
     $usersWeights = [];
     foreach ($users as $key => $user) {
         $usersWeights[$key] = 0;
         if ($user->getBranch() == $this->user->getBranch()) {
             $usersWeights[$key]++;
         }
         if ($user->getNiveau() == $this->user->getNiveau()) {
             $usersWeights[$key]++;
         }
     }
     array_multisort($usersWeights, SORT_DESC, SORT_NUMERIC, $users);
     $result = array_slice($users, 0, 3);
     if ($this->stopwatch) {
         $this->stopwatch->stop('block_birthdays');
     }
     return $result;
 }
コード例 #3
0
 /**
  * @param User $user
  * @return Course[]
  */
 public function getUserNextCourses(User $user)
 {
     /** @var Course[] $todayCourses */
     $todayCourses = $this->createQueryBuilder('c')->where('c.user = :user')->andWhere('c.day = :day')->orderBy('c.start', 'ASC')->setParameter('user', $user->getId())->setParameter('day', Course::getTodayConstant())->getQuery()->getResult();
     $nextCourses = [];
     foreach ($todayCourses as $course) {
         if ($course->getStartAsInt() >= (int) date('Hi') - 15) {
             $nextCourses[$course->getStart()][] = $course;
         }
     }
     return array_slice($nextCourses, 0, 5);
 }
コード例 #4
0
ファイル: Covoit.php プロジェクト: ChrisdAutume/EtuUTT
 /**
  * @param User $user
  * @return bool
  */
 public function hasUser(User $user)
 {
     if ($this->author->getId() == $user->getId()) {
         return true;
     }
     foreach ($this->subscriptions as $subscription) {
         if ($subscription->getUser()->getId() == $user->getId()) {
             return true;
         }
     }
     return false;
 }