public function update_skills_to_gradebook($gradebook_id, $skill_list) { if (!empty($skill_list)) { //Cleaning skills $skill_list = array_map('intval', $skill_list); $skill_list = array_filter($skill_list); $skill_gradebook = new SkillRelGradebook(); $skill_gradebooks_source = $skill_gradebook->get_all(array('where' => array('gradebook_id = ?' => $gradebook_id))); $clean_gradebook = array(); if (!empty($skill_gradebooks_source)) { foreach ($skill_gradebooks_source as $source) { $clean_gradebook[] = $source['skill_id']; } } if (!empty($clean_gradebook)) { $skill_to_remove = array_diff($clean_gradebook, $skill_list); } foreach ($skill_list as $skill_id) { $params = array(); $params['gradebook_id'] = $gradebook_id; $params['skill_id'] = $skill_id; if (!$skill_gradebook->exists_gradebook_skill($gradebook_id, $skill_id)) { $skill_gradebook->save($params); } } if (!empty($skill_to_remove)) { foreach ($skill_to_remove as $remove) { $skill_item = $skill_gradebook->get_skill_info($remove, $gradebook_id); $skill_gradebook->delete($skill_item['id']); } } return true; } return false; }
/** * @param array $params * @return null */ public function edit($params) { if (!isset($params['parent_id'])) { $params['parent_id'] = 1; } $skill_rel_skill = new SkillRelSkill(); $skill_rel_gradebook = new SkillRelGradebook(); //Saving name, description $this->update($params); $skill_id = $params['id']; if ($skill_id) { //Saving skill_rel_skill (parent_id, relation_type) if (!is_array($params['parent_id'])) { $params['parent_id'] = array($params['parent_id']); } foreach ($params['parent_id'] as $parent_id) { $relation_exists = $skill_rel_skill->relation_exists($skill_id, $parent_id); if (!$relation_exists) { $attributes = array('skill_id' => $skill_id, 'parent_id' => $parent_id, 'relation_type' => $params['relation_type']); $skill_rel_skill->update_by_skill($attributes); } } $gradeBookId = isset($params['gradebook_id']) ? $params['gradebook_id'] : null; $skill_rel_gradebook->update_gradebooks_by_skill($skill_id, $gradeBookId); return $skill_id; } return null; }
/* For licensing terms, see /license.txt */ use Chamilo\CoreBundle\Framework\Container; /** * Responses to AJAX calls */ //require_once '../global.inc.php'; $action = isset($_REQUEST['a']) ? $_REQUEST['a'] : null; if (api_get_setting('skill.allow_skills_tool') != 'true') { exit; } Container::$legacyTemplate = 'layout_one_col_no_content.html.twig'; api_block_anonymous_users(); $skill = new Skill(); $gradebook = new Gradebook(); $skill_gradebook = new SkillRelGradebook(); switch ($action) { case 'add': if (api_is_platform_admin() || api_is_drh()) { if (isset($_REQUEST['id']) && !empty($_REQUEST['id'])) { $skill_id = $skill->edit($_REQUEST); } else { $skill_id = $skill->add($_REQUEST); } } echo $skill_id; break; case 'delete_skill': if (api_is_platform_admin() || api_is_drh()) { echo $skill->delete($_REQUEST['skill_id']); }