Пример #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;
 }
Пример #2
0
 /**
  * Returns a list of valid data types for a given target.
  *
  * @param $target
  * @return array [string]
  * @throws \invalid_parameter_exception
  */
 public static function get_datatypes($target)
 {
     $params = self::validate_parameters(self::get_datatypes_parameters(), array('target' => $target));
     $obj = \tool_cat\target::create_target($params['target']);
     $keys = $obj->get_supported_datatypes();
     return array_combine($keys, array_map('ucwords', $keys));
 }