Skip to content

Commit

Permalink
Fix double icon in course home see BT#13665
Browse files Browse the repository at this point in the history
  • Loading branch information
jmontoyaa committed Nov 13, 2017
1 parent a6b651f commit 47a4fa8
Showing 1 changed file with 58 additions and 24 deletions.
82 changes: 58 additions & 24 deletions main/inc/lib/course_home.lib.php
Expand Up @@ -489,56 +489,64 @@ public static function get_tools_category(
case TOOL_STUDENT_VIEW:
$conditions = ' WHERE visibility = 1 AND (category = "authoring" OR category = "interaction" OR category = "plugin") ';
if ((api_is_coach() || api_is_course_tutor()) && $_SESSION['studentview'] != 'studentview') {
$conditions = ' WHERE (visibility = 1 AND (category = "authoring" OR category = "interaction" OR category = "plugin") OR (name = "'.TOOL_TRACKING.'") ) ';
$conditions = ' WHERE (
visibility = 1 AND (
category = "authoring" OR
category = "interaction" OR
category = "plugin"
) OR (name = "'.TOOL_TRACKING.'")
)';
}
$sql = "SELECT *
FROM $course_tool_table t
$conditions AND
c_id = $course_id $condition_session
ORDER BY id";
";
$result = Database::query($sql);
break;
case TOOL_AUTHORING:
$sql = "SELECT * FROM $course_tool_table t
WHERE category = 'authoring' AND c_id = $course_id $condition_session
ORDER BY id";
";
$result = Database::query($sql);
break;
case TOOL_INTERACTION:
$sql = "SELECT * FROM $course_tool_table t
WHERE category = 'interaction' AND c_id = $course_id $condition_session
ORDER BY id";
";
$result = Database::query($sql);
break;
case TOOL_ADMIN_VISIBLE:
$sql = "SELECT * FROM $course_tool_table t
WHERE category = 'admin' AND visibility ='1' AND c_id = $course_id $condition_session
ORDER BY id";
";
$result = Database::query($sql);
break;
case TOOL_ADMIN_PLATFORM:
$sql = "SELECT * FROM $course_tool_table t
WHERE category = 'admin' AND c_id = $course_id $condition_session
ORDER BY id";
";
$result = Database::query($sql);
break;
case TOOL_DRH:
$sql = "SELECT * FROM $course_tool_table t
WHERE name IN ('tracking') AND c_id = $course_id $condition_session
ORDER BY id";
";
$result = Database::query($sql);
break;
case TOOL_COURSE_PLUGIN:
//Other queries recover id, name, link, image, visibility, admin, address, added_tool, target, category and session_id
// but plugins are not present in the tool table, only globally and inside the course_settings table once configured
$sql = "SELECT * FROM $course_tool_table t
WHERE category = 'plugin' AND name <> 'courseblock' AND c_id = $course_id $condition_session
ORDER BY id";
";
$result = Database::query($sql);
break;
}

//Get the list of hidden tools - this might imply performance slowdowns
$sql .= " ORDER BY id ";

// Get the list of hidden tools - this might imply performance slowdowns
// if the course homepage is loaded many times, so the list of hidden
// tools might benefit from a shared memory storage later on
$list = api_get_settings('Tools', 'list', api_get_current_access_url_id());
Expand All @@ -556,7 +564,20 @@ public static function get_tools_category(
}

$allowEditionInSession = api_get_configuration_value('allow_edit_tool_visibility_in_session');
while ($temp_row = Database::fetch_assoc($result)) {

$tools = [];
while ($row = Database::fetch_assoc($result)) {
$tools[] = $row;
}

$toolWithSessionValue = [];
foreach ($tools as $row) {
if (!empty($row['session_id'])) {
$toolWithSessionValue[$row['name']] = $row;
}
}

foreach ($tools as $temp_row) {
$add = false;
if ($check) {
if (!in_array($temp_row['name'], $hide_list)) {
Expand All @@ -566,17 +587,24 @@ public static function get_tools_category(
$add = true;
}

if (isset($toolWithSessionValue[$temp_row['name']])) {
if (!empty($temp_row['session_id'])) {
continue;

This comment has been minimized.

Copy link
@AngelFQC

AngelFQC Mar 12, 2018

Member

@jmontoyaa Entiendo que este commit fue para evitar mostrar los íconos duplicados, pero hace que no se muestre el ícono del tool en la sesión si yo registré un tool en una sessión.
Por favor revisa si el commit que envié 8706747 no rompe lo que corrige tu commit; mi commit mostraría el ícono del tool de la sesión en lugar del ícono del tool del curso base, en caso dede estar duplicado

This comment has been minimized.

Copy link
@jmontoyaa

jmontoyaa Mar 13, 2018

Author Member

Tu cambio 8706747
hace esto:

selection_003

This comment has been minimized.

Copy link
@jmontoyaa

This comment has been minimized.

Copy link
@AngelFQC

AngelFQC Mar 13, 2018

Member

Sin mi commit, si en una sesión, por ejemplo, configuras una lección para que aparezca en el homepage del curso, la lección no aparece, porque tiene session_id != 0
Hice revert de mi commit y mandé este otro 6011aed

This comment has been minimized.

Copy link
@jmontoyaa

jmontoyaa Mar 14, 2018

Author Member

Ahora se ve bien. Ya no me muestra el Documents repetido. 👍

}
//$temp_row = $toolWithSessionValue[$temp_row['name']];
}

if ($allowEditionInSession && !empty($sessionId)) {
// Checking if exist row in session
$criteria = [
'cId' => $course_id,
'name' => $temp_row['name'],
'sessionId' => $sessionId,
];
/** @var CTool $tool */
/** @var CTool $toolObj */
$toolObj = Database::getManager()->getRepository('ChamiloCourseBundle:CTool')->findOneBy($criteria);
if ($toolObj) {
if (api_is_allowed_to_edit() == false && $toolObj->getVisibility() == 0) {
if (api_is_allowed_to_edit() == false && $toolObj->getVisibility() == false) {
continue;
}
}
Expand All @@ -590,6 +618,7 @@ public static function get_tools_category(
$userId
);
$path = $lp->get_preview_image_path(ICON_SIZE_BIG);

$add = learnpath::is_lp_visible_for_student(
$lp_id,
$userId,
Expand Down Expand Up @@ -674,7 +703,6 @@ public static function get_tools_category(
// Edited by Kevin Van Den Haute (kevin@develop-it.be) for integrating Smartblogs
if ($sql_links != null) {
$result_links = Database::query($sql_links);

if (Database::num_rows($result_links) > 0) {
while ($links_row = Database::fetch_array($result_links, 'ASSOC')) {
$properties = array();
Expand Down Expand Up @@ -717,7 +745,6 @@ public static function get_tools_category(
}
}
}

$all_tools_list = CourseHome::filterPluginTools($all_tools_list, $course_tool_category);

return $all_tools_list;
Expand All @@ -737,9 +764,9 @@ private static function filterPluginTools($dataIcons, $courseToolCategory)
if ($courseToolCategory == TOOL_STUDENT_VIEW) {
//Fix only coach can see external pages - see #8236 - icpna
if (api_is_coach()) {
foreach ($dataIcons as $indice => $array) {
foreach ($dataIcons as $index => $array) {
if (isset($array['name'])) {
$dataIcons[$indice]['name'] = str_replace($patronKey, '', $array['name']);
$dataIcons[$index]['name'] = str_replace($patronKey, '', $array['name']);
}
}

Expand All @@ -748,15 +775,15 @@ private static function filterPluginTools($dataIcons, $courseToolCategory)

$flagOrder = false;

foreach ($dataIcons as $indice => $array) {
foreach ($dataIcons as $index => $array) {
if (!isset($array['name'])) {
continue;
}

$pos = strpos($array['name'], $patronKey);

if ($pos !== false) {
unset($dataIcons[$indice]);
unset($dataIcons[$index]);
$flagOrder = true;
}
}
Expand All @@ -769,9 +796,9 @@ private static function filterPluginTools($dataIcons, $courseToolCategory)
}

// clean patronKey of name icons
foreach ($dataIcons as $indice => $array) {
foreach ($dataIcons as $index => $array) {
if (isset($array['name'])) {
$dataIcons[$indice]['name'] = str_replace($patronKey, '', $array['name']);
$dataIcons[$index]['name'] = str_replace($patronKey, '', $array['name']);
}
}

Expand All @@ -783,7 +810,7 @@ private static function filterPluginTools($dataIcons, $courseToolCategory)
* @param array $all_tools_list List of tools as returned by get_tools_category()
* @param bool $rows
*
* @return string
* @return array
*/
public static function show_tools_category($all_tools_list, $rows = false)
{
Expand Down Expand Up @@ -895,9 +922,13 @@ public static function show_tools_category($all_tools_list, $rows = false)
/** @var CTool $tool */
$toolObj = Database::getManager()->getRepository('ChamiloCourseBundle:CTool')->findOneBy($criteria);
if ($toolObj) {
$visibility = $toolObj->getVisibility();
$visibility = (int) $toolObj->getVisibility();
switch ($visibility) {
case '0':
$info = pathinfo($tool['image']);
$basename = basename($tool['image'], '.'.$info['extension']); // $file is set to "index"
$tool['image'] = $basename.'_na.'.$info['extension'];

$link['name'] = Display::return_icon(
'invisible.png',
get_lang('Activate'),
Expand Down Expand Up @@ -933,7 +964,9 @@ public static function show_tools_category($all_tools_list, $rows = false)
}
}
if (!empty($tool['adminlink'])) {
$item['extra'] = '<a href="'.$tool['adminlink'].'">'.Display::return_icon('edit.gif', get_lang('Edit')).'</a>';
$item['extra'] = '<a href="'.$tool['adminlink'].'">'.
Display::return_icon('edit.gif', get_lang('Edit')).
'</a>';
}
}

Expand All @@ -948,7 +981,8 @@ public static function show_tools_category($all_tools_list, $rows = false)
if (isset($lnk) && is_array($lnk)) {
foreach ($lnk as $this_link) {
if (empty($tool['adminlink'])) {
$item['visibility'] .= '<a class="make_visible_and_invisible" href="'.api_get_self().'?'.api_get_cidreq().'&id='.$tool['iid'].'&'.$this_link['cmd'].'">'.
$item['visibility'] .=
'<a class="make_visible_and_invisible" href="'.api_get_self().'?'.api_get_cidreq().'&id='.$tool['iid'].'&'.$this_link['cmd'].'">'.
$this_link['name'].'</a>';
}
}
Expand Down

0 comments on commit 47a4fa8

Please sign in to comment.