public function filter($data, $group = null) { // Make sure there is a valid MForm XML document. if (!$this->xml instanceof SimpleXMLElement) { return false; } // Initialise variables. $input = new MRegistry($data); $output = new MRegistry(); // Get the fields for which to filter the data. $fields = $this->findFieldsByGroup($group); if (!$fields) { // PANIC! return false; } // Filter the fields. foreach ($fields as $field) { // Initialise variables. $name = (string) $field['name']; // Get the field groups for the element. $attrs = $field->xpath('ancestor::fields[@name]/@name'); $groups = array_map('strval', $attrs ? $attrs : array()); $group = implode('.', $groups); // Get the field value from the data input. if ($group) { // Filter the value if it exists. if ($input->exists($group . '.' . $name)) { $output->set($group . '.' . $name, $this->filterField($field, $input->get($group . '.' . $name, (string) $field['default']))); } } else { // Filter the value if it exists. if ($input->exists($name)) { $output->set($name, $this->filterField($field, $input->get($name, (string) $field['default']))); } } } return $output->toArray(); }
public function getItem($pk = null) { $pk = !empty($pk) ? $pk : (int) $this->getState($this->getName() . '.id'); $table = $this->getTable(); if ($pk > 0) { // Attempt to load the row. $return = $table->load($pk); // Check for a table object error. if ($return === false && $table->getError()) { $this->setError($table->getError()); return false; } } // Convert to the MObject before adding other data. $properties = $table->getProperties(1); $item = MArrayHelper::toObject($properties, 'MObject'); if (property_exists($item, 'params')) { $registry = new MRegistry(); $registry->loadString($item->params); $item->params = $registry->toArray(); } return $item; }