Beispiel #1
0
 /**
  * Create a new rule object from record.
  */
 public static function from_record($record)
 {
     $record = (object) $record;
     $obj = static::create_rule($record->rule, $record->config);
     $obj->id = $record->id;
     $obj->target = \tool_cat\target::create_target($record->target, $record->targetid);
     if (empty($record->datatype)) {
         $record->datatype = 'standard';
         $record->data = null;
     }
     // Add a datatype to the rule.
     $datatype = \tool_cat\datatype::create_datatype($record->datatype, $record->data);
     $obj->target->set_datatype($datatype);
     return $obj;
 }
Beispiel #2
0
 /**
  * Return the rendered text.
  *
  * @return string The data.
  */
 public function get_data()
 {
     $data = parent::get_data();
     $text = $data->text;
     // Check we aren't a template.
     if (isset($data->template) && $data->template) {
         $context = $this->get_context();
         if (empty($context)) {
             debugging("Cannot render a template string with a blank context! Make sure you call set_context first.");
             $context = new \stdClass();
         }
         // Render as a template.
         $text = $this->render_template($text, $context);
     }
     return $text;
 }
Beispiel #3
0
 /**
  * Returns a list of valid activities for the activity.
  *
  * @return array [string]
  * @throws \invalid_parameter_exception
  */
 public static function get_activities()
 {
     $obj = \tool_cat\datatype::create_datatype('activity');
     $keys = $obj->get_supported_activities();
     $values = array_map(function ($str) {
         return get_string('pluginname', "mod_{$str}");
     }, $keys);
     return array_combine($keys, $values);
 }
Beispiel #4
0
 /**
  * Get data (CM).
  */
 public function get_data()
 {
     global $DB;
     $context = $this->get_context();
     if (!is_array($context) || !isset($context['course']) || !isset($context['section'])) {
         throw new \moodle_exception("Invalid activity datatype context!");
     }
     $data = parent::get_data();
     // Get the module.
     $module = $DB->get_record('modules', array('name' => $data->activity), '*', \MUST_EXIST);
     // Create our instance.
     $activity = \tool_cat\activity::create_activity($data->activity, serialize($data));
     $instance = $activity->get_instance($context['course']);
     // Create the cm.
     return $this->create_cm($context['course'], $context['section'], $module, $instance, $data);
 }
Beispiel #5
0
 /**
  * Return the block name.
  */
 public function get_data()
 {
     $data = parent::get_data();
     return $data->block;
 }