Example #1
0
	} else {
	    return false;
	}
}
</script>';
$filter_confirm_msg = true;
$filter_warning_msg = true;
// ACTIONS
//this is called when there is no data for the course admin
if (isset($_GET['createallcategories'])) {
    GradebookUtils::block_students();
    $coursecat = Category::get_not_created_course_categories(api_get_user_id());
    if (!count($coursecat) == 0) {
        foreach ($coursecat as $row) {
            $cat = new Category();
            $cat->set_name($row[1]);
            $cat->set_course_code($row[0]);
            $cat->set_description(null);
            $cat->set_user_id(api_get_user_id());
            $cat->set_parent_id(0);
            $cat->set_weight(0);
            $cat->set_visible(0);
            $cat->add();
            unset($cat);
        }
    }
    header('Location: ' . $_SESSION['gradebook_dest'] . '?addallcat=&selectcat=0');
    exit;
}
//move a category
$selectcat = isset($_GET['selectcat']) ? Security::remove_XSS($_GET['selectcat']) : '';
 private static function create_category_objects_from_sql_result($result)
 {
     $allcat = array();
     while ($data = Database::fetch_array($result)) {
         $cat = new Category();
         $cat->set_id($data['id']);
         $cat->set_name($data['name']);
         $cat->set_description($data['description']);
         $cat->set_user_id($data['user_id']);
         $cat->set_course_code($data['course_code']);
         $cat->set_parent_id($data['parent_id']);
         $cat->set_weight($data['weight']);
         $cat->set_visible($data['visible']);
         $cat->set_session_id($data['session_id']);
         $cat->set_certificate_min_score($data['certif_min_score']);
         $cat->set_grade_model_id($data['grade_model_id']);
         $cat->set_locked($data['locked']);
         $allcat[] = $cat;
     }
     return $allcat;
 }
Example #3
0
 public static function search($values = array())
 {
     $result1 = DB::getInstance()->search("category", $values);
     if (count($result1) != 0) {
         $category_data = array("cat_name" => $result1[0]["category_name"], "cat_label" => $result1[0]["category_no"]);
         $new_category = new Category();
         $new_category->set_name($result1[0]["category_name"]);
         $new_category->set_label($result1[0]["category_no"]);
         $itemList = DB::getInstance()->search("item_category", array("category_id" => $result1[0]["category_id"]));
         foreach ($itemList as $item) {
             $new_category->addItem(Item::search(array("item_id" => $item["item_id"])));
         }
         return $new_category;
     } else {
         return null;
     }
 }
 /**
  * @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();
         $t = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
         $sql = "SELECT * FROM {$t} WHERE course_code = '" . Database::escape_string($course_code) . "' ";
         if (!empty($session_id)) {
             $sql .= " AND session_id = " . (int) $session_id;
         } else {
             $sql .= " AND (session_id IS NULL OR session_id = 0) ";
         }
         $sql .= " ORDER BY id";
         $res = Database::query($sql);
         if (Database::num_rows($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_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 = Database::fetch_array($res);
             $category_id = $row['id'];
         }
     }
     return $category_id;
 }
<?php

/* For licensing terms, see /license.txt */
/**
 * Script
 * @package chamilo.gradebook
 */
//require_once '../inc/global.inc.php';
$current_course_tool = TOOL_GRADEBOOK;
api_protect_course_script(true);
api_block_anonymous_users();
GradebookUtils::block_students();
$catadd = new Category();
$catadd->set_user_id(api_get_user_id());
$catadd->set_parent_id($_GET['selectcat']);
$catcourse = Category::load($_GET['selectcat']);
$form = new CatForm(CatForm::TYPE_SELECT_COURSE, $catadd, 'add_cat_form', null, api_get_self() . '?selectcat=' . Security::remove_XSS($_GET['selectcat']) . '&' . api_get_cidreq());
if ($form->validate()) {
    $values = $form->exportValues();
    $cat = new Category();
    $cat->set_course_code($values['select_course']);
    $cat->set_name($values['name']);
    header('location: gradebook_add_link.php?selectcat=' . Security::remove_XSS($_GET['selectcat']) . '&course_code=' . Security::remove_XSS($values['select_course']) . '&' . api_get_cidreq());
    exit;
}
$interbreadcrumb[] = array('url' => Security::remove_XSS($_SESSION['gradebook_dest']) . '?selectcat=' . Security::remove_XSS($_GET['selectcat']) . '&' . api_get_cidreq(), 'name' => get_lang('Gradebook'));
Display::display_header(get_lang('NewCategory'));
$form->display();
Display::display_footer();
Example #6
0
 // When *inside* a course, we want to make sure there is one (and only
 // one) category for this course or for this session.
 //hack for delete a gradebook from inside course
 /*
         $clean_deletecat = isset($_GET['deletecat']) ? intval($_GET['deletecat']) : null;
         if (!empty($clean_deletecat)) {
             exit;
         }
         //end hack*/
 $cats = Category::load(null, null, $course_code, null, null, $session_id, false);
 if (empty($cats)) {
     // There is no category for this course+session, so create one
     $cat = new Category();
     if (!empty($session_id)) {
         $s_name = api_get_session_name($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($stud_id);
     $cat->set_parent_id(0);
     $cat->set_weight(100);
     $cat->set_visible(0);
     $cat->set_certificate_min_score(75);
     $can_edit = api_is_allowed_to_edit(true, true);
     if ($can_edit) {
         $cat->add();
     }
 /**
  * Create a category object from a GradebookCategory entity
  * @param Chamilo\CoreBundle\Entity\GradebookCategory $gradebookCategory
  *         The entity
  * @return \Category
  */
 public static function createCategoryObjectFromEntity(Chamilo\CoreBundle\Entity\GradebookCategory $gradebookCategory)
 {
     $category = new Category();
     $category->set_id($gradebookCategory->getId());
     $category->set_name($gradebookCategory->getName());
     $category->set_description($gradebookCategory->getDescription());
     $category->set_user_id($gradebookCategory->getUserId());
     $category->set_course_code($gradebookCategory->getCourseCode());
     $category->set_parent_id($gradebookCategory->getParentId());
     $category->set_weight($gradebookCategory->getWeight());
     $category->set_visible($gradebookCategory->getVisible());
     $category->set_session_id($gradebookCategory->getSessionId());
     $category->set_certificate_min_score($gradebookCategory->getCertifMinScore());
     $category->set_grade_model_id($gradebookCategory->getGradeModelId());
     $category->set_locked($gradebookCategory->getLocked());
     $category->setGenerateCertificates($gradebookCategory->getGenerateCertificates());
     $category->setIsRequirement($gradebookCategory->getIsRequirement());
     return $category;
 }
 /**
  * @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;
 }