Example #1
0
 /**
  * Export the step configuration.
  *
  * @param   renderer_base   $output     The renderer.
  * @return  object
  */
 public function export_for_template(\renderer_base $output)
 {
     global $PAGE;
     $step = $this->step;
     $result = (object) ['stepid' => $step->get_id(), 'title' => external_format_text(stepsource::get_string_from_input($step->get_title()), FORMAT_HTML, $PAGE->context->id, 'tool_usertours')[0], 'content' => external_format_text(stepsource::get_string_from_input($step->get_content()), FORMAT_HTML, $PAGE->context->id, 'tool_usertours')[0], 'element' => $step->get_target()->convert_to_css()];
     $result->content = str_replace("\n", "<br>\n", $result->content);
     foreach ($step->get_config_keys() as $key) {
         $result->{$key} = $step->get_config($key);
     }
     return $result;
 }
Example #2
0
 /**
  * A helper to create an empty step for the specified tour.
  *
  * @param   stdClass    $stepconfig     The configuration for the new step
  * @param   bool        $persist        Whether to persist the data
  * @return  \tool_usertours\step
  */
 public function helper_create_step(\stdClass $stepconfig = null, $persist = true)
 {
     $minvalues = ['id' => null, 'title' => '', 'content' => '', 'targettype' => \tool_usertours\target::TARGET_UNATTACHED, 'targetvalue' => '', 'sortorder' => 0, 'configdata' => ''];
     if ($stepconfig === null) {
         $stepconfig = new \stdClass();
     }
     foreach ($minvalues as $key => $value) {
         if (!isset($stepconfig->{$key})) {
             $stepconfig->{$key} = $value;
         }
     }
     $step = \tool_usertours\step::load_from_record($stepconfig, true);
     if ($persist) {
         $step->persist(true);
     }
     return $step;
 }
Example #3
0
 /**
  * Format the current row's actions column.
  *
  * @param   step    $step       The step for this row.
  * @return  string
  */
 protected function col_actions(step $step)
 {
     $actions = [];
     if ($step->is_first_step()) {
         $actions[] = helper::get_filler_icon();
     } else {
         $actions[] = helper::format_icon_link($step->get_moveup_link(), 't/up', get_string('movestepup', 'tool_usertours'));
     }
     if ($step->is_last_step()) {
         $actions[] = helper::get_filler_icon();
     } else {
         $actions[] = helper::format_icon_link($step->get_movedown_link(), 't/down', get_string('movestepdown', 'tool_usertours'));
     }
     $actions[] = helper::format_icon_link($step->get_edit_link(), 't/edit', get_string('edit'));
     $actions[] = helper::format_icon_link($step->get_delete_link(), 't/delete', get_string('delete'), 'moodle', ['data-action' => 'delete', 'data-id' => $step->get_id()]);
     return implode('&nbsp;', $actions);
 }
Example #4
0
 /**
  * Delete the step.
  *
  * @param   int         $stepid     The ID of the step to remove.
  */
 protected function delete_step($stepid)
 {
     require_sesskey();
     $step = step::instance($stepid);
     $tour = $step->get_tour();
     $step->remove();
     redirect($tour->get_view_link());
 }
Example #5
0
 /**
  * Ensure that the get_string_from_input function returns langstring strings correctly.
  *
  * @dataProvider get_string_from_input_provider
  * @param   string  $string     The string to test
  * @param   string  $expected   The expected result
  */
 public function test_get_string_from_input($string, $expected)
 {
     $this->assertEquals($expected, \tool_usertours\step::get_string_from_input($string));
 }
Example #6
0
 /**
  * Mark the specified toru step as shown 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 step_shown($tourid, $context, $pageurl, $stepid, $stepindex)
 {
     $params = self::validate_parameters(self::step_shown_parameters(), ['tourid' => $tourid, 'context' => $context, 'pageurl' => $pageurl, 'stepid' => $stepid, 'stepindex' => $stepindex]);
     $context = \context_helper::instance_by_id($params['context']);
     self::validate_context($context);
     $step = step::instance($params['stepid']);
     if ($step->get_tourid() != $params['tourid']) {
         throw new \moodle_exception('Incorrect tour specified.');
     }
     \tool_usertours\event\step_shown::create(['contextid' => $context->id, 'objectid' => $params['stepid'], 'other' => ['pageurl' => $params['pageurl'], 'tourid' => $params['tourid'], 'stepindex' => $params['stepindex']]])->trigger();
     return [];
 }