예제 #1
0
 /**
  * Insert this category into the database
  */
 public function add()
 {
     if (isset($this->name) && '-1' == $this->name) {
         return false;
     }
     if (isset($this->name) && isset($this->user_id)) {
         $em = Database::getManager();
         $category = new \Chamilo\CoreBundle\Entity\GradebookCategory();
         $category->setName($this->name);
         $category->setDescription($this->description);
         $category->setUserId($this->user_id);
         $category->setCourseCode($this->course_code);
         $category->setParentId($this->parent);
         $category->setWeight($this->weight);
         $category->setVisible($this->visible);
         $category->setCertifMinScore($this->certificate_min_score);
         $category->setSessionId($this->session_id);
         $category->setGenerateCertificates($this->generateCertificates);
         $category->setGradeModelId($this->grade_model_id);
         $category->setIsRequirement($this->isRequirement);
         $category->setLocked(false);
         $em->persist($category);
         $em->flush();
         $id = $category->getId();
         $this->set_id($id);
         if (!empty($id)) {
             $parent_id = $this->get_parent_id();
             $grade_model_id = $this->get_grade_model_id();
             if ($parent_id == 0) {
                 //do something
                 if (isset($grade_model_id) && !empty($grade_model_id) && $grade_model_id != '-1') {
                     $obj = new GradeModel();
                     $components = $obj->get_components($grade_model_id);
                     $default_weight_setting = api_get_setting('gradebook.gradebook_default_weight');
                     $default_weight = 100;
                     if (isset($default_weight_setting)) {
                         $default_weight = $default_weight_setting;
                     }
                     foreach ($components as $component) {
                         $gradebook = new Gradebook();
                         $params = array();
                         $params['name'] = $component['acronym'];
                         $params['description'] = $component['title'];
                         $params['user_id'] = api_get_user_id();
                         $params['parent_id'] = $id;
                         $params['weight'] = $component['percentage'] / 100 * $default_weight;
                         $params['session_id'] = api_get_session_id();
                         $params['course_code'] = $this->get_course_code();
                         $gradebook->save($params);
                     }
                 }
             }
         }
         $gradebook = new Gradebook();
         $gradebook->update_skills_to_gradebook($this->id, $this->get_skills(false));
         return $id;
     }
 }