コード例 #1
0
ファイル: helper_trait.php プロジェクト: dg711/moodle
 /**
  * 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;
 }
コード例 #2
0
 /**
  * Import the provided tour JSON.
  *
  * @param   string      $json           The tour configuration.
  * @return  tour
  */
 public static function import_tour_from_json($json)
 {
     $tourconfig = json_decode($json);
     // We do not use this yet - we may do in the future.
     unset($tourconfig->version);
     $steps = $tourconfig->steps;
     unset($tourconfig->steps);
     $tourconfig->id = null;
     $tourconfig->sortorder = null;
     $tour = tour::load_from_record($tourconfig, true);
     $tour->persist(true);
     // Ensure that steps are orderered by their sortorder.
     \core_collator::asort_objects_by_property($steps, 'sortorder', \core_collator::SORT_NUMERIC);
     foreach ($steps as $stepconfig) {
         $stepconfig->id = null;
         $stepconfig->tourid = $tour->get_id();
         $step = step::load_from_record($stepconfig, true);
         $step->persist(true);
     }
     return $tour;
 }