function __construct() { parent::__construct("campus"); if (!isset($GLOBALS["DB_ADAPTER"])) { $GLOBALS["DB_ADAPTER"] = new DBCon(); $GLOBALS["DB_ADAPTER"]->Link(); } $this->db = $GLOBALS["DB_ADAPTER"]; $this->db->setTBL(self::getClass()); // ArrayClass function }
function __construct() { parent::__construct("Client"); if (!isset($GLOBALS["App"]["DBAdapter"])) { include_once "include/data/DBCon.php"; $GLOBALS["App"]["DBAdapter"] = new DBCon(); $GLOBALS["App"]["DBAdapter"]->Link(); } $this->db = $GLOBALS["App"]["DBAdapter"]; $this->db->setTBL(self::getClass()); }
function return_exercise_block($personal_course_list) { $exercise_list = array(); if (!empty($personal_course_list)) { foreach ($personal_course_list as $course_item) { $course_code = $course_item['c']; $session_id = $course_item['id_session']; $exercises = ExerciseLib::get_exercises_to_be_taken($course_code, $session_id); foreach ($exercises as $exercise_item) { $exercise_item['course_code'] = $course_code; $exercise_item['session_id'] = $session_id; $exercise_item['tms'] = api_strtotime($exercise_item['end_time'], 'UTC'); $exercise_list[] = $exercise_item; } } if (!empty($exercise_list)) { $exercise_list = ArrayClass::msort($exercise_list, 'tms'); $my_exercise = $exercise_list[0]; $url = Display::url($my_exercise['title'], api_get_path(WEB_CODE_PATH) . 'exercice/overview.php?exerciseId=' . $my_exercise['id'] . '&cidReq=' . $my_exercise['course_code'] . '&id_session=' . $my_exercise['session_id']); $this->tpl->assign('exercise_url', $url); $this->tpl->assign('exercise_end_date', api_convert_and_format_date($my_exercise['end_time'], DATE_FORMAT_SHORT)); } } }
/** * Search a term in the language * @param string $term the term to search * @param bool $search_in_variable the search will include the variable definition of the term * @param bool $search_in_english the search will include the english language variables * @param bool $search_in_parent the search will include the parent language variables of the sub language * @param bool $search_in_sub_language the search will include the sub language variables * @author Julio Montoya * */ function search_language_term($term, $search_in_variable = true, $search_in_english = true, $search_in_parent = true, $search_in_sub_language = true) { //These the $_REQUEST['id'] and the $_REQUEST['sub_language_id'] variables are process in global.inc.php (LOAD LANGUAGE FILES SECTION) /* These 4 arrays are set in global.inc.php with the condition that will be load from sub_language.php or sub_language_ajax.inc.php $english_language_array $parent_language_array $sub_language_array $language_files_to_load */ global $language_files_to_load, $sub_language_array, $english_language_array, $parent_language_array; $language_files_to_load_keys = array_flip($language_files_to_load); $array_to_search = $parent_language_array; $list_info = array(); $term = '/' . Security::remove_XSS(trim($_REQUEST['txt_search_word'])) . '/i'; //@todo optimize this foreach foreach ($language_files_to_load as $lang_file) { //searching in parent language of the sub language if ($search_in_parent) { $variables = $parent_language_array[$lang_file]; foreach ($variables as $parent_name_variable => $parent_variable_value) { //arrays are avoided if (is_array($parent_variable_value)) { continue; } $founded = false; // searching the item in the parent tool if (preg_match($term, $parent_variable_value) !== 0) { $founded = true; } if ($founded) { //loading variable from the english array $sub_language_name_variable = $sub_language_array[$lang_file][$parent_name_variable]; //loading variable from the english array $english_name_variable = $english_language_array[$lang_file][$parent_name_variable]; //config buttons /*if (strlen($english_name_variable)>1500) { $size =20; } else { $size =4; }*/ $obj_text = '<textarea rows="10" cols="40" name="txt|' . $parent_name_variable . '|' . $language_files_to_load_keys[$lang_file] . '" id="txtid_' . $language_files_to_load_keys[$lang_file] . '_' . $parent_name_variable . '" >' . $sub_language_name_variable . '</textarea>'; $obj_button = '<button class="save" type="button" name="btn|' . $parent_name_variable . '|' . $language_files_to_load_keys[$lang_file] . '" id="btnid_' . $parent_name_variable . '" />' . get_lang('Save') . '</button>'; $list_info[] = array($lang_file . '.inc.php', $parent_name_variable, $english_name_variable, $parent_variable_value, $obj_text, $obj_button); } } } //search in english if ($search_in_english || $search_in_variable) { $variables = $english_language_array[$lang_file]; foreach ($variables as $name_variable => $variable_value) { if (is_array($variable_value)) { continue; } if (is_array($variable_value)) { echo $lang_file; } $founded = false; if ($search_in_english && $search_in_variable) { // searching the item in the parent tool if (preg_match($term, $variable_value) !== 0 || preg_match($term, $name_variable) !== 0) { $founded = true; } } else { if ($search_in_english) { if (preg_match($term, $variable_value) !== 0) { $founded = true; } } else { if (preg_match($term, $name_variable) !== 0) { $founded = true; } } } if ($founded) { //loading variable from the english array $sub_language_name_variable = null; if (isset($sub_language_array[$lang_file][$name_variable])) { $sub_language_name_variable = $sub_language_array[$lang_file][$name_variable]; } $parent_variable_value = null; if (isset($parent_language_array[$lang_file][$name_variable])) { $parent_variable_value = $parent_language_array[$lang_file][$name_variable]; } //config buttons $obj_text = '<textarea rows="10" cols="40" name="txt|' . $name_variable . '|' . $language_files_to_load_keys[$lang_file] . '" id="txtid_' . $language_files_to_load_keys[$lang_file] . '_' . $name_variable . '" >' . $sub_language_name_variable . ' </textarea>'; $obj_button = '<button class="save" type="button" name="btn|' . $name_variable . '|' . $language_files_to_load_keys[$lang_file] . '" id="btnid_' . $name_variable . '" />' . get_lang('Save') . '</button>'; //loading variable from the english array $english_name_variable = $english_language_array[$lang_file][$name_variable]; $list_info[] = array($lang_file . '.inc.php', $name_variable, $english_name_variable, $parent_variable_value, $obj_text, $obj_button); } } } // Search in sub language if ($search_in_sub_language) { $variables = $sub_language_array[$lang_file]; foreach ($variables as $name_variable => $variable_value) { if (is_array($parent_variable_value)) { continue; } $founded = false; // searching the item in the parent tool if (preg_match($term, $variable_value) !== 0) { $founded = true; } if ($founded) { //loading variable from the english array $sub_language_name_variable = $sub_language_array[$lang_file][$name_variable]; $parent_variable_value = $parent_language_array[$lang_file][$name_variable]; //config buttons $obj_text = '<textarea rows="10" cols="40" name="txt|' . $name_variable . '|' . $language_files_to_load_keys[$lang_file] . '" id="txtid_' . $language_files_to_load_keys[$lang_file] . '_' . $name_variable . '" >' . $sub_language_name_variable . '</textarea>'; $obj_button = '<button class="save" type="button" name="btn|' . $name_variable . '|' . $language_files_to_load_keys[$lang_file] . '" id="btnid_' . $name_variable . '" />' . get_lang('Save') . '</button>'; //loading variable from the english array $english_name_variable = $english_language_array[$lang_file][$name_variable]; $list_info[] = array($lang_file . '.inc.php', $name_variable, $english_name_variable, $parent_variable_value, $obj_text, $obj_button); } } } } $list_info = ArrayClass::array_unique_dimensional($list_info); return $list_info; }
public function testNestedClassConversion() { $n = new ArrayClass(); $n->setName("test"); $n->setDescription("description"); // $n->setTags(array('payment', 'info', 'test')); $o = new NestedClass(); $o->setId('123'); $o->setInfo($n); $this->assertEquals("123", $o->getId()); $this->assertEquals("test", $o->getInfo()->getName()); // $this->assertEquals(array('payment', 'info', 'test'), $o->getInfo()->getTags()); $json = $o->toJSON(); // $this->assertEquals('{"id":"123","info":{"name":"test","desc":"description","tags":["payment","info","test"]}}', $json); $this->assertEquals('{"id":"123","info":{"name":"test","desc":"description"}}', $json); $newO = new NestedClass(); $newO->fromJson($json); $this->assertEquals($o, $newO); }
$url = 'class.php?action=remove_class_from_course&id=' . $group['id']; $icon = Display::return_icon('delete.png', get_lang('Remove')); } else { $url = 'class.php?action=add_class_to_course&id=' . $group['id']; $icon = Display::return_icon('add.png', get_lang('Add')); } $group['actions'] = Display::url($icon, $url); $new_result[] = $group; } $result = $new_result; } if (!in_array($sidx, $columns)) { $sidx = 'name'; } //Multidimensional sort ArrayClass::msort($result, $sidx); break; default: exit; } $allowed_actions = array('get_careers', 'get_promotions', 'get_usergroups', 'get_usergroups_teacher', 'get_gradebooks', 'get_sessions', 'get_exercise_results', 'get_admin_exercise_results', 'get_hotpotatoes_exercise_results', 'get_work_user_list', 'get_work_user_list_others', 'get_work_user_list_all', 'get_timelines', 'get_grade_models', 'get_event_email_template', 'get_user_skill_ranking', 'get_extra_fields', 'get_extra_field_options', 'get_course_exercise_medias', 'get_user_course_report', 'get_user_course_report_resumed', 'get_group_reporting', 'get_question_list', 'get_user_list_plugin_widescale'); //5. Creating an obj to return a json if (in_array($action, $allowed_actions)) { $response = new stdClass(); $response->page = $page; $response->total = $total_pages; $response->records = $count; if ($operation && $operation == 'excel') { $j = 1; $array = array(); if (empty($column_names)) {
/** * Show the monthcalender of the given month * @param array Agendaitems * @param int Month number * @param int Year number * @param array Array of strings containing long week day names (deprecated, you can send an empty array instead) * @param string The month name * @return void Direct output */ function display_mymonthcalendar($user_id, $agendaitems, $month, $year, $weekdaynames = array(), $monthName, $show_content = true) { global $DaysShort, $course_path; //Handle leap year $numberofdays = array(0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); if ($year % 400 == 0 or $year % 4 == 0 and $year % 100 != 0) { $numberofdays[2] = 29; } //Get the first day of the month $dayone = getdate(mktime(0, 0, 0, $month, 1, $year)); //Start the week on monday $startdayofweek = $dayone['wday'] != 0 ? $dayone['wday'] - 1 : 6; $g_cc = isset($_GET['courseCode']) ? $_GET['courseCode'] : ''; $prev_icon = Display::return_icon('action_prev.png', get_lang('Previous')); $next_icon = Display::return_icon('action_next.png', get_lang('Next')); $next_month = $month == 1 ? 12 : $month - 1; $prev_month = $month == 12 ? 1 : $month + 1; $next_year = $month == 1 ? $year - 1 : $year; $prev_year = $month == 12 ? $year + 1 : $year; if ($show_content) { $back_url = Display::url($prev_icon, api_get_self() . "?coursePath=" . urlencode($course_path) . "&courseCode=" . Security::remove_XSS($g_cc) . "&action=view&view=month&month=" . $next_month . "&year=" . $next_year); $next_url = Display::url($next_icon, api_get_self() . "?coursePath=" . urlencode($course_path) . "&courseCode=" . Security::remove_XSS($g_cc) . "&action=view&view=month&month=" . $prev_month . "&year=" . $prev_year); } else { $back_url = Display::url($prev_icon, '', array('onclick' => "load_calendar('" . $user_id . "','" . $next_month . "', '" . $next_year . "'); ")); $next_url = Display::url($next_icon, '', array('onclick' => "load_calendar('" . $user_id . "','" . $prev_month . "', '" . $prev_year . "'); ")); } echo '<table id="agenda_list"><tr>'; echo '<th width="10%">' . $back_url . '</th>'; echo '<th width="80%" colspan="5"><br /><h3>' . $monthName . " " . $year . '</h3></th>'; echo '<th width="10%">' . $next_url . '</th>'; echo '</tr>'; echo '<tr>'; for ($ii = 1; $ii < 8; $ii++) { echo '<td class="weekdays">' . $DaysShort[$ii % 7] . '</td>'; } echo '</tr>'; $curday = -1; $today = getdate(); while ($curday <= $numberofdays[$month]) { echo "<tr>"; for ($ii = 0; $ii < 7; $ii++) { if ($curday == -1 && $ii == $startdayofweek) { $curday = 1; } if ($curday > 0 && $curday <= $numberofdays[$month]) { $bgcolor = $class = 'class="days_week"'; $dayheader = Display::div($curday, array('class' => 'agenda_day')); if ($curday == $today['mday'] && $year == $today['year'] && $month == $today['mon']) { $class = "class=\"days_today\" style=\"width:10%;\""; } echo "<td " . $class . ">" . $dayheader; if (!empty($agendaitems[$curday])) { $items = $agendaitems[$curday]; $items = ArrayClass::msort($items, 'start_date_tms'); foreach ($items as $value) { $value['title'] = Security::remove_XSS($value['title']); $start_time = api_format_date($value['start_date'], TIME_NO_SEC_FORMAT); $end_time = ''; if (!empty($value['end_date']) && $value['end_date'] != '0000-00-00 00:00:00') { $end_time = '- <i>' . api_format_date($value['end_date'], DATE_TIME_FORMAT_LONG) . '</i>'; } $complete_time = '<i>' . api_format_date($value['start_date'], DATE_TIME_FORMAT_LONG) . '</i> ' . $end_time; $time = '<i>' . $start_time . '</i>'; switch ($value['calendar_type']) { case 'personal': $bg_color = '#D0E7F4'; $icon = Display::return_icon('user.png', get_lang('MyAgenda'), array(), ICON_SIZE_SMALL); break; case 'global': $bg_color = '#FFBC89'; $icon = Display::return_icon('view_remove.png', get_lang('GlobalEvent'), array(), ICON_SIZE_SMALL); break; case 'course': $bg_color = '#CAFFAA'; $icon_name = 'course.png'; if (!empty($value['session_id'])) { $icon_name = 'session.png'; } if ($show_content) { $icon = Display::url(Display::return_icon($icon_name, $value['course_name'] . ' ' . get_lang('Course'), array(), ICON_SIZE_SMALL), $value['url']); } else { $icon = Display::return_icon($icon_name, $value['course_name'] . ' ' . get_lang('Course'), array(), ICON_SIZE_SMALL); } break; default: break; } $result = '<div class="rounded_div_agenda" style="background-color:' . $bg_color . ';">'; if ($show_content) { //Setting a personal event to green $icon = Display::div($icon, array('style' => 'float:right')); $link = $value['calendar_type'] . '_' . $value['id'] . '_' . $value['course_id'] . '_' . $value['session_id']; //Link to bubble $url = Display::url(Text::cut($value['title'], 40), '#', array('id' => $link, 'class' => 'opener')); $result .= $time . ' ' . $icon . ' ' . Display::div($url); //Hidden content $content = Display::div($icon . Display::tag('h2', $value['course_name']) . '<hr />' . Display::tag('h3', $value['title']) . $complete_time . '<hr />' . Security::remove_XSS($value['content'])); //Main div $result .= Display::div($content, array('id' => 'main_' . $link, 'class' => 'dialog', 'style' => 'display:none')); $result .= '</div>'; echo $result; //echo Display::div($content, array('id'=>'main_'.$value['calendar_type'].'_'.$value['id'], 'class' => 'dialog')); } else { echo $result .= $icon . '</div>'; } } } echo "</td>"; $curday++; } else { echo "<td></td>"; } } echo "</tr>"; } echo "</table>"; }
/** * Displays all the agenda items * @author Patrick Cool <*****@*****.**>, Ghent University * @author Yannick Warnier <*****@*****.**> - cleanup * @author Julio Montoya <*****@*****.**> - Refactoring */ function display_agenda_items($agenda_items, $day = false) { global $charset; if (isset($day) && $day) { $new_items = array(); foreach ($agenda_items as $item) { if (substr($item['start_date'], 8, 2) == $day) { $new_items[] = $item; } } $agenda_items = $new_items; } if (isset($_GET['sort']) && $_GET['sort'] == 'asc') { $sort_inverse = 'desc'; $sort = 'asc'; } else { $sort_inverse = 'asc'; $sort = 'desc'; } if (isset($_GET['col']) && $_GET['col'] == 'end') { $sort_item = 'end_date_tms'; $col = 'end'; } else { $sort_item = 'start_date_tms'; $col = 'start'; } $agenda_items = ArrayClass::msort($agenda_items, $sort_item, $sort); //DISPLAY: NO ITEMS if (empty($agenda_items)) { echo Display::display_warning_message(get_lang('NoAgendaItems')); } else { echo '<table class="data_table">'; $th = Display::tag('th', get_lang('Title')); $month = isset($_GET['month']) ? intval($_GET['month']) : null; $year = isset($_GET['year']) ? intval($_GET['year']) : null; $day = isset($_GET['day']) ? intval($_GET['day']) : null; $url = api_get_self() . '?' . api_get_cidreq() . '&month=' . $month . '&year=' . $year . '&day=' . $day; $th .= Display::tag('th', Display::url(get_lang('StartTimeWindow'), $url . '&sort=' . $sort_inverse . '&col=start')); $th .= Display::tag('th', Display::url(get_lang('EndTimeWindow'), $url . '&sort=' . $sort_inverse . '&col=end')); if (api_is_allowed_to_edit(false, true) or api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous()) { $th .= Display::tag('th', get_lang('Modify')); } echo Display::tag('tr', $th); $counter = 0; foreach ($agenda_items as $myrow) { $is_repeated = !empty($myrow['parent_event_id']); $class = 'row_even'; if ($counter % 2) { $class = 'row_odd'; } /* display: the icon, title, destinees of the item */ echo '<tr class="' . $class . '">'; //Title echo "<td>"; $attach_icon = ''; // attachment list $attachment_list = get_attachment($myrow['id']); if (!empty($attachment_list)) { $attach_icon = ' ' . Display::return_icon('attachment.gif', get_lang('Attachment')); } $title_class = ''; if (isset($myrow['visibility']) && $myrow['visibility'] == 0) { $title_class = 'invisible'; } switch ($myrow['calendar_type']) { case 'global': $icon_type = Display::return_icon('view_remove.png', get_lang('GlobalEvent'), array(), 22); echo $icon_type . ' ' . $myrow['title'] . $attach_icon; break; case 'personal': $icon_type = Display::return_icon('user.png', get_lang(' '), array(), 22); echo $icon_type . ' ' . $myrow['title'] . $attach_icon; break; case 'course': $icon_type = Display::return_icon('course.png', get_lang('Course'), array(), 22); $agenda_url = api_get_path(WEB_CODE_PATH) . 'calendar/agenda.php?agenda_id=' . $myrow['id'] . '&action=view'; echo Display::url($icon_type . ' ' . $myrow['title'] . $attach_icon, $agenda_url, array('class' => $title_class)); break; } echo '</td>'; //Start date echo '<td>'; if (!empty($myrow['start_date']) && $myrow['start_date'] != '0000-00-00 00:00:00') { echo api_format_date($myrow['start_date']); } echo '</td>'; //End date echo '<td>'; if (!empty($myrow['end_date']) && $myrow['end_date'] != '0000-00-00 00:00:00') { echo api_format_date($myrow['end_date']); } echo '</td>'; /* Display: edit delete button (course admin only) */ if (!$is_repeated && (api_is_allowed_to_edit(false, true) or api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous()) && $myrow['calendar_type'] == 'course') { echo '<td align="center">'; if (!(api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, $myrow['id']))) { // a coach can only delete an element belonging to his session $mylink = api_get_self() . '?' . api_get_cidreq() . '&origin=' . Security::remove_XSS($_GET['origin']) . '&id=' . $myrow['id'] . '&sort=' . $sort . '&col=' . $col . '&'; // edit echo '<a href="' . $mylink . api_get_cidreq() . "&toolgroup=" . Security::remove_XSS($_GET['toolgroup']) . '&action=edit&id_attach=' . $attachment_list['id'] . '" title="' . get_lang("ModifyCalendarItem") . '">'; echo Display::return_icon('edit.png', get_lang('ModifyCalendarItem'), '', ICON_SIZE_SMALL) . "</a>"; echo '<a href="' . $mylink . api_get_cidreq() . "&toolgroup=" . Security::remove_XSS($_GET['toolgroup']) . '&action=announce" title="' . get_lang("AddAnnouncement") . '">'; echo Display::return_icon('new_announce.png', get_lang('AddAnnouncement'), array(), ICON_SIZE_SMALL) . "</a> "; if ($myrow['visibility'] == 1) { $image_visibility = "visible"; $text_visibility = get_lang("Hide"); $next_action = 0; } else { $image_visibility = "invisible"; $text_visibility = get_lang("Show"); $next_action = 1; } echo '<a href="' . $mylink . api_get_cidreq() . '&toolgroup=' . Security::remove_XSS($_GET['toolgroup']) . '&action=showhide&next_action=' . $next_action . '" title="' . $text_visibility . '">' . Display::return_icon($image_visibility . '.png', $text_visibility, '', ICON_SIZE_SMALL) . '</a> '; echo "<a href=\"" . $mylink . api_get_cidreq() . "&toolgroup=" . Security::remove_XSS($_GET['toolgroup']) . "&action=delete\" onclick=\"javascript:if(!confirm('" . addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES, $charset)) . "')) return false;\" title=\"" . get_lang("Delete") . "\"> "; echo Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL) . " </a>"; } $mylink = 'ical_export.php?' . api_get_cidreq() . '&type=course&id=' . $myrow['id']; //echo '<a class="ical_export" href="'.$mylink.'&class=confidential" title="'.get_lang('ExportiCalConfidential').'">'.Display::return_icon($export_icon_high, get_lang('ExportiCalConfidential')).'</a> '; //echo '<a class="ical_export" href="'.$mylink.'&class=private" title="'.get_lang('ExportiCalPrivate').'">'.Display::return_icon($export_icon_low, get_lang('ExportiCalPrivate')).'</a> '; //echo '<a class="ical_export" href="'.$mylink.'&class=public" title="'.get_lang('ExportiCalPublic').'">'.Display::return_icon($export_icon, get_lang('ExportiCalPublic')).'</a> '; echo '<a href="#" onclick="javascript:win_print=window.open(\'print.php?id=' . $myrow['id'] . '\',\'popup\',\'left=100,top=100,width=700,height=500,scrollbars=1,resizable=0\'); win_print.focus(); return false;">' . Display::return_icon('printer.png', get_lang('Print'), '', ICON_SIZE_SMALL) . '</a> '; echo '</td>'; } else { if ($is_repeated && (api_is_allowed_to_edit(false, true) || api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous())) { echo '<td align="center">'; echo get_lang('RepeatedEvent'), ' <a href="', api_get_self(), '?', api_get_cidreq(), '&agenda_id=', $myrow['parent_event_id'], '" alt="', get_lang('RepeatedEventViewOriginalEvent'), '">', get_lang('RepeatedEventViewOriginalEvent'), '</a>'; echo '</td>'; } if ((api_is_allowed_to_edit(false, true) || api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous()) && ($myrow['calendar_type'] == 'personal' or $myrow['calendar_type'] == 'global')) { echo '<td align="center">'; echo '</td>'; } } $counter++; echo "</tr>"; } // end while ($myrow=Database::fetch_array($result)) echo "</table><br /><br />"; } if (!empty($event_list)) { $event_list = api_substr($event_list, 0, -1); } else { $event_list = '0'; } echo "<form name=\"event_list_form\"><input type=\"hidden\" name=\"event_list\" value=\"{$event_list}\" /></form>"; // closing the layout table echo "</td>", "</tr>", "</table>"; }
/** * Shows the right menu of the Social Network tool * * @param string highlight link possible values: group_add, home, messages, messages_inbox, messages_compose ,messages_outbox ,invitations, shared_profile, friends, groups search * @param int group id * @param int user id * @param bool show profile or not (show or hide the user image/information) * */ public static function show_social_menu($show = '', $group_id = 0, $user_id = 0, $show_full_profile = false, $show_delete_account_button = false) { if (empty($user_id)) { $user_id = api_get_user_id(); } $usergroup = new UserGroup(); $user_info = api_get_user_info($user_id, true); $current_user_id = api_get_user_id(); $current_user_info = api_get_user_info($current_user_id, true); if ($current_user_id == $user_id) { $user_friend_relation = null; } else { $user_friend_relation = SocialManager::get_relation_between_contacts($current_user_id, $user_id); } $show_groups = array('groups', 'group_messages', 'messages_list', 'group_add', 'mygroups', 'group_edit', 'member_list', 'invite_friends', 'waiting_list', 'browse_groups'); // get count unread message and total invitations $count_unread_message = MessageManager::get_number_of_messages(true); $count_unread_message = !empty($count_unread_message) ? Display::badge($count_unread_message) : ''; $number_of_new_messages_of_friend = SocialManager::get_message_number_invitation_by_user_id(api_get_user_id()); $group_pending_invitations = $usergroup->get_groups_by_user(api_get_user_id(), GROUP_USER_PERMISSION_PENDING_INVITATION, false); $group_pending_invitations = count($group_pending_invitations); $total_invitations = $number_of_new_messages_of_friend + $group_pending_invitations; $total_invitations = !empty($total_invitations) ? Display::badge($total_invitations) : ''; $html = '<div class="social-menu">'; if (in_array($show, $show_groups) && !empty($group_id)) { //--- Group image $group_info = $usergroup->get($group_id); $big = $usergroup->get_picture_group($group_id, $group_info['picture'], 160, GROUP_IMAGE_SIZE_BIG); $html .= '<div class="social-content-image">'; $html .= '<div class="well social-background-content">'; $html .= Display::url('<img src=' . $big['file'] . ' class="social-groups-image" /> </a><br /><br />', api_get_path(WEB_PATH) . 'main/social/groups.php?id=' . $group_id); if ($usergroup->is_group_admin($group_id, api_get_user_id())) { $html .= '<div id="edit_image" class="hidden_message" style="display:none"><a href="' . api_get_path(WEB_PATH) . 'main/social/group_edit.php?id=' . $group_id . '">' . get_lang('EditGroup') . '</a></div>'; } $html .= '</div>'; $html .= '</div>'; } else { $img_array = UserManager::get_user_picture_path_by_id($user_id, 'web', true, true); $big_image = UserManager::get_picture_user($user_id, $img_array['file'], '', USER_IMAGE_SIZE_BIG); $big_image = $big_image['file']; $normal_image = $img_array['dir'] . $img_array['file']; //--- User image $html .= '<div class="well social-background-content">'; if ($img_array['file'] != 'unknown.jpg') { $html .= '<a class="thumbnail ajax" href="' . $big_image . '"><img src=' . $normal_image . ' /> </a>'; } else { $html .= '<img src=' . $normal_image . ' width="110px" />'; } if (api_get_user_id() == $user_id) { $html .= '<div id="edit_image" class="hidden_message" style="display:none">'; $html .= '<a href="' . api_get_path(WEB_PATH) . 'main/auth/profile.php">' . get_lang('EditProfile') . '</a></div>'; } $html .= '</div>'; } if (!in_array($show, array('shared_profile', 'groups', 'group_edit', 'member_list', 'waiting_list', 'invite_friends'))) { $html .= '<div class="well sidebar-nav"><ul class="nav nav-list">'; $active = $show == 'home' ? 'active' : null; $html .= '<li class="' . $active . '"><a href="' . api_get_path(WEB_PATH) . 'main/social/home.php">' . Display::return_icon('home.png', get_lang('Home'), array()) . get_lang('Home') . '</a></li>'; if (api_get_setting('allow_message_tool') == 'true') { $active = $show == 'messages' ? 'active' : null; $html .= '<li class="' . $active . '"><a href="' . api_get_path(WEB_PATH) . 'main/messages/inbox.php?f=social">' . Display::return_icon('instant_message.png', get_lang('Messages'), array()) . get_lang('Messages') . $count_unread_message . '</a></li>'; } // Invitations if (api_get_setting('allow_message_tool') == 'true') { $active = $show == 'invitations' ? 'active' : null; $html .= '<li class="' . $active . '"><a href="' . api_get_path(WEB_PATH) . 'main/social/invitations.php">' . Display::return_icon('invitation.png', get_lang('Invitations'), array()) . get_lang('Invitations') . $total_invitations . '</a></li>'; } //Shared profile and groups $active = $show == 'shared_profile' ? 'active' : null; $html .= '<li class="' . $active . '"><a href="' . api_get_path(WEB_PATH) . 'main/social/profile.php">' . Display::return_icon('my_shared_profile.png', get_lang('ViewMySharedProfile'), array()) . get_lang('ViewMySharedProfile') . '</a></li>'; $active = $show == 'friends' ? 'active' : null; $html .= '<li class="' . $active . '"><a href="' . api_get_path(WEB_PATH) . 'main/social/friends.php">' . Display::return_icon('friend.png', get_lang('Friends'), array()) . get_lang('Friends') . '</a></li>'; $active = $show == 'browse_groups' ? 'active' : null; $html .= '<li class="' . $active . '"><a href="' . api_get_path(WEB_PATH) . 'main/social/groups.php">' . Display::return_icon('group_s.png', get_lang('SocialGroups'), array()) . get_lang('SocialGroups') . '</a></li>'; //Search users $active = $show == 'search' ? 'active' : null; $html .= '<li class="' . $active . '"><a href="' . api_get_path(WEB_PATH) . 'main/social/search.php">' . Display::return_icon('zoom.png', get_lang('Search'), array()) . get_lang('Search') . '</a></li>'; $html .= '</ul> </div>'; } if (in_array($show, $show_groups) && !empty($group_id)) { $html .= $usergroup->show_group_column_information($group_id, api_get_user_id(), $show); } if ($show == 'shared_profile') { //echo '<div align="center" class="social-menu-title" ><span class="social-menu-text1">'.get_lang('Menu').'</span></div>'; $html .= '<div class="well sidebar-nav"> <ul class="nav nav-list">'; // My own profile if ($show_full_profile && $user_id == intval(api_get_user_id())) { $html .= '<li><a href="' . api_get_path(WEB_PATH) . 'main/social/home.php">' . Display::return_icon('home.png', get_lang('Home'), array()) . get_lang('Home') . '</a></li>'; if (api_get_setting('allow_message_tool') == 'true') { $html .= '<li><a href="' . api_get_path(WEB_PATH) . 'main/messages/inbox.php?f=social">' . Display::return_icon('instant_message.png', get_lang('Messages'), array()) . get_lang('Messages') . $count_unread_message . '</a></li>'; $active = $show == 'invitations' ? 'active' : null; $html .= '<li class="' . $active . '"><a href="' . api_get_path(WEB_PATH) . 'main/social/invitations.php">' . Display::return_icon('invitation.png', get_lang('Invitations'), array()) . get_lang('Invitations') . $total_invitations . '</a></li>'; } $html .= '<li class="active"><a href="' . api_get_path(WEB_PATH) . 'main/social/profile.php">' . Display::return_icon('my_shared_profile.png', get_lang('ViewMySharedProfile'), array('style' => 'float:left')) . '' . get_lang('ViewMySharedProfile') . '</a></li> <li><a href="' . api_get_path(WEB_PATH) . 'main/social/friends.php">' . Display::return_icon('friend.png', get_lang('Friends'), array()) . get_lang('Friends') . '</a></li> <li><a href="' . api_get_path(WEB_PATH) . 'main/social/groups.php">' . Display::return_icon('group_s.png', get_lang('SocialGroups'), array()) . get_lang('SocialGroups') . '</a></li>'; $active = $show == 'search' ? 'active' : null; $html .= '<li class="' . $active . '"><a href="' . api_get_path(WEB_PATH) . 'main/social/search.php">' . Display::return_icon('zoom.png', get_lang('Search'), array()) . get_lang('Search') . '</a></li>'; } // My friend profile if (api_get_setting('allow_message_tool') == 'true') { if ($user_id != api_get_user_id()) { $html .= '<li><a href="javascript:void(0);" onclick="javascript:send_message_to_user(\'' . $user_id . '\');" title="' . get_lang('SendMessage') . '">'; $html .= Display::return_icon('compose_message.png', get_lang('SendMessage')) . ' ' . get_lang('SendMessage') . '</a></li>'; } //check if I already sent an invitation message $invitation_sent_list = SocialManager::get_list_invitation_sent_by_user_id(api_get_user_id()); if (isset($invitation_sent_list[$user_id]) && is_array($invitation_sent_list[$user_id]) && count($invitation_sent_list[$user_id]) > 0) { $html .= '<li><a href="' . api_get_path(WEB_PATH) . 'main/social/invitations.php">' . Display::return_icon('invitation.png', get_lang('YouAlreadySentAnInvitation')) . ' ' . get_lang('YouAlreadySentAnInvitation') . '</a></li>'; } else { if (!$show_full_profile) { $html .= '<li><a href="javascript:void(0);" onclick="javascript:send_invitation_to_user(\'' . $user_id . '\');" title="' . get_lang('SendInvitation') . '">' . Display::return_icon('invitation.png', get_lang('SocialInvitationToFriends')) . ' ' . get_lang('SendInvitation') . '</a></li>'; } } } //@todo check if user is online and if it's a friend to show the chat link if (api_is_global_chat_enabled()) { $user_name = $user_info['complete_name']; if ($user_friend_relation == USER_RELATION_TYPE_FRIEND) { if ($user_id != api_get_user_id()) { //Only show chat if I'm available to talk if ($current_user_info['user_is_online_in_chat'] == 1) { $options = array('onclick' => "javascript:chatWith('" . $user_id . "', '" . Security::remove_XSS($user_name) . "', '" . $user_info['user_is_online_in_chat'] . "')"); $chat_icon = $user_info['user_is_online_in_chat'] ? Display::return_icon('online.png', get_lang('Online')) : Display::return_icon('offline.png', get_lang('Offline')); $html .= Display::tag('li', Display::url($chat_icon . ' ' . get_lang('Chat'), 'javascript:void(0);', $options)); } } } else { // Do something? if ($user_id != api_get_user_id()) { if ($current_user_info['user_is_online_in_chat'] == 1) { $message = Security::remove_XSS(sprintf(get_lang("YouHaveToAddXAsAFriendFirst"), $user_name)); $options = array('onclick' => "javascript:chatNotYetWith('" . $message . "')"); $chat_icon = $user_info['user_is_online_in_chat'] ? Display::return_icon('online.png', get_lang('Online')) : Display::return_icon('offline.png', get_lang('Offline')); $html .= Display::tag('li', Display::url($chat_icon . ' ' . get_lang('Chat'), 'javascript:void(0);', $options)); } } } } $html .= '</ul></div>'; if ($show_full_profile && $user_id == intval(api_get_user_id())) { $personal_course_list = UserManager::get_personal_session_course_list($user_id); $course_list_code = array(); $i = 1; if (is_array($personal_course_list)) { foreach ($personal_course_list as $my_course) { if ($i <= 10) { $course_list_code[] = array('code' => $my_course['code']); } else { break; } $i++; } //to avoid repeted courses $course_list_code = ArrayClass::array_unique_dimensional($course_list_code); } //-----Announcements $my_announcement_by_user_id = intval($user_id); $announcements = array(); foreach ($course_list_code as $course) { $course_info = api_get_course_info($course['code']); if (!empty($course_info)) { $content = AnnouncementManager::get_all_annoucement_by_user_course($course_info['code'], $my_announcement_by_user_id); if (!empty($content)) { $url = Display::url(Display::return_icon('announcement.png', get_lang('Announcements')) . $course_info['name'] . ' (' . $content['count'] . ')', api_get_path(WEB_CODE_PATH) . 'announcements/announcements.php?cidReq=' . $course['code']); $announcements[] = Display::tag('li', $url); } } } if (!empty($announcements)) { //echo '<div align="center" class="social-menu-title" ><span class="social-menu-text1">'.get_lang('ToolAnnouncement').'</span></div>'; $html .= '<div class="social_menu_items">'; $html .= '<ul>'; foreach ($announcements as $announcement) { $html .= $announcement; } $html .= '</ul>'; $html .= '</div>'; } } } if ($show_delete_account_button) { $html .= '<div class="sidebar-nav"><ul><li>'; $url = api_get_path(WEB_CODE_PATH) . 'auth/unsubscribe_account.php'; $html .= Display::url(Display::return_icon('delete.png', get_lang('Unsubscribe'), array(), ICON_SIZE_TINY) . get_lang('Unsubscribe'), $url); $html .= '</li></ul></div>'; } $html .= '</div>'; return $html; }
case 1: $group['group_type'] = Display::label(get_lang('Social'), 'success'); break; } $role = $obj->getUserRoleToString(api_get_user_id(), $group['id']); $group['status'] = $role; $group['actions'] = Display::url($icon, $url); $new_result[] = $group; } $result = $new_result; } if (!in_array($sidx, $columns)) { $sidx = 'name'; } // Multidimensional sort $result = ArrayClass::msort($result, $sidx, $sord); break; default: exit; } $allowed_actions = array('get_careers', 'get_promotions', 'get_usergroups', 'get_usergroups_teacher', 'get_gradebooks', 'get_sessions', 'get_session_access_overview', 'get_sessions_tracking', 'get_session_lp_progress', 'get_survey_overview', 'get_session_progress', 'get_exercise_progress', 'get_exercise_results', 'get_work_student_list_overview', 'get_hotpotatoes_exercise_results', 'get_work_teacher', 'get_work_student', 'get_work_user_list', 'get_work_user_list_others', 'get_work_user_list_all', 'get_timelines', 'get_grade_models', 'get_event_email_template', 'get_user_skill_ranking', 'get_extra_fields', 'get_extra_field_options', 'get_user_course_report', 'get_user_course_report_resumed', 'get_exercise_grade', 'get_group_reporting', 'get_course_announcements'); //5. Creating an obj to return a json if (in_array($action, $allowed_actions)) { $response = new stdClass(); $response->page = $page; $response->total = $total_pages; $response->records = $count; if ($operation && $operation == 'excel') { $j = 1; $array = array(); if (empty($column_names)) {
public static function get_coachs_from_course_to_string($session_id = 0, $courseId = null, $separator = self::USER_SEPARATOR, $add_link_to_profile = false) { $coachs_course = self::get_coachs_from_course($session_id, $courseId); $course_coachs = array(); if (is_array($coachs_course)) { foreach ($coachs_course as $coach_course) { $coach_name = api_get_person_name($coach_course['firstname'], $coach_course['lastname']); if ($add_link_to_profile) { $url = api_get_path(WEB_AJAX_PATH) . 'user_manager.ajax.php?a=get_user_popup&resizable=0&height=300&user_id=' . $coach_course['user_id']; $coach_name = Display::url($coach_name, $url, array('class' => 'ajax')); } $course_coachs[] = $coach_name; } } $coaches_to_string = null; if (is_array($course_coachs) && count($course_coachs) > 0) { $coaches_to_string = ArrayClass::array_to_string($course_coachs, $separator); } return $coaches_to_string; }
if ($exercise_info->start_time != '0000-00-00 00:00:00') { $allowed_time = api_strtotime($exercise_info->start_time, 'UTC'); if ($now < $allowed_time) { continue; } } $exercise_info->exercise = Display::url($exercise_info->exercise, api_get_path(WEB_CODE_PATH) . "exercice/overview.php?cidReq={$my_course_code}&exerciseId={$exercise_info->id}&id_session={$session_id}", array('target' => SESSION_LINK_TARGET)); $new_exercises[] = array('status' => Display::return_icon('star.png', get_lang('New'), array('width' => ICON_SIZE_SMALL)), 'date' => $start_date, 'course' => $course_data['name'], 'exercise' => $exercise_info->exercise, 'attempt' => '-', 'result' => '-', 'best_result' => '-', 'position' => '-'); } } } } } } } $my_real_array = ArrayClass::msort($my_real_array, 'date', 'asc'); if (!empty($new_exercises)) { $my_real_array = array_merge($new_exercises, $my_real_array); } $start = $end = $start_only = $end_only = ''; if (!empty($session_info['access_start_date']) && $session_info['access_start_date'] != '0000-00-00') { $start = api_convert_and_format_date($session_info['access_start_date'], DATE_FORMAT_SHORT); $start_only = get_lang('From') . ' ' . $session_info['access_start_date']; } if (!empty($session_info['access_start_date']) && $session_info['access_end_date'] != '0000-00-00') { $end = api_convert_and_format_date($session_info['access_end_date'], DATE_FORMAT_SHORT); $end_only = get_lang('Until') . ' ' . $session_info['access_end_date']; } if (!empty($start) && !empty($end)) { $dates = Display::tag('i', sprintf(get_lang('FromDateXToDateY'), $start, $end)); } else {
$personal_course_list = UserManager::get_personal_session_course_list($my_user_id); $course_list_code = array(); $i = 1; $list = []; if (is_array($personal_course_list)) { foreach ($personal_course_list as $my_course) { if ($i <= 10) { $list[] = SocialManager::get_logged_user_course_html($my_course, $i); $course_list_code[] = array('code' => $my_course['code']); } else { break; } $i++; } //to avoid repeted courses $course_list_code = ArrayClass::array_unique_dimensional($course_list_code); } //Social Block Menu $social_menu_block = SocialManager::show_social_menu('shared_profile', null, $user_id, $show_full_profile); //Setting some session info $user_info = api_get_user_info($my_user_id); $sessionList = SessionManager::getSessionsFollowedByUser($my_user_id, $user_info['status']); // My friends $friend_html = SocialManager::listMyFriendsBlock($user_id, $link_shared, $show_full_profile); $wallSocialAddPost = SocialManager::getWallForm($show_full_profile); $social_wall_block = $wallSocialAddPost; // Social Post Wall $posts = SocialManager::getWallMessagesByUser($my_user_id, $friendId); $posts = empty($posts) ? '<p>' . get_lang("NoPosts") . '</p>' : $posts; $social_post_wall_block = Display::panel($posts, get_lang('Posts')); $socialAutoExtendLink = Display::url(get_lang('SeeMore'), $socialAjaxUrl . '?u=' . $my_user_id . '&a=listWallMessage&start=10&length=5', array('class' => 'nextPage next'));
/** * @param Application $app * @return string */ public function indexAction(Application $app) { $request = $app['request']; $language_file = array('admin', 'exercice', 'gradebook', 'tracking'); // 1. Setting variables needed by jqgrid $action = $request->get('a'); $page = $request->get('page'); //page $limit = $request->get('rows'); //quantity of rows $sidx = $request->get('sidx'); //index (field) to filter $sord = $request->get('sord'); //asc or desc if (strpos(strtolower($sidx), 'asc') !== false) { $sidx = str_replace(array('asc', ','), '', $sidx); $sord = 'asc'; } if (strpos(strtolower($sidx), 'desc') !== false) { $sidx = str_replace(array('desc', ','), '', $sidx); $sord = 'desc'; } if (!in_array($sord, array('asc', 'desc'))) { $sord = 'desc'; } if (!in_array($action, array('get_exercise_results', 'get_hotpotatoes_exercise_results', 'get_work_user_list', 'get_timelines', 'get_user_skill_ranking', 'get_usergroups_teacher', 'get_question_list', 'get_user_list_plugin_widescale'))) { api_protect_admin_script(true); } if ($action == 'get_user_list_plugin_widescale') { $allowed = api_is_drh() || api_is_platform_admin(); if (!$allowed) { api_not_allowed(); } } // Search features. // If there is no search request sent by jqgrid, $where should be empty. $where_condition = ""; $operation = $request->get('oper'); $export_format = $request->get('export_format'); $search_field = $request->get('searchField'); $search_oper = $request->get('searchOper'); $search_string = $request->get('searchString'); $isSearch = $request->get('_search'); $filters = $request->get('filters'); $type = $request->get('type'); $extra_fields = array(); $questionFields = array(); if ($isSearch == 'true') { $where_condition = ' 1 = 1 '; $where_condition_in_form = $this->getWhereClause($search_field, $search_oper, $search_string); if (!empty($where_condition_in_form)) { $where_condition .= ' AND ' . $where_condition_in_form; } $filters = isset($filters) ? json_decode($filters) : false; // for now if (!empty($filters)) { switch ($action) { case 'get_questions': $extraFieldtype = 'question'; break; case 'get_sessions': $extraFieldtype = 'session'; break; } // Extra field. $extraField = new \ExtraField($extraFieldtype); $result = $extraField->getExtraFieldRules($filters, 'extra_'); $extra_fields = $result['extra_fields']; $condition_array = $result['condition_array']; if (!empty($condition_array)) { $where_condition .= ' AND ( '; $where_condition .= implode($filters->groupOp, $condition_array); $where_condition .= ' ) '; } // Question field. $resultQuestion = $extraField->getExtraFieldRules($filters, 'question_'); $questionFields = $resultQuestion['extra_fields']; $condition_array = $resultQuestion['condition_array']; if (!empty($condition_array)) { $where_condition .= ' AND ( '; $where_condition .= implode($filters->groupOp, $condition_array); $where_condition .= ' ) '; } } } // get index row - i.e. user click to sort $sord = $_GET['sord']; // get the direction if (!$sidx) { $sidx = 1; } //2. Selecting the count FIRST //@todo rework this switch ($action) { case 'get_questions': $categoryId = $request->get('categoryId'); $exerciseId = $request->get('exerciseId'); //$courseId = null; //$request->get('courseId'); $courseId = $request->get('courseId'); // Question manager can view all questions if (api_is_question_manager()) { $courseId = null; } $count = \Question::getQuestions($app, $categoryId, $exerciseId, $courseId, array('where' => $where_condition, 'extra' => $extra_fields, 'question' => $questionFields), true); break; case 'get_user_list_plugin_widescale': $count = \UserManager::get_user_data(null, null, null, null, true); break; case 'get_question_list': require_once api_get_path(SYS_CODE_PATH) . 'exercice/exercise.class.php'; $exerciseId = $request->get('exerciseId'); $exercise = new \Exercise(api_get_course_int_id()); $exercise->read($exerciseId); $count = $exercise->selectNbrQuestions(); break; case 'get_group_reporting': $course_id = $request->get('course_id'); $group_id = $request->get('gidReq'); $count = \Tracking::get_group_reporting($course_id, $group_id, 'count'); break; case 'get_user_course_report_resumed': $count = \CourseManager::get_count_user_list_from_course_code(true, 'ruc'); break; case 'get_user_course_report': $count = \CourseManager::get_count_user_list_from_course_code(false); break; case 'get_course_exercise_medias': $course_id = api_get_course_int_id(); $count = \Question::get_count_course_medias($course_id); break; case 'get_user_skill_ranking': $skill = new \Skill(); $count = $skill->get_user_list_skill_ranking_count(); break; case 'get_work_user_list': require_once api_get_path(SYS_CODE_PATH) . 'work/work.lib.php'; $work_id = $request->get('work_id'); //$_REQUEST['work_id']; $count = get_count_work($work_id); break; case 'get_exercise_results': $exercise_id = $request->get('exerciseId'); //$_REQUEST['exerciseId']; $filter_by_user = $request->get('filter_by_user'); if (isset($filter_by_user) && !empty($filter_by_user)) { $filter_user = intval($filter_by_user); if ($where_condition == "") { $where_condition .= " te.exe_user_id = '{$filter_user}'"; } else { $where_condition .= " AND te.exe_user_id = '{$filter_user}'"; } } $count = \ExerciseLib::get_count_exam_results($exercise_id, $where_condition); break; case 'get_hotpotatoes_exercise_results': $hotpot_path = $request->get('path'); //$_REQUEST['path']; $count = \ExerciseLib::get_count_exam_hotpotatoes_results($hotpot_path); break; case 'get_sessions': $list_type = $request->get('list_type'); if ($list_type == 'simple' || empty($list_type)) { $count = \SessionManager::get_sessions_admin(array('where' => $where_condition, 'extra' => $extra_fields), true); } else { $count = \SessionManager::get_count_admin_complete(array('where' => $where_condition, 'extra' => $extra_fields)); } break; case 'get_extra_fields': $obj = new \ExtraField($type); $count = $obj->get_count(); break; case 'get_extra_field_options': $field_id = $request->get('field_id'); $obj = new \ExtraFieldOption($type); $count = $obj->get_count_by_field_id($field_id); break; case 'get_timelines': $obj = new \Timeline(); $count = $obj->get_count(); break; case 'get_gradebooks': $obj = new \Gradebook(); $count = $obj->get_count(); break; case 'get_event_email_template': $obj = new \EventEmailTemplate(); $count = $obj->get_count(); break; case 'get_careers': $obj = new \Career(); $count = $obj->get_count(); break; case 'get_promotions': $obj = new \Promotion(); $count = $obj->get_count(); break; case 'get_grade_models': $obj = new \GradeModel(); $count = $obj->get_count(); break; case 'get_usergroups': $obj = new \UserGroup(); $count = $obj->get_count(); break; case 'get_usergroups_teacher': $obj = new \UserGroup(); $course_id = api_get_course_int_id(); if ($type == 'registered') { $count = $obj->get_usergroup_by_course_with_data_count($course_id); } else { $count = $obj->get_count(); } break; default: exit; } //3. Calculating first, end, etc $total_pages = 0; if ((int) $count > 0) { if (!empty($limit)) { $total_pages = ceil($count / $limit); } } if ($page > $total_pages) { $page = $total_pages; } $start = $limit * $page - $limit; if ($start < 0) { $start = 0; } //4. Deleting an element if the user wants to if ($operation == 'del') { $obj->delete($request->get('id')); } $is_allowedToEdit = api_is_allowed_to_edit(null, true) || api_is_allowed_to_edit(true) || api_is_drh(); //5. Querying the DB for the elements $columns = array(); switch ($action) { case 'get_questions': $columns = \Question::getQuestionColumns(api_get_course_id(), $extra_fields, $questionFields, true); $columns = $columns['simple_column_name']; $result = \Question::getQuestions($app, $categoryId, $exerciseId, $courseId, array('where' => $where_condition, 'order' => "{$sidx} {$sord}", 'extra' => $extra_fields, 'question' => $questionFields, 'limit' => "{$start} , {$limit}")); //var_dump($result); break; case 'get_user_list_plugin_widescale': $columns = array('username', 'firstname', 'lastname', 'exam_password'); $column_names = array(get_lang('Username'), get_lang('Firstname'), get_lang('Lastname'), get_lang('Password')); $result = \UserManager::get_user_data($start, $limit, $sidx, $sord); break; case 'get_question_list': if (isset($exercise) && !empty($exercise)) { $columns = array('question', 'type', 'category', 'level', 'score', 'actions'); $result = $exercise->getQuestionListPagination($start, $limit, $sidx, $sord, $where_condition); } break; case 'get_group_reporting': $columns = array('name', 'time', 'progress', 'score', 'works', 'messages', 'actions'); $result = \Tracking::get_group_reporting($course_id, $group_id, 'all', $start, $limit, $sidx, $sord, $where_condition); break; case 'get_course_exercise_medias': $columns = array('question'); $result = \Question::get_course_medias($course_id, $start, $limit, $sidx, $sord, $where_condition); if (!empty($result)) { foreach ($result as &$media) { $media['id'] = $media['iid']; } } break; case 'get_user_course_report_resumed': $columns = array('extra_ruc', 'training_hours', 'count_users', 'count_users_registered', 'average_hours_per_user', 'count_certificates'); $column_names = array(get_lang('Company'), get_lang('TrainingHoursAccumulated'), get_lang('CountOfSubscriptions'), get_lang('CountOfUsers'), get_lang('AverageHoursPerStudent'), get_lang('CountCertificates')); $result = \CourseManager::get_user_list_from_course_code(null, null, "LIMIT {$start}, {$limit}", " {$sidx} {$sord}", null, null, true, true, 'ruc'); $new_result = array(); if (!empty($result)) { foreach ($result as $row) { $row['training_hours'] = api_time_to_hms($row['training_hours']); $row['average_hours_per_user'] = api_time_to_hms($row['average_hours_per_user']); $new_result[] = $row; } $result = $new_result; } break; case 'get_user_course_report': $columns = array('course', 'user', 'time', 'certificate', 'progress_100', 'progress'); $column_names = array(get_lang('Course'), get_lang('User'), get_lang('ManHours'), get_lang('CertificateGenerated'), get_lang('Approved'), get_lang('CourseAdvance')); $extra_fields = \UserManager::get_extra_fields(0, 100, null, null, true, true); if (!empty($extra_fields)) { foreach ($extra_fields as $extra) { $columns[] = $extra['1']; $column_names[] = $extra['3']; } } $result = \CourseManager::get_user_list_from_course_code(null, null, "LIMIT {$start}, {$limit}", " {$sidx} {$sord}", null, null, true); break; case 'get_user_skill_ranking': $columns = array('photo', 'firstname', 'lastname', 'skills_acquired', 'currently_learning', 'rank'); $result = $skill->get_user_list_skill_ranking($start, $limit, $sidx, $sord, $where_condition); $result = \ArrayClass::msort($result, 'skills_acquired', 'asc'); $skills_in_course = array(); if (!empty($result)) { //$counter = 1; foreach ($result as &$item) { $user_info = api_get_user_info($item['user_id']); $personal_course_list = \UserManager::get_personal_session_course_list($item['user_id']); $count_skill_by_course = array(); foreach ($personal_course_list as $course_item) { if (!isset($skills_in_course[$course_item['code']])) { $count_skill_by_course[$course_item['code']] = $skill->get_count_skills_by_course($course_item['code']); $skills_in_course[$course_item['code']] = $count_skill_by_course[$course_item['code']]; } else { $count_skill_by_course[$course_item['code']] = $skills_in_course[$course_item['code']]; } } $item['photo'] = \Display::img($user_info['avatar_small']); $item['currently_learning'] = !empty($count_skill_by_course) ? array_sum($count_skill_by_course) : 0; } } break; case 'get_work_user_list': if (isset($type) && $type == 'simple') { $columns = array('type', 'firstname', 'lastname', 'username', 'title', 'qualification', 'sent_date', 'qualificator_id', 'actions'); } else { $columns = array('type', 'firstname', 'lastname', 'username', 'title', 'sent_date', 'actions'); } $result = get_work_user_list($start, $limit, $sidx, $sord, $work_id, $where_condition); break; case 'get_exercise_results': $course = api_get_course_info(); //used inside get_exam_results_data() $documentPath = api_get_path(SYS_COURSE_PATH) . $course['path'] . "/document"; if ($is_allowedToEdit) { $columns = array('firstname', 'lastname', 'username', 'group_name', 'exe_duration', 'start_date', 'exe_date', 'score', 'status', 'lp', 'actions'); } else { //$columns = array('exe_duration', 'start_date', 'exe_date', 'score', 'status', 'actions'); } $result = \ExerciseLib::get_exam_results_data($start, $limit, $sidx, $sord, $exercise_id, $where_condition); break; case 'get_hotpotatoes_exercise_results': $course = api_get_course_info(); //used inside get_exam_results_data() $documentPath = api_get_path(SYS_COURSE_PATH) . $course['path'] . "/document"; $columns = array('firstname', 'lastname', 'username', 'group_name', 'exe_date', 'score', 'actions'); $result = ExerciseLib::get_exam_results_hotpotatoes_data($start, $limit, $sidx, $sord, $hotpot_path, $where_condition); //get_exam_results_data($start, $limit, $sidx, $sord, $exercise_id, $where_condition); break; case 'get_sessions': $session_columns = \SessionManager::get_session_columns($list_type); $columns = $session_columns['simple_column_name']; if ($list_type == 'simple') { $result = SessionManager::get_sessions_admin(array('where' => $where_condition, 'order' => "{$sidx} {$sord}", 'extra' => $extra_fields, 'limit' => "{$start} , {$limit}"), false); } else { $result = SessionManager::get_sessions_admin_complete(array('where' => $where_condition, 'order' => "{$sidx} {$sord}", 'extra' => $extra_fields, 'limit' => "{$start} , {$limit}")); } break; case 'get_timelines': $columns = array('headline', 'actions'); //$columns = array('headline', 'type', 'start_date', 'end_date', 'text', 'media', 'media_credit', 'media_caption', 'title_slide', 'parent_id'); if (!in_array($sidx, $columns)) { $sidx = 'headline'; } $course_id = api_get_course_int_id(); $result = Database::select('*', $obj->table, array('where' => array('parent_id = ? AND c_id = ?' => array('0', $course_id)), 'order' => "{$sidx} {$sord}", 'LIMIT' => "{$start} , {$limit}")); $new_result = array(); foreach ($result as $item) { if (!$item['status']) { $item['name'] = '<font style="color:#AAA">' . $item['name'] . '</font>'; } $item['headline'] = Display::url($item['headline'], api_get_path(WEB_CODE_PATH) . 'timeline/view.php?id=' . $item['id']); $item['actions'] = Display::url(Display::return_icon('add.png', get_lang('AddItems')), api_get_path(WEB_CODE_PATH) . 'timeline/?action=add_item&parent_id=' . $item['id']); $item['actions'] .= Display::url(Display::return_icon('edit.png', get_lang('Edit')), api_get_path(WEB_CODE_PATH) . 'timeline/?action=edit&id=' . $item['id']); $item['actions'] .= Display::url(Display::return_icon('delete.png', get_lang('Delete')), api_get_path(WEB_CODE_PATH) . 'timeline/?action=delete&id=' . $item['id']); $new_result[] = $item; } $result = $new_result; break; case 'get_gradebooks': $columns = array('name', 'certificates', 'skills', 'actions', 'has_certificates'); if (!in_array($sidx, $columns)) { $sidx = 'name'; } $result = Database::select('*', $obj->table, array('order' => "{$sidx} {$sord}", 'LIMIT' => "{$start} , {$limit}")); $new_result = array(); foreach ($result as $item) { if ($item['parent_id'] != 0) { continue; } $skills = $obj->get_skills_by_gradebook($item['id']); //Fixes bug when gradebook doesn't have names if (empty($item['name'])) { $item['name'] = $item['course_code']; } else { //$item['name'] = $item['name'].' ['.$item['course_code'].']'; } $item['name'] = Display::url($item['name'], api_get_path(WEB_CODE_PATH) . 'gradebook/index.php?id_session=0&cidReq=' . $item['course_code']); if (!empty($item['certif_min_score']) && !empty($item['document_id'])) { $item['certificates'] = Display::return_icon('accept.png', get_lang('WithCertificate'), array(), ICON_SIZE_SMALL); $item['has_certificates'] = '1'; } else { $item['certificates'] = Display::return_icon('warning.png', get_lang('NoCertificate'), array(), ICON_SIZE_SMALL); $item['has_certificates'] = '0'; } if (!empty($skills)) { foreach ($skills as $skill) { $item['skills'] .= Display::span($skill['name'], array('class' => 'label_tag skill')); } } $new_result[] = $item; } $result = $new_result; break; case 'get_event_email_template': $columns = array('subject', 'event_type_name', 'language_id', 'activated', 'actions'); if (!in_array($sidx, $columns)) { $sidx = 'subject'; } $result = Database::select('*', $obj->table, array('order' => "{$sidx} {$sord}", 'LIMIT' => "{$start} , {$limit}")); $new_result = array(); foreach ($result as $item) { $language_info = api_get_language_info($item['language_id']); $item['language_id'] = $language_info['english_name']; $item['actions'] = Display::url(Display::return_icon('edit.png', get_lang('Edit')), api_get_path(WEB_CODE_PATH) . 'admin/event_type.php?action=edit&event_type_name=' . $item['event_type_name']); $item['actions'] .= Display::url(Display::return_icon('delete.png', get_lang('Delete')), api_get_path(WEB_CODE_PATH) . 'admin/event_controller.php?action=delete&id=' . $item['id']); /*if (!$item['status']) { $item['name'] = '<font style="color:#AAA">'.$item['subject'].'</font>'; }*/ $new_result[] = $item; } $result = $new_result; break; case 'get_careers': $columns = array('name', 'description', 'actions'); if (!in_array($sidx, $columns)) { $sidx = 'name'; } $result = Database::select('*', $obj->table, array('order' => "{$sidx} {$sord}", 'LIMIT' => "{$start} , {$limit}")); $new_result = array(); foreach ($result as $item) { if (!$item['status']) { $item['name'] = '<font style="color:#AAA">' . $item['name'] . '</font>'; } $new_result[] = $item; } $result = $new_result; break; case 'get_promotions': $columns = array('name', 'career', 'description', 'actions'); if (!in_array($sidx, $columns)) { $sidx = 'name'; } $result = Database::select('p.id,p.name, p.description, c.name as career, p.status', "{$obj->table} p LEFT JOIN " . Database::get_main_table(TABLE_CAREER) . " c ON c.id = p.career_id ", array('order' => "{$sidx} {$sord}", 'LIMIT' => "{$start} , {$limit}")); $new_result = array(); foreach ($result as $item) { if (!$item['status']) { $item['name'] = '<font style="color:#AAA">' . $item['name'] . '</font>'; } $new_result[] = $item; } $result = $new_result; break; case 'get_grade_models': $columns = array('name', 'description', 'actions'); if (!in_array($sidx, $columns)) { $sidx = 'name'; } $result = Database::select('*', "{$obj->table} ", array('order' => "{$sidx} {$sord}", 'LIMIT' => "{$start} , {$limit}")); $new_result = array(); foreach ($result as $item) { $new_result[] = $item; } $result = $new_result; break; case 'get_usergroups': $columns = array('name', 'users', 'courses', 'sessions', 'group_type', 'actions'); $result = Database::select('*', $obj->table, array('order' => "name {$sord}", 'LIMIT' => "{$start} , {$limit}")); $new_result = array(); if (!empty($result)) { foreach ($result as $group) { $group['sessions'] = count($obj->get_sessions_by_usergroup($group['id'])); $group['courses'] = count($obj->get_courses_by_usergroup($group['id'])); $group['users'] = count($obj->get_users_by_usergroup($group['id'])); switch ($group['group_type']) { case '0': $group['group_type'] = Display::label(get_lang('Class'), 'info'); break; case '1': $group['group_type'] = Display::label(get_lang('Social'), 'success'); break; } $new_result[] = $group; } $result = $new_result; } $columns = array('name', 'users', 'courses', 'sessions', 'group_type'); if (!in_array($sidx, $columns)) { $sidx = 'name'; } //Multidimensional sort ArrayClass::msort($result, $sidx); break; case 'get_extra_fields': $obj = new \ExtraField($type); $columns = array('field_display_text', 'field_variable', 'field_type', 'field_changeable', 'field_visible', 'field_filter', 'field_order'); $result = \Database::select('*', $obj->table, array('order' => "{$sidx} {$sord}", 'LIMIT' => "{$start} , {$limit}")); $new_result = array(); if (!empty($result)) { foreach ($result as $item) { $item['field_type'] = $obj->get_field_type_by_id($item['field_type']); $item['field_changeable'] = $item['field_changeable'] ? Display::return_icon('right.gif') : Display::return_icon('wrong.gif'); $item['field_visible'] = $item['field_visible'] ? Display::return_icon('right.gif') : Display::return_icon('wrong.gif'); $item['field_filter'] = $item['field_filter'] ? Display::return_icon('right.gif') : Display::return_icon('wrong.gif'); $new_result[] = $item; } $result = $new_result; } break; case 'get_extra_field_options': $obj = new \ExtraFieldOption($type); $columns = array('option_display_text', 'option_value', 'option_order'); $result = \Database::select('*', $obj->table, array('where' => array("field_id = ? " => $field_id), 'order' => "{$sidx} {$sord}", 'LIMIT' => "{$start} , {$limit}")); /*$new_result = array(); if (!empty($result)) { foreach ($result as $item) { $item['field_type'] = $obj->get_field_type_by_id($item['field_type']); $item['field_changeable'] = $item['field_changeable'] ? Display::return_icon('right.gif') : Display::return_icon('wrong.gif'); $item['field_visible'] = $item['field_visible'] ? Display::return_icon('right.gif') : Display::return_icon('wrong.gif'); $item['field_filter'] = $item['field_filter'] ? Display::return_icon('right.gif') : Display::return_icon('wrong.gif'); $new_result[] = $item; } $result = $new_result; }*/ break; case 'get_usergroups_teacher': $columns = array('name', 'users', 'actions'); $options = array('order' => "name {$sord}", 'LIMIT' => "{$start} , {$limit}"); $options['course_id'] = $course_id; switch ($type) { case 'not_registered': $options['where'] = array(" (course_id IS NULL OR course_id != ?) " => $course_id); $result = $obj->get_usergroup_not_in_course($options); break; case 'registered': $options['where'] = array(" usergroup.course_id = ? " => $course_id); $result = $obj->get_usergroup_in_course($options); break; } $new_result = array(); if (!empty($result)) { foreach ($result as $group) { $group['users'] = count($obj->get_users_by_usergroup($group['id'])); if ($obj->usergroup_was_added_in_course($group['id'], $course_id)) { $url = 'class.php?action=remove_class_from_course&id=' . $group['id']; $icon = Display::return_icon('delete.png', get_lang('Remove')); } else { $url = 'class.php?action=add_class_to_course&id=' . $group['id']; $icon = Display::return_icon('add.png', get_lang('Add')); } $group['actions'] = Display::url($icon, $url); $new_result[] = $group; } $result = $new_result; } if (!in_array($sidx, $columns)) { $sidx = 'name'; } //Multidimensional sort \ArrayClass::msort($result, $sidx); break; default: exit; } $allowed_actions = array('get_careers', 'get_promotions', 'get_usergroups', 'get_usergroups_teacher', 'get_gradebooks', 'get_sessions', 'get_exercise_results', 'get_hotpotatoes_exercise_results', 'get_work_user_list', 'get_timelines', 'get_grade_models', 'get_event_email_template', 'get_user_skill_ranking', 'get_extra_fields', 'get_extra_field_options', 'get_course_exercise_medias', 'get_user_course_report', 'get_user_course_report_resumed', 'get_group_reporting', 'get_question_list', 'get_user_list_plugin_widescale', 'get_questions'); //5. Creating an obj to return a json if (in_array($action, $allowed_actions)) { $response = new \stdClass(); $response->page = $page; $response->total = $total_pages; $response->records = $count; if ($operation && $operation == 'excel') { $j = 1; $array = array(); if (empty($column_names)) { $column_names = $columns; } //Headers foreach ($column_names as $col) { $array[0][] = $col; } foreach ($result as $row) { foreach ($columns as $col) { $array[$j][] = strip_tags($row[$col]); } $j++; } switch ($export_format) { case 'xls': Export::export_table_xls($array, 'company_report'); break; case 'csv': default: Export::export_table_csv($array, 'company_report'); break; } exit; } $i = 0; if (!empty($result)) { foreach ($result as $row) { //print_r($row); // if results tab give not id, set id to $i otherwise id="null" for all <tr> of the jqgrid - ref #4235 if (!isset($row['id']) || isset($row['id']) && $row['id'] == "") { $response->rows[$i]['id'] = $i; } else { $response->rows[$i]['id'] = $row['id']; } $array = array(); foreach ($columns as $col) { $array[] = isset($row[$col]) ? $row[$col] : null; } $response->rows[$i]['cell'] = $array; $i++; } } return json_encode($response); } }
/** * Set footer parameters */ private function setFooterParameters() { //Show admin data //$this->assign('show_administrator_data', api_get_setting('show_administrator_data')); if (api_get_setting('show_administrator_data') == 'true') { //Administrator name $administrator_data = get_lang('Manager') . ' : ' . Display::encrypted_mailto_link(api_get_setting('admin.administrator_email'), api_get_person_name(api_get_setting('admin.administrator_name'), api_get_setting('admin.administrator_surname'))); $this->assign('administrator_name', $administrator_data); } //Loading footer extra content if (!api_is_platform_admin()) { //$extra_footer = trim(api_get_setting('footer_extra_content')); if (!empty($extra_footer)) { $this->assign('footer_extra_content', $extra_footer); } } $courseId = api_get_course_int_id(); //Tutor name if (api_get_setting('show_tutor_data') == 'true') { // Course manager $id_session = api_get_session_id(); if (isset($courseId) && $courseId != -1 && !empty($courseId)) { $tutor_data = ''; if ($id_session != 0) { $coachs_email = CourseManager::get_email_of_tutor_to_session($id_session, $courseId); $email_link = array(); foreach ($coachs_email as $coach) { $email_link[] = Display::encrypted_mailto_link($coach['email'], $coach['complete_name']); } if (count($coachs_email) > 1) { $tutor_data .= get_lang('Coachs') . ' : '; $tutor_data .= ArrayClass::array_to_string($email_link, CourseManager::USER_SEPARATOR); } elseif (count($coachs_email) == 1) { $tutor_data .= get_lang('Coach') . ' : '; $tutor_data .= ArrayClass::array_to_string($email_link, CourseManager::USER_SEPARATOR); } elseif (count($coachs_email) == 0) { $tutor_data .= ''; } } $this->assign('session_teachers', $tutor_data); } } if (api_get_setting('show_teacher_data') == 'true') { // course manager if (isset($courseId) && $courseId != -1 && !empty($courseId)) { $courseInfo = api_get_course_info(); $teacher_data = null; $label = get_lang('Teacher'); if (count($courseInfo['teacher_list']) > 1) { $label = get_lang('Teachers'); } $teacher_data .= $label . ' : ' . $courseInfo['teacher_list_formatted']; $this->assign('teachers', $teacher_data); } } }
/** * @param int $session_id * @param int $courseId * @param string $separator * @param bool $add_link_to_profile * @return null|string */ public static function get_coachs_from_course_to_string($session_id = 0, $courseId = null, $separator = self::USER_SEPARATOR, $add_link_to_profile = false, $orderList = false) { $coachs_course = self::get_coachs_from_course($session_id, $courseId); $course_coachs = array(); $html = ''; if (is_array($coachs_course)) { foreach ($coachs_course as $coach_course) { $coach_name = api_get_person_name($coach_course['firstname'], $coach_course['lastname']); if ($add_link_to_profile) { $url = api_get_path(WEB_AJAX_PATH) . 'user_manager.ajax.php?a=get_user_popup&user_id=' . $coach_course['user_id']; $coach_name = Display::url($coach_name, $url, ['class' => 'ajax', 'data-title' => $coach_name]); } $course_coachs[] = $coach_name; } } $coaches_to_string = null; if (!empty($course_coachs)) { if ($orderList === true) { $html .= '<ul class="user-coachs">'; foreach ($course_coachs as $coachs) { $html .= Display::tag('li', Display::return_icon('teacher.png', $coachs, null, ICON_SIZE_TINY) . ' ' . $coachs); } $html .= '</ul>'; } else { $coaches_to_string = ArrayClass::array_to_string($course_coachs, $separator); } } return $html; }
continue; } } if (!empty($lp_item['expired_on']) && $lp_item['expired_on'] != '0000-00-00 00:00:00') { if ($now > api_strtotime($lp_item['expired_on'], 'UTC')) { continue; } } $temp[$count]['cell'] = array($date, $item['title'], Display::url($icons . ' ' . $lp_item['lp_name'], $lp_url, array('target' => SESSION_LINK_TARGET))); $temp[$count]['course'] = strip_tags($item['title']); $temp[$count]['lp'] = $lp_item['lp_name']; $temp[$count]['date'] = $lp_item['publicated_on']; $count++; } } $temp = ArrayClass::msort($temp, $sidx, $sord); $response = new stdClass(); $i = 0; foreach ($temp as $key => $row) { $row = $row['cell']; if (!empty($row)) { if ($key >= $start && $key < $start + $limit) { $response->rows[$i]['id'] = $key; $response->rows[$i]['cell'] = array($row[0], $row[1], $row[2]); $i++; } } } if ($count > 0 && $limit > 0) { $total_pages = ceil($count / $limit); } else {
/** * Shows the user progress (when clicking in the Progress tab) * * @param int $user_id * @param int $session_id * @param string $extra_params * @param bool $show_courses * @param bool $showAllSessions * * @return string */ public static function show_user_progress($user_id, $session_id = 0, $extra_params = '', $show_courses = true, $showAllSessions = true) { $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE); $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION); $tbl_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER); $tbl_access_rel_course = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE); $tbl_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); $tbl_access_rel_session = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); $user_id = intval($user_id); $session_id = intval($session_id); if (api_is_multiple_url_enabled()) { $sql = "SELECT c.code, title\n FROM {$tbl_course_user} cu\n INNER JOIN {$tbl_course} c\n ON (cu.c_id = c.id)\n INNER JOIN {$tbl_access_rel_course} a\n ON (a.c_id = c.id)\n WHERE\n cu.user_id = {$user_id} AND\n relation_type<> " . COURSE_RELATION_TYPE_RRHH . " AND\n access_url_id = " . api_get_current_access_url_id() . "\n ORDER BY title"; } else { $sql = "SELECT c.code, title\n FROM {$tbl_course_user} u\n INNER JOIN {$tbl_course} c ON (c_id = c.id)\n WHERE\n u.user_id= {$user_id} AND\n relation_type<>" . COURSE_RELATION_TYPE_RRHH . "\n ORDER BY title"; } $rs = Database::query($sql); $courses = $course_in_session = $temp_course_in_session = array(); while ($row = Database::fetch_array($rs, 'ASSOC')) { $courses[$row['code']] = $row['title']; } $orderBy = " ORDER BY name "; $extraInnerJoin = null; if (SessionManager::orderCourseIsEnabled() && !empty($session_id)) { $orderBy = " ORDER BY s.id, position "; $tableSessionRelCourse = Database::get_main_table(TABLE_MAIN_SESSION_COURSE); $extraInnerJoin = " INNER JOIN {$tableSessionRelCourse} src\n ON (cu.c_id = src.c_id AND src.session_id = {$session_id}) "; } $sessionCondition = ''; if (!empty($session_id)) { $sessionCondition = " AND s.id = {$session_id}"; } // Get the list of sessions where the user is subscribed as student if (api_is_multiple_url_enabled()) { $sql = "SELECT DISTINCT c.code, s.id as session_id, name\n FROM {$tbl_session_course_user} cu\n INNER JOIN {$tbl_access_rel_session} a\n ON (a.session_id = cu.session_id)\n INNER JOIN {$tbl_session} s\n ON (s.id = a.session_id)\n INNER JOIN {$tbl_course} c\n ON (c.id = cu.c_id)\n {$extraInnerJoin}\n WHERE\n cu.user_id = {$user_id} AND\n access_url_id = " . api_get_current_access_url_id() . "\n {$sessionCondition}\n {$orderBy} "; } else { $sql = "SELECT DISTINCT c.code, s.id as session_id, name\n FROM {$tbl_session_course_user} cu\n INNER JOIN {$tbl_session} s\n ON (s.id = cu.session_id)\n INNER JOIN {$tbl_course} c\n ON (c.id = cu.c_id)\n {$extraInnerJoin}\n WHERE\n cu.user_id = {$user_id}\n {$sessionCondition}\n {$orderBy} "; } $rs = Database::query($sql); $simple_session_array = array(); while ($row = Database::fetch_array($rs)) { $course_info = CourseManager::get_course_information($row['code']); $temp_course_in_session[$row['session_id']]['course_list'][$course_info['real_id']] = $course_info; $temp_course_in_session[$row['session_id']]['name'] = $row['name']; $simple_session_array[$row['session_id']] = $row['name']; } foreach ($simple_session_array as $my_session_id => $session_name) { $course_list = $temp_course_in_session[$my_session_id]['course_list']; $my_course_data = array(); foreach ($course_list as $course_data) { $my_course_data[$course_data['id']] = $course_data['title']; } if (empty($session_id)) { $my_course_data = ArrayClass::utf8_sort($my_course_data); } $final_course_data = array(); foreach ($my_course_data as $course_id => $value) { $final_course_data[$course_id] = $course_list[$course_id]; } $course_in_session[$my_session_id]['course_list'] = $final_course_data; $course_in_session[$my_session_id]['name'] = $session_name; } $html = ''; // Course list if ($show_courses) { if (!empty($courses)) { $html .= Display::page_subheader(Display::return_icon('course.png', get_lang('MyCourses'), array(), ICON_SIZE_SMALL) . ' ' . get_lang('MyCourses')); $html .= '<table class="data_table" width="100%">'; $html .= '<tr> ' . Display::tag('th', get_lang('Course'), array('width' => '300px')) . ' ' . Display::tag('th', get_lang('TimeSpentInTheCourse'), array('class' => 'head')) . ' ' . Display::tag('th', get_lang('Progress'), array('class' => 'head')) . ' ' . Display::tag('th', get_lang('Score') . Display::return_icon('info3.gif', get_lang('ScormAndLPTestTotalAverage'), array('align' => 'absmiddle', 'hspace' => '3px')), array('class' => 'head')) . ' ' . Display::tag('th', get_lang('LastConnexion'), array('class' => 'head')) . ' ' . Display::tag('th', get_lang('Details'), array('class' => 'head')) . ' </tr>'; foreach ($courses as $course_code => $course_title) { $courseInfo = api_get_course_info($course_code); $courseId = $courseInfo['real_id']; $total_time_login = Tracking::get_time_spent_on_the_course($user_id, $courseId); $time = api_time_to_hms($total_time_login); $progress = Tracking::get_avg_student_progress($user_id, $course_code); $percentage_score = Tracking::get_avg_student_score($user_id, $course_code, array()); $last_connection = Tracking::get_last_connection_date_on_the_course($user_id, $courseInfo); if (is_null($progress)) { $progress = '0%'; } else { $progress = $progress . '%'; } if (isset($_GET['course']) && $course_code == $_GET['course'] && empty($_GET['session_id'])) { $html .= '<tr class="row_odd" style="background-color:#FBF09D">'; } else { $html .= '<tr class="row_even">'; } $url = api_get_course_url($course_code, $session_id); $course_url = Display::url($course_title, $url, array('target' => SESSION_LINK_TARGET)); $html .= '<td>' . $course_url . '</td>'; $html .= '<td align="center">' . $time . '</td>'; $html .= '<td align="center">' . $progress . '</td>'; $html .= '<td align="center">'; if (is_numeric($percentage_score)) { $html .= $percentage_score . '%'; } else { $html .= '0%'; } $html .= '</td>'; $html .= '<td align="center">' . $last_connection . '</td>'; $html .= '<td align="center">'; if (isset($_GET['course']) && $course_code == $_GET['course'] && empty($_GET['session_id'])) { $html .= '<a href="#">'; $html .= Display::return_icon('2rightarrow_na.png', get_lang('Details')); } else { $html .= '<a href="' . api_get_self() . '?course=' . $course_code . $extra_params . '">'; $html .= Display::return_icon('2rightarrow.png', get_lang('Details')); } $html .= '</a>'; $html .= '</td></tr>'; } $html .= '</table>'; } } // Session list if (!empty($course_in_session)) { $main_session_graph = ''; //Load graphics only when calling to an specific session $session_graph = array(); $all_exercise_graph_name_list = array(); $my_results = array(); $all_exercise_graph_list = array(); $all_exercise_start_time = array(); foreach ($course_in_session as $my_session_id => $session_data) { $course_list = $session_data['course_list']; $session_name = $session_data['name']; $user_count = count(SessionManager::get_users_by_session($my_session_id)); $exercise_graph_name_list = array(); //$user_results = array(); $exercise_graph_list = array(); foreach ($course_list as $course_data) { $exercise_list = ExerciseLib::get_all_exercises($course_data, $my_session_id, false, null, false, 1); foreach ($exercise_list as $exercise_data) { $exercise_obj = new Exercise($course_data['id']); $exercise_obj->read($exercise_data['id']); //Exercise is not necessary to be visible to show results check the result_disable configuration instead //$visible_return = $exercise_obj->is_visible(); if ($exercise_data['results_disabled'] == 0 || $exercise_data['results_disabled'] == 2) { $best_average = intval(ExerciseLib::get_best_average_score_by_exercise($exercise_data['id'], $course_data['id'], $my_session_id, $user_count)); $exercise_graph_list[] = $best_average; $all_exercise_graph_list[] = $best_average; $user_result_data = ExerciseLib::get_best_attempt_by_user(api_get_user_id(), $exercise_data['id'], $course_data['real_id'], $my_session_id); $score = 0; if (!empty($user_result_data['exe_weighting']) && intval($user_result_data['exe_weighting']) != 0) { $score = intval($user_result_data['exe_result'] / $user_result_data['exe_weighting'] * 100); } $time = api_strtotime($exercise_data['start_time']) ? api_strtotime($exercise_data['start_time'], 'UTC') : 0; $all_exercise_start_time[] = $time; $my_results[] = $score; if (count($exercise_list) <= 10) { $title = cut($course_data['title'], 30) . " \n " . cut($exercise_data['title'], 30); $exercise_graph_name_list[] = $title; $all_exercise_graph_name_list[] = $title; } else { // if there are more than 10 results, space becomes difficult to find, so only show the title of the exercise, not the tool $title = cut($exercise_data['title'], 30); $exercise_graph_name_list[] = $title; $all_exercise_graph_name_list[] = $title; } } } } } // Complete graph if (!empty($my_results) && !empty($all_exercise_graph_list)) { asort($all_exercise_start_time); //Fix exams order $final_all_exercise_graph_name_list = array(); $my_results_final = array(); $final_all_exercise_graph_list = array(); foreach ($all_exercise_start_time as $key => $time) { $label_time = ''; if (!empty($time)) { $label_time = date('d-m-y', $time); } $final_all_exercise_graph_name_list[] = $all_exercise_graph_name_list[$key] . ' ' . $label_time; $my_results_final[] = $my_results[$key]; $final_all_exercise_graph_list[] = $all_exercise_graph_list[$key]; } $main_session_graph = self::generate_session_exercise_graph($final_all_exercise_graph_name_list, $my_results_final, $final_all_exercise_graph_list); } $html .= Display::page_subheader(Display::return_icon('session.png', get_lang('Sessions'), array(), ICON_SIZE_SMALL) . ' ' . get_lang('Sessions')); $html .= '<table class="data_table" width="100%">'; $html .= '<tr> ' . Display::tag('th', get_lang('Session'), array('width' => '300px')) . ' ' . Display::tag('th', get_lang('PublishedExercises'), array('width' => '300px')) . ' ' . Display::tag('th', get_lang('NewExercises'), array('class' => 'head')) . ' ' . Display::tag('th', get_lang('AverageExerciseResult'), array('class' => 'head')) . ' ' . Display::tag('th', get_lang('Details'), array('class' => 'head')) . ' </tr>'; foreach ($course_in_session as $my_session_id => $session_data) { $course_list = $session_data['course_list']; $session_name = $session_data['name']; if ($showAllSessions == false) { if (isset($session_id) && !empty($session_id)) { if ($session_id != $my_session_id) { continue; } } } $all_exercises = 0; $all_unanswered_exercises_by_user = 0; $all_average = 0; $stats_array = array(); foreach ($course_list as $course_data) { //All exercises in the course @todo change for a real count $exercises = ExerciseLib::get_all_exercises($course_data, $my_session_id); $count_exercises = 0; if (is_array($exercises) && !empty($exercises)) { $count_exercises = count($exercises); } // Count of user results $done_exercises = null; $courseInfo = api_get_course_info($course_data['code']); $answered_exercises = 0; if (!empty($exercises)) { foreach ($exercises as $exercise_item) { $attempts = Event::count_exercise_attempts_by_user(api_get_user_id(), $exercise_item['id'], $courseInfo['real_id'], $my_session_id); if ($attempts > 1) { $answered_exercises++; } } } // Average $average = ExerciseLib::get_average_score_by_course($courseInfo['real_id'], $my_session_id); $all_exercises += $count_exercises; $all_unanswered_exercises_by_user += $count_exercises - $answered_exercises; $all_average += $average; } $all_average = $all_average / count($course_list); if (isset($_GET['session_id']) && $my_session_id == $_GET['session_id']) { $html .= '<tr style="background-color:#FBF09D">'; } else { $html .= '<tr>'; } $url = api_get_path(WEB_CODE_PATH) . "session/index.php?session_id={$my_session_id}"; $html .= Display::tag('td', Display::url($session_name, $url, array('target' => SESSION_LINK_TARGET))); $html .= Display::tag('td', $all_exercises); $html .= Display::tag('td', $all_unanswered_exercises_by_user); //$html .= Display::tag('td', $all_done_exercise); $html .= Display::tag('td', ExerciseLib::convert_to_percentage($all_average)); if (isset($_GET['session_id']) && $my_session_id == $_GET['session_id']) { $icon = Display::url(Display::return_icon('2rightarrow_na.png', get_lang('Details')), '?session_id=' . $my_session_id); } else { $icon = Display::url(Display::return_icon('2rightarrow.png', get_lang('Details')), '?session_id=' . $my_session_id); } $html .= Display::tag('td', $icon); $html .= '</tr>'; } $html .= '</table><br />'; $html .= Display::div($main_session_graph, array('id' => 'session_graph', 'class' => 'chart-session', 'style' => 'position:relative; text-align: center;')); // Checking selected session. if (isset($_GET['session_id'])) { $session_id_from_get = intval($_GET['session_id']); $session_data = $course_in_session[$session_id_from_get]; $course_list = $session_data['course_list']; $html .= Display::tag('h3', $session_data['name'] . ' - ' . get_lang('CourseList')); $html .= '<table class="data_table" width="100%">'; //'.Display::tag('th', get_lang('DoneExercises'), array('class'=>'head')).' $html .= ' <tr> <th width="300px">' . get_lang('Course') . '</th> ' . Display::tag('th', get_lang('PublishedExercises'), array('class' => 'head')) . ' ' . Display::tag('th', get_lang('NewExercises'), array('class' => 'head')) . ' ' . Display::tag('th', get_lang('MyAverage'), array('class' => 'head')) . ' ' . Display::tag('th', get_lang('AverageExerciseResult'), array('class' => 'head')) . ' ' . Display::tag('th', get_lang('TimeSpentInTheCourse'), array('class' => 'head')) . ' ' . Display::tag('th', get_lang('LPProgress'), array('class' => 'head')) . ' ' . Display::tag('th', get_lang('Score') . Display::return_icon('info3.gif', get_lang('ScormAndLPTestTotalAverage'), array('align' => 'absmiddle', 'hspace' => '3px')), array('class' => 'head')) . ' ' . Display::tag('th', get_lang('LastConnexion'), array('class' => 'head')) . ' ' . Display::tag('th', get_lang('Details'), array('class' => 'head')) . ' </tr>'; foreach ($course_list as $course_data) { $course_code = $course_data['code']; $course_title = $course_data['title']; $courseInfo = api_get_course_info($course_code); $courseId = $courseInfo['real_id']; // All exercises in the course @todo change for a real count $exercises = ExerciseLib::get_all_exercises($course_data, $session_id_from_get); $count_exercises = 0; if (!empty($exercises)) { $count_exercises = count($exercises); } $answered_exercises = 0; foreach ($exercises as $exercise_item) { $attempts = Event::count_exercise_attempts_by_user(api_get_user_id(), $exercise_item['id'], $courseId, $session_id_from_get); if ($attempts > 1) { $answered_exercises++; } } $unanswered_exercises = $count_exercises - $answered_exercises; // Average $average = ExerciseLib::get_average_score_by_course($courseId, $session_id_from_get); $my_average = ExerciseLib::get_average_score_by_course_by_user(api_get_user_id(), $courseId, $session_id_from_get); $stats_array[$course_code] = array('exercises' => $count_exercises, 'unanswered_exercises_by_user' => $unanswered_exercises, 'done_exercises' => $done_exercises, 'average' => $average, 'my_average' => $my_average); $weighting = 0; $last_connection = Tracking::get_last_connection_date_on_the_course($user_id, $courseInfo, $session_id_from_get); $progress = Tracking::get_avg_student_progress($user_id, $course_code, array(), $session_id_from_get); $total_time_login = Tracking::get_time_spent_on_the_course($user_id, $courseId, $session_id_from_get); $time = api_time_to_hms($total_time_login); $percentage_score = Tracking::get_avg_student_score($user_id, $course_code, array(), $session_id_from_get); $courseCodeFromGet = isset($_GET['course']) ? $_GET['course'] : null; if ($course_code == $courseCodeFromGet && $_GET['session_id'] == $session_id_from_get) { $html .= '<tr class="row_odd" style="background-color:#FBF09D" >'; } else { $html .= '<tr class="row_even">'; } $url = api_get_course_url($course_code, $session_id_from_get); $course_url = Display::url($course_title, $url, array('target' => SESSION_LINK_TARGET)); $html .= Display::tag('td', $course_url); $html .= Display::tag('td', $stats_array[$course_code]['exercises']); $html .= Display::tag('td', $stats_array[$course_code]['unanswered_exercises_by_user']); //$html .= Display::tag('td', $stats_array[$course_code]['done_exercises']); $html .= Display::tag('td', ExerciseLib::convert_to_percentage($stats_array[$course_code]['my_average'])); $html .= Display::tag('td', $stats_array[$course_code]['average'] == 0 ? '-' : '(' . ExerciseLib::convert_to_percentage($stats_array[$course_code]['average']) . ')'); $html .= Display::tag('td', $time, array('align' => 'center')); if (is_numeric($progress)) { $progress = $progress . '%'; } else { $progress = '0%'; } //Progress $html .= Display::tag('td', $progress, array('align' => 'center')); if (is_numeric($percentage_score)) { $percentage_score = $percentage_score . '%'; } else { $percentage_score = '0%'; } //Score $html .= Display::tag('td', $percentage_score, array('align' => 'center')); $html .= Display::tag('td', $last_connection, array('align' => 'center')); if ($course_code == $courseCodeFromGet && $_GET['session_id'] == $session_id_from_get) { $details = '<a href="#">'; $details .= Display::return_icon('2rightarrow_na.png', get_lang('Details')); } else { $details = '<a href="' . api_get_self() . '?course=' . $course_code . '&session_id=' . $session_id_from_get . $extra_params . '">'; $details .= Display::return_icon('2rightarrow.png', get_lang('Details')); } $details .= '</a>'; $html .= Display::tag('td', $details, array('align' => 'center')); $html .= '</tr>'; } $html .= '</table>'; } } return $html; }
/** * * @params array question list * @params bool expand or not question list (true show all questions, false show media question id instead of the question ids) * **/ public function transformQuestionListWithMedias($question_list, $expand_media_questions = false) { $new_question_list = array(); if (!empty($question_list)) { $media_questions = $this->getMediaList(); $media_active = $this->mediaIsActivated($media_questions); if ($media_active) { $counter = 1; foreach ($question_list as $question_id) { $add_question = true; foreach ($media_questions as $media_id => $question_list_in_media) { if ($media_id != 999 && in_array($question_id, $question_list_in_media)) { $add_question = false; if (!in_array($media_id, $new_question_list)) { $new_question_list[$counter] = $media_id; $counter++; } break; } } if ($add_question) { $new_question_list[$counter] = $question_id; $counter++; } } if ($expand_media_questions) { $media_key_list = array_keys($media_questions); foreach ($new_question_list as &$question_id) { if (in_array($question_id, $media_key_list)) { $question_id = $media_questions[$question_id]; } } $new_question_list = ArrayClass::array_flatten($new_question_list); } } else { $new_question_list = $question_list; } } return $new_question_list; }
/** * @param int $sidx * @param int $sord * @param int $start * @param int $limit * @return array */ public function getUsergroupsPagination($sidx, $sord, $start, $limit) { $sord = in_array(strtolower($sord), array('asc', 'desc')) ? $sord : 'desc'; $start = intval($start); $limit = intval($limit); if ($this->useMultipleUrl) { $urlId = api_get_current_access_url_id(); $from = $this->table . " u INNER JOIN {$this->access_url_rel_usergroup} a ON (u.id = a.usergroup_id)"; $where = array(' access_url_id = ?' => $urlId); } else { $from = $this->table . " u "; $where = array(); } $result = Database::select('u.*', $from, array('where' => $where, 'order' => "name {$sord}", 'LIMIT' => "{$start} , {$limit}")); $new_result = array(); if (!empty($result)) { foreach ($result as $group) { $group['sessions'] = count($this->get_sessions_by_usergroup($group['id'])); $group['courses'] = count($this->get_courses_by_usergroup($group['id'])); $group['users'] = count($this->get_users_by_usergroup($group['id'])); switch ($group['group_type']) { case 0: $group['group_type'] = Display::label(get_lang('Class'), 'info'); break; case 1: $group['group_type'] = Display::label(get_lang('Social'), 'success'); break; } $new_result[] = $group; } $result = $new_result; } $columns = array('name', 'users', 'courses', 'sessions', 'group_type'); if (!in_array($sidx, $columns)) { $sidx = 'name'; } // Multidimensional sort $result = ArrayClass::msort($result, $sidx, $sord); return $result; }
/** * Shows the right menu of the Social Network tool * * @param string $show highlight link possible values: * group_add, * home, * messages, * messages_inbox, * messages_compose , * messages_outbox, * invitations, * shared_profile, * friends, * groups search * @param int $group_id group id * @param int $user_id user id * @param bool $show_full_profile show profile or not (show or hide the user image/information) * @param bool $show_delete_account_button * */ public static function show_social_menu($show = '', $group_id = 0, $user_id = 0, $show_full_profile = false, $show_delete_account_button = false) { if (empty($user_id)) { $user_id = api_get_user_id(); } $usergroup = new UserGroup(); $user_info = api_get_user_info($user_id, true); $current_user_id = api_get_user_id(); $current_user_info = api_get_user_info($current_user_id, true); if ($current_user_id == $user_id) { $user_friend_relation = null; } else { $user_friend_relation = SocialManager::get_relation_between_contacts($current_user_id, $user_id); } $show_groups = array('groups', 'group_messages', 'messages_list', 'group_add', 'mygroups', 'group_edit', 'member_list', 'invite_friends', 'waiting_list', 'browse_groups'); // get count unread message and total invitations $count_unread_message = MessageManager::get_number_of_messages(true); $count_unread_message = !empty($count_unread_message) ? Display::badge($count_unread_message) : null; $number_of_new_messages_of_friend = SocialManager::get_message_number_invitation_by_user_id(api_get_user_id()); $group_pending_invitations = $usergroup->get_groups_by_user(api_get_user_id(), GROUP_USER_PERMISSION_PENDING_INVITATION, false); $group_pending_invitations = count($group_pending_invitations); $total_invitations = $number_of_new_messages_of_friend + $group_pending_invitations; $total_invitations = !empty($total_invitations) ? Display::badge($total_invitations) : ''; $filesIcon = Display::return_icon('sn-files.png', get_lang('MyFiles'), '', ICON_SIZE_SMALL); $friendsIcon = Display::return_icon('sn-friends.png', get_lang('Friends'), '', ICON_SIZE_SMALL); $groupsIcon = Display::return_icon('sn-groups.png', get_lang('SocialGroups'), '', ICON_SIZE_SMALL); $homeIcon = Display::return_icon('sn-home.png', get_lang('Home'), '', ICON_SIZE_SMALL); $invitationsIcon = Display::return_icon('sn-invitations.png', get_lang('Invitations'), '', ICON_SIZE_SMALL); $messagesIcon = Display::return_icon('sn-message.png', get_lang('Messages'), '', ICON_SIZE_SMALL); $sharedProfileIcon = Display::return_icon('sn-profile.png', get_lang('ViewMySharedProfile')); $searchIcon = Display::return_icon('sn-search.png', get_lang('Search'), '', ICON_SIZE_SMALL); $html = ''; $active = null; if (!in_array($show, array('shared_profile', 'groups', 'group_edit', 'member_list', 'waiting_list', 'invite_friends'))) { $links = '<ul class="nav nav-pills nav-stacked">'; $active = $show == 'home' ? 'active' : null; $links .= ' <li class="home-icon ' . $active . '"> <a href="' . api_get_path(WEB_CODE_PATH) . 'social/home.php"> ' . $homeIcon . ' ' . get_lang('Home') . ' </a> </li>'; $active = $show == 'messages' ? 'active' : null; $links .= ' <li class="messages-icon ' . $active . '"> <a href="' . api_get_path(WEB_CODE_PATH) . 'messages/inbox.php?f=social"> ' . $messagesIcon . ' ' . get_lang('Messages') . $count_unread_message . ' </a> </li>'; //Invitations $active = $show == 'invitations' ? 'active' : null; $links .= ' <li class="invitations-icon ' . $active . '"> <a href="' . api_get_path(WEB_CODE_PATH) . 'social/invitations.php"> ' . $invitationsIcon . ' ' . get_lang('Invitations') . $total_invitations . ' </a> </li>'; //Shared profile and groups $active = $show == 'shared_profile' ? 'active' : null; $links .= ' <li class="shared-profile-icon' . $active . '"> <a href="' . api_get_path(WEB_CODE_PATH) . 'social/profile.php"> ' . $sharedProfileIcon . ' ' . get_lang('ViewMySharedProfile') . ' </a> </li>'; $active = $show == 'friends' ? 'active' : null; $links .= ' <li class="friends-icon ' . $active . '"> <a href="' . api_get_path(WEB_CODE_PATH) . 'social/friends.php"> ' . $friendsIcon . ' ' . get_lang('Friends') . ' </a> </li>'; $active = $show == 'browse_groups' ? 'active' : null; $links .= ' <li class="browse-groups-icon ' . $active . '"> <a href="' . api_get_path(WEB_CODE_PATH) . 'social/groups.php"> ' . $groupsIcon . ' ' . get_lang('SocialGroups') . ' </a> </li>'; //Search users $active = $show == 'search' ? 'active' : null; $links .= ' <li class="search-icon ' . $active . '"> <a href="' . api_get_path(WEB_CODE_PATH) . 'social/search.php"> ' . $searchIcon . ' ' . get_lang('Search') . ' </a> </li>'; //My files $active = $show == 'myfiles' ? 'active' : null; $myFiles = ' <li class="myfiles-icon ' . $active . '"> <a href="' . api_get_path(WEB_CODE_PATH) . 'social/myfiles.php"> ' . $filesIcon . ' ' . get_lang('MyFiles') . ' </a> </li>'; if (api_get_setting('platform.allow_my_files') === 'false') { $myFiles = ''; } $links .= $myFiles; $links .= '</ul>'; $html .= Display::panelCollapse(get_lang('SocialNetwork'), $links, 'social-network-menu', null, 'sn-sidebar', 'sn-sidebar-collapse'); } if (in_array($show, $show_groups) && !empty($group_id)) { $html .= $usergroup->show_group_column_information($group_id, api_get_user_id(), $show); } if ($show == 'shared_profile') { $links = '<ul class="nav nav-pills nav-stacked">'; // My own profile if ($show_full_profile && $user_id == intval(api_get_user_id())) { $links .= ' <li class="home-icon ' . $active . '"> <a href="' . api_get_path(WEB_CODE_PATH) . 'social/home.php"> ' . $homeIcon . ' ' . get_lang('Home') . ' </a> </li> <li class="messages-icon ' . $active . '"> <a href="' . api_get_path(WEB_CODE_PATH) . 'messages/inbox.php?f=social"> ' . $messagesIcon . ' ' . get_lang('Messages') . $count_unread_message . ' </a> </li>'; $active = $show == 'invitations' ? 'active' : null; $links .= ' <li class="invitations-icon' . $active . '"> <a href="' . api_get_path(WEB_CODE_PATH) . 'social/invitations.php"> ' . $invitationsIcon . ' ' . get_lang('Invitations') . $total_invitations . ' </a> </li>'; $links .= ' <li class="shared-profile-icon active"> <a href="' . api_get_path(WEB_CODE_PATH) . 'social/profile.php"> ' . $sharedProfileIcon . ' ' . get_lang('ViewMySharedProfile') . ' </a> </li> <li class="friends-icon"> <a href="' . api_get_path(WEB_CODE_PATH) . 'social/friends.php"> ' . $friendsIcon . ' ' . get_lang('Friends') . ' </a> </li> <li class="browse-groups-icon"> <a href="' . api_get_path(WEB_CODE_PATH) . 'social/groups.php"> ' . $groupsIcon . ' ' . get_lang('SocialGroups') . ' </a> </li>'; $active = $show == 'search' ? 'active' : null; $links .= ' <li class="search-icon ' . $active . '"> <a href="' . api_get_path(WEB_CODE_PATH) . 'social/search.php"> ' . $searchIcon . ' ' . get_lang('Search') . ' </a> </li>'; $active = $show == 'myfiles' ? 'active' : null; $myFiles = ' <li class="myfiles-icon ' . $active . '"> <a href="' . api_get_path(WEB_CODE_PATH) . 'social/myfiles.php"> ' . $filesIcon . ' ' . get_lang('MyFiles') . ' </a> </li>'; if (api_get_setting('platform.allow_my_files') === 'false') { $myFiles = ''; } $links .= $myFiles; } // My friend profile. if ($user_id != api_get_user_id()) { $sendMessageText = get_lang('SendMessage'); $sendMessageIcon = Display::return_icon('new-message.png', $sendMessageText); $sendMesssageUrl = api_get_path(WEB_AJAX_PATH) . 'user_manager.ajax.php?' . http_build_query(['a' => 'get_user_popup', 'user_id' => $user_id]); $links .= '<li>'; $links .= Display::url("{$sendMessageIcon} {$sendMessageText}", $sendMesssageUrl, ['class' => 'ajax', 'title' => $sendMessageText, 'data-title' => $sendMessageText]); $links .= '</li>'; } // Check if I already sent an invitation message $invitation_sent_list = SocialManager::get_list_invitation_sent_by_user_id(api_get_user_id()); if (isset($invitation_sent_list[$user_id]) && is_array($invitation_sent_list[$user_id]) && count($invitation_sent_list[$user_id]) > 0) { $links .= '<li><a href="' . api_get_path(WEB_CODE_PATH) . 'social/invitations.php">' . Display::return_icon('invitation.png', get_lang('YouAlreadySentAnInvitation')) . ' ' . get_lang('YouAlreadySentAnInvitation') . '</a></li>'; } else { if (!$show_full_profile) { $links .= '<li><a class="btn-to-send-invitation" href="#" data-send-to="' . $user_id . '" title="' . get_lang('SendInvitation') . '">' . Display::return_icon('invitation.png', get_lang('SocialInvitationToFriends')) . ' ' . get_lang('SendInvitation') . '</a></li>'; } } $links .= '</ul>'; $html .= Display::panelCollapse(get_lang('SocialNetwork'), $links, 'social-network-menu', null, 'sn-sidebar', 'sn-sidebar-collapse'); if ($show_full_profile && $user_id == intval(api_get_user_id())) { $personal_course_list = UserManager::get_personal_session_course_list($user_id); $course_list_code = array(); $i = 1; if (is_array($personal_course_list)) { foreach ($personal_course_list as $my_course) { if ($i <= 10) { $course_list_code[] = array('code' => $my_course['code']); } else { break; } $i++; } // To avoid repeated courses $course_list_code = ArrayClass::array_unique_dimensional($course_list_code); } // Announcements $my_announcement_by_user_id = intval($user_id); $announcements = array(); foreach ($course_list_code as $course) { $course_info = api_get_course_info($course['code']); if (!empty($course_info)) { $content = AnnouncementManager::get_all_annoucement_by_user_course($course_info['code'], $my_announcement_by_user_id); if (!empty($content)) { $url = Display::url(Display::return_icon('announcement.png', get_lang('Announcements')) . $course_info['name'] . ' (' . $content['count'] . ')', api_get_path(WEB_CODE_PATH) . 'announcements/announcements.php?cidReq=' . $course['code']); $announcements[] = Display::tag('li', $url); } } } if (!empty($announcements)) { $html .= '<div class="social_menu_items">'; $html .= '<ul>'; foreach ($announcements as $announcement) { $html .= $announcement; } $html .= '</ul>'; $html .= '</div>'; } } } if ($show_delete_account_button) { $html .= '<div class="sidebar-nav"><ul><li>'; $url = api_get_path(WEB_CODE_PATH) . 'auth/unsubscribe_account.php'; $html .= Display::url(Display::return_icon('delete.png', get_lang('Unsubscribe'), array(), ICON_SIZE_TINY) . get_lang('Unsubscribe'), $url); $html .= '</li></ul></div>'; } $html .= ''; return $html; }
/** * @param int $exercise_id * @param int $course_id * @param string $order * @return array */ public function getCategoryExerciseTree($exercise_id, $course_id, $order = null, $shuffle = false, $excludeCategoryWithNoQuestions = true) { $table = Database::get_course_table(TABLE_QUIZ_REL_CATEGORY); $table_category = Database::get_course_table(TABLE_QUIZ_CATEGORY); $sql = "SELECT * FROM {$table} qc INNER JOIN {$table_category} c ON (category_id = c.iid)\n WHERE exercise_id = {$exercise_id} "; if (!empty($order)) { $sql .= "ORDER BY {$order}"; } $categories = array(); $result = Database::query($sql); if (Database::num_rows($result)) { while ($row = Database::fetch_array($result, 'ASSOC')) { if ($excludeCategoryWithNoQuestions) { if ($row['count_questions'] == 0) { continue; } } $categories[$row['category_id']] = $row; } } if ($shuffle) { ArrayClass::shuffle_assoc($categories); } return $categories; }
<?php include_once 'php/ArrayClass.php'; for ($i = 0; $i < rand(10, 30); $i++) { $arr[] = rand(0, 100); } //echo "<p>исходный массив: <br> " . implode(" | ", $arr) . '</p>' ; $arrClass = new ArrayClass(); $descArr = $arrClass->sortDesc($arr); //echo "<p>sortDesc() массив: <br> " . implode(" | ", $descArr) . '</p>' ; $ascArr = $arr; qSortAsc($ascArr, 0, count($ascArr) - 1); //echo "<p>qSortAsc() массив: <br> " . implode(" | ", $ascArr) . '</p>' ; /* * Сортировка по возрастанию: метод "Быстрая сортировка". * */ function qSortAsc(&$array, $inLeft, $inRight) { $l = $inLeft; $r = $inRight; $refElement = $array[floor(($inLeft + $inRight) / 2)]; do { while ($array[$r] > $refElement) { $r--; } while ($array[$l] < $refElement) { $l++; } if ($l <= $r) { list($array[$r], $array[$l]) = array($array[$l], $array[$r]);