/** * Validate the data. * * @param array $data The data to validate. * @return bool */ public static function validate_data($data) { $valid = true; foreach ($data as $key => $value) { if (!$valid) { break; } if ($key === '_class') { $reflexion = new ReflectionClass($value); $valid = $reflexion->isSubclassOf('block_xp_rule'); } else { if (is_array($value)) { $valid = block_xp_rule::validate_data($value); } } } return $valid; }
public function test_export_create() { $rule = new block_xp_rule_property(block_xp_rule_base::CT, 'I', 'str'); $newrule = block_xp_rule::create($rule->export()); $this->assertEquals($rule, $newrule); $rule = new block_xp_rule_property(block_xp_rule_base::CT, 'I', 'str'); $rs = new block_xp_ruleset(array($rule), block_xp_ruleset::ALL); $newrs = block_xp_rule::create($rs->export()); $this->assertEquals($rs, $newrs); // Test with bad data. $data = $rs->export(); $data['_class'] = 'Does not exist'; $this->assertFalse(block_xp_rule::create($data)); }
/** * Returns a form element for this rule. * * @param string $basename The form element base name. * @return string */ public function get_form($basename) { global $COURSE; $options = array(); $modinfo = get_fast_modinfo($this->courseid); $courseformat = course_get_format($this->courseid); foreach ($modinfo->get_sections() as $sectionnum => $cmids) { $modules = array(); foreach ($cmids as $cmid) { $cm = $modinfo->get_cm($cmid); $modules[$cm->context->id] = $cm->name; } $options[] = array($courseformat->get_section_name($sectionnum) => $modules); } $o = block_xp_rule::get_form($basename); $modules = html_writer::select($options, $basename . '[value]', $this->value, '', array('id' => '', 'class' => '')); $o .= get_string('activityoresourceis', 'block_xp', $modules); return $o; }
/** * Export the properties and their values. * * @return array Keys are properties, values are the values. */ public function export() { $properties = parent::export(); $properties['method'] = $this->method; $properties['rules'] = array(); foreach ($this->rules as $rule) { $properties['rules'][] = $rule->export(); } return $properties; }
/** * Export the properties and their values. * * This must return all the values required by the {@link self::create()} method. * * @return array Keys are properties, values are the values. */ public function export() { $properties = parent::export(); $properties['compare'] = $this->compare; $properties['value'] = $this->value; return $properties; }
public function test_export_create() { $rule = new block_xp_rule_property(block_xp_rule_base::CT, 'I', 'str'); $newrule = block_xp_rule::create($rule->export()); $this->assertEquals($rule, $newrule); $rule = new block_xp_rule_property(block_xp_rule_base::CT, 'I', 'str'); $rs = new block_xp_ruleset(array($rule), block_xp_ruleset::ALL); $newrs = block_xp_rule::create($rs->export()); $this->assertEquals($rs, $newrs); }
/** * Returns a form element for this rule. * * @param string $basename The form element base name. * @return string */ public function get_form($basename) { $o = block_xp_rule::get_form($basename); $modules = html_writer::select(self::get_events_list(), $basename . '[value]', $this->value, '', array('id' => '', 'class' => '')); $o .= get_string('eventis', 'block_xp', $modules); return $o; }
/** * Import the properties. * * @param array $properties Array of properties acquired from {@link self::export()}. * @return exportable */ protected function import(array $properties) { if (isset($properties['rules'])) { $ruleslist = array(); foreach ($properties['rules'] as $rule) { $ruleobject = block_xp_rule::create($rule); if ($ruleobject) { $ruleslist[] = $ruleobject; } } $this->rules = $ruleslist; } unset($properties['rules']); parent::import($properties); }
/** * Overrides the rule of the filter. * * @param block_xp_rule $rule */ public function set_rule(block_xp_rule $rule) { $this->rule = $rule; $this->ruledata = json_encode($rule->export()); }