/** * Move a tour up or down. * * @param int $id The tour to move. */ protected function move_tour($id) { require_sesskey(); $direction = required_param('direction', PARAM_INT); $tour = tour::instance($id); $currentsortorder = $tour->get_sortorder(); $targetsortorder = $currentsortorder + $direction; $swapwith = helper::get_tour_from_sortorder($targetsortorder); // Set the sort order to something out of the way. $tour->set_sortorder(-1); $tour->persist(); // Swap the two sort orders. $swapwith->set_sortorder($currentsortorder); $swapwith->persist(); $tour->set_sortorder($targetsortorder); $tour->persist(); redirect(helper::get_list_tour_link()); }
/** * Mark the specified tour as completed for the current user. * * @param int $tourid The ID of the tour. * @param int $context The Context ID of the current page. * @param string $pageurl The path of the current page. * @param int $stepid The step id * @param int $stepindex The step index * @return array As described in complete_tour_returns */ public static function complete_tour($tourid, $context, $pageurl, $stepid, $stepindex) { $params = self::validate_parameters(self::complete_tour_parameters(), ['tourid' => $tourid, 'context' => $context, 'pageurl' => $pageurl, 'stepid' => $stepid, 'stepindex' => $stepindex]); $context = \context_helper::instance_by_id($params['context']); self::validate_context($context); $tour = tourinstance::instance($params['tourid']); $tour->mark_user_completed(); \tool_usertours\event\tour_ended::create(['contextid' => $context->id, 'objectid' => $params['tourid'], 'other' => ['pageurl' => $params['pageurl'], 'stepid' => $params['stepid'], 'stepindex' => $params['stepindex']]])->trigger(); return []; }