/** * Update the properties of this link in the database */ public function save() { $this->save_linked_data(); $tbl_grade_links = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK); $sql = "UPDATE {$tbl_grade_links} SET\n type = " . intval($this->get_type()) . ",\n ref_id = " . intval($this->get_ref_id()) . ",\n user_id = " . intval($this->get_user_id()) . ",\n course_code = '" . Database::escape_string($this->get_course_code()) . "',\n category_id = " . intval($this->get_category_id()) . ",\n weight = '" . Database::escape_string($this->get_weight()) . "',\n visible = " . intval($this->is_visible()) . "\n WHERE id = " . intval($this->id); AbstractLink::add_link_log($this->id); Database::query($sql); }
$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['weight']; $masked_total = $parent_cat[0]->get_weight(); $sql = 'SELECT * FROM ' . $table_link . ' WHERE category_id = ' . $my_selectcat; $result = Database::query($sql); while ($row = Database::fetch_array($result)) { $item_weight = $row['weight']; //$item_weight = $masked_total*$item_weight/$original_total; //update only if value changed if (isset($_POST['link'][$row['id']])) { //$new_weight = trim($_POST['link'][$row['id']]*$original_total/$masked_total); $new_weight = trim($_POST['link'][$row['id']]); AbstractLink::add_link_log($row['id']); Database::query('UPDATE ' . $table_link . ' SET weight = ' . "'" . Database::escape_string($new_weight) . "'" . ' WHERE id = ' . $row['id']); $item_weight = trim($_POST['link'][$row['id']]); //Update weight for attendance $sql = 'SELECT ref_id FROM ' . $table_link . ' WHERE id = ' . intval($row['id']) . ' AND type=' . LINK_ATTENDANCE; $rs_attendance = Database::query($sql); if (Database::num_rows($rs_attendance) > 0) { $row_attendance = Database::fetch_array($rs_attendance); $upd_attendance = 'UPDATE ' . $tbl_attendance . ' SET attendance_weight =' . floatval($_POST['link'][$row['id']]) . ' WHERE c_id = ' . $course_id . ' AND id = ' . intval($row_attendance['ref_id']); Database::query($upd_attendance); } //Update weight into forum thread $sql_t = 'UPDATE ' . $tbl_forum_thread . ' SET thread_weight=' . floatval($_POST['link'][$row['id']]) . ' WHERE c_id = ' . $course_id . ' AND thread_id = (SELECT ref_id FROM ' . $table_link . ' WHERE id=' . intval($row['id']) . ' AND type=' . LINK_FORUM_THREAD . ' ) '; Database::query($sql_t);
/** * @param int $linkId * @param float $weight */ public static function updateLinkWeight($linkId, $name, $weight) { $linkId = intval($linkId); $weight = floatval($weight); $course_id = api_get_course_int_id(); AbstractLink::add_link_log($linkId, $name); $table_link = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK); $table_evaluation = Database::get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); $tbl_forum_thread = Database::get_course_table(TABLE_FORUM_THREAD); $tbl_work = Database::get_course_table(TABLE_STUDENT_PUBLICATION); $tbl_attendance = Database::get_course_table(TABLE_ATTENDANCE); $sql = 'UPDATE ' . $table_link . ' SET weight = ' . "'" . Database::escape_string($weight) . "'" . ' WHERE id = ' . $linkId; Database::query($sql); // Update weight for attendance $sql = 'SELECT ref_id FROM ' . $table_link . ' WHERE id = ' . $linkId . ' AND type=' . LINK_ATTENDANCE; $rs_attendance = Database::query($sql); if (Database::num_rows($rs_attendance) > 0) { $row_attendance = Database::fetch_array($rs_attendance); $sql = 'UPDATE ' . $tbl_attendance . ' SET attendance_weight =' . $weight . ' WHERE c_id = ' . $course_id . ' AND id = ' . intval($row_attendance['ref_id']); Database::query($sql); } // Update weight into forum thread $sql = 'UPDATE ' . $tbl_forum_thread . ' SET thread_weight=' . $weight . ' WHERE c_id = ' . $course_id . ' AND thread_id = ( SELECT ref_id FROM ' . $table_link . ' WHERE id=' . $linkId . ' AND type=' . LINK_FORUM_THREAD . ' ) '; Database::query($sql); //Update weight into student publication(work) $sql = 'UPDATE ' . $tbl_work . ' SET weight=' . $weight . ' WHERE c_id = ' . $course_id . ' AND id = ( SELECT ref_id FROM ' . $table_link . ' WHERE id=' . $linkId . ' AND type = ' . LINK_STUDENTPUBLICATION . ' ) '; Database::query($sql); }
/** * Update the properties of this link in the database */ public function save() { $this->save_linked_data(); $table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK); $params = ['type' => $this->get_type(), 'ref_id' => $this->get_ref_id(), 'user_id' => $this->get_user_id(), 'course_code' => $this->get_course_code(), 'category_id' => $this->get_category_id(), 'weight' => $this->get_weight(), 'visible' => $this->is_visible()]; Database::update($table, $params, ['id = ?' => $this->id]); AbstractLink::add_link_log($this->id); }
/** * Update the properties of this link in the database */ public function save() { $em = Database::getManager(); $link = $em->find('ChamiloCoreBundle:GradebookLink', $this->id); if (!$link) { return; } AbstractLink::add_link_log($this->id); $this->save_linked_data(); $course = $em->find('ChamiloCoreBundle:Course', $this->course_id); $link->setType($this->get_type())->setRefId($this->get_ref_id())->setUserId($this->get_user_id())->setCourse($course)->setCategoryId($this->get_category_id())->setWeight($this->get_weight())->setVisible($this->is_visible()); $em->merge($link); $em->flush(); }
/** * @param int $linkId * @param float $weight */ public static function updateLinkWeight($linkId, $name, $weight) { $linkId = intval($linkId); $weight = floatval($weight); $course_id = api_get_course_int_id(); AbstractLink::add_link_log($linkId, $name); $em = Database::getManager(); $gradebookLink = $em->find('ChamiloCoreBundle:GradebookLink', $linkId); if (!$gradebookLink) { return false; } $gradebookLink->setWeight($weight); $em->persist($gradebookLink); $em->flush(); // Update weight for attendance if ($gradebookLink->getType() == LINK_ATTENDANCE) { $em->createQuery(' UPDATE ChamiloCourseBundle:CAttendance ca SET ca.attendanceWeight = :weight WHERE ca.cId = :course AND ca.id = :reference ')->execute(['weight' => $weight, 'course' => $course_id, 'reference' => $gradebookLink->getRefId()]); } // Update weight into forum thread if ($gradebookLink->getType() == LINK_FORUM_THREAD) { $em->createQuery(' UPDATE ChamiloCourseBundle:CForumThread cft SET cft.threadWeight = :weight WHERE cft.cId = :course AND cft.threadId = :reference ')->execute(['weight' => $weight, 'course' => $course_id, 'reference' => $gradebookLink->getRefId()]); } //Update weight into student publication(work) if ($gradebookLink->getType() == LINK_STUDENTPUBLICATION) { $em->createQuery(' UPDATE ChamiloCourseBundle:CStudentPublication csp SET csp.weight = :weight WHERE csp.cId = :course AND csp.id = :reference ')->execute(['weight' => $weight, 'course' => $course_id, 'reference' => $gradebookLink->getRefId()]); } }