diff --git a/assets/css/scss/atoms/_buttons.scss b/assets/css/scss/atoms/_buttons.scss index 37573a68a0..ff2c33e4f4 100644 --- a/assets/css/scss/atoms/_buttons.scss +++ b/assets/css/scss/atoms/_buttons.scss @@ -40,11 +40,11 @@ } &--plain { - @apply bg-gray-90 text-white; + @apply bg-gray-30 text-white mr-1.5; &:hover, &:focus { - @apply bg-black; + @apply bg-gray-90; } } diff --git a/public/main/course_progress/index.php b/public/main/course_progress/index.php index 831b93c1ae..d03d1f8be6 100644 --- a/public/main/course_progress/index.php +++ b/public/main/course_progress/index.php @@ -595,25 +595,9 @@ switch ($action) { ['class' => 'btn btn--plain'] ); if (0 == api_get_session_id()) { - if ($thematic->getDisplayOrder() > 1) { - $toolbarThematic .= ' '. - Display::getMdiIcon(ActionIcon::UP, 'ch-tool-icon', null, ICON_SIZE_TINY, get_lang('Up')).''; - } else { - $toolbarThematic .= '
'. - Display::getMdiIcon(ActionIcon::UP, 'ch-tool-icon-disabled', null, ICON_SIZE_TINY, get_lang('Up')).'
'; - } - //$thematic->getDisplayOrder() - if ($thematic->getDisplayOrder() < $max_thematic_item) { - $toolbarThematic .= ' '. - Display::getMdiIcon(ActionIcon::DOWN, 'ch-tool-icon', null, ICON_SIZE_TINY, get_lang('Down')).''; - } else { - $toolbarThematic .= '
'. - Display::getMdiIcon(ActionIcon::DOWN, 'ch-tool-icon-disabled', null, ICON_SIZE_TINY, get_lang('Down')).'
'; - } + $currentOrder = $thematic->getResourceNode()->getDisplayOrder(); + $moveButtons = $thematicManager->getMoveActions($id, $currentOrder, count($thematic_data)); + $toolbarThematic .= $moveButtons; } if (true) { @@ -1232,6 +1216,7 @@ switch ($action) { } break; case 'thematic_advance_list': + $interbreadcrumb[] = ['url' => '#', 'name' => get_lang('Thematic advance').' ('.$cleanThematicTitle.')']; // thematic advance list diff --git a/public/main/inc/lib/thematic.lib.php b/public/main/inc/lib/thematic.lib.php index d3d1346b67..3ab187c701 100644 --- a/public/main/inc/lib/thematic.lib.php +++ b/public/main/inc/lib/thematic.lib.php @@ -65,233 +65,73 @@ class Thematic } /** - * Get the thematics to display on the current page (fill the sortable-table). - * - * @param int offset of first user to recover - * @param int Number of users to get - * @param int Column to sort on - * @param string Order (ASC,DESC) - * - * @return array - * - * @see SortableTable#get_table_data($from) + * Moves a thematic item up or down in the list by adjusting its display order in the associated resource node. */ - public function get_thematic_data($from, $number_of_items, $column, $direction) + public function moveThematic(string $direction, int $thematicId, Course $course, ?Session $session = null): bool { - $column = (int) $column; - $from = (int) $from; - $number_of_items = (int) $number_of_items; + $em = Database::getManager(); + $thematicRepo = $em->getRepository(CThematic::class); - if (!in_array($direction, ['ASC', 'DESC'])) { - $direction = 'ASC'; + $thematic = $thematicRepo->find($thematicId); + if (null === $thematic) { + return false; } - /* - $course = api_get_course_entity(); - $session = api_get_session_entity(); - $sql = "SELECT id AS col0, title AS col1, display_order AS col2, session_id - FROM $tbl_thematic - WHERE c_id = $course_id AND active = 1 $condition_session - ORDER BY col2 - LIMIT $from,$number_of_items "; - $res = Database::query($sql); + $resourceNode = $thematic->getResourceNode(); + if (null === $resourceNode) { + return false; + } - $thematics = []; - $user_info = api_get_user_info(api_get_user_id()); - while ($thematic = Database::fetch_row($res)) { - $session_star = ''; - if (api_get_session_id() == $thematic[3]) { - $session_star = api_get_session_image(api_get_session_id(), $user_info['status']); - } - $thematic[1] = ''. - Security::remove_XSS($thematic[1], STUDENT).$session_star.''; - if (api_is_allowed_to_edit(null, true)) { - $actions = ''; + $currentDisplayOrder = $resourceNode->getDisplayOrder(); - if (api_get_session_id()) { - if (api_get_session_id() == $thematic[3]) { - $actions .= ''. - Display::getMdiIcon(ToolIcon::COURSE_PROGRESS_PLAN, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Thematic plan')).' '; - $actions .= ''. - Display::getMdiIcon(ToolIcon::COURSE_PROGRESS_SCHEDULE, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Thematic advance')).' '; - - $actions .= ''. - Display::getMdiIcon(ActionIcon::EDIT, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Edit')).''; - $actions .= ''. - Display::getMdiIcon(ActionIcon::DELETE, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Delete')).''; - } else { - $actions .= Display::getMdiIcon(ToolIcon::COURSE_PROGRESS_PLAN, 'ch-tool-icon-disabled', null, ICON_SIZE_SMALL, get_lang('Thematic plan')).' '; - $actions .= Display::getMdiIcon(ToolIcon::COURSE_PROGRESS_SCHEDULE, 'ch-tool-icon-disabled', null, ICON_SIZE_SMALL, get_lang('Thematic advance')).' '; - $actions .= Display::getMdiIcon(ActionIcon::EDIT, 'ch-tool-icon-disabled', null, ICON_SIZE_SMALL, get_lang('Edit')); - $actions .= Display::getMdiIcon(ActionIcon::DELETE, 'ch-tool-icon-disabled', null, ICON_SIZE_SMALL, get_lang('Delete')).' '; - $actions .= Display::url( - Display::getMdiIcon(ActionIcon::COPY_CONTENT, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Copy')), - 'index.php?'.api_get_cidreq().'&action=thematic_copy&thematic_id='.$thematic[0] - ); - } - } else { - $actions .= ''. - Display::getMdiIcon(ToolIcon::COURSE_PROGRESS_PLAN, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Thematic plan')).' '; - $actions .= ''. - Display::getMdiIcon(ToolIcon::COURSE_PROGRESS_SCHEDULE, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Thematic advance')).' '; - - if ($thematic[2] > 1) { - $actions .= ''. - Display::getMdiIcon(ActionIcon::UP, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Up')).''; - } else { - $actions .= Display::getMdiIcon(ActionIcon::UP, 'ch-tool-icon-disabled', null, ICON_SIZE_SMALL); - } - /*if ($thematic[2] < self::get_max_thematic_item()) { - $actions .= ''. - Display::getMdiIcon(ActionIcon::DOWN, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('down')).''; - } else { - $actions .= Display::getMdiIcon(ActionIcon::DOWN, 'ch-tool-icon-disabled', null, ICON_SIZE_SMALL); - } - $actions .= ''. - Display::getMdiIcon(ActionIcon::EDIT, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Edit')).''; - $actions .= ''. - Display::getMdiIcon(ActionIcon::DELETE, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Delete')).''; - } - $thematics[] = [$thematic[0], $thematic[1], $actions]; - } - }*/ + $newPosition = $currentDisplayOrder + ($direction === 'down' ? 1 : -1); + $newPosition = max(0, $newPosition); - //return $thematics; - } + $resourceNode->setDisplayOrder($newPosition); + $em->flush(); - /** - * Get the maximum display order of the thematic item. - * - * @return int Maximum display order - */ - public function get_max_thematic_item(Course $course, Session $session = null) - { - // Database table definition - /*$tbl_thematic = Database::get_course_table(TABLE_THEMATIC); - $session_id = api_get_session_id(); - if ($use_session) { - $condition_session = api_get_session_condition($session_id); - } else { - $condition_session = ''; - } - $course_id = api_get_course_int_id(); - $sql = "SELECT MAX(display_order) - FROM $tbl_thematic - WHERE c_id = $course_id AND active = 1 $condition_session"; - $rs = Database::query($sql); - $row = Database::fetch_array($rs); + // update done advances with de current thematic list + $last_done_thematic_advance = $this->get_last_done_thematic_advance($course, $session); + $this->updateDoneThematicAdvance($last_done_thematic_advance, $course, $session); - return $row[0];*/ + return true; } /** - * Move a thematic. + * Get thematic list. * - * @param string $direction (up, down) - * @param int $thematic_id + * @return CThematic[] */ - public function moveThematic($direction, $thematic_id, $course, $session = null) + public static function getThematicList(Course $course, Session $session = null): array { - // Database table definition - $tbl_thematic = Database::get_course_table(TABLE_THEMATIC); - - // sort direction - if ('up' === $direction) { - $sortorder = 'DESC'; - } else { - $sortorder = 'ASC'; - } - $course_id = api_get_course_int_id(); - $session_id = api_get_session_id(); - $condition_session = api_get_session_condition($session_id); - - $sql = "SELECT id, display_order - FROM $tbl_thematic - WHERE c_id = $course_id AND active = 1 $condition_session - ORDER BY display_order $sortorder"; - $res = Database::query($sql); - $found = false; - - // Variable definition - $current_id = 0; - $next_id = 0; - while ($row = Database::fetch_array($res)) { - if ($found && empty($next_id)) { - $next_id = intval($row['id']); - $next_display_order = intval($row['display_order']); - } - - if ($row['id'] == $thematic_id) { - $current_id = intval($thematic_id); - $current_display_order = intval($row['display_order']); - $found = true; - } - } - - // get last done thematic advance before move thematic list - $last_done_thematic_advance = $this->get_last_done_thematic_advance($course, $session); - - if (!empty($next_display_order) && !empty($current_id)) { - $sql = "UPDATE $tbl_thematic SET display_order = $next_display_order - WHERE c_id = $course_id AND id = $current_id "; - Database::query($sql); - } - if (!empty($current_display_order) && !empty($next_id)) { - $sql = "UPDATE $tbl_thematic SET - display_order = $current_display_order - WHERE c_id = $course_id AND id = $next_id "; - Database::query($sql); - } + $repo = Container::getThematicRepository(); + $qb = $repo->getResourcesByCourse($course, $session, null, null, true, true); + $qb->andWhere('resource.active = 1'); - // update done advances with de current thematic list - $this->updateDoneThematicAdvance($last_done_thematic_advance, $course, $session); + return $qb->getQuery()->getResult(); } /** - * Get thematic list. - * - * @return CThematic[] + * Generates HTML for move up and move down action buttons for a thematic item. */ - public static function getThematicList(Course $course, Session $session = null) + public function getMoveActions(int $thematicId, int $currentOrder, int $maxOrder): string { - // set current course and session - /*$tbl_thematic = Database::get_course_table(TABLE_THEMATIC); - $course_info = api_get_course_info($course_code); - $course_id = $course_info['real_id']; + $toolbarThematic = ''; + $params = '&thematic_id=' . $thematicId . '&sec_token=' . Security::get_token(); - if (!empty($session_id)) { - $session_id = (int) $session_id; + if ($currentOrder > 0) { + $toolbarThematic .= '' . Display::getMdiIcon(ActionIcon::UP, 'ch-tool-icon', null, ICON_SIZE_TINY, get_lang('Up')) . ''; } else { - $session_id = api_get_session_id(); + $toolbarThematic .= '
' . Display::getMdiIcon(ActionIcon::UP, 'ch-tool-icon-disabled', null, ICON_SIZE_TINY, '') . '
'; } - $data = []; - if (empty($session_id)) { - $condition_session = api_get_session_condition(0); + if ($currentOrder < $maxOrder - 1) { + $toolbarThematic .= '' . Display::getMdiIcon(ActionIcon::DOWN, 'ch-tool-icon', null, ICON_SIZE_TINY, get_lang('Down')) . ''; } else { - $condition_session = api_get_session_condition($session_id, true, true); - } - $condition = " WHERE active = 1 $condition_session ";*/ - - $repo = Container::getThematicRepository(); - $qb = $repo->getResourcesByCourse($course, $session); - $qb->andWhere('resource.active = 1'); - - return $qb->getQuery()->getResult(); - - /*$sql = "SELECT * - FROM $tbl_thematic $condition AND c_id = $course_id - ORDER BY display_order "; - - $res = Database::query($sql); - if (Database::num_rows($res) > 0) { - while ($row = Database::fetch_array($res, 'ASSOC')) { - $entity = $repo->find($row['iid']); - $data[$row['iid']] = $entity; - } + $toolbarThematic .= '
' . Display::getMdiIcon(ActionIcon::DOWN, 'ch-tool-icon-disabled', null, ICON_SIZE_TINY, '') . '
'; } - return $data;*/ + return $toolbarThematic; } /**