'; if (isset($_POST['evaluation'])) { $eval_log = new Evaluation(); } } $output = ''; $my_cat = Category::load($my_selectcat); $my_cat = $my_cat[0]; $parent_id = $my_cat->get_parent_id(); $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->getWeight(); $masked_total = $parent_cat[0]->get_weight(); $links = $em ->getRepository('ChamiloCoreBundle:GradebookLink') ->findBy([ 'categoryId' => $my_selectcat ]); $linksInfo = []; foreach ($links as $row) { $item_weight = $row->getWeight(); $sql = 'SELECT * FROM '.GradebookUtils::get_table_type_course($row->getType()).' WHERE c_id = '.$course_id.' AND '.$table_evaluated[$row->getType()][2].' = '.$row->getRefId(); $result = Database::query($sql); $resource_name = Database::fetch_array($result); if (isset($resource_name['lp_type'])) { $resource_name = $resource_name[4]; } else { $resource_name = $resource_name[3]; } $linksInfo[] = [ 'id' => $row->getId(), 'resource_name' => $resource_name ]; // Update only if value changed if (isset($_POST['link'][$row->getId()])) { $new_weight = trim($_POST['link'][$row->getId()]); GradebookUtils::updateLinkWeight( $row->getId(), $resource_name, $new_weight ); $item_weight = $new_weight; } $output .= ''.GradebookUtils::build_type_icon_tag($row->getType()).' '.$resource_name.' '.Display::label( $table_evaluated[$row->getType()][3], 'info' ).' '; $output .= ' '; } $evaluations = $em ->getRepository('ChamiloCoreBundle:GradebookEvaluation') ->findBy([ 'categoryId' => $my_selectcat ]); foreach ($evaluations as $evaluationRow) { $item_weight = $evaluationRow->getWeight(); // update only if value changed if (isset($_POST['evaluation'][$evaluationRow->getId()])) { $new_weight = trim($_POST['evaluation'][$evaluationRow->getId()]); GradebookUtils::updateEvaluationWeight( $evaluationRow->getId(), $new_weight ); $item_weight = $new_weight; } $output .= ' '.GradebookUtils::build_type_icon_tag('evalnotempty').' '.$evaluationRow->getName().' '.Display::label( get_lang('Evaluation') ).''; $output .= ' '; } $my_api_cidreq = api_get_cidreq(); if ($my_api_cidreq == '') { $my_api_cidreq = 'cidReq='.$my_category->getCourse()->getCode(); } $currentUrl = api_get_self().'?'.api_get_cidreq().'&selectcat='.$my_selectcat; $form = new FormValidator('auto_weight', 'post', $currentUrl); $form->addHeader(get_lang('AutoWeight')); $form->addLabel(null, get_lang('AutoWeightExplanation')); $form->addButtonUpdate(get_lang('AutoWeight')); if ($form->validate()) { $itemCount = count($links) + count($evaluations); $weight = 0; if ($itemCount > 0) { $weight = round($original_total / $itemCount, 2); } $total = $weight * $itemCount; $diff = null; if ($original_total !== $total) { if ($total > $original_total) { $diff = $total - $original_total; } } $total = 0; $diffApplied = false; foreach ($linksInfo as $link) { $weightToApply = $weight; if ($diffApplied == false) { if (!empty($diff)) { $weightToApply = $weight - $diff; $diffApplied = true; } } GradebookUtils::updateLinkWeight( $link['id'], $link['resource_name'], $weightToApply ); } foreach ($evaluations as $evaluation) { $weightToApply = $weight; if ($diffApplied == false) { if (!empty($diff)) { $weightToApply = $weight - $diff; $diffApplied = true; } } GradebookUtils::updateEvaluationWeight( $evaluation['id'], $weightToApply ); } header('Location:'.$currentUrl); exit; } // DISPLAY HEADERS AND MESSAGES if (!isset($_GET['exportpdf']) and !isset($_GET['export_certificate'])) { if (isset ($_GET['studentoverview'])) { $interbreadcrumb[] = array( 'url' => Security::remove_XSS( $_SESSION['gradebook_dest'] ).'?selectcat='.$my_selectcat, 'name' => get_lang('Gradebook'), ); Display:: display_header(get_lang('FlatView')); } elseif (isset ($_GET['search'])) { $interbreadcrumb[] = array( 'url' => Security::remove_XSS( $_SESSION['gradebook_dest'] ).'?selectcat='.$my_selectcat, 'name' => get_lang('Gradebook'), ); Display:: display_header(get_lang('SearchResults')); } else { $interbreadcrumb[] = array( 'url' => Security::remove_XSS( $_SESSION['gradebook_dest'] ).'?selectcat=1', 'name' => get_lang('Gradebook'), ); $interbreadcrumb[] = array( 'url' => '#', 'name' => get_lang('EditAllWeights'), ); Display:: display_header(''); } } ?>
display(); $formNormal = new FormValidator('normal_weight', 'post', $currentUrl); $formNormal->addHeader(get_lang('EditWeight')); $formNormal->display(); $warning_message = sprintf(get_lang('TotalWeightMustBeX'), $original_total); Display::display_warning_message($warning_message, false); ?>