Exemplo n.º 1
0
 /**
  * @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;
 }
Exemplo n.º 2
0
} else {
    $evaladd->set_category_id(0);
}
$form = new EvalForm(EvalForm::TYPE_ADD, $evaladd, null, 'add_eval_form', null, api_get_self() . '?selectcat=' . $select_cat . '&' . api_get_cidreq());
if ($form->validate()) {
    $values = $form->exportValues();
    $eval = new Evaluation();
    $eval->set_name($values['name']);
    $eval->set_description($values['description']);
    $eval->set_user_id($values['hid_user_id']);
    if (!empty($values['hid_course_code'])) {
        $eval->set_course_code($values['hid_course_code']);
    }
    //Always add the gradebook to the course
    $eval->set_course_code(api_get_course_id());
    $eval->set_category_id($values['hid_category_id']);
    $parent_cat = Category::load($values['hid_category_id']);
    $global_weight = $cat[0]->get_weight();
    //$values['weight'] = $values['weight_mask']/$global_weight*$parent_cat[0]->get_weight();
    $values['weight'] = $values['weight_mask'];
    $eval->set_weight($values['weight']);
    $eval->set_max($values['max']);
    if (empty($values['visible'])) {
        $visible = 0;
    } else {
        $visible = 1;
    }
    $eval->set_visible($visible);
    $eval->add();
    if ($eval->get_course_code() == null) {
        if ($values['adduser'] == 1) {
 static function add_gradebook_result_with_evaluation($data)
 {
     error_log('add_gradebook_result_with_evaluation');
     $session_id = isset($data['session_id']) ? $data['session_id'] : null;
     $user_id = isset($data['user_id']) ? $data['user_id'] : null;
     //Default evaluation title
     $title = 'Evaluación General';
     if (!empty($session_id) && !empty($user_id)) {
         global $data_list, $utc_datetime;
         //$course_list = SessionManager::get_course_list_by_session_id($session_id);
         $course_list = array(0 => array('code' => $data_list['session_course'][$session_id]));
         if (!empty($course_list)) {
             $course_data = current($course_list);
             if (isset($course_data['code'])) {
                 $gradebook = array('id' => $data_list['session_course_gradebook'][$course_data['code']][$session_id]);
                 //Get gradebook
                 //$gradebook = new Gradebook();
                 //$gradebook = $gradebook->get_first(array('where' => array('course_code = ? AND session_id = ?' => array($course_data['code'], $session_id))));
                 //error_log("Looking gradebook in course code:  {$course_data['code']} - session_id: $session_id, user_id: $user_id");
                 if (!empty($gradebook)) {
                     error_log("Gradebook exists: {$gradebook['id']}");
                     //Creates
                     $eval = new Evaluation();
                     $evals_found = false;
                     if (isset($data_list['course_evals'][$course_data['code']][$gradebook['id']][$title])) {
                         $evals_found = $data_list['course_evals'][$course_data['code']][$gradebook['id']][$title];
                     }
                     if (empty($evals_found)) {
                         $eval->set_name($title);
                         //$eval->set_evaluation_type_id($data['gradebook_evaluation_type_id']);
                         $eval->set_user_id(self::default_admin_id);
                         $eval->set_course_code($course_data['code']);
                         $eval->set_category_id($gradebook['id']);
                         //harcoded values
                         $eval->set_weight(100);
                         $eval->set_max(100);
                         //score of tinNota is over 100
                         $eval->set_visible(1);
                         $eval->add();
                         $eval_id = $eval->get_id();
                         $data_list['course_evals'][$course_data['code']][$gradebook['id']][$title] = $eval_id;
                     } else {
                         $eval_id = $evals_found;
                     }
                     if ($eval_id) {
                         //Check if already exists
                         //$check_result = Result :: load (null, $user_id, $eval_id);
                         $check_result = $data_list['course_eval_results'][$eval_id][$user_id];
                         if (empty($check_result)) {
                             //$res = new Result();
                             //$res->set_evaluation_id($eval_id);
                             //$res->set_user_id($user_id);
                             ////if no scores are given, don't set the score
                             //$res->set_score($data['nota']);
                             //$res_id = $res->add();
                             $eval_data = array('user_id' => $user_id, 'evaluation_id' => $eval_id, 'created_at' => $utc_datetime, 'score' => $data['nota']);
                             $data_list['course_eval_results'][$eval_id][$user_id] = $res_id;
                             $limit = $data_list['create_eval_results_limit'];
                             if (count($data_list['create_eval_results']) > $limit) {
                                 $data_list['create_eval_results'][] = $eval_data;
                                 $res = new Result();
                                 $res->group_add($data_list['create_eval_results']);
                                 $data_list['create_eval_results'] = array();
                             } else {
                                 $data_list['create_eval_results'][] = $eval_data;
                             }
                         } else {
                             error_log("Result already added ");
                         }
                     } else {
                         error_log("Evaluation not detected");
                     }
                 } else {
                     error_log("Gradebook does not exists");
                 }
             } else {
                 error_log("Something is wrong with the course ");
             }
         } else {
             error_log("NO course found for session id: {$session_id}");
         }
     } else {
         error_log("NO session id found: {$session_id}");
     }
 }
Exemplo n.º 4
0
 /**
  * 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;
 }
Exemplo n.º 5
0
 /**
  * Creates a course
  * @param   array   with the columns in the main.course table
  * @param   mixed   false if the course was not created, array with the course info
  * @return mixed False on error, or an array with course attributes on success
  * @todo remove globals
  * @assert () === false
  */
 public static function create_course($params)
 {
     global $_configuration;
     // Check portal limits
     $access_url_id = 1;
     if (api_get_multiple_access_url()) {
         $access_url_id = api_get_current_access_url_id();
     }
     if (is_array($_configuration[$access_url_id]) && isset($_configuration[$access_url_id]['hosting_limit_courses']) && $_configuration[$access_url_id]['hosting_limit_courses'] > 0) {
         $num = self::count_courses();
         if ($num >= $_configuration[$access_url_id]['hosting_limit_courses']) {
             return api_set_failure('PortalCoursesLimitReached');
         }
     }
     if (empty($params['title'])) {
         return false;
     }
     if (empty($params['wanted_code'])) {
         $params['wanted_code'] = $params['title'];
         // Check whether the requested course code has already been occupied.
         $params['wanted_code'] = self::generate_course_code(api_substr($params['title'], 0, self::MAX_COURSE_LENGTH_CODE));
     }
     // Create the course keys
     $keys = self::define_course_keys($params['wanted_code']);
     $params['exemplary_content'] = isset($params['exemplary_content']) ? $params['exemplary_content'] : false;
     if (count($keys)) {
         $params['code'] = $keys['currentCourseCode'];
         $params['visual_code'] = $keys['currentCourseId'];
         $params['directory'] = $keys['currentCourseRepository'];
         $course_info = api_get_course_info($params['code']);
         if (empty($course_info)) {
             $course_id = self::register_course($params);
             $course_info = api_get_course_info_by_id($course_id);
             if (!empty($course_info)) {
                 self::prepare_course_repository($course_info['directory'], $course_info['code']);
                 self::fill_db_course($course_id, $course_info['directory'], $course_info['course_language'], $params['exemplary_content']);
                 //Create an empty gradebook
                 if (isset($params['create_gradebook_evaluation']) && $params['create_gradebook_evaluation'] == true) {
                     require_once api_get_path(SYS_CODE_PATH) . 'gradebook/lib/gradebook_functions.inc.php';
                     $category_id = create_default_course_gradebook($course_info['code']);
                     if ($category_id && isset($params['gradebook_params'])) {
                         $eval = new Evaluation();
                         $eval->set_name($params['gradebook_params']['name']);
                         $eval->set_user_id($params['gradebook_params']['user_id']);
                         $eval->set_course_code($course_info['code']);
                         $eval->set_category_id($category_id);
                         $eval->set_weight($params['gradebook_params']['weight']);
                         $eval->set_max($params['gradebook_params']['max']);
                         $eval->set_visible(0);
                         $eval->add();
                     }
                 }
                 if (api_get_setting('gradebook.gradebook_enable_grade_model') == 'true') {
                     //Create gradebook_category for the new course and add a gradebook model for the course
                     if (isset($params['gradebook_model_id']) && !empty($params['gradebook_model_id']) && $params['gradebook_model_id'] != '-1') {
                         require_once api_get_path(SYS_CODE_PATH) . 'gradebook/lib/gradebook_functions.inc.php';
                         create_default_course_gradebook($course_info['code'], $params['gradebook_model_id']);
                     }
                 }
                 //Saving extra course fields
                 $field_value = new ExtraFieldValue('course');
                 $params['course_code'] = $course_info['code'];
                 $field_value->save_field_values($params);
                 return $course_info;
             }
         } else {
             //Course already exists
             if (isset($params['return_item_if_already_exists']) && $params['return_item_if_already_exists']) {
                 return $course_info;
             }
         }
     }
     return false;
 }