/**
  * Lazy load function to get the linked evaluation
  */
 protected function get_evaluation()
 {
     if (!isset($this->evaluation)) {
         if (isset($this->ref_id)) {
             $evalarray = Evaluation::load($this->get_ref_id());
             $this->evaluation = $evalarray[0];
         } else {
             $eval = new Evaluation();
             $eval->set_category_id(-1);
             $eval->set_date(api_get_utc_datetime());
             // these values will be changed
             $eval->set_weight(0);
             //   when the link setter
             $eval->set_visible(0);
             //     is called
             $eval->set_id(-1);
             // a 'real' id will be set when eval is added to db
             $eval->set_user_id($this->get_user_id());
             $eval->set_course_code($this->get_course_code());
             $this->evaluation = $eval;
             $this->set_ref_id($eval->get_id());
         }
     }
     return $this->evaluation;
 }
 /**
  * @param array $result
  * @return array
  */
 private static function create_evaluation_objects_from_sql_result($result)
 {
     $alleval = array();
     if (Database::num_rows($result)) {
         while ($data = Database::fetch_array($result)) {
             $eval = new Evaluation();
             $eval->set_id($data['id']);
             $eval->set_name($data['name']);
             $eval->set_description($data['description']);
             $eval->set_user_id($data['user_id']);
             $eval->set_course_code($data['course_code']);
             $eval->set_category_id($data['category_id']);
             $eval->set_date(api_get_local_time($data['created_at']));
             $eval->set_weight($data['weight']);
             $eval->set_max($data['max']);
             $eval->set_visible($data['visible']);
             $eval->set_type($data['type']);
             $eval->set_locked($data['locked']);
             $eval->setSessionId(api_get_session_id());
             $alleval[] = $eval;
         }
     }
     return $alleval;
 }
/**
 * Script
 * @package chamilo.gradebook
 */
require_once '../inc/global.inc.php';
api_block_anonymous_users();
GradebookUtils::block_students();
$evaledit = Evaluation::load($_GET['editeval']);
if ($evaledit[0]->is_locked() && !api_is_platform_admin()) {
    api_not_allowed();
}
$form = new EvalForm(EvalForm::TYPE_EDIT, $evaledit[0], null, 'edit_eval_form', null, api_get_self() . '?editeval=' . Security::remove_XSS($_GET['editeval']));
if ($form->validate()) {
    $values = $form->exportValues();
    $eval = new Evaluation();
    $eval->set_id($values['hid_id']);
    $eval->set_name($values['name']);
    $eval->set_description($values['description']);
    $eval->set_user_id($values['hid_user_id']);
    $eval->set_course_code($values['hid_course_code']);
    $eval->set_category_id($values['hid_category_id']);
    $parent_cat = Category::load($values['hid_category_id']);
    $final_weight = $values['weight_mask'];
    $eval->set_weight($final_weight);
    $eval->set_max($values['max']);
    if (empty($values['visible'])) {
        $visible = 0;
    } else {
        $visible = 1;
    }
    $eval->set_visible($visible);