/** * Constructor. * * @param array $data */ public function __construct(array $data) { parent::__construct($data); $this->title = isset($data['title']) ? $data['title'] : null; if (null !== $this->name && false !== strpos($this->name, ':')) { list($this->ncName, $this->reference) = explode(':', $this->name, 2); } }
function __construct($hp = 0) { parent::__construct(); $this->set_type(LINK_EXERCISE); $this->is_hp = $hp; if ($this->is_hp == 1) { $this->set_type(LINK_HOTPOTATOES); } }
protected function onComponentTag(ComponentTag $tag) { parent::onComponentTag($tag); $url = $this->urlForListener($this); $tag->put('href', $this->popupSettings == null ? $url : 'javascript:;'); if ($this->popupSettings != null) { $properties = $this->popupSettings; $tag->put('onClick', sprintf("javascript:window.open('%s','%s','width=%s,height=%s');", $url, $properties->name, $properties->width, $properties->height)); } }
public function __construct() { parent::__construct(); $this->set_type(LINK_FORUM_THREAD); }
/** * Constructor */ function __construct() { parent::__construct(); }
/** * Constructor */ public function __construct() { parent::__construct(); $this->set_type(LINK_ATTENDANCE); }
/** * Calculate the score of this category * @param $stud_id student id (default: all students - then the average is returned) * @return array (score sum, weight sum) * or null if no scores available */ public function calc_score($stud_id = null, $type = null, $course_code = '', $session_id = null) { // Get appropriate subcategories, evaluations and links if (!empty($course_code)) { $cats = $this->get_subcategories($stud_id, $course_code, $session_id); $evals = $this->get_evaluations($stud_id, false, $course_code); $links = $this->get_links($stud_id, false, $course_code); } else { $cats = $this->get_subcategories($stud_id); $evals = $this->get_evaluations($stud_id); $links = $this->get_links($stud_id); } // Calculate score $rescount = 0; $ressum = 0; $weightsum = 0; $bestResult = 0; $students = []; if (!empty($cats)) { /** @var Category $cat */ foreach ($cats as $cat) { $score = $cat->calc_score($stud_id, $type, $course_code, $session_id); if ($cat->get_weight() != 0) { $catweight = $cat->get_weight(); $rescount++; $weightsum += $catweight; } if (isset($score)) { $ressum += $score[0] / $score[1] * $catweight; $bestResult += $ressum; } } } if (!empty($evals)) { /** @var Evaluation $eval */ foreach ($evals as $eval) { $evalres = $eval->calc_score($stud_id, $type); $students[$stud_id] = $evalres[0]; if (isset($evalres) && $eval->get_weight() != 0) { $evalweight = $eval->get_weight(); $weightsum += $evalweight; $rescount++; $ressum += $evalres[0] / $evalres[1] * $evalweight; } else { if ($eval->get_weight() != 0) { $evalweight = $eval->get_weight(); $weightsum += $evalweight; } } } } if (!empty($links)) { $bestResult = 0; $weight = 0; /** @var EvalLink|ExerciseLink $link */ foreach ($links as $link) { $linkres = $link->calc_score($stud_id, $type); if (!empty($linkres) && $link->get_weight() != 0) { $students[$stud_id] = $linkres[0]; $linkweight = $link->get_weight(); $link_res_denom = $linkres[1] == 0 ? 1 : $linkres[1]; $rescount++; $weightsum += $linkweight; $ressum += $linkres[0] / $link_res_denom * $linkweight; } else { // Adding if result does not exists if ($link->get_weight() != 0) { $linkweight = $link->get_weight(); $weightsum += $linkweight; } } } } if ($rescount == 0) { return null; } else { switch ($type) { case 'best': return array($ressum, $weightsum); break; case 'average': return array($ressum, $weightsum); break; case 'ranking': return null; return AbstractLink::getCurrentUserRanking($stud_id, $students); break; default: return array($ressum, $weightsum); break; } } }
/** * @param null $stud_id * @return array|null */ public function calc_score($stud_id = null, $type = null) { $stud_id = intval($stud_id); $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION); $sql = 'SELECT * FROM ' . $table . "\n \t\t\tWHERE\n \t\t\t\tc_id = {$this->course_id} AND\n \t\t\t\tid = '" . intval($this->get_ref_id()) . "' AND\n \t\t\t\tsession_id\t= " . api_get_session_id() . "\n\t\t\t\t"; $query = Database::query($sql); $assignment = Database::fetch_array($query); if (count($assignment) == 0) { $parentId = '0'; } else { $parentId = $assignment['id']; } $sql = 'SELECT * FROM ' . $table . ' WHERE c_id = ' . $this->course_id . ' AND active = 1 AND parent_id = "' . $parentId . '" AND session_id = ' . api_get_session_id() . ' AND qualificator_id <> 0 '; if (!empty($stud_id)) { $sql .= " AND user_id = {$stud_id} "; } $order = api_get_setting('gradebook.student_publication_to_take_in_gradebook'); switch ($order) { case 'last': // latest attempt $sql .= ' ORDER BY sent_date DESC'; break; case 'first': default: // first attempt $sql .= ' ORDER BY id'; break; } $scores = Database::query($sql); // for 1 student if (!empty($stud_id)) { if ($data = Database::fetch_array($scores)) { return array($data['qualification'], $assignment['qualification']); } else { return ''; } } else { $students = array(); // user list, needed to make sure we only // take first attempts into account $rescount = 0; $sum = 0; $bestResult = 0; $weight = 0; $sumResult = 0; $myResult = 0; while ($data = Database::fetch_array($scores)) { if (!array_key_exists($data['user_id'], $students)) { if ($assignment['qualification'] != 0) { $students[$data['user_id']] = $data['qualification']; $rescount++; $sum += $data['qualification'] / $assignment['qualification']; $sumResult += $data['qualification']; if ($data['qualification'] > $bestResult) { $bestResult = $data['qualification']; } $weight = $assignment['qualification']; } } } if ($rescount == 0) { return null; } else { switch ($type) { case 'best': return array($bestResult, $weight); break; case 'average': return array($sumResult / $rescount, $weight); break; case 'ranking': return AbstractLink::getCurrentUserRanking($stud_id, $students); break; default: return array($sum, $rescount); break; } } } }
/** * Builds the course or platform admin icons to edit a link * @param AbstractLink $link * @param int $selectcat id of selected category */ 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() . '?movelink=' . $link->get_id() . '&selectcat=' . $selectcat . '"><img src="../img/deplacer_fichier.gif" border="0" title="' . get_lang('Move') . '" alt="" /></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; } }
public function __construct() { parent::__construct(); $this->set_type(LINK_STUDENTPUBLICATION); }
/** * @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); $table_link = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK); $table_evaluation = Database::get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); $tbl_forum_thread = Database::get_course_table(TABLE_FORUM_THREAD); $tbl_work = Database::get_course_table(TABLE_STUDENT_PUBLICATION); $tbl_attendance = Database::get_course_table(TABLE_ATTENDANCE); $sql = 'UPDATE ' . $table_link . ' SET weight = ' . "'" . Database::escape_string($weight) . "'" . ' WHERE id = ' . $linkId; Database::query($sql); // Update weight for attendance $sql = 'SELECT ref_id FROM ' . $table_link . ' WHERE id = ' . $linkId . ' AND type=' . LINK_ATTENDANCE; $rs_attendance = Database::query($sql); if (Database::num_rows($rs_attendance) > 0) { $row_attendance = Database::fetch_array($rs_attendance); $sql = 'UPDATE ' . $tbl_attendance . ' SET attendance_weight =' . $weight . ' WHERE c_id = ' . $course_id . ' AND id = ' . intval($row_attendance['ref_id']); Database::query($sql); } // Update weight into forum thread $sql = 'UPDATE ' . $tbl_forum_thread . ' SET thread_weight=' . $weight . ' WHERE c_id = ' . $course_id . ' AND thread_id = ( SELECT ref_id FROM ' . $table_link . ' WHERE id=' . $linkId . ' AND type=' . LINK_FORUM_THREAD . ' ) '; Database::query($sql); //Update weight into student publication(work) $sql = 'UPDATE ' . $tbl_work . ' SET weight=' . $weight . ' WHERE c_id = ' . $course_id . ' AND id = ( SELECT ref_id FROM ' . $table_link . ' WHERE id=' . $linkId . ' AND type = ' . LINK_STUDENTPUBLICATION . ' ) '; Database::query($sql); }
/** * @param int $idevaluation */ public static function add_link_log($idevaluation) { $tbl_grade_linkeval_log = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINKEVAL_LOG); $dateobject = AbstractLink::load($idevaluation, null, null, null, null); $current_date_server = api_get_utc_datetime(); $arreval = get_object_vars($dateobject[0]); $description_log = isset($arreval['description']) ? $arreval['description'] : ''; if (isset($_POST['name_link'])) { $name_log = isset($_POST['name_link']) ? Security::remove_XSS($_POST['name_link']) : $arreval['course_code']; } elseif ($_POST['link_' . $idevaluation]) { $name_log = $_POST['link_' . $idevaluation]; } else { $name_log = $arreval['course_code']; } $sql = "INSERT INTO " . $tbl_grade_linkeval_log . "(id_linkeval_log,name,description,created_at,weight,visible,type,user_id_log)\n VALUES('" . Database::escape_string($arreval['id']) . "','" . Database::escape_string($name_log) . "','" . Database::escape_string($description_log) . "','" . Database::escape_string($current_date_server) . "','" . Database::escape_string($arreval['weight']) . "','" . Database::escape_string($arreval['visible']) . "','Link'," . api_get_user_id() . ")"; Database::query($sql); }
protected function onComponentTag(ComponentTag $tag) { parent::onComponentTag($tag); $tag->put('href', 'javascript:;'); }
public function __construct() { parent::__construct(); $this->set_type(LINK_SURVEY); }
/** * Calculate the score of this evaluation * @param int $stud_id (default: all students who have results for this eval - then the average is returned) * @param string $type (best, average, ranking) * @return array (score, max) if student is given * array (sum of scores, number of scores) otherwise * or null if no scores available */ public function calc_score($stud_id = null, $type = null) { $results = Result::load(null, $stud_id, $this->id); $rescount = 0; $sum = 0; $bestResult = 0; $weight = 0; $sumResult = 0; $students = []; /** @var Result $res */ foreach ($results as $res) { $score = $res->get_score(); if (!empty($score) || $score == '0') { $rescount++; $sum += $score / $this->get_max(); $sumResult += $score; if ($score > $bestResult) { $bestResult = $score; } $weight = $this->get_max(); } $students[$res->get_user_id()] = $score; } if ($rescount == 0) { return null; } else { if (isset($stud_id)) { return array($score, $this->get_max()); } else { switch ($type) { case 'best': return array($bestResult, $weight); break; case 'average': return array($sumResult / $rescount, $weight); break; case 'ranking': return AbstractLink::getCurrentUserRanking($stud_id, $students); break; default: return array($sum, $rescount); break; } } } }
/** * Calculate the score of this category * @param $stud_id student id (default: all students - then the average is returned) * @return array (score sum, weight sum) * or null if no scores available */ public function calc_score($stud_id = null, $type = null, $course_code = '', $session_id = null) { // Classic if (!empty($stud_id) && $type == '') { if (!empty($course_code)) { $cats = $this->get_subcategories($stud_id, $course_code, $session_id); $evals = $this->get_evaluations($stud_id, false, $course_code); $links = $this->get_links($stud_id, false, $course_code); } else { $cats = $this->get_subcategories($stud_id); $evals = $this->get_evaluations($stud_id); $links = $this->get_links($stud_id); } // Calculate score $count = 0; $ressum = 0; $weightsum = 0; if (!empty($cats)) { /** @var Category $cat */ foreach ($cats as $cat) { $cat->setStudentList($this->getStudentList()); $score = $cat->calc_score($stud_id, null, $course_code, $session_id); $catweight = 0; if ($cat->get_weight() != 0) { $catweight = $cat->get_weight(); $weightsum += $catweight; } if (isset($score) && !empty($score[1]) && !empty($catweight)) { $ressum += $score[0] / $score[1] * $catweight; } } } $students = array(); if (!empty($evals)) { /** @var Evaluation $eval */ foreach ($evals as $eval) { $eval->setStudentList($this->getStudentList()); $evalres = $eval->calc_score($stud_id, null); if (isset($evalres) && $eval->get_weight() != 0) { $evalweight = $eval->get_weight(); $weightsum += $evalweight; $count++; if (!empty($evalres[1])) { $ressum += $evalres[0] / $evalres[1] * $evalweight; } } else { if ($eval->get_weight() != 0) { $evalweight = $eval->get_weight(); $weightsum += $evalweight; } } } } if (!empty($links)) { /** @var EvalLink|ExerciseLink $link */ foreach ($links as $link) { $link->setStudentList($this->getStudentList()); $linkres = $link->calc_score($stud_id, null); if (!empty($linkres) && $link->get_weight() != 0) { $students[$stud_id] = $linkres[0]; $linkweight = $link->get_weight(); $link_res_denom = $linkres[1] == 0 ? 1 : $linkres[1]; $count++; $weightsum += $linkweight; $ressum += $linkres[0] / $link_res_denom * $linkweight; } else { // Adding if result does not exists if ($link->get_weight() != 0) { $linkweight = $link->get_weight(); $weightsum += $linkweight; } } } } } else { if (!empty($course_code)) { $cats = $this->get_subcategories(null, $course_code, $session_id); $evals = $this->get_evaluations(null, false, $course_code); $links = $this->get_links(null, false, $course_code); } else { $cats = $this->get_subcategories(null); $evals = $this->get_evaluations(null); $links = $this->get_links(null); } // Calculate score $count = 0; $ressum = 0; $weightsum = 0; $bestResult = 0; if (!empty($cats)) { /** @var Category $cat */ foreach ($cats as $cat) { $cat->setStudentList($this->getStudentList()); $score = $cat->calc_score(null, $type, $course_code, $session_id); $catweight = 0; if ($cat->get_weight() != 0) { $catweight = $cat->get_weight(); $weightsum += $catweight; } if (isset($score) && !empty($score[1]) && !empty($catweight)) { $ressum += $score[0] / $score[1] * $catweight; if ($ressum > $bestResult) { $bestResult = $ressum; } } } } if (!empty($evals)) { /** @var Evaluation $eval */ foreach ($evals as $eval) { $evalres = $eval->calc_score(null, $type); $eval->setStudentList($this->getStudentList()); if (isset($evalres) && $eval->get_weight() != 0) { $evalweight = $eval->get_weight(); $weightsum += $evalweight; $count++; if (!empty($evalres[1])) { $ressum += $evalres[0] / $evalres[1] * $evalweight; } if ($ressum > $bestResult) { $bestResult = $ressum; } } else { if ($eval->get_weight() != 0) { $evalweight = $eval->get_weight(); $weightsum += $evalweight; } } } } if (!empty($links)) { /** @var EvalLink|ExerciseLink $link */ foreach ($links as $link) { $link->setStudentList($this->getStudentList()); $linkres = $link->calc_score($stud_id, $type); if (!empty($linkres) && $link->get_weight() != 0) { $students[$stud_id] = $linkres[0]; $linkweight = $link->get_weight(); $link_res_denom = $linkres[1] == 0 ? 1 : $linkres[1]; $count++; $weightsum += $linkweight; $ressum += $linkres[0] / $link_res_denom * $linkweight; if ($ressum > $bestResult) { $bestResult = $ressum; } } else { // Adding if result does not exists if ($link->get_weight() != 0) { $linkweight = $link->get_weight(); $weightsum += $linkweight; } } } } } switch ($type) { case 'best': if (empty($bestResult)) { return null; } return array($bestResult, $weightsum); break; case 'average': if (empty($ressum)) { return null; } return array($ressum, $weightsum); break; case 'ranking': // category ranking is calculated in gradebook_data_generator.class.php // function get_data return null; return AbstractLink::getCurrentUserRanking($stud_id, array()); break; default: return array($ressum, $weightsum); break; } }
/** * Get actual array data * @return array 2-dimensional array - each array contains the elements: * 0: cat/eval/link object * 1: item name * 2: description * 3: weight * 4: date * 5: student's score (if student logged in) */ public function get_data($sorting = 0, $start = 0, $count = null, $ignore_score_color = false, $studentList = array()) { //$status = CourseManager::get_user_in_course_status(api_get_user_id(), api_get_course_id()); // do some checks on count, redefine if invalid value if (!isset($count)) { $count = count($this->items) - $start; } if ($count < 0) { $count = 0; } $allitems = $this->items; /* // sort array if ($sorting & self :: GDG_SORT_TYPE) { usort($allitems, array('GradebookDataGenerator', 'sort_by_type')); } elseif ($sorting & self :: GDG_SORT_ID) { usort($allitems, array('GradebookDataGenerator', 'sort_by_id')); } elseif ($sorting & self :: GDG_SORT_NAME) { usort($allitems, array('GradebookDataGenerator', 'sort_by_name')); } elseif ($sorting & self :: GDG_SORT_DESCRIPTION) { usort($allitems, array('GradebookDataGenerator', 'sort_by_description')); } elseif ($sorting & self :: GDG_SORT_WEIGHT) { usort($allitems, array('GradebookDataGenerator', 'sort_by_weight')); } elseif ($sorting & self :: GDG_SORT_DATE) { //usort($allitems, array('GradebookDataGenerator', 'sort_by_date')); } if ($sorting & self :: GDG_SORT_DESC) { $allitems = array_reverse($allitems); }*/ usort($allitems, array('GradebookDataGenerator', 'sort_by_name')); $userId = $this->userId; // Get selected items $visibleitems = array_slice($allitems, $start, $count); $course_code = api_get_course_id(); $sessionId = api_get_session_id(); $status_user = api_get_status_of_user_in_course(api_get_user_id(), api_get_course_int_id()); $userCount = count($studentList); // Generate the data to display $data = array(); /** @var GradebookItem $item */ $totalWeight = 0; foreach ($visibleitems as $item) { $row = array(); $row[] = $item; $row[] = $item->get_name(); // display the 2 first line of description, and all description on mouseover (https://support.chamilo.org/issues/6588) $row[] = '<span title="' . api_remove_tags_with_space($item->get_description()) . '">' . api_get_short_text_from_html($item->get_description(), 160) . '</span>'; $totalWeight += $item->get_weight(); $row[] = $item->get_weight(); $item->setStudentList($studentList); //if (count($this->evals_links) > 0) { if (get_class($item) == 'Evaluation') { // Items inside a category. if (1) { $resultColumn = $this->build_result_column($userId, $item, $ignore_score_color); $row[] = $resultColumn['display']; $row['result_score'] = $resultColumn['score']; $row['result_score_weight'] = $resultColumn['score_weight']; // Best $best = $this->buildBestResultColumn($item); $row['best'] = $best['display']; $row['best_score'] = $best['score']; // Average $average = $this->buildAverageResultColumn($item); $row['average'] = $average['display']; $row['average_score'] = $average['score']; // Ranking $ranking = $this->buildRankingColumn($item, $userId, $userCount); $row['ranking'] = $ranking['display']; $row['ranking_score'] = $ranking['score']; $row[] = $item; } } else { // Category. $result = $this->build_result_column($userId, $item, $ignore_score_color, true); $row[] = $result['display']; $row['result_score'] = $result['score']; $row['result_score_weight'] = $result['score']; // Best $best = $this->buildBestResultColumn($item); $row['best'] = $best['display']; $row['best_score'] = $best['score']; // Average $average = $this->buildAverageResultColumn($item); $row['average'] = $average['display']; $row['average_score'] = $average['score']; // Ranking $rankingStudentList = array(); $invalidateResults = true; foreach ($studentList as $user) { $score = $this->build_result_column($user['user_id'], $item, $ignore_score_color, true); if (!empty($score['score'][0])) { $invalidateResults = false; } $rankingStudentList[$user['user_id']] = $score['score'][0]; } $scoreDisplay = ScoreDisplay::instance(); $score = AbstractLink::getCurrentUserRanking($userId, $rankingStudentList); $row['ranking'] = $scoreDisplay->display_score($score, SCORE_DIV, SCORE_BOTH, true); if ($invalidateResults) { $row['ranking'] = null; } } $data[] = $row; } return $data; }
/** * Function used by SortableTable to generate the data to display * @param int $from * @param int $per_page * @param int $column * @param string $direction * @param int $sort * @return array|mixed */ public function get_table_data($from = 1, $per_page = null, $column = null, $direction = null, $sort = null) { //variables load in index.php global $certificate_min_score; // determine sorting type $col_adjust = api_is_allowed_to_edit() ? 1 : 0; // By id $this->column = 5; switch ($this->column) { // Type case 0 + $col_adjust: $sorting = GradebookDataGenerator::GDG_SORT_TYPE; break; case 1 + $col_adjust: $sorting = GradebookDataGenerator::GDG_SORT_NAME; break; case 2 + $col_adjust: $sorting = GradebookDataGenerator::GDG_SORT_DESCRIPTION; break; case 3 + $col_adjust: $sorting = GradebookDataGenerator::GDG_SORT_WEIGHT; break; case 4 + $col_adjust: $sorting = GradebookDataGenerator::GDG_SORT_DATE; case 5 + $col_adjust: $sorting = GradebookDataGenerator::GDG_SORT_ID; break; } if ($this->direction == 'DESC') { $sorting |= GradebookDataGenerator::GDG_SORT_DESC; } else { $sorting |= GradebookDataGenerator::GDG_SORT_ASC; } // Status of user in course. $user_id = $this->userId; $course_code = api_get_course_id(); $session_id = api_get_session_id(); $status_user = api_get_status_of_user_in_course(api_get_user_id(), api_get_course_int_id()); if (empty($session_id)) { $statusToFilter = STUDENT; } else { $statusToFilter = 0; } if (empty($this->studentList)) { $studentList = CourseManager::get_user_list_from_course_code($course_code, $session_id, null, null, $statusToFilter); $this->studentList = $studentList; } $this->datagen->userId = $this->userId; $data_array = $this->datagen->get_data($sorting, $from, $this->per_page, false, $this->studentList); // generate the data to display $sortable_data = array(); $weight_total_links = 0; $main_categories = array(); $main_cat = Category::load(null, null, $course_code, null, null, $session_id, 'ORDER BY id'); $total_categories_weight = 0; $scoredisplay = ScoreDisplay::instance(); $totalResult = [0, 0]; $totalBest = [0, 0]; $totalAverage = [0, 0]; $type = 'detail'; if ($this->exportToPdf) { $type = 'simple'; } // Categories. if (!empty($data_array)) { foreach ($data_array as $data) { // list of items inside the gradebook (exercises, lps, forums, etc) $row = array(); /** @var AbstractLink $item */ $item = $mainCategory = $data[0]; //if the item is invisible, wrap it in a span with class invisible $invisibility_span_open = api_is_allowed_to_edit() && $item->is_visible() == '0' ? '<span class="invisible">' : ''; $invisibility_span_close = api_is_allowed_to_edit() && $item->is_visible() == '0' ? '</span>' : ''; // Id if ($this->teacherView) { if ($this->exportToPdf == false) { $row[] = $this->build_id_column($item); } } // Type. $row[] = $this->build_type_column($item); // Name. if (get_class($item) == 'Category') { $row[] = $invisibility_span_open . '<strong>' . $item->get_name() . '</strong>' . $invisibility_span_close; $main_categories[$item->get_id()]['name'] = $item->get_name(); } else { $name = $this->build_name_link($item, $type); $row[] = $invisibility_span_open . $name . $invisibility_span_close; $main_categories[$item->get_id()]['name'] = $name; } $this->dataForGraph['categories'][] = $item->get_name(); $main_categories[$item->get_id()]['weight'] = $item->get_weight(); $total_categories_weight += $item->get_weight(); // Description. if ($this->exportToPdf == false) { $row[] = $invisibility_span_open . $data[2] . $invisibility_span_close; } // Weight. $weight = $scoredisplay->display_score(array($data['3'], $this->currentcat->get_weight()), SCORE_SIMPLE, SCORE_BOTH, true); if ($this->teacherView) { $row[] = $invisibility_span_open . Display::tag('p', $weight, array('class' => 'score')) . $invisibility_span_close; } else { $row[] = $invisibility_span_open . $weight . $invisibility_span_close; } $category_weight = $item->get_weight(); $mainCategoryWeight = $main_cat[0]->get_weight(); if ($this->teacherView) { $weight_total_links += $data[3]; } else { $cattotal = Category::load($_GET['selectcat']); $scoretotal = $cattotal[0]->calc_score($this->userId); $item_value = $scoredisplay->display_score($scoretotal, SCORE_SIMPLE); } // Edit (for admins). if ($this->teacherView) { $cat = new Category(); $show_message = $cat->show_message_resource_delete($item->get_course_code()); if ($show_message === false) { $row[] = $this->build_edit_column($item); } } else { $score = $item->calc_score($this->userId); if (!empty($score[1])) { $completeScore = $scoredisplay->display_score($score, SCORE_DIV_PERCENT); $score = $score[0] / $score[1] * $item->get_weight(); $score = $scoredisplay->display_score(array($score, null), SCORE_SIMPLE); $scoreToDisplay = Display::tip($score, $completeScore); } else { $scoreToDisplay = '-'; $categoryScore = null; } // Students get the results and certificates columns //if (count($this->evals_links) > 0 && $status_user != 1) { if (1) { $value_data = isset($data[4]) ? $data[4] : null; $best = isset($data['best']) ? $data['best'] : null; $average = isset($data['average']) ? $data['average'] : null; $ranking = isset($data['ranking']) ? $data['ranking'] : null; $totalResult = [$totalResult[0] + $data['result_score_weight'][0], $totalResult[1] + $data['result_score_weight'][1]]; $totalBest = [$totalBest[0] + $data['best_score'][0], $totalBest[1] + $data['best_score'][1]]; $totalAverage = [$totalAverage[0] + $data['average_score'][0], $totalAverage[1] + $data['average_score'][1]]; // Student result $row[] = $value_data; $totalResultAverageValue = strip_tags($scoredisplay->display_score($totalResult, SCORE_AVERAGE)); $this->dataForGraph['my_result'][] = (double) str_replace('%', '', $totalResultAverageValue); $totalAverageValue = strip_tags($scoredisplay->display_score($totalAverage, SCORE_AVERAGE)); $this->dataForGraph['average'][] = (double) str_replace('%', '', $totalAverageValue); // Ranking $row[] = $ranking; // Best $row[] = $best; // Average $row[] = $average; if (get_class($item) == 'Category') { if ($this->exportToPdf == false) { $row[] = $this->build_edit_column($item); } } } else { $row[] = $scoreToDisplay; if (!empty($this->cats)) { if ($this->exportToPdf == false) { $row[] = $this->build_edit_column($item); } } } } // Category added. $sortable_data[] = $row; // Loading children if (get_class($item) == 'Category') { $course_code = api_get_course_id(); $session_id = api_get_session_id(); $parent_id = $item->get_id(); $cats = Category::load($parent_id, null, null, null, null, null); if (isset($cats[0])) { $allcat = $cats[0]->get_subcategories($this->userId, $course_code, $session_id); $alleval = $cats[0]->get_evaluations($this->userId); $alllink = $cats[0]->get_links($this->userId); $sub_cat_info = new GradebookDataGenerator($allcat, $alleval, $alllink); $sub_cat_info->userId = $user_id; $data_array2 = $sub_cat_info->get_data($sorting, $from, $this->per_page, false, $this->studentList); $total_weight = 0; // Links. foreach ($data_array2 as $data) { $row = array(); $item = $data[0]; //if the item is invisible, wrap it in a span with class invisible $invisibility_span_open = api_is_allowed_to_edit() && $item->is_visible() == '0' ? '<span class="invisible">' : ''; $invisibility_span_close = api_is_allowed_to_edit() && $item->is_visible() == '0' ? '</span>' : ''; if (isset($item)) { $main_categories[$parent_id]['children'][$item->get_id()]['name'] = $item->get_name(); $main_categories[$parent_id]['children'][$item->get_id()]['weight'] = $item->get_weight(); } if ($this->teacherView) { if ($this->exportToPdf == false) { $row[] = $this->build_id_column($item); } } // Type $row[] = $this->build_type_column($item, array('style' => 'padding-left:5px')); // Name. $row[] = $invisibility_span_open . " " . $this->build_name_link($item, $type) . $invisibility_span_close; // Description. if ($this->exportToPdf == false) { $row[] = $invisibility_span_open . $data[2] . $invisibility_span_close; } $weight = $data[3]; $total_weight += $weight; // Weight $row[] = $invisibility_span_open . $weight . $invisibility_span_close; if ($this->teacherView) { //$weight_total_links += intval($data[3]); } else { $cattotal = Category::load($_GET['selectcat']); $scoretotal = $cattotal[0]->calc_score($this->userId); $item_value = $scoretotal[0]; } // Admins get an edit column. if (api_is_allowed_to_edit(null, true) && isset($_GET['user_id']) == false && (isset($_GET['action']) && $_GET['action'] != 'export_all' || !isset($_GET['action']))) { $cat = new Category(); $show_message = $cat->show_message_resource_delete($item->get_course_code()); if ($show_message === false) { if ($this->exportToPdf == false) { $row[] = $this->build_edit_column($item); } } } else { // Students get the results and certificates columns $eval_n_links = array_merge($alleval, $alllink); if (count($eval_n_links) > 0) { $value_data = isset($data[4]) ? $data[4] : null; if (!is_null($value_data)) { //$score = $item->calc_score(api_get_user_id()); //$new_score = $data[3] * $score[0] / $score[1]; //$new_score = floatval(number_format($new_score, api_get_setting('gradebook_number_decimals'))); // Result $row[] = $value_data; $best = isset($data['best']) ? $data['best'] : null; $average = isset($data['average']) ? $data['average'] : null; $ranking = isset($data['ranking']) ? $data['ranking'] : null; // Ranking $row[] = $ranking; // Best $row[] = $best; // Average $row[] = $average; } } if (!empty($cats)) { if ($this->exportToPdf == false) { $row[] = null; } } } if ($this->exportToPdf == false) { $row['child_of'] = $parent_id; } $sortable_data[] = $row; } // "Warning row" if (!empty($data_array)) { if ($this->teacherView) { // Compare the category weight to the sum of all weights inside the category if (intval($total_weight) == $category_weight) { $label = null; $total = GradebookUtils::score_badges(array($total_weight . ' / ' . $category_weight, '100')); } else { $label = Display::return_icon('warning.png', sprintf(get_lang('TotalWeightMustBeX'), $category_weight)); $total = Display::badge($total_weight . ' / ' . $category_weight, 'warning'); } $row = array(null, null, " <h5>" . get_lang('SubTotal') . '</h5>', null, $total . ' ' . $label, 'child_of' => $parent_id); $sortable_data[] = $row; } } } } } } //end looping categories $main_weight = 0; if (count($main_cat) > 1) { /** @var Category $myCat */ foreach ($main_cat as $myCat) { $myParentId = $myCat->get_parent_id(); if ($myParentId == 0) { $main_weight = intval($myCat->get_weight()); } } } if ($this->teacherView) { // Total for teacher. if (count($main_cat) > 1) { if (intval($total_categories_weight) == $main_weight) { $total = GradebookUtils::score_badges(array($total_categories_weight . ' / ' . $main_weight, '100')); } else { $total = Display::badge($total_categories_weight . ' / ' . $main_weight, 'warning'); } $row = array(null, null, '<strong>' . get_lang('Total') . '</strong>', null, $total); $sortable_data[] = $row; } } else { // Total for student. if (count($main_cat) > 1) { $main_weight = intval($main_cat[0]->get_weight()); $global = null; $average = null; // Overwrite main weight $totalResult[1] = $main_weight; $totalResult = $scoredisplay->display_score($totalResult, SCORE_DIV); $totalRanking = array(); $invalidateRanking = true; $average = 0; foreach ($this->studentList as $student) { $score = $main_cat[0]->calc_score($student['user_id']); if (!empty($score[0])) { $invalidateRanking = false; } $totalRanking[$student['user_id']] = $score[0]; $average += $score[0]; } $totalRanking = AbstractLink::getCurrentUserRanking($user_id, $totalRanking); $totalRanking = $scoredisplay->display_score($totalRanking, SCORE_DIV, SCORE_BOTH, true); if ($invalidateRanking) { $totalRanking = null; } // Overwrite main weight $totalBest[1] = $main_weight; $totalBest = $scoredisplay->display_score($totalBest, SCORE_DIV, SCORE_BOTH, true); // Overwrite main weight $totalAverage[0] = $average / count($this->studentList); $totalAverage[1] = $main_weight; $totalAverage = $scoredisplay->display_score($totalAverage, SCORE_DIV, SCORE_BOTH, true); if ($this->exportToPdf) { $row = array(null, '<h3>' . get_lang('Total') . '</h3>', $main_weight, $totalResult, $totalRanking, $totalBest, $totalAverage); } else { $row = array(null, '<h3>' . get_lang('Total') . '</h3>', null, $main_weight, $totalResult, $totalRanking, $totalBest, $totalAverage); } $sortable_data[] = $row; } } // Warning messages $view = isset($_GET['view']) ? $_GET['view'] : null; if ($this->teacherView) { if (isset($_GET['selectcat']) && $_GET['selectcat'] > 0 && $view != 'presence') { $id_cat = intval($_GET['selectcat']); $category = Category::load($id_cat); $weight_category = intval($this->build_weight($category[0])); $course_code = $this->build_course_code($category[0]); $weight_total_links = round($weight_total_links); if ($weight_total_links > $weight_category || $weight_total_links < $weight_category || $weight_total_links > $weight_category) { $warning_message = sprintf(get_lang('TotalWeightMustBeX'), $weight_category); $modify_icons = '<a href="gradebook_edit_cat.php?editcat=' . $id_cat . '&cidReq=' . $course_code . '&id_session=' . api_get_session_id() . '">' . Display::return_icon('edit.png', $warning_message, array(), ICON_SIZE_SMALL) . '</a>'; $warning_message .= $modify_icons; Display::display_warning_message($warning_message, false); } $content_html = DocumentManager::replace_user_info_into_html(api_get_user_id(), $course_code); if (!empty($content_html)) { $new_content = explode('</head>', $content_html['content']); } if (empty($new_content[0])) { // Set default certificate $courseData = api_get_course_info($course_code); DocumentManager::generateDefaultCertificate($courseData); } } if (empty($_GET['selectcat'])) { $categories = Category::load(); $weight_categories = $certificate_min_scores = $course_codes = array(); foreach ($categories as $category) { $course_code_category = $this->build_course_code($category); if (!empty($course_code)) { if ($course_code_category == $course_code) { $weight_categories[] = intval($this->build_weight($category)); $certificate_min_scores[] = intval($this->build_certificate_min_score($category)); $course_codes[] = $course_code; break; } } else { $weight_categories[] = intval($this->build_weight($category)); $certificate_min_scores[] = intval($this->build_certificate_min_score($category)); $course_codes[] = $course_code_category; } } if (is_array($weight_categories) && is_array($certificate_min_scores) && is_array($course_codes)) { $warning_message = ''; for ($x = 0; $x < count($weight_categories); $x++) { $weight_category = intval($weight_categories[$x]); $certificate_min_score = intval($certificate_min_scores[$x]); $course_code = $course_codes[$x]; if (empty($certificate_min_score) || $certificate_min_score > $weight_category) { $warning_message .= $course_code . ' - ' . get_lang('CertificateMinimunScoreIsRequiredAndMustNotBeMoreThan') . ' ' . $weight_category . '<br />'; } } if (!empty($warning_message)) { Display::display_warning_message($warning_message, false); } } } } return $sortable_data; }
/** * @param int $stud_id * @param string $type * * @return array|null */ public function calc_score($stud_id = null, $type = null) { require_once api_get_path(SYS_CODE_PATH) . 'forum/forumfunction.inc.php'; $threadInfo = get_thread_information($this->get_ref_id()); $thread_qualify = Database::get_course_table(TABLE_FORUM_THREAD_QUALIFY); $sql = 'SELECT thread_qualify_max FROM ' . Database::get_course_table(TABLE_FORUM_THREAD) . "\n \t\t\t\tWHERE c_id = " . $this->course_id . " AND thread_id = '" . $this->get_ref_id() . "'"; $query = Database::query($sql); $assignment = Database::fetch_array($query); $sql = "SELECT * FROM {$thread_qualify}\n\t\t\t\tWHERE c_id = " . $this->course_id . " AND thread_id = " . $this->get_ref_id(); if (isset($stud_id)) { $sql .= ' AND user_id = ' . intval($stud_id); } // order by id, that way the student's first attempt is accessed first $sql .= ' ORDER BY qualify_time DESC'; $scores = Database::query($sql); // for 1 student if (isset($stud_id)) { if ($threadInfo['thread_peer_qualify'] == 0) { // Classic way of calculate score if ($data = Database::fetch_array($scores)) { return array($data['qualify'], $assignment['thread_qualify_max']); } else { // We sent the 0/thread_qualify_max instead of null for correct calculations return array(0, $assignment['thread_qualify_max']); } } else { // Take average $score = 0; $counter = 0; if (Database::num_rows($scores)) { while ($data = Database::fetch_array($scores, 'ASSOC')) { $score += $data['qualify']; $counter++; } } // If no result if (empty($counter) || $counter <= 2) { return array(0, $assignment['thread_qualify_max']); } return [$score / $counter, $assignment['thread_qualify_max']]; } } else { // All students -> get average $students = array(); // user list, needed to make sure we only // take first attempts into account $counter = 0; $sum = 0; $bestResult = 0; $weight = 0; $sumResult = 0; while ($data = Database::fetch_array($scores)) { if (!array_key_exists($data['user_id'], $students)) { if ($assignment['thread_qualify_max'] != 0) { $students[$data['user_id']] = $data['qualify']; $counter++; $sum += $data['qualify'] / $assignment['thread_qualify_max']; $sumResult += $data['qualify']; if ($data['qualify'] > $bestResult) { $bestResult = $data['qualify']; } $weight = $assignment['thread_qualify_max']; } } } if ($counter == 0) { return null; } else { switch ($type) { case 'best': return array($bestResult, $weight); break; case 'average': return array($sumResult / $counter, $weight); break; case 'ranking': return AbstractLink::getCurrentUserRanking($stud_id, $students); break; default: return array($sum, $counter); break; } } } }
/** * @param int $stud_id * @return array|null */ public function calc_score($stud_id = null, $type = null) { $tbl_attendance_result = Database::get_course_table(TABLE_ATTENDANCE_RESULT); $session_id = api_get_session_id(); // get attendance qualify max $sql = 'SELECT att.attendance_qualify_max FROM ' . $this->get_attendance_table() . ' att WHERE att.c_id = ' . $this->course_id . ' AND att.id = ' . intval($this->get_ref_id()) . ' AND att.session_id=' . intval($session_id) . ''; $query = Database::query($sql); $attendance = Database::fetch_array($query, 'ASSOC'); // Get results $sql = 'SELECT * FROM ' . $tbl_attendance_result . ' WHERE c_id = ' . $this->course_id . ' AND attendance_id = ' . intval($this->get_ref_id()); if (isset($stud_id)) { $sql .= ' AND user_id = ' . intval($stud_id); } $scores = Database::query($sql); // for 1 student if (isset($stud_id)) { if ($data = Database::fetch_array($scores, 'ASSOC')) { return array($data['score'], $attendance['attendance_qualify_max']); } else { //We sent the 0/attendance_qualify_max instead of null for correct calculations return array(0, $attendance['attendance_qualify_max']); } } else { // all students -> get average $students = array(); // user list, needed to make sure we only // take first attempts into account $rescount = 0; $sum = 0; $sumResult = 0; $bestResult = 0; while ($data = Database::fetch_array($scores)) { if (!array_key_exists($data['user_id'], $students)) { if ($attendance['attendance_qualify_max'] != 0) { $students[$data['user_id']] = $data['score']; $rescount++; $sum += $data['score'] / $attendance['attendance_qualify_max']; $sumResult += $data['score']; if ($data['score'] > $bestResult) { $bestResult = $data['score']; } $weight = $attendance['attendance_qualify_max']; } } } if ($rescount == 0) { return null; } else { switch ($type) { case 'best': return array($bestResult, $weight); break; case 'average': return array($sumResult / $rescount, $weight); break; case 'ranking': return AbstractLink::getCurrentUserRanking($stud_id, $students); break; default: return array($sum, $rescount); break; } } } }
public function __construct($id, $name = '') { parent::__construct($id); $this->name = $name; }
$parent_cat = Category::load($parent_id); $my_category = array(); $cat = new Category(); $my_category = $cat->shows_all_information_an_category($my_selectcat); $original_total = $my_category['weight']; $masked_total = $parent_cat[0]->get_weight(); $sql = 'SELECT * FROM ' . $table_link . ' WHERE category_id = ' . $my_selectcat; $result = Database::query($sql); while ($row = Database::fetch_array($result)) { $item_weight = $row['weight']; //$item_weight = $masked_total*$item_weight/$original_total; //update only if value changed if (isset($_POST['link'][$row['id']])) { //$new_weight = trim($_POST['link'][$row['id']]*$original_total/$masked_total); $new_weight = trim($_POST['link'][$row['id']]); AbstractLink::add_link_log($row['id']); Database::query('UPDATE ' . $table_link . ' SET weight = ' . "'" . Database::escape_string($new_weight) . "'" . ' WHERE id = ' . $row['id']); $item_weight = trim($_POST['link'][$row['id']]); //Update weight for attendance $sql = 'SELECT ref_id FROM ' . $table_link . ' WHERE id = ' . intval($row['id']) . ' AND type=' . LINK_ATTENDANCE; $rs_attendance = Database::query($sql); if (Database::num_rows($rs_attendance) > 0) { $row_attendance = Database::fetch_array($rs_attendance); $upd_attendance = 'UPDATE ' . $tbl_attendance . ' SET attendance_weight =' . floatval($_POST['link'][$row['id']]) . ' WHERE c_id = ' . $course_id . ' AND id = ' . intval($row_attendance['ref_id']); Database::query($upd_attendance); } //Update weight into forum thread $sql_t = 'UPDATE ' . $tbl_forum_thread . ' SET thread_weight=' . floatval($_POST['link'][$row['id']]) . ' WHERE c_id = ' . $course_id . ' AND thread_id = (SELECT ref_id FROM ' . $table_link . ' WHERE id=' . intval($row['id']) . ' AND type=' . LINK_FORUM_THREAD . ' ) '; Database::query($sql_t);
/** * @param int $idevaluation */ public static function add_link_log($idevaluation, $nameLog = null) { $table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINKEVAL_LOG); $dateobject = AbstractLink::load($idevaluation, null, null, null, null); $current_date_server = api_get_utc_datetime(); $arreval = get_object_vars($dateobject[0]); $description_log = isset($arreval['description']) ? $arreval['description'] : ''; if (empty($nameLog)) { if (isset($_POST['name_link'])) { $name_log = isset($_POST['name_link']) ? $_POST['name_link'] : $arreval['course_code']; } elseif (isset($_POST['link_' . $idevaluation]) && $_POST['link_' . $idevaluation]) { $name_log = $_POST['link_' . $idevaluation]; } else { $name_log = $arreval['course_code']; } } else { $name_log = $nameLog; } $params = ['id_linkeval_log' => $arreval['id'], 'name' => $name_log, 'description' => $description_log, 'created_at' => $current_date_server, 'weight' => $arreval['weight'], 'visible' => $arreval['visible'], 'type' => 'Link', 'user_id_log' => api_get_user_id()]; Database::insert($table, $params); }
/** * Find links by name * @param string $name_mask search string * @return array link objects matching the search criterium */ public function find_links($name_mask, $selectcat) { return AbstractLink::find_links($name_mask, $selectcat); }
/** * Get the progress of this learnpath. Only the last attempt are taken into account. * @param $stud_id student id (default: all students who have results - then the average is returned) * @return array (score, max) if student is given * array (sum of scores, number of scores) otherwise * or null if no scores available */ public function calc_score($stud_id = null, $type = null) { $tbl_stats = Database::get_course_table(TABLE_LP_VIEW); $session_id = api_get_session_id(); $sql = "SELECT * FROM {$tbl_stats}\n WHERE\n \tc_id = " . $this->course_id . " AND\n lp_id = " . $this->get_ref_id() . " AND\n session_id = {$session_id} "; if (isset($stud_id)) { $sql .= ' AND user_id = ' . intval($stud_id); } // order by id, that way the student's first attempt is accessed first $sql .= ' ORDER BY view_count DESC'; $scores = Database::query($sql); // for 1 student if (isset($stud_id)) { if ($data = Database::fetch_array($scores)) { return array($data['progress'], 100); } else { return null; } } else { // all students -> get average $students = array(); // user list, needed to make sure we only // take first attempts into account $rescount = 0; $sum = 0; $bestResult = 0; $sumResult = 0; while ($data = Database::fetch_array($scores)) { if (!array_key_exists($data['user_id'], $students)) { $students[$data['user_id']] = $data['progress']; $rescount++; $sum += $data['progress'] / 100; $sumResult += $data['progress']; if ($data['progress'] > $bestResult) { $bestResult = $data['progress']; } } } if ($rescount == 0) { return null; } else { switch ($type) { case 'best': return array($bestResult, 100); break; case 'average': return array($sumResult / $rescount, 100); break; case 'ranking': return AbstractLink::getCurrentUserRanking($stud_id, $students); break; default: return array($sum, $rescount); break; } } } }
/** * Calculate the score of this evaluation * @param int $stud_id (default: all students who have results for this eval - then the average is returned) * @param string $type (best, average, ranking) * @return array (score, max) if student is given * array (sum of scores, number of scores) otherwise * or null if no scores available */ public function calc_score($stud_id = null, $type = null) { $useSession = true; if (isset($stud_id) && empty($type)) { $key = 'result_score_student_list_' . api_get_course_int_id() . '_' . api_get_session_id() . '_' . $this->id . '_' . $stud_id; $data = Session::read('calc_score'); $results = isset($data[$key]) ? $data[$key] : null; if ($useSession == false) { $results = null; } if (empty($results)) { $results = Result::load(null, $stud_id, $this->id); Session::write('calc_score', array($key => $results)); } $score = 0; /** @var Result $res */ foreach ($results as $res) { $score = $res->get_score(); } return array($score, $this->get_max()); } else { $count = 0; $sum = 0; $bestResult = 0; $weight = 0; $sumResult = 0; $key = 'result_score_student_list_' . api_get_course_int_id() . '_' . api_get_session_id() . '_' . $this->id; $data = Session::read('calc_score'); $allResults = isset($data[$key]) ? $data[$key] : null; if ($useSession == false) { $allResults = null; } if (empty($allResults)) { $allResults = Result::load(null, null, $this->id); Session::write($key, $allResults); } $students = array(); /** @var Result $res */ foreach ($allResults as $res) { $score = $res->get_score(); if (!empty($score) || $score == '0') { $count++; $sum += $score / $this->get_max(); $sumResult += $score; if ($score > $bestResult) { $bestResult = $score; } $weight = $this->get_max(); } $students[$res->get_user_id()] = $score; } if (empty($count)) { return null; } switch ($type) { case 'best': return array($bestResult, $weight); break; case 'average': return array($sumResult / $count, $weight); break; case 'ranking': $students = array(); /** @var Result $res */ foreach ($allResults as $res) { $score = $res->get_score(); $students[$res->get_user_id()] = $score; } return AbstractLink::getCurrentUserRanking($stud_id, $students); break; default: return array($sum, $count); break; } } }
/** * Get the score of this exercise. Only the first attempts are taken into account. * @param int $stud_id student id (default: all students who have results - * then the average is returned) * @return array (score, max) if student is given * array (sum of scores, number of scores) otherwise * or null if no scores available */ public function calc_score($stud_id = null, $type = null) { $tblStats = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES); $tblHp = Database::get_main_table(TABLE_STATISTIC_TRACK_E_HOTPOTATOES); $tblDoc = Database::get_course_table(TABLE_DOCUMENT); /* the following query should be similar (in conditions) to the one used in exercice/exercice.php, look for note-query-exe-results marker*/ $session_id = $this->get_session_id(); $courseId = $this->getCourseId(); $exercise = new Exercise($courseId); $exercise->read($this->get_ref_id()); if (!$this->is_hp) { if ($exercise->exercise_was_added_in_lp == false) { $sql = "SELECT * FROM {$tblStats}\n\t\t\t WHERE\n\t\t\t exe_exo_id = " . intval($this->get_ref_id()) . " AND\n\t\t\t orig_lp_id = 0 AND\n\t\t\t orig_lp_item_id = 0 AND\n\t\t\t status <> 'incomplete' AND\n\t\t\t session_id = {$session_id} AND\n c_id = {$courseId}\n "; } else { $lpId = null; if (!empty($exercise->lpList)) { // Taking only the first LP $lpId = current($exercise->lpList); $lpId = $lpId['lp_id']; } $sql = "SELECT * FROM {$tblStats}\n\t\t WHERE\n\t\t exe_exo_id = " . intval($this->get_ref_id()) . " AND\n\t\t orig_lp_id = {$lpId} AND\n\t\t status <> 'incomplete' AND\n\t\t session_id = {$session_id} AND\n c_id = {$courseId}\n "; } if (!empty($stud_id) && $type != 'ranking') { $sql .= " AND exe_user_id = {$stud_id} "; } $sql .= ' ORDER BY exe_id DESC'; } else { $sql = "SELECT * FROM {$tblHp} hp, {$tblDoc} doc\n WHERE\n hp.c_id = {$courseId} AND\n hp.exe_user_id = {$stud_id} AND\n hp.exe_name = doc.path AND\n doc.c_id = hp.c_id AND\n doc.id = " . intval($this->get_ref_id()); } $scores = Database::query($sql); if (isset($stud_id) && empty($type)) { // for 1 student if ($data = Database::fetch_array($scores)) { return array($data['exe_result'], $data['exe_weighting']); } else { return null; } } else { // all students -> get average // normal way of getting the info $students = array(); // user list, needed to make sure we only // take first attempts into account $student_count = 0; $sum = 0; $bestResult = 0; $weight = 0; $sumResult = 0; while ($data = Database::fetch_array($scores, 'ASSOC')) { if (!isset($students[$data['exe_user_id']])) { if ($data['exe_weighting'] != 0) { $students[$data['exe_user_id']] = $data['exe_result']; $student_count++; if ($data['exe_result'] > $bestResult) { $bestResult = $data['exe_result']; } $sum += $data['exe_result'] / $data['exe_weighting']; $sumResult += $data['exe_result']; $weight = $data['exe_weighting']; } } } if ($student_count == 0) { return null; } else { switch ($type) { case 'best': return array($bestResult, $weight); break; case 'average': $count = count($this->getStudentList()); if (empty($count)) { return array(0, $weight); } return array($sumResult / $count, $weight); break; case 'ranking': return AbstractLink::getCurrentUserRanking($stud_id, $students); break; default: return array($sum, $student_count); break; } } } }
function __construct() { parent::__construct(); $this->set_type(LINK_LEARNPATH); }
/** * @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()]); } }