12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553 |
- <?php
- /* For licensing terms, see /license.txt */
- /**
- * Class GradebookUtils
- */
- class GradebookUtils
- {
- /**
- * Adds a resource to the unique gradebook of a given course
- * @param int
- * @param string Course code
- * @param int Resource type (use constants defined in linkfactory.class.php)
- * @param int Resource ID in the corresponding tool
- * @param string Resource name to show in the gradebook
- * @param int Resource weight to set in the gradebook
- * @param int Resource max
- * @param string Resource description
- * @param int Visibility (0 hidden, 1 shown)
- * @param int Session ID (optional or 0 if not defined)
- * @param int
- * @return boolean True on success, false on failure
- */
- public static function add_resource_to_course_gradebook(
- $category_id,
- $course_code,
- $resource_type,
- $resource_id,
- $resource_name = '',
- $weight = 0,
- $max = 0,
- $resource_description = '',
- $visible = 0,
- $session_id = 0,
- $link_id = null
- ) {
- $link = LinkFactory :: create($resource_type);
- $link->set_user_id(api_get_user_id());
- $link->set_course_code($course_code);
- if (empty($category_id)) {
- return false;
- }
- $link->set_category_id($category_id);
- if ($link->needs_name_and_description()) {
- $link->set_name($resource_name);
- } else {
- $link->set_ref_id($resource_id);
- }
- $link->set_weight($weight);
- if ($link->needs_max()) {
- $link->set_max($max);
- }
- if ($link->needs_name_and_description()) {
- $link->set_description($resource_description);
- }
- $link->set_visible(empty($visible) ? 0 : 1);
- if (!empty($session_id)) {
- $link->set_session_id($session_id);
- }
- $link->add();
- return true;
- }
- /**
- * Update a resource weight
- * @param int Link/Resource ID
- * @param string
- * @param float
- * @return bool false on error, true on success
- */
- public static function update_resource_from_course_gradebook($link_id, $course_code, $weight)
- {
- $course_code = Database::escape_string($course_code);
- if (empty($link_id)) {
- return false;
- }
- $link_id = intval($link_id);
- $weight = floatval($weight);
- $courseId = api_get_course_int_id($course_code);
- $em = Database::getManager();
- $em
- ->createQuery('
- UPDATE ChamiloCoreBundle:GradebookLink gl
- SET gl.weight = :weight
- WHERE gl.course = :course AND gl = :id
- ')
- ->execute([
- 'weight' => $weight,
- 'course' => $courseId,
- 'id' => $link_id
- ]);
- return true;
- }
- /**
- * Remove a resource from the unique gradebook of a given course
- * @param int Link/Resource ID
- * @return bool false on error, true on success
- */
- public static function remove_resource_from_course_gradebook($link_id)
- {
- if (empty($link_id)) {
- return false;
- }
- // TODO find the corresponding category (the first one for this course, ordered by ID)
- $em = Database::getManager();
- $gradebookLink = $em->find('ChamiloCoreBundle:GradebookLink', intval($link_id));
- if ($gradebookLink) {
- $em->remove($gradebookLink);
- $em->flush();
- }
- return true;
- }
- /**
- * Block students
- */
- public static function block_students()
- {
- if (!api_is_allowed_to_edit()) {
- api_not_allowed();
- }
- }
- /**
- * Builds an img tag for a gradebook item
- * @param string $type value returned by a gradebookitem's get_icon_name()
- */
- public static function build_type_icon_tag($kind, $attributes = array())
- {
- return Display::return_icon(self::get_icon_file_name($kind), ' ', $attributes, ICON_SIZE_SMALL);
- }
- /**
- * Returns the icon filename for a gradebook item
- * @param string $type value returned by a gradebookitem's get_icon_name()
- */
- public static function get_icon_file_name($type)
- {
- switch ($type) {
- case 'cat':
- $icon = 'gradebook.png';
- break;
- case 'evalempty':
- $icon = 'empty_evaluation.png';
- break;
- case 'evalnotempty':
- $icon = 'no_empty_evaluation.png';
- break;
- case 'exercise':
- case LINK_EXERCISE:
- $icon = 'quiz.gif';
- break;
- case 'learnpath':
- case LINK_LEARNPATH:
- $icon = 'learnpath.png';
- break;
- case 'studentpublication':
- case LINK_STUDENTPUBLICATION:
- $icon = 'works.gif';
- break;
- case 'link':
- $icon = 'link.gif';
- break;
- case 'forum':
- case LINK_FORUM_THREAD:
- $icon = 'forum.gif';
- break;
- case 'attendance':
- case LINK_ATTENDANCE:
- $icon = 'attendance.gif';
- break;
- case 'survey':
- case LINK_SURVEY:
- $icon = 'survey.gif';
- break;
- case 'dropbox':
- case LINK_DROPBOX:
- $icon = 'dropbox.gif';
- break;
- default:
- $icon = 'link.gif';
- break;
- }
- return $icon;
- }
- /**
- * Builds the course or platform admin icons to edit a category
- * @param Category $cat category
- * @param Category $selectcat id of selected category
- */
- public static function build_edit_icons_cat($cat, $selectcat)
- {
- $show_message = $cat->show_message_resource_delete($cat->get_course_code());
- $grade_model_id = $selectcat->get_grade_model_id();
- $selectcat = $selectcat->get_id();
- $modify_icons = null;
- if ($show_message === false) {
- $visibility_icon = ($cat->is_visible() == 0) ? 'invisible' : 'visible';
- $visibility_command = ($cat->is_visible() == 0) ? 'set_visible' : 'set_invisible';
- $modify_icons .= '<a class="view_children" data-cat-id="' . $cat->get_id() . '" href="javascript:void(0);">' .
- Display::return_icon('view_more_stats.gif', get_lang('Show'), '', ICON_SIZE_SMALL) . '</a>';
- if (!api_is_allowed_to_edit(null, true)) {
- $modify_icons .= Display::url(
- Display::return_icon(
- 'stats.png',
- get_lang('FlatView'),
- '',
- ICON_SIZE_SMALL
- ),
- 'personal_stats.php?' . http_build_query([
- 'selectcat' => $cat->get_id()
- ]) . '&' . api_get_cidreq(),
- [
- 'class' => 'ajax',
- 'data-title' => get_lang('FlatView')
- ]
- );
- }
- if (api_is_allowed_to_edit(null, true)) {
- // Locking button
- if (api_get_setting(
- 'gradebook.gradebook_locking_enabled'
- ) == 'true'
- ) {
- if ($cat->is_locked()) {
- if (api_is_platform_admin()) {
- $modify_icons .= ' <a onclick="javascript:if (!confirm(\'' . addslashes(get_lang('ConfirmToUnlockElement')) . '\')) return false;" href="' . api_get_self() . '?' . api_get_cidreq() . '&category_id=' . $cat->get_id() . '&action=unlock">' .
- Display::return_icon('lock.png', get_lang('UnLockEvaluation'), '', ICON_SIZE_SMALL) . '</a>';
- } else {
- $modify_icons .= ' <a href="#">' . Display::return_icon('lock_na.png', get_lang('GradebookLockedAlert'), '', ICON_SIZE_SMALL) . '</a>';
- }
- $modify_icons .= ' <a href="gradebook_flatview.php?export_pdf=category&selectcat=' . $cat->get_id() . '" >' . Display::return_icon('pdf.png', get_lang('ExportToPDF'), '', ICON_SIZE_SMALL) . '</a>';
- } else {
- $modify_icons .= ' <a onclick="javascript:if (!confirm(\'' . addslashes(get_lang('ConfirmToLockElement')) . '\')) return false;" href="' . api_get_self() . '?' . api_get_cidreq() . '&category_id=' . $cat->get_id() . '&action=lock">' .
- Display::return_icon('unlock.png', get_lang('LockEvaluation'), '', ICON_SIZE_SMALL) . '</a>';
- $modify_icons .= ' <a href="#" >' . Display::return_icon('pdf_na.png', get_lang('ExportToPDF'), '', ICON_SIZE_SMALL) . '</a>';
- }
- }
- if (empty($grade_model_id) || $grade_model_id == -1) {
- if ($cat->is_locked() && !api_is_platform_admin()) {
- $modify_icons .= Display::return_icon('edit_na.png', get_lang('Modify'), '', ICON_SIZE_SMALL);
- } else {
- $modify_icons .= '<a href="gradebook_edit_cat.php?' .'editcat=' . $cat->get_id() . '&cidReq=' .$cat->get_course_code() . '&id_session='.$cat->get_session_id().'">' .
- Display::return_icon(
- 'edit.png',
- get_lang('Modify'),
- '',
- ICON_SIZE_SMALL
- ) . '</a>';
- }
- }
- $modify_icons .= '<a href="gradebook_edit_all.php?selectcat=' .$cat->get_id() . '&cidReq=' . $cat->get_course_code() . '&id_session='.$cat->get_session_id().'">' .
- Display::return_icon(
- 'percentage.png',
- get_lang('EditAllWeights'),
- '',
- ICON_SIZE_SMALL
- ) . '</a>';
- $modify_icons .= '<a href="gradebook_flatview.php?selectcat=' .$cat->get_id() . '&cidReq=' . $cat->get_course_code() . '&id_session='.$cat->get_session_id(). '">' .
- Display::return_icon(
- 'stats.png',
- get_lang('FlatView'),
- '',
- ICON_SIZE_SMALL
- ) . '</a>';
- $modify_icons .= ' <a href="' . api_get_self() .'?visiblecat=' . $cat->get_id() . '&' .$visibility_command . '=&selectcat=' . $selectcat .'&cidReq=' . $cat->get_course_code() . '&id_session='.$cat->get_session_id(). '">' .
- Display::return_icon(
- $visibility_icon . '.png',
- get_lang('Visible'),
- '',
- ICON_SIZE_SMALL
- ) . '</a>';
- if ($cat->is_locked() && !api_is_platform_admin()) {
- $modify_icons .= Display::return_icon('delete_na.png', get_lang('DeleteAll'), '', ICON_SIZE_SMALL);
- } else {
- $modify_icons .= ' <a href="' . api_get_self() . '?deletecat=' . $cat->get_id() . '&selectcat=' . $selectcat . '&cidReq=' . $cat->get_course_code() . '&id_session='.$cat->get_session_id(). '" onclick="return confirmation();">' .
- Display::return_icon('delete.png', get_lang('DeleteAll'), '', ICON_SIZE_SMALL) . '</a>';
- }
- }
- return $modify_icons;
- }
- }
- /**
- * Builds the course or platform admin icons to edit an evaluation
- * @param Evaluation $eval evaluation object
- * @param int $selectcat id of selected category
- */
- public static function build_edit_icons_eval($eval, $selectcat)
- {
- $status = CourseManager::get_user_in_course_status(api_get_user_id(), api_get_course_id());
- $is_locked = $eval->is_locked();
- $eval->get_course_code();
- $cat = new Category();
- $message_eval = $cat->show_message_resource_delete($eval->get_course_code());
- if ($message_eval === false && api_is_allowed_to_edit(null, true)) {
- $visibility_icon = ($eval->is_visible() == 0) ? 'invisible' : 'visible';
- $visibility_command = ($eval->is_visible() == 0) ? 'set_visible' : 'set_invisible';
- if ($is_locked && !api_is_platform_admin()) {
- $modify_icons = Display::return_icon('edit_na.png', get_lang('Modify'), '', ICON_SIZE_SMALL);
- } else {
- $modify_icons = '<a href="gradebook_edit_eval.php?editeval=' . $eval->get_id() . '&cidReq=' . $eval->get_course_code() . '&id_session='.$eval->getSessionId(). '">' .
- Display::return_icon('edit.png', get_lang('Modify'), '', ICON_SIZE_SMALL) . '</a>';
- }
- $modify_icons .= ' <a href="' . api_get_self() . '?visibleeval=' . $eval->get_id() . '&' . $visibility_command . '=&selectcat=' . $selectcat . '&id_session='.$eval->getSessionId(). ' ">' .
- Display::return_icon($visibility_icon . '.png', get_lang('Visible'), '', ICON_SIZE_SMALL) . '</a>';
- if (api_is_allowed_to_edit(null, true)) {
- $modify_icons .= ' <a href="gradebook_showlog_eval.php?visiblelog=' . $eval->get_id() . '&selectcat=' . $selectcat . ' &cidReq=' . $eval->get_course_code() . '&id_session='.$eval->getSessionId(). '">' .
- Display::return_icon('history.png', get_lang('GradebookQualifyLog'), '', ICON_SIZE_SMALL) . '</a>';
- }
- if ($is_locked && !api_is_platform_admin()) {
- $modify_icons .= ' ' . Display::return_icon('delete_na.png', get_lang('Delete'), '', ICON_SIZE_SMALL);
- } else {
- $modify_icons .= ' <a href="' . api_get_self() . '?deleteeval=' . $eval->get_id() . '&selectcat=' . $selectcat . ' &cidReq=' . $eval->get_course_code() . '&id_session='.$eval->getSessionId(). '" onclick="return confirmation();">' . Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL) . '</a>';
- }
- return $modify_icons;
- }
- }
- /**
- * Builds the course or platform admin icons to edit a link
- * @param AbstractLink $link
- * @param int $selectcat id of selected category
- */
- public static function build_edit_icons_link($link, $selectcat)
- {
- $cat = new Category();
- $message_link = $cat->show_message_resource_delete($link->get_course_code());
- $is_locked = $link->is_locked();
- $modify_icons = null;
- if (!api_is_allowed_to_edit(null, true)) {
- return null;
- }
- if ($message_link === false) {
- $visibility_icon = ($link->is_visible() == 0) ? 'invisible' : 'visible';
- $visibility_command = ($link->is_visible() == 0) ? 'set_visible' : 'set_invisible';
- if ($is_locked && !api_is_platform_admin()) {
- $modify_icons = Display::return_icon('edit_na.png', get_lang('Modify'), '', ICON_SIZE_SMALL);
- } else {
- $modify_icons = '<a href="gradebook_edit_link.php?editlink=' . $link->get_id() . '&cidReq=' . $link->get_course_code() . '&id_session='.$link->get_session_id().'">' .
- Display::return_icon('edit.png', get_lang('Modify'), '', ICON_SIZE_SMALL) . '</a>';
- }
- $modify_icons .= ' <a href="' . api_get_self() . '?visiblelink=' . $link->get_id() . '&' . $visibility_command . '=&selectcat=' . $selectcat . '&id_session='.$link->get_session_id(). ' ">' .
- Display::return_icon($visibility_icon . '.png', get_lang('Visible'), '', ICON_SIZE_SMALL) . '</a>';
- $modify_icons .= ' <a href="gradebook_showlog_link.php?visiblelink=' . $link->get_id() . '&selectcat=' . $selectcat . '&cidReq=' . $link->get_course_code() . '&id_session='.$link->get_session_id(). '">' .
- Display::return_icon('history.png', get_lang('GradebookQualifyLog'), '', ICON_SIZE_SMALL) . '</a>';
- //If a work is added in a gradebook you can only delete the link in the work tool
- if ($is_locked && !api_is_platform_admin()) {
- $modify_icons .= ' ' . Display::return_icon('delete_na.png', get_lang('Delete'), '', ICON_SIZE_SMALL);
- } else {
- $modify_icons .= ' <a href="' . api_get_self() . '?deletelink=' . $link->get_id() . '&selectcat=' . $selectcat . ' &cidReq=' . $link->get_course_code() . '&id_session='.$link->get_session_id(). '" onclick="return confirmation();">' .
- Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL) . '</a>';
- }
- return $modify_icons;
- }
- }
- /**
- * Checks if a resource is in the unique gradebook of a given course
- * @param string Course code
- * @param int Resource type (use constants defined in linkfactory.class.php)
- * @param int Resource ID in the corresponding tool
- * @param int Session ID (optional - 0 if not defined)
- * @return int false on error or array of resource
- */
- public static function is_resource_in_course_gradebook($course_code, $resource_type, $resource_id, $session_id = 0)
- {
- $course_code = Database::escape_string($course_code);
- $em = Database::getManager();
- $course = $em
- ->getRepository('ChamiloCoreBundle:Course')
- ->findOneBy(['code' => $course_code]);
- $gradebookLinks = $em
- ->getRepository('ChamiloCoreBundle:GradebookLink')
- ->getLinksByCourseAndReferenceAndType($course, $resource_id, $resource_type);
- if ($gradebookLinks->count() < 1) {
- return false;
- }
- return $gradebookLinks->current();
- }
- /**
- * Remove a resource from the unique gradebook of a given course
- * @param int Link/Resource ID
- * @return bool false on error, true on success
- */
- public static function get_resource_from_course_gradebook($link_id)
- {
- if (empty($link_id)) {
- return false;
- }
- $em = Database::getManager();
- // TODO find the corresponding category (the first one for this course, ordered by ID)
- $gradebookLink = $em->find('ChamiloCoreBundle:GradebookLink', $link_id);
- return $gradebookLink;
- }
- /**
- * Return the course id
- * @param int
- * @return String
- */
- public static function get_course_id_by_link_id($id_link)
- {
- $id_link = intval($id_link);
- $em = Database::getManager();
- $qb = $em->createQueryBuilder();
- $qb
- ->select('gl')
- ->from('ChamiloCoreBundle:GradebookLink', 'gl')
- ->where(
- $qb->expr()->eq('gl.id', $id_link)
- )
- ->orWhere(
- $qb->expr()->eq('gl.categoryId', $id_link)
- );
- $result = $qb->getQuery()->getResult();
- if (count($result) === 0) {
- return false;
- }
- $array = current($result);
- return $array->getCourse()->getId();
- }
- /**
- * @param $type
- * @return string
- */
- public static function get_table_type_course($type)
- {
- $table_evaluated = self::getTables();
- return Database::get_course_table($table_evaluated[$type][0]);
- }
- /**
- * @return array
- */
- public static function getTables()
- {
- $table_evaluated = [];
- $table_evaluated[LINK_EXERCISE] = array(
- TABLE_QUIZ_TEST,
- 'title',
- 'id',
- get_lang('Exercise'),
- );
- $table_evaluated[LINK_DROPBOX] = array(
- TABLE_DROPBOX_FILE,
- 'name',
- 'id',
- get_lang('Dropbox'),
- );
- $table_evaluated[LINK_STUDENTPUBLICATION] = array(
- TABLE_STUDENT_PUBLICATION,
- 'url',
- 'id',
- get_lang('Student_publication'),
- );
- $table_evaluated[LINK_LEARNPATH] = array(
- TABLE_LP_MAIN,
- 'name',
- 'id',
- get_lang('Learnpath'),
- );
- $table_evaluated[LINK_FORUM_THREAD] = array(
- TABLE_FORUM_THREAD,
- 'thread_title_qualify',
- 'thread_id',
- get_lang('Forum'),
- );
- $table_evaluated[LINK_ATTENDANCE] = array(
- TABLE_ATTENDANCE,
- 'attendance_title_qualify',
- 'id',
- get_lang('Attendance'),
- );
- $table_evaluated[LINK_SURVEY] = array(
- TABLE_SURVEY,
- 'code',
- 'survey_id',
- get_lang('Survey'),
- );
- return $table_evaluated;
- }
- /**
- * @param Category $cat
- * @param $users
- * @param $alleval
- * @param $alllinks
- * @param $params
- * @param null $mainCourseCategory
- * @return array
- */
- public static function get_printable_data($cat, $users, $alleval, $alllinks, $params, $mainCourseCategory = null)
- {
- $datagen = new FlatViewDataGenerator(
- $users,
- $alleval,
- $alllinks,
- $params,
- $mainCourseCategory
- );
- $offset = isset($_GET['offset']) ? $_GET['offset'] : '0';
- $offset = intval($offset);
- // step 2: generate rows: students
- $datagen->category = $cat;
- $count = (($offset + 10) > $datagen->get_total_items_count()) ? ($datagen->get_total_items_count() - $offset) : GRADEBOOK_ITEM_LIMIT;
- $header_names = $datagen->get_header_names($offset, $count, true);
- $data_array = $datagen->get_data(
- FlatViewDataGenerator :: FVDG_SORT_LASTNAME,
- 0,
- null,
- $offset,
- $count,
- true,
- true
- );
- $result = array();
- foreach ($data_array as $data) {
- $result[] = array_slice($data, 1);
- }
- $return = array($header_names, $result);
- return $return;
- }
- /**
- * XML-parser: handle character data
- */
- public static function character_data($parser, $data)
- {
- global $current_value;
- $current_value = $data;
- }
- /**
- * XML-parser: handle end of element
- */
- public static function element_end($parser, $data)
- {
- global $user;
- global $users;
- global $current_value;
- switch ($data) {
- case 'Result' :
- $users[] = $user;
- break;
- default :
- $user[$data] = $current_value;
- break;
- }
- }
- /**
- * XML-parser: handle start of element
- */
- public static function element_start($parser, $data)
- {
- global $user;
- global $current_tag;
- switch ($data) {
- case 'Result' :
- $user = array();
- break;
- default :
- $current_tag = $data;
- }
- }
- public static function overwritescore($resid, $importscore, $eval_max)
- {
- $result = Result :: load($resid);
- if ($importscore > $eval_max) {
- header('Location: gradebook_view_result.php?selecteval=' . Security::remove_XSS($_GET['selecteval']) . '&overwritemax=');
- exit;
- }
- $result[0]->set_score($importscore);
- $result[0]->save();
- unset($result);
- }
- /**
- * Read the XML-file
- * @param string $file Path to the XML-file
- * @return array All user information read from the file
- */
- public static function parse_xml_data($file)
- {
- global $current_tag;
- global $current_value;
- global $user;
- global $users;
- $users = array();
- $parser = xml_parser_create();
- xml_set_element_handler($parser, 'element_start', 'element_end');
- xml_set_character_data_handler($parser, "character_data");
- xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, false);
- xml_parse($parser, file_get_contents($file));
- xml_parser_free($parser);
- return $users;
- }
- /**
- * register user info about certificate
- * @param int The category id
- * @param int The user id
- * @param float The score obtained for certified
- * @param Datetime The date when you obtained the certificate
- * @return void()
- */
- public static function register_user_info_about_certificate($cat_id, $user_id, $score_certificate, $date_certificate)
- {
- $table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE);
- $sql = 'SELECT COUNT(*) as count
- FROM ' . $table . ' gc
- WHERE gc.cat_id="' . intval($cat_id) . '" AND user_id="' . intval($user_id) . '" ';
- $rs_exist = Database::query($sql);
- $row = Database::fetch_array($rs_exist);
- if ($row['count'] == 0) {
- $params = [
- 'cat_id' => $cat_id,
- 'user_id' => $user_id,
- 'score_certificate' => $score_certificate,
- 'created_at' => $date_certificate
- ];
- Database::insert($table, $params);
- }
- }
- /**
- * Get date of user certificate
- * @param int $cat_id The category id
- * @param int $user_id The user id
- * @return Datetime The date when you obtained the certificate
- */
- public static function get_certificate_by_user_id($cat_id, $user_id)
- {
- $table_certificate = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE);
- $sql = 'SELECT * FROM ' . $table_certificate . '
- WHERE cat_id="' . intval($cat_id) . '" AND user_id="' . intval($user_id) . '"';
- $result = Database::query($sql);
- $row = Database::fetch_array($result, 'ASSOC');
- return $row;
- }
- /**
- * Get list of users certificates
- * @param int $cat_id The category id
- * @param array $userList Only users in this list
- * @return array
- */
- public static function get_list_users_certificates($cat_id = null, $userList = array())
- {
- $table_certificate = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE);
- $table_user = Database::get_main_table(TABLE_MAIN_USER);
- $sql = 'SELECT DISTINCT u.user_id, u.lastname, u.firstname, u.username
- FROM ' . $table_user . ' u
- INNER JOIN ' . $table_certificate . ' gc
- ON u.user_id=gc.user_id ';
- if (!is_null($cat_id) && $cat_id > 0) {
- $sql.=' WHERE cat_id=' . intval($cat_id);
- }
- if (!empty($userList)) {
- $userList = array_map('intval', $userList);
- $userListCondition = implode("','", $userList);
- $sql .= " AND u.user_id IN ('$userListCondition')";
- }
- $sql.=' ORDER BY u.firstname';
- $rs = Database::query($sql);
- $list_users = array();
- while ($row = Database::fetch_array($rs)) {
- $list_users[] = $row;
- }
- return $list_users;
- }
- /**
- * Gets the certificate list by user id
- * @param int $user_id The user id
- * @param int $cat_id The category id
- * @return array
- */
- public static function get_list_gradebook_certificates_by_user_id($user_id, $cat_id = null)
- {
- $table_certificate = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE);
- $sql = 'SELECT gc.score_certificate, gc.created_at, gc.path_certificate, gc.cat_id, gc.user_id, gc.id
- FROM ' . $table_certificate . ' gc
- WHERE gc.user_id="' . intval($user_id) . '" ';
- if (!is_null($cat_id) && $cat_id > 0) {
- $sql.=' AND cat_id=' . intval($cat_id);
- }
- $rs = Database::query($sql);
- $list_certificate = array();
- while ($row = Database::fetch_array($rs)) {
- $list_certificate[] = $row;
- }
- return $list_certificate;
- }
- /**
- * @param int $user_id
- * @param string $course_code
- * @param int $sessionId
- * @param bool $is_preview
- * @param bool $hide_print_button
- *
- * @return array
- */
- public static function get_user_certificate_content($user_id, $course_code, $sessionId, $is_preview = false, $hide_print_button = false)
- {
- // Generate document HTML
- $content_html = DocumentManager::replace_user_info_into_html($user_id, $course_code, $sessionId, $is_preview);
- $new_content_html = null;
- $variables = null;
- $contentHead = null;
- if (isset($content_html['content'])) {
- $new_content = explode('</head>', $content_html['content']);
- $new_content_html = $new_content[1];
- $contentHead = $new_content[0];
- }
- if (isset($content_html['variables'])) {
- $variables = $content_html['variables'];
- }
- $path_image = api_get_path(WEB_COURSE_PATH) . api_get_course_path($course_code) . '/document/images/gallery';
- $new_content_html = str_replace('../images/gallery', $path_image, $new_content_html);
- $path_image_in_default_course = api_get_path(WEB_CODE_PATH) . 'default_course_document';
- $new_content_html = str_replace('/main/default_course_document', $path_image_in_default_course, $new_content_html);
- $new_content_html = str_replace(SYS_CODE_PATH . 'img/', api_get_path(WEB_IMG_PATH), $new_content_html);
- $print = '';
- //add print header
- if ($hide_print_button == false) {
- $print .= '<style media="print" type="text/css">#print_div {visibility:hidden;}</style>';
- $print .= '<a href="javascript:window.print();" style="float:right; padding:4px;" id="print_div">';
- $print .= Display::return_icon('printmgr.gif', get_lang('Print'));
- $print .= '</a>';
- }
- // Add header
- $new_content_html = $contentHead. $print . '</head>' . $new_content_html;
- return array(
- 'content' => $new_content_html,
- 'variables' => $variables
- );
- }
- /**
- * @param null $course_code
- * @param int $gradebook_model_id
- * @return mixed
- */
- public static function create_default_course_gradebook($course_code = null, $gradebook_model_id = 0)
- {
- if (api_is_allowed_to_edit(true, true)) {
- if (!isset($course_code) || empty($course_code)) {
- $course_code = api_get_course_id();
- }
- $session_id = api_get_session_id();
- $courseId = api_get_course_int_id($course_code);
- $em = Database::getManager();
- $qb = $em->createQueryBuilder();
- $qb
- ->select('gc')
- ->from('ChamiloCoreBundle:GradebookCategory', 'gc');
- $qb->where(
- $qb->expr()->eq('gc.course', $courseId)
- );
- if (!empty($session_id)) {
- $qb->andWhere(
- $qb->expr()->eq('gc.sessionId', $session_id)
- );
- } else {
- $qb->andWhere(
- $qb->expr()->orX(
- $qb->expr()->isNull('gc.sessionId'),
- $qb->expr()->eq('gc.sessionId', 0)
- )
- );
- }
- $qb->orderBy('gc.id', 'ASC');
- $res = $qb->getQuery()->getResult();
- if (count($res) < 1) {
- //there is no unique category for this course+session combination,
- $cat = new Category();
- if (!empty($session_id)) {
- $my_session_id = api_get_session_id();
- $s_name = api_get_session_name($my_session_id);
- $cat->set_name($course_code . ' - ' . get_lang('Session') . ' ' . $s_name);
- $cat->set_session_id($session_id);
- } else {
- $cat->set_name($course_code);
- }
- $cat->set_course_code($course_code);
- $cat->set_description(null);
- $cat->set_user_id(api_get_user_id());
- $cat->set_parent_id(0);
- $default_weight_setting = api_get_setting(
- 'gradebook.gradebook_default_weight'
- );
- $default_weight = isset($default_weight_setting) && !empty($default_weight_setting) ? $default_weight_setting : 100;
- $cat->set_weight($default_weight);
- $cat->set_grade_model_id($gradebook_model_id);
- $cat->set_certificate_min_score(75);
- $cat->set_visible(0);
- $cat->add();
- $category_id = $cat->get_id();
- unset($cat);
- } else {
- $row = current($res);
- $category_id = $row->getId();
- }
-
- return $category_id;
- }
- return false;
- }
- /**
- * @param FormValidator $form
- */
- public static function load_gradebook_select_in_tool($form)
- {
- $course_code = api_get_course_id();
- $session_id = api_get_session_id();
- self::create_default_course_gradebook();
- // Cat list
- $all_categories = Category :: load(null, null, $course_code, null, null, $session_id, false);
- $select_gradebook = $form->addElement('select', 'category_id', get_lang('SelectGradebook'));
- if (!empty($all_categories)) {
- foreach ($all_categories as $my_cat) {
- if ($my_cat->get_course_code() == api_get_course_id()) {
- $grade_model_id = $my_cat->get_grade_model_id();
- if (empty($grade_model_id)) {
- if ($my_cat->get_parent_id() == 0) {
- //$default_weight = $my_cat->get_weight();
- $select_gradebook->addoption(get_lang('Default'), $my_cat->get_id());
- $cats_added[] = $my_cat->get_id();
- } else {
- $select_gradebook->addoption($my_cat->get_name(), $my_cat->get_id());
- $cats_added[] = $my_cat->get_id();
- }
- } else {
- $select_gradebook->addoption(get_lang('Select'), 0);
- }
- }
- }
- }
- }
- /**
- * @param FlatViewTable $flatviewtable
- * @param Category $cat
- * @param $users
- * @param $alleval
- * @param $alllinks
- * @param array $params
- * @param null $mainCourseCategory
- */
- public static function export_pdf_flatview(
- $flatviewtable,
- $cat,
- $users,
- $alleval,
- $alllinks,
- $params = array(),
- $mainCourseCategory = null
- ) {
- // Getting data
- $printable_data = self::get_printable_data($cat[0], $users, $alleval, $alllinks, $params, $mainCourseCategory);
- // HTML report creation first
- $course_code = trim($cat[0]->get_course_code());
- $displayscore = ScoreDisplay :: instance();
- $customdisplays = $displayscore->get_custom_score_display_settings();
- $total = array();
- if (is_array($customdisplays) && count(($customdisplays))) {
- foreach ($customdisplays as $custom) {
- $total[$custom['display']] = 0;
- }
- $user_results = $flatviewtable->datagen->get_data_to_graph2(false);
- foreach ($user_results as $user_result) {
- $total[$user_result[count($user_result) - 1][1]]++;
- }
- }
- $parent_id = $cat[0]->get_parent_id();
- if (isset($cat[0]) && isset($parent_id)) {
- if ($parent_id == 0) {
- $grade_model_id = $cat[0]->get_grade_model_id();
- } else {
- $parent_cat = Category::load($parent_id);
- $grade_model_id = $parent_cat[0]->get_grade_model_id();
- }
- }
- $use_grade_model = true;
- if (empty($grade_model_id) || $grade_model_id == -1) {
- $use_grade_model = false;
- }
- if ($use_grade_model) {
- if ($parent_id == 0) {
- $title = api_strtoupper(get_lang('Average')) . '<br />' . get_lang('Detailed');
- } else {
- $title = api_strtoupper(get_lang('Average')) . '<br />' . $cat[0]->get_description() . ' - (' . $cat[0]->get_name() . ')';
- }
- } else {
- if ($parent_id == 0) {
- $title = api_strtoupper(get_lang('Average')) . '<br />' . get_lang('Detailed');
- } else {
- $title = api_strtoupper(get_lang('Average'));
- }
- }
- $columns = count($printable_data[0]);
- $has_data = is_array($printable_data[1]) && count($printable_data[1]) > 0;
- $table = new HTML_Table(array('class' => 'data_table'));
- $row = 0;
- $column = 0;
- $table->setHeaderContents($row, $column, get_lang('NumberAbbreviation'));
- $column++;
- foreach ($printable_data[0] as $printable_data_cell) {
- if (!is_array($printable_data_cell)) {
- $printable_data_cell = strip_tags($printable_data_cell);
- }
- $table->setHeaderContents($row, $column, $printable_data_cell);
- $column++;
- }
- $row++;
- if ($has_data) {
- $counter = 1;
- foreach ($printable_data[1] as &$printable_data_row) {
- $column = 0;
- $table->setCellContents($row, $column, $counter);
- $table->updateCellAttributes($row, $column, 'align="center"');
- $column++;
- $counter++;
- foreach ($printable_data_row as $key => &$printable_data_cell) {
- $attributes = array();
- $attributes['align'] = 'center';
- $attributes['style'] = null;
- if ($key === 'name') {
- $attributes['align'] = 'left';
- }
- if ($key === 'total') {
- $attributes['style'] = 'font-weight:bold';
- }
- $table->setCellContents($row, $column, $printable_data_cell);
- $table->updateCellAttributes($row, $column, $attributes);
- $column++;
- }
- $table->updateRowAttributes($row, $row % 2 ? 'class="row_even"' : 'class="row_odd"', true);
- $row++;
- }
- } else {
- $column = 0;
- $table->setCellContents($row, $column, get_lang('NoResults'));
- $table->updateCellAttributes($row, $column, 'colspan="' . $columns . '" align="center" class="row_odd"');
- }
- $pdfParams = array(
- 'filename' => get_lang('FlatView') . '_' . api_get_utc_datetime(),
- 'pdf_title' => $title,
- 'course_code' => $course_code,
- 'add_signatures' => true
- );
- $page_format = $params['orientation'] == 'landscape' ? 'A4-L' : 'A4';
- ob_start();
- $pdf = new PDF($page_format, $page_format, $pdfParams);
- $pdf->html_to_pdf_with_template($flatviewtable->return_table());
- $content = ob_get_contents();
- ob_end_clean();
- echo $content;
- exit;
- }
- /**
- * @param array $list_values
- * @return string
- */
- public static function score_badges($list_values)
- {
- $counter = 1;
- $badges = array();
- foreach ($list_values as $value) {
- $class = 'warning';
- if ($counter == 1) {
- $class = 'success';
- }
- $counter++;
- $badges[] = Display::badge($value, $class);
- }
- return Display::badge_group($badges);
- }
- /**
- * returns users within a course given by param
- * @param string $courseCode
- */
- public static function get_users_in_course($courseCode)
- {
- $tbl_course_user = Database:: get_main_table(TABLE_MAIN_COURSE_USER);
- $tbl_session_course_user = Database:: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
- $tbl_user = Database:: get_main_table(TABLE_MAIN_USER);
- $order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname ASC' : ' ORDER BY lastname, firstname ASC';
- $current_session = api_get_session_id();
- $courseCode = Database::escape_string($courseCode);
- $courseInfo = api_get_course_info($courseCode);
- $courseId = $courseInfo['real_id'];
- if (!empty($current_session)) {
- $sql = "SELECT user.user_id, user.username, lastname, firstname, official_code
- FROM $tbl_session_course_user as scru, $tbl_user as user
- WHERE
- scru.user_id = user.user_id AND
- scru.status=0 AND
- scru.c_id='$courseId' AND
- session_id ='$current_session'
- $order_clause
- ";
- } else {
- $sql = 'SELECT user.user_id, user.username, lastname, firstname, official_code
- FROM '.$tbl_course_user.' as course_rel_user, '.$tbl_user.' as user
- WHERE
- course_rel_user.user_id=user.user_id AND
- course_rel_user.status='.STUDENT.' AND
- course_rel_user.c_id = "'.$courseId.'" '.
- $order_clause;
- }
- $result = Database::query($sql);
- return self::get_user_array_from_sql_result($result);
- }
- /**
- * @param $result
- * @return array
- */
- public static function get_user_array_from_sql_result($result)
- {
- $a_students = array();
- while ($user = Database::fetch_array($result)) {
- if (!array_key_exists($user['user_id'], $a_students)) {
- $a_current_student = array ();
- $a_current_student[] = $user['user_id'];
- $a_current_student[] = $user['username'];
- $a_current_student[] = $user['lastname'];
- $a_current_student[] = $user['firstname'];
- $a_current_student[] = $user['official_code'];
- $a_students['STUD'.$user['user_id']] = $a_current_student;
- }
- }
- return $a_students;
- }
- /**
- * @param array $evals
- * @param array $links
- * @return array
- */
- public static function get_all_users($evals = array(), $links = array())
- {
- $coursecodes = array();
- $users = array();
- // By default add all user in course
- $coursecodes[api_get_course_id()] = '1';
- $users = GradebookUtils::get_users_in_course(api_get_course_id());
- foreach ($evals as $eval) {
- $coursecode = $eval->get_course_code();
- // evaluation in course
- if (isset($coursecode) && !empty($coursecode)) {
- if (!array_key_exists($coursecode, $coursecodes)) {
- $coursecodes[$coursecode] = '1';
- $users = array_merge($users, GradebookUtils::get_users_in_course($coursecode));
- }
- } else {
- // course independent evaluation
- $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
- $tbl_res = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
- $sql = 'SELECT user.user_id, lastname, firstname, user.official_code
- FROM '.$tbl_res.' as res, '.$tbl_user.' as user
- WHERE
- res.evaluation_id = '.intval($eval->get_id()).' AND
- res.user_id = user.user_id
- ';
- $sql .= ' ORDER BY lastname, firstname';
- if (api_is_western_name_order()) {
- $sql .= ' ORDER BY firstname, lastname';
- }
- $result = Database::query($sql);
- $users = array_merge($users, GradebookUtils::get_user_array_from_sql_result($result));
- }
- }
- foreach ($links as $link) {
- // links are always in a course
- $coursecode = $link->get_course_code();
- if (!array_key_exists($coursecode,$coursecodes)) {
- $coursecodes[$coursecode] = '1';
- $users = array_merge($users, GradebookUtils::get_users_in_course($coursecode));
- }
- }
- return $users;
- }
- /**
- * Search students matching a given last name and/or first name
- * @author Bert Steppé
- */
- public static function find_students($mask= '')
- {
- // students shouldn't be here // don't search if mask empty
- if (!api_is_allowed_to_edit() || empty ($mask)) {
- return null;
- }
- $mask = Database::escape_string($mask);
- $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
- $tbl_cru = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
- $sql = 'SELECT DISTINCT user.user_id, user.lastname, user.firstname, user.email, user.official_code
- FROM ' . $tbl_user . ' user';
- if (!api_is_platform_admin()) {
- $sql .= ', ' . $tbl_cru . ' cru';
- }
- $sql .= ' WHERE user.status = ' . STUDENT;
- $sql .= ' AND (user.lastname LIKE '."'%" . $mask . "%'";
- $sql .= ' OR user.firstname LIKE '."'%" . $mask . "%')";
- if (!api_is_platform_admin()) {
- $sql .= ' AND user.user_id = cru.user_id AND
- cru.relation_type <> '.COURSE_RELATION_TYPE_RRHH.' AND
- cru.c_id in (
- SELECT c_id FROM '.$tbl_cru . '
- WHERE
- user_id = ' . api_get_user_id() . ' AND
- status = ' . COURSEMANAGER . '
- )
- ';
- }
- $sql .= ' ORDER BY lastname, firstname';
- if (api_is_western_name_order()) {
- $sql .= ' ORDER BY firstname, lastname';
- }
- $result = Database::query($sql);
- $users = Database::store_result($result);
- return $users;
- }
- /**
- * @param int $linkId
- * @param float $weight
- */
- public static function updateLinkWeight($linkId, $name, $weight)
- {
- $linkId = intval($linkId);
- $weight = floatval($weight);
- $course_id = api_get_course_int_id();
- AbstractLink::add_link_log($linkId, $name);
- $em = Database::getManager();
- $gradebookLink = $em->find('ChamiloCoreBundle:GradebookLink', $linkId);
- if (!$gradebookLink) {
- return false;
- }
-
- $gradebookLink->setWeight($weight);
- $em->persist($gradebookLink);
- $em->flush();
- // Update weight for attendance
- if ($gradebookLink->getType() == LINK_ATTENDANCE) {
- $em
- ->createQuery('
- UPDATE ChamiloCourseBundle:CAttendance ca
- SET ca.attendanceWeight = :weight
- WHERE ca.cId = :course AND ca.id = :reference
- ')
- ->execute([
- 'weight' => $weight,
- 'course' => $course_id,
- 'reference' => $gradebookLink->getRefId()
- ]);
- }
- // Update weight into forum thread
- if ($gradebookLink->getType() == LINK_FORUM_THREAD) {
- $em
- ->createQuery('
- UPDATE ChamiloCourseBundle:CForumThread cft
- SET cft.threadWeight = :weight
- WHERE cft.cId = :course AND cft.threadId = :reference
- ')
- ->execute([
- 'weight' => $weight,
- 'course' => $course_id,
- 'reference' => $gradebookLink->getRefId()
- ]);
- }
- //Update weight into student publication(work)
- if ($gradebookLink->getType() == LINK_STUDENTPUBLICATION) {
- $em
- ->createQuery('
- UPDATE ChamiloCourseBundle:CStudentPublication csp
- SET csp.weight = :weight
- WHERE csp.cId = :course AND csp.id = :reference
- ')
- ->execute([
- 'weight' => $weight,
- 'course' => $course_id,
- 'reference' => $gradebookLink->getRefId()
- ]);
- }
- }
- /**
- * @param int $id
- * @param float $weight
- */
- public static function updateEvaluationWeight($id, $weight)
- {
- $em = Database::getManager();
- $gradebookEvaluation = $em->find('ChamiloCoreBundle:GradebookEvaluation', $id);
- $gradebookEvaluation->setWeight($weight);
- $em->persist($gradebookEvaluation);
- $em->flush();
- }
- /**
- *
- * Get the achieved certificates for a user in courses
- * @param int $userId The user id
- * @param bool $includeNonPublicCertificates Whether include the non-plublic certificates
- * @return array
- */
- public static function getUserCertificatesInCourses($userId, $includeNonPublicCertificates = true)
- {
- $userId = intval($userId);
- $courseList = [];
- $courses = CourseManager::get_courses_list_by_user_id($userId);
- foreach ($courses as $course) {
- if (!$includeNonPublicCertificates) {
- $allowPublicCertificates = api_get_course_setting('allow_public_certificates', $course['code']);
- if (empty($allowPublicCertificates)) {
- continue;
- }
- }
- $courseGradebookCategory = Category::load(null, null, $course['code']);
- if (empty($courseGradebookCategory)) {
- continue;
- }
- $courseGradebookId = $courseGradebookCategory[0]->get_id();
- $certificateInfo = GradebookUtils::get_certificate_by_user_id($courseGradebookId, $userId);
- if (empty($certificateInfo)) {
- continue;
- }
- $courseInfo = api_get_course_info_by_id($course['real_id']);
- $courseList[] = [
- 'course' => $courseInfo['title'],
- 'score' => $certificateInfo['score_certificate'],
- 'date' => api_format_date($certificateInfo['created_at'], DATE_FORMAT_SHORT),
- 'link' => api_get_path(WEB_PATH) . "certificates/index.php?id={$certificateInfo['id']}"
- ];
- }
- return $courseList;
- }
- /**
- * Get the achieved certificates for a user in course sessions
- * @param int $userId The user id
- * @param bool $includeNonPublicCertificates Whether include the non-plublic certificates
- * @return array
- */
- public static function getUserCertificatesInSessions($userId, $includeNonPublicCertificates = true)
- {
- $userId = intval($userId);
- $sessionList = [];
- $sessions = SessionManager::get_sessions_by_user($userId, true, true);
- foreach ($sessions as $session) {
- if (empty($session['courses'])) {
- continue;
- }
- $sessionCourses = SessionManager::get_course_list_by_session_id($session['session_id']);
- foreach ($sessionCourses as $course) {
- if (!$includeNonPublicCertificates) {
- $allowPublicCertificates = api_get_course_setting('allow_public_certificates', $course['code']);
- if (empty($allowPublicCertificates)) {
- continue;
- }
- }
- $courseGradebookCategory = Category::load(
- null,
- null,
- $course['code'],
- null,
- null,
- $session['session_id']
- );
- if (empty($courseGradebookCategory)) {
- continue;
- }
- $courseGradebookId = $courseGradebookCategory[0]->get_id();
- $certificateInfo = GradebookUtils::get_certificate_by_user_id(
- $courseGradebookId,
- $userId
- );
- if (empty($certificateInfo)) {
- continue;
- }
- $sessionList[] = [
- 'session' => $session['session_name'],
- 'course' => $course['title'],
- 'score' => $certificateInfo['score_certificate'],
- 'date' => api_format_date($certificateInfo['created_at'], DATE_FORMAT_SHORT),
- 'link' => api_get_path(WEB_PATH) . "certificates/index.php?id={$certificateInfo['id']}"
- ];
- }
- }
- return $sessionList;
- }
- /**
- * @param int $userId
- * @param array $cats
- * @param bool $saveToFile
- * @param bool $saveToHtmlFile
- * @param array $studentList
- * @param PDF $pdf
- *
- * @return string
- */
- public static function generateTable(
- $userId,
- $cats,
- $saveToFile = false,
- $saveToHtmlFile = false,
- $studentList = array(),
- $pdf = null
- ) {
- $courseInfo = api_get_course_info();
- $userInfo = api_get_user_info($userId);
- $cat = $cats[0];
- $allcat = $cats[0]->get_subcategories(
- $userId,
- api_get_course_id(),
- api_get_session_id()
- );
- $alleval = $cats[0]->get_evaluations($userId);
- $alllink = $cats[0]->get_links($userId);
- $gradebooktable = new GradebookTable(
- $cat,
- $allcat,
- $alleval,
- $alllink,
- null, // params
- true, // $exportToPdf
- false, // showteacher
- $userId,
- $studentList
- );
- $gradebooktable->userId = $userId;
- if (api_is_allowed_to_edit()) {
- $gradebooktable->td_attributes = [
- 4 => 'class=centered'
- ];
- } else {
- $gradebooktable->td_attributes = [
- 3 => 'class=centered',
- 4 => 'class=centered',
- 5 => 'class=centered',
- 6 => 'class=centered',
- 7 => 'class=centered'
- ];
- }
- $table = $gradebooktable->return_table();
- $graph = $gradebooktable->getGraph();
- $sessionName = api_get_session_name(api_get_session_id());
- $sessionName = !empty($sessionName) ? " - $sessionName" : '';
- $params = array(
- 'pdf_title' => sprintf(get_lang('GradeFromX'), $courseInfo['department_name']),
- 'session_info' => '',
- 'course_info' => '',
- 'pdf_date' => '',
- 'course_code' => api_get_course_id(),
- 'add_signatures' => false,
- 'student_info' => $userInfo,
- 'show_grade_generated_date' => true,
- 'show_real_course_teachers' => false,
- 'show_teacher_as_myself' => false,
- 'orientation' => 'P'
- );
- if (empty($pdf)) {
- $pdf = new PDF('A4', $params['orientation'], $params);
- }
- $pdf->params['student_info'] = $userInfo;
- $file = api_get_path(SYS_ARCHIVE_PATH).uniqid().'.html';
- $content =
- $table.
- $graph.
- '<br />'.get_lang('Feedback').'<br />
- <textarea rows="5" cols="100" ></textarea>';
- $address = api_get_setting('platform.institution_address');
- $phone = api_get_setting('admin.administrator_phone');
- $address = str_replace('\n', '<br />', $address);
- $pdf->custom_header = array('html' => "<h5 align='right'>$address <br />$phone</h5>");
- $result = $pdf->html_to_pdf_with_template(
- $content,
- $saveToFile,
- $saveToHtmlFile
- );
- if ($saveToHtmlFile) {
- file_put_contents($file, $result);
- return $file;
- }
- return $file;
- }
- }
|