/** * Reorder this competency. * * Requires moodle/competency:competencymanage capability at the system context. * * @param int $id The id of the competency to move. * @return boolean */ public static function move_up_competency($id) { static::require_enabled(); $current = new competency($id); // First we do a permissions check. require_capability('moodle/competency:competencymanage', $current->get_context()); $sortorder = $current->get_sortorder(); if ($sortorder == 0) { return false; } $sortorder = $sortorder - 1; $current->set_sortorder($sortorder); $filters = array('parentid' => $current->get_parentid(), 'competencyframeworkid' => $current->get_competencyframeworkid(), 'sortorder' => $sortorder); $children = self::list_competencies($filters, 'id'); foreach ($children as $needtoswap) { $needtoswap->set_sortorder($sortorder + 1); $needtoswap->update(); } // OK - all set. $result = $current->update(); return $result; }