/** * Reset the sortorder for all tours. */ public static function reset_tour_sortorder() { global $DB; $tours = $DB->get_records('tool_usertours_tours', null, 'sortorder ASC, pathmatch DESC', 'id, sortorder'); $index = 0; foreach ($tours as $tour) { if ($tour->sortorder != $index) { $DB->set_field('tool_usertours_tours', 'sortorder', $index, array('id' => $tour->id)); } $index++; } // Notify the cache that a tour has changed. // Tours are only stored in the cache if there are steps. // If there step count has changed for some reason, this will change the potential cache results. cache::notify_tour_change(); }
/** * Save the tour and it's configuration to the database. * * @param boolean $force Whether to force writing to the database. * @return $this */ public function persist($force = false) { global $DB; if (!$this->dirty && !$force) { return $this; } if ($this->id) { $record = $this->to_record(); $DB->update_record('tool_usertours_tours', $record); } else { $this->calculate_sortorder(); $record = $this->to_record(); unset($record->id); $this->id = $DB->insert_record('tool_usertours_tours', $record); } $this->reload(); // Notify the cache that a tour has changed. cache::notify_tour_change(); return $this; }
/** * Remove this step. */ public function remove() { global $DB; if ($this->id === null) { return; } $DB->delete_records('tool_usertours_steps', array('id' => $this->id)); $this->get_tour()->reset_step_sortorder(); // Notify of a change to the step configuration. // This must be done separately to tour change notifications. cache::notify_step_change($this->get_id()); // Notify the cache that a tour has changed. // Tours are only stored in the cache if there are steps. // If there step count has changed for some reason, this will change the potential cache results. cache::notify_tour_change(); }