';
- $html .= '
param_prefix.'selectall=1"
onclick="javascript: setCheckbox(true, \''.$table_id.'\'); return false;">'.get_lang('Select all').'';
- $html .= '
'.get_lang('UnSelect all').' ';
$html .= '
-
';
$html .= '';
@@ -881,7 +881,7 @@ class SortableTable extends HTML_Table
* @param string $label The label
* @param bool $sortable Is the table sortable by this column? (defatult
* = true)
- * @param string $th_attributes Additional attributes for the th-tag of the
+ * @param array $th_attributes Additional attributes for the th-tag of the
* table header
* @param string $td_attributes Additional attributes for the td-tags of the
* column
diff --git a/public/main/inc/lib/thematic.lib.php b/public/main/inc/lib/thematic.lib.php
index 399852ce72..4cd8551031 100644
--- a/public/main/inc/lib/thematic.lib.php
+++ b/public/main/inc/lib/thematic.lib.php
@@ -654,20 +654,20 @@ class Thematic
public function getThematicAdvance($id)
{
$repo = Container::getThematicAdvanceRepository();
-
+ /*
$courseEntity = api_get_course_entity($courseId);
$sessionEntity = null;
if ($sessionId) {
$sessionEntity = api_get_session_entity($sessionId);
- /*$list = api_get_item_property_by_tool(
+ $list = api_get_item_property_by_tool(
'thematic_advance',
$course_info['code'],
api_get_session_id()
);
foreach ($list as $value) {
$elements[$value['ref']] = $value;
- }*/
- }
+ }
+ }*/
return $repo->find($id);
}
diff --git a/public/main/inc/lib/usergroup.lib.php b/public/main/inc/lib/usergroup.lib.php
index c7e4b1c124..a45daac96c 100644
--- a/public/main/inc/lib/usergroup.lib.php
+++ b/public/main/inc/lib/usergroup.lib.php
@@ -1,4 +1,5 @@
usergroup_rel_user_table u
- INNER JOIN $this->access_url_rel_user a
+ INNER JOIN $this->access_url_rel_user a
ON (u.user_id = a.user_id)
WHERE u.usergroup_id = $id AND access_url_id = $urlId ";
} else {
@@ -212,7 +213,7 @@ class UserGroup extends Model
if ($this->getUseMultipleUrl()) {
$urlId = api_get_current_access_url_id();
- $sql = "SELECT count(u.id) as count
+ $sql = "SELECT count(u.id) as count
FROM $this->table u
INNER JOIN $this->access_url_rel_usergroup a
ON (u.id = a.usergroup_id)
@@ -459,7 +460,7 @@ class UserGroup extends Model
ON (a.usergroup_id = u.id)
";
} else {
- $sql = "SELECT $select
+ $sql = "SELECT $select
FROM {$this->usergroup_rel_course_table} usergroup
INNER JOIN {$this->table} u
ON (u.id = usergroup.usergroup_id)
@@ -586,7 +587,7 @@ class UserGroup extends Model
],
],
];
- $from = " $this->usergroup_rel_course_table as c
+ $from = " $this->usergroup_rel_course_table as c
INNER JOIN $this->access_url_rel_usergroup a
ON c.usergroup_id = a.usergroup_id ";
} else {
@@ -792,7 +793,7 @@ class UserGroup extends Model
if ($this->getUseMultipleUrl()) {
$urlId = api_get_current_access_url_id();
$from = $this->usergroup_rel_user_table." u
- INNER JOIN {$this->access_url_rel_usergroup} a
+ INNER JOIN {$this->access_url_rel_usergroup} a
ON (a.usergroup_id = u.usergroup_id) ";
$where = ['where' => ['user_id = ? AND access_url_id = ? ' => [$userId, $urlId]]];
} else {
@@ -1093,7 +1094,7 @@ class UserGroup extends Model
if ($this->getUseMultipleUrl()) {
$urlId = api_get_current_access_url_id();
$sql = "SELECT * FROM $this->table u
- INNER JOIN {$this->access_url_rel_usergroup} a
+ INNER JOIN {$this->access_url_rel_usergroup} a
ON (a.usergroup_id = u.id)
WHERE name = '".$name."' AND access_url_id = $urlId";
} else {
@@ -1203,7 +1204,7 @@ class UserGroup extends Model
{
if ($this->getUseMultipleUrl()) {
$urlId = api_get_current_access_url_id();
- $from = $this->table." u
+ $from = $this->table." u
INNER JOIN {$this->access_url_rel_usergroup} a
ON (u.id = a.usergroup_id)";
$options = ['where' => ['access_url_id = ? ' => $urlId]];
@@ -1359,34 +1360,31 @@ class UserGroup extends Model
return false;
}
- /**
- * {@inheritdoc}
- */
- public function update($values, $showQuery = false)
+ public function update($params, $showQuery = false)
{
- $values['updated_on'] = api_get_utc_datetime();
- $values['group_type'] = isset($values['group_type']) ? self::SOCIAL_CLASS : self::NORMAL_CLASS;
- $values['allow_members_leave_group'] = isset($values['allow_members_leave_group']) ? 1 : 0;
- $values['crop_image'] = isset($values['picture_crop_result']) ? $values['picture_crop_result'] : null;
+ $params['updated_on'] = api_get_utc_datetime();
+ $params['group_type'] = isset($params['group_type']) ? self::SOCIAL_CLASS : self::NORMAL_CLASS;
+ $params['allow_members_leave_group'] = isset($params['allow_members_leave_group']) ? 1 : 0;
+ $params['crop_image'] = isset($params['picture_crop_result']) ? $params['picture_crop_result'] : null;
- if (isset($values['id'])) {
+ if (isset($params['id'])) {
$picture = isset($_FILES['picture']) ? $_FILES['picture'] : null;
if (!empty($picture)) {
- $picture = $this->manageFileUpload($values['id'], $picture, $values['crop_image']);
+ $picture = $this->manageFileUpload($params['id'], $picture, $params['crop_image']);
if ($picture) {
- $values['picture'] = $picture;
+ $params['picture'] = $picture;
}
}
- if (isset($values['delete_picture'])) {
- $values['picture'] = null;
+ if (isset($params['delete_picture'])) {
+ $params['picture'] = null;
}
}
- parent::update($values, $showQuery);
+ parent::update($params, $showQuery);
- if (isset($values['delete_picture'])) {
- $this->delete_group_picture($values['id']);
+ if (isset($params['delete_picture'])) {
+ $this->delete_group_picture($params['id']);
}
return true;
@@ -1588,7 +1586,7 @@ class UserGroup extends Model
$needle = api_convert_encoding($needle, $charset, 'utf-8');
$needle = Database::escape_string($needle);
- $sql = 'SELECT id, name
+ $sql = 'SELECT id, name
FROM '.Database::get_main_table(TABLE_USERGROUP).' u
WHERE name LIKE "'.$needle.'%"
ORDER BY name
@@ -1717,7 +1715,7 @@ class UserGroup extends Model
* @param string $id group id
* @param string picture group name
* @param string height
- * @param string $size_picture picture size it can be small_, medium_ or big_
+ * @param int $size_picture picture size it can be small_, medium_ or big_
* @param string style css
*
* @return array with the file and the style of an image i.e $array['file'] $array['style']
@@ -1885,9 +1883,9 @@ class UserGroup extends Model
$user_role = $this->get_user_group_role($user_id, $group_id);
if (in_array($user_role, [GROUP_USER_PERMISSION_ADMIN])) {
return true;
- } else {
- return false;
}
+
+ return false;
}
/**
@@ -1955,7 +1953,7 @@ class UserGroup extends Model
$group_id = (int) $group_id;
if (!empty($user_id) && !empty($group_id)) {
- $sql = "SELECT relation_type
+ $sql = "SELECT relation_type
FROM $table_group_rel_user
WHERE
usergroup_id = $group_id AND
@@ -2134,7 +2132,7 @@ class UserGroup extends Model
/**
* Gets the inner join from users and group table.
*
- * @return array Database::store_result of the result
+ * @return array|int Database::store_result of the result
*
* @author Julio Montoya
* */
@@ -2219,9 +2217,9 @@ class UserGroup extends Model
$num = (int) $num;
}
// only show admins and readers
- $whereCondition = " WHERE
+ $whereCondition = " WHERE
g.group_type = ".self::SOCIAL_CLASS." AND
- gu.relation_type IN
+ gu.relation_type IN
('".GROUP_USER_PERMISSION_ADMIN."' , '".GROUP_USER_PERMISSION_READER."', '".GROUP_USER_PERMISSION_HRM."') ";
$sql = 'SELECT DISTINCT count(user_id) as count, g.picture, g.name, g.description, g.id ';
@@ -2284,13 +2282,13 @@ class UserGroup extends Model
$num = (int) $num;
}
- $where = " WHERE
+ $where = " WHERE
g.group_type = ".self::SOCIAL_CLASS." AND
- gu.relation_type IN
- ('".GROUP_USER_PERMISSION_ADMIN."' ,
+ gu.relation_type IN
+ ('".GROUP_USER_PERMISSION_ADMIN."' ,
'".GROUP_USER_PERMISSION_READER."',
- '".GROUP_USER_PERMISSION_MODERATOR."',
- '".GROUP_USER_PERMISSION_HRM."')
+ '".GROUP_USER_PERMISSION_MODERATOR."',
+ '".GROUP_USER_PERMISSION_HRM."')
";
$sql = 'SELECT DISTINCT
count(user_id) as count,
@@ -2571,7 +2569,7 @@ class UserGroup extends Model
/**
* @param string $user_id
- * @param string $relation_type
+ * @param int $relation_type
* @param bool $with_image
*
* @deprecated
@@ -2585,12 +2583,12 @@ class UserGroup extends Model
) {
$table_group_rel_user = $this->usergroup_rel_user_table;
$tbl_group = $this->table;
- $user_id = intval($user_id);
+ $user_id = (int) $user_id;
if (0 == $relation_type) {
$where_relation_condition = '';
} else {
- $relation_type = intval($relation_type);
+ $relation_type = (int) $relation_type;
$where_relation_condition = "AND gu.relation_type = $relation_type ";
}
@@ -2642,7 +2640,7 @@ class UserGroup extends Model
g.name LIKE '%".$keyword."%' OR
g.description LIKE '%".$keyword."%' OR
g.url LIKE '%".$keyword."%'
- ) $urlCondition
+ ) $urlCondition
";
} else {
$sql .= " WHERE 1 = 1 $urlCondition ";
@@ -2690,11 +2688,11 @@ class UserGroup extends Model
$select_part .= "rg$rg_number.group_id as id_$rg_number, ";
}
if (1 == $i) {
- $cond_part .= "FROM $t_rel_group rg0
- LEFT JOIN $t_rel_group rg$i
+ $cond_part .= "FROM $t_rel_group rg0
+ LEFT JOIN $t_rel_group rg$i
ON rg$rg_number.group_id = rg$i.subgroup_id ";
} else {
- $cond_part .= " LEFT JOIN $t_rel_group rg$i
+ $cond_part .= " LEFT JOIN $t_rel_group rg$i
ON rg$rg_number.group_id = rg$i.subgroup_id ";
}
}
@@ -2793,7 +2791,7 @@ class UserGroup extends Model
$select .= $i != $levels ? ', ' : null;
if (1 == $i) {
- $from .= " INNER JOIN $groupRelGroupTable gg0
+ $from .= " INNER JOIN $groupRelGroupTable gg0
ON g1.id = gg0.subgroup_id and gg0.group_id = $groupId ";
} else {
$from .= "LEFT JOIN $groupRelGroupTable gg$tableIndexJoinNumber ";
diff --git a/public/main/inc/lib/webservices/Rest.php b/public/main/inc/lib/webservices/Rest.php
index e95b050931..6286ba93fe 100644
--- a/public/main/inc/lib/webservices/Rest.php
+++ b/public/main/inc/lib/webservices/Rest.php
@@ -153,9 +153,7 @@ class Rest extends WebService
return;
}
- $em = Database::getManager();
- /** @var Course $course */
- $course = $em->find('ChamiloCoreBundle:Course', $id);
+ $course = api_get_course_entity($id);
if (!$course) {
throw new Exception(get_lang('NoCourse'));
@@ -179,9 +177,7 @@ class Rest extends WebService
return;
}
- $em = Database::getManager();
- /** @var Session $session */
- $session = $em->find('ChamiloCoreBundle:Session', $id);
+ $session = api_get_session_entity( $id);
if (!$session) {
throw new Exception(get_lang('NoSession'));
@@ -325,8 +321,7 @@ class Rest extends WebService
$data = [];
foreach ($courses as $courseInfo) {
- /** @var Course $course */
- $course = Database::getManager()->find('ChamiloCoreBundle:Course', $courseInfo['real_id']);
+ $course = api_get_course_entity($courseInfo['real_id']);
$teachers = CourseManager::getTeacherListFromCourseCodeToString($course->getCode());
$picturePath = CourseManager::getPicturePath($course, true)
?: Display::return_icon('session_default.png', null, null, null, null, true);
diff --git a/public/main/portfolio/index.php b/public/main/portfolio/index.php
index 0639124427..7a444646c2 100644
--- a/public/main/portfolio/index.php
+++ b/public/main/portfolio/index.php
@@ -24,12 +24,9 @@ $em = Database::getManager();
$currentUserId = api_get_user_id();
$userId = isset($_GET['user']) ? (int) $_GET['user'] : $currentUserId;
-/** @var User $user */
$user = api_get_user_entity($userId);
-/** @var Course $course */
-$course = $em->find('ChamiloCoreBundle:Course', api_get_course_int_id());
-/** @var Session $session */
-$session = $em->find('ChamiloCoreBundle:Session', api_get_session_id());
+$course = api_get_course_entity( api_get_course_int_id());
+$session = api_get_session_entity(api_get_session_id());
$action = isset($_GET['action']) ? $_GET['action'] : 'list';
$cidreq = api_get_cidreq();
diff --git a/public/main/session/index.php b/public/main/session/index.php
index b52a7ef6e1..4c346a3633 100644
--- a/public/main/session/index.php
+++ b/public/main/session/index.php
@@ -189,7 +189,7 @@ if (false == api_is_coach_of_course_in_session($session_id)) {
}
$entityManager = Database::getManager();
-$session = $entityManager->find('ChamiloCoreBundle:Session', $session_id);
+$session = api_get_session_entity($session_id);
$sessionTitleLink = api_get_configuration_value('courses_list_session_title_link');
if (2 == $sessionTitleLink && 1 === $session->getNbrCourses()) {
diff --git a/public/main/session/session_course_user.php b/public/main/session/session_course_user.php
index 1a3157e2c5..679f599196 100644
--- a/public/main/session/session_course_user.php
+++ b/public/main/session/session_course_user.php
@@ -58,8 +58,7 @@ if ($form->validate()) {
}
foreach ($values['courses_to_avoid'] as $courseId) {
- /** @var Course $course */
- $course = $em->find('ChamiloCoreBundle:Course', $courseId);
+ $course = api_get_course_entity($courseId);
if (!$session->getUserInCourse($user, $course)->count()) {
continue;
@@ -71,8 +70,7 @@ if ($form->validate()) {
$coursesToResubscribe = array_diff($avoidedCourseIds, $values['courses_to_avoid']);
foreach ($coursesToResubscribe as $courseId) {
- /** @var Course $course */
- $course = $em->find('ChamiloCoreBundle:Course', $courseId);
+ $course = api_get_course_entity($courseId);
if ($session->getUserInCourse($user, $course)->count()) {
continue;
diff --git a/public/main/survey/pending.php b/public/main/survey/pending.php
index bdfd4d47e6..79b9959387 100644
--- a/public/main/survey/pending.php
+++ b/public/main/survey/pending.php
@@ -30,10 +30,8 @@ foreach ($pending as $i => $item) {
$survey = $item;
/** @var CSurveyInvitation invitation */
$invitation = $pending[$i + 1];
- /** @var Course $course */
- $course = $em->find('ChamiloCoreBundle:Course', $survey->getCId());
- /** @var Session $session */
- $session = $em->find('ChamiloCoreBundle:Session', $survey->getSessionId());
+ $course = api_get_course_entity($survey->getCId());
+ $session = api_get_session_entity( $survey->getSessionId());
$course = $course ? ['id' => $course->getId(), 'title' => $course->getTitle(), 'code' => $course->getCode()] : null;
$session = $session ? ['id' => $session->getId(), 'name' => $session->getName()] : null;
diff --git a/public/plugin/bbb/lib/bbb.lib.php b/public/plugin/bbb/lib/bbb.lib.php
index d80f251fc7..72870774db 100644
--- a/public/plugin/bbb/lib/bbb.lib.php
+++ b/public/plugin/bbb/lib/bbb.lib.php
@@ -1147,8 +1147,8 @@ class bbb
}
$item = array_merge($item, $meetingDB, $meetingBBB);
- $item['course'] = $em->find('ChamiloCoreBundle:Course', $item['c_id']);
- $item['session'] = $em->find('ChamiloCoreBundle:Session', $item['session_id']);
+ $item['course'] = api_get_course_entity($item['c_id']);
+ $item['session'] = api_get_session_entity($item['session_id']);
$newMeetingList[] = $item;
}
diff --git a/src/CoreBundle/Entity/Session.php b/src/CoreBundle/Entity/Session.php
index 412f285284..ce8ada976e 100644
--- a/src/CoreBundle/Entity/Session.php
+++ b/src/CoreBundle/Entity/Session.php
@@ -495,6 +495,21 @@ class Session
return false;
}
+ /**
+ * Check for existence of a relation (SessionRelCourse) between a course and this session.
+ *
+ * @return bool whether the course is related to this session
+ */
+ public function isRelatedToCourse(Course $course): bool
+ {
+ return !is_null(
+ \Database::getManager()->getRepository(SessionRelCourse::class)->findOneBy([
+ 'session' => $this,
+ 'course' => $course,
+ ])
+ );
+ }
+
/**
* Remove $course.
*
@@ -980,6 +995,24 @@ class Session
return $this->compareDates($start, $end);
}
+ /**
+ * Compare the current date with start and end access dates.
+ * Either missing date is interpreted as no limit.
+ *
+ * @return bool whether now is between the session access start and end dates
+ */
+ public function isCurrentlyAccessible()
+ {
+ try {
+ $now = new \Datetime();
+ } catch (\Exception $exception) {
+ return false;
+ }
+
+ return (is_null($this->accessStartDate) || $this->accessStartDate < $now)
+ && (is_null($this->accessEndDate) || $now < $this->accessEndDate);
+ }
+
public function addCourse(Course $course)
{
$entity = new SessionRelCourse();
@@ -987,6 +1020,26 @@ class Session
$this->addCourses($entity);
}
+ /**
+ * Removes a course from this session.
+ *
+ * @param Course $course the course to remove from this session
+ *
+ * @return bool whether the course was actually found in this session and removed from it
+ */
+ public function removeCourse(Course $course)
+ {
+ $relCourse = $this->getCourseSubscription($course);
+ if ($relCourse) {
+ $this->courses->removeElement($relCourse);
+ $this->setNbrCourses(count($this->courses));
+
+ return true;
+ }
+
+ return false;
+ }
+
/**
* @return ArrayCollection
*/
diff --git a/src/CoreBundle/Entity/User.php b/src/CoreBundle/Entity/User.php
index a245cd11a1..49551a283c 100644
--- a/src/CoreBundle/Entity/User.php
+++ b/src/CoreBundle/Entity/User.php
@@ -2217,4 +2217,64 @@ class User implements UserInterface, EquatableInterface
return $this->courseGroupsAsTutor->matching($criteria);
}
+
+
+ /**
+ * Retreives this user's related sessions.
+ *
+ * @param int $relationType \Chamilo\CoreBundle\Entity\SessionRelUser::relationTypeList key
+ *
+ * @return Session[]
+ */
+ public function getSessions($relationType)
+ {
+ $sessions = [];
+ foreach ($this->sessions as $sessionRelUser) {
+ if ($sessionRelUser->getRelationType() == $relationType) {
+ $sessions[] = $sessionRelUser->getSession();
+ }
+ }
+
+ return $sessions;
+ }
+
+ /**
+ * Retreives this user's related student sessions.
+ *
+ * @return Session[]
+ */
+ public function getStudentSessions()
+ {
+ return $this->getSessions(0);
+ }
+
+ /**
+ * Retreives this user's related DRH sessions.
+ *
+ * @return Session[]
+ */
+ public function getDRHSessions()
+ {
+ return $this->getSessions(1);
+ }
+
+ /**
+ * Get this user's related accessible sessions of a type, student by default.
+ *
+ * @param int $relationType \Chamilo\CoreBundle\Entity\SessionRelUser::relationTypeList key
+ *
+ * @return Session[]
+ */
+ public function getCurrentlyAccessibleSessions($relationType = 0)
+ {
+ $sessions = [];
+ foreach ($this->getSessions($relationType) as $session) {
+ if ($session->isCurrentlyAccessible()) {
+ $sessions[] = $session;
+ }
+ }
+
+ return $sessions;
+ }
+
}
diff --git a/src/CoreBundle/Framework/Container.php b/src/CoreBundle/Framework/Container.php
index d6cafd24e4..4a4be08bec 100644
--- a/src/CoreBundle/Framework/Container.php
+++ b/src/CoreBundle/Framework/Container.php
@@ -10,6 +10,8 @@ use Chamilo\CoreBundle\Repository\AccessUrlRepository;
use Chamilo\CoreBundle\Repository\CourseCategoryRepository;
use Chamilo\CoreBundle\Repository\CourseRepository;
use Chamilo\CoreBundle\Repository\IllustrationRepository;
+use Chamilo\CoreBundle\Repository\SequenceRepository;
+use Chamilo\CoreBundle\Repository\SequenceResourceRepository;
use Chamilo\CoreBundle\Repository\UserRepository;
use Chamilo\CoreBundle\ToolChain;
use Chamilo\CourseBundle\Repository\CAnnouncementAttachmentRepository;
@@ -519,6 +521,22 @@ class Container
return self::$container->get(CStudentPublicationCommentRepository::class);
}
+ /**
+ * @return SequenceResourceRepository
+ */
+ public static function getSequenceResourceRepository()
+ {
+ return self::$container->get(SequenceResourceRepository::class);
+ }
+
+ /**
+ * @return SequenceRepository
+ */
+ public static function getSequenceRepository()
+ {
+ return self::$container->get(SequenceRepository::class);
+ }
+
public static function getThematicRepository()
{
return self::$container->get(CThematicRepository::class);
diff --git a/src/CoreBundle/Traits/CourseControllerTrait.php b/src/CoreBundle/Traits/CourseControllerTrait.php
index b67fb406a1..6a54fbdd8c 100644
--- a/src/CoreBundle/Traits/CourseControllerTrait.php
+++ b/src/CoreBundle/Traits/CourseControllerTrait.php
@@ -66,7 +66,7 @@ trait CourseControllerTrait
return null;
}
- return $this->getDoctrine()->getManager()->find('ChamiloCoreBundle:Session', $sessionId);
+ return $this->getDoctrine()->getManager()->find(Session::class, $sessionId);
}
public function getGroup()
diff --git a/src/CourseBundle/Entity/CAttendanceCalendar.php b/src/CourseBundle/Entity/CAttendanceCalendar.php
index 4580ce5335..534e6d09b3 100644
--- a/src/CourseBundle/Entity/CAttendanceCalendar.php
+++ b/src/CourseBundle/Entity/CAttendanceCalendar.php
@@ -12,7 +12,6 @@ use Doctrine\ORM\Mapping as ORM;
* @ORM\Table(
* name="c_attendance_calendar",
* indexes={
- * @ORM\Index(name="course", columns={"c_id"}),
* @ORM\Index(name="attendance_id", columns={"attendance_id"}),
* @ORM\Index(name="done_attendance", columns={"done_attendance"})
* }
@@ -30,13 +29,6 @@ class CAttendanceCalendar
*/
protected $iid;
- /**
- * @var int
- *
- * @ORM\Column(name="c_id", type="integer")
- */
- protected $cId;
-
/**
* @var int
*
@@ -129,28 +121,4 @@ class CAttendanceCalendar
{
return $this->doneAttendance;
}
-
- /**
- * Set cId.
- *
- * @param int $cId
- *
- * @return CAttendanceCalendar
- */
- public function setCId($cId)
- {
- $this->cId = $cId;
-
- return $this;
- }
-
- /**
- * Get cId.
- *
- * @return int
- */
- public function getCId()
- {
- return $this->cId;
- }
}