/**
  * Get the last registered access by an user
  * @param \Chamilo\UserBundle\Entity\User $user The user
  * @return \ChamiloCoreBundle\TrackECourseAcess The access if exists.
  *          Otherwise return null
  */
 public function getLastAccessByUser(User $user)
 {
     if (empty($user)) {
         return null;
     }
     $lastAccess = $this->findBy(['userId' => $user->getId()], ['courseAccessId' => 'DESC'], 1);
     if (!empty($lastAccess)) {
         return $lastAccess[0];
     }
     return null;
 }
 /**
  * Get the last acquired skill by a user on course and/or session
  * @param User $user The user
  * @param Course $course The course
  * @param Session $session The session
  * @return Skill
  */
 public function getLastByUser(User $user, Course $course = null, Session $session = null)
 {
     $qb = $this->createQueryBuilder('s');
     $qb->innerJoin('ChamiloCoreBundle:SkillRelUser', 'su', Join::WITH, $qb->expr()->eq('s', 'su.skill'))->where($qb->expr()->eq('su.user', $user->getId()));
     if ($course) {
         $qb->andWhere($qb->expr()->eq('su.course', $course->getId()));
     }
     if ($session) {
         $qb->andWhere($qb->expr()->eq('su.session', $session->getId()));
     }
     $qb->setMaxResults(1)->orderBy('su.id', 'DESC');
     return $qb->getQuery()->getOneOrNullResult();
 }
Esempio n. 3
0
 /**
  * Check if the $fromUser can comment the $toUser skill issue 
  * @param Chamilo\UserBundle\Entity\User $fromUser
  * @param Chamilo\UserBundle\Entity\User $toUser
  * @return boolean
  */
 public static function userCanAddFeedbackToUser(User $fromUser, User $toUser)
 {
     if (api_is_platform_admin()) {
         return true;
     }
     $entityManager = Database::getManager();
     $userRepo = $entityManager->getRepository('ChamiloUserBundle:User');
     $fromUserStatus = $fromUser->getStatus();
     switch ($fromUserStatus) {
         case SESSIONADMIN:
             if (api_get_setting('allow_session_admins_to_manage_all_sessions') === 'true') {
                 if ($toUser->getCreatorId() === $fromUser->getId()) {
                     return true;
                 }
             }
             $sessionAdmins = $userRepo->getSessionAdmins($toUser);
             foreach ($sessionAdmins as $sessionAdmin) {
                 if ($sessionAdmin->getId() !== $fromUser->getId()) {
                     continue;
                 }
                 return true;
             }
             break;
         case STUDENT_BOSS:
             $studentBosses = $userRepo->getStudentBosses($toUser);
             foreach ($studentBosses as $studentBoss) {
                 if ($studentBoss->getId() !== $fromUser->getId()) {
                     continue;
                 }
                 return true;
             }
         case DRH:
             return UserManager::is_user_followed_by_drh($toUser->getId(), $fromUser->getId());
     }
     return false;
 }
Esempio n. 4
0
 /**
  * Get the student bosses for a user
  * @param User $user The user
  * @return array
  */
 public function getStudentBosses(User $user)
 {
     $queryBuilder = $this->createQueryBuilder('u');
     $queryBuilder->distinct()->innerJoin('ChamiloCoreBundle:UserRelUser', 'uu', Join::WITH, $queryBuilder->expr()->eq('u.id', 'uu.friendUserId'))->where($queryBuilder->expr()->eq('uu.relationType', USER_RELATION_TYPE_BOSS))->andWhere($queryBuilder->expr()->eq('uu.userId', $user->getId()));
     return $queryBuilder->getQuery()->getResult();
 }
 /**
  * Get the course template for a user
  * @param Course $course
  * @param User $user
  * @return ArrayCollection
  */
 public function getCourseTemplates(Course $course, User $user)
 {
     $qb = $this->createQueryBuilder('t');
     $qb->select('t', 'd.path')->innerJoin('ChamiloCoreBundle:Course', 'c', Join::WITH, $qb->expr()->eq('t.courseCode', 'c.code'))->innerJoin('ChamiloCourseBundle:CDocument', 'd', Join::WITH, $qb->expr()->eq('c.id', 'd.cId'))->where($qb->expr()->eq('d.iid', 't.refDoc'))->andWhere($qb->expr()->eq('c.id', $course->getId()))->andWhere($qb->expr()->eq('t.userId', $user->getId()));
     return $qb->getQuery()->getResult();
 }
Esempio n. 6
0
 /**
  * @param User $insertUser
  *
  * @return $this
  */
 public function setInsertUser(User $insertUser)
 {
     $this->insertUser = $insertUser;
     $this->lasteditUserId = $insertUser->getId();
     return $this;
 }
Esempio n. 7
0
 /**
  * @param string $attribute
  * @param CGroupInfo $group
  * @param User $user
  * @return bool
  */
 protected function isGranted($attribute, $group, $user = null)
 {
     // make sure there is a user object (i.e. that the user is logged in)
     if (!$user instanceof UserInterface) {
         return false;
     }
     if ($group == false) {
         return false;
     }
     $authChecker = $this->container->get('security.authorization_checker');
     // Admins have access to everything
     if ($authChecker->isGranted('ROLE_ADMIN')) {
         return true;
     }
     $groupInfo = ['id' => $group->getId(), 'session_id' => 0, 'status' => $group->getStatus()];
     // Legacy
     return \GroupManager::userHasAccessToBrowse($user->getId(), $groupInfo);
     switch ($attribute) {
         case self::VIEW:
             if (!$group->hasUserInCourse($user, $course)) {
                 $user->addRole('ROLE_CURRENT_SESSION_COURSE_STUDENT');
                 return true;
             }
             break;
         case self::EDIT:
         case self::DELETE:
             if (!$session->hasCoachInCourseWithStatus($user, $course)) {
                 $user->addRole('ROLE_CURRENT_SESSION_COURSE_TEACHER');
                 return true;
             }
             break;
     }
     dump("You don't have access to this group!!");
     return false;
 }