/** * @author Sebastien Piraux <*****@*****.**> old code * @author Julio Montoya 2013 * @desc Record information for login event when an user identifies himself with username & password */ function event_login(\Entity\User $user) { $userId = $user->getUserId(); $TABLETRACK_LOGIN = Database::get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN); $reallyNow = api_get_utc_datetime(); $sql = "INSERT INTO " . $TABLETRACK_LOGIN . " (login_user_id, login_ip, login_date, logout_date) VALUES\n ('" . $userId . "',\n \t\t'" . Database::escape_string(api_get_real_ip()) . "',\n \t\t'" . $reallyNow . "',\n \t\t'" . $reallyNow . "'\n \t\t)"; Database::query($sql); $roles = $user->getRolesObj(); // auto subscribe /** @var \Entity\Role $role */ foreach ($roles as $role) { $role = $role->getRole(); $userStatusParsed = 'student'; switch ($role) { case 'ROLE_SESSION_MANAGER': $userStatusParsed = 'sessionadmin'; break; case 'ROLE_TEACHER': $userStatusParsed = 'teacher'; break; case 'ROLE_RRHH': $userStatusParsed = 'DRH'; break; } $autoSubscribe = api_get_setting($userStatusParsed . '_autosubscribe'); if ($autoSubscribe) { $autoSubscribe = explode('|', $autoSubscribe); foreach ($autoSubscribe as $code) { if (CourseManager::course_exists($code)) { CourseManager::subscribe_user($userId, $code); } } } } }
/** * * @param \Entity\User $user */ public function delete($user) { $sql = 'delete from user WHERE user_id=:id'; $stmt = $this->db->getConnection()->prepare($sql); $stmt->bindParam('id', $user->getUserId()); return $stmt->execute(); }
public function transform(\Entity\User $user) { return ['id' => (int) $user->getUserId(), 'email' => $user->getEmail(), 'name' => $user->getName(), 'active' => $user->getActive(), 'group' => $user->getGroup(), 'links' => ['rel' => 'self', 'uri' => \Util\SlimUtil::absoluteUrlFor('user_by_id', ['id' => $user->getUserId()]), 'method' => 'GET']]; }
/** * Get all users that are registered in the course. No matter the status * * @param \Entity\CurriculumItem $course * @return bool */ public function isAllowToInsert(\Entity\CurriculumItem $item, \Entity\User $user) { $max = $item->getMaxRepeat(); $count = $this->createQueryBuilder('a')->select('COUNT(a)')->where('a.itemId = :itemId')->andWhere('a.userId = :userId')->setParameters(array('itemId' => $item->getId(), 'userId' => $user->getUserId()))->getQuery()->getSingleScalarResult(); return $count <= $max ? true : false; }
/** * Get course user relationship based in the course_rel_user table. * @return array */ public function getCourses(User $user) { $queryBuilder = $this->createQueryBuilder('user'); // Selecting course info. $queryBuilder->select('c'); // Loading User. //$qb->from('Entity\User', 'u'); // Selecting course $queryBuilder->innerJoin('Entity\\Course', 'c'); //@todo check app settings //$qb->add('orderBy', 'u.lastname ASC'); $wherePart = $queryBuilder->expr()->andx(); // Get only users subscribed to this course $wherePart->add($queryBuilder->expr()->eq('user.userId', $user->getUserId())); $queryBuilder->where($wherePart); $query = $queryBuilder->getQuery(); return $query->execute(); }