/** * Validate. * * If fields are present, build address. */ function validate(T_Cage_Array $src) { $this->clean = null; $this->error = false; foreach ($this->children as $child) { $child->validate($src); } $alias = $this->getAlias(); // check address components are present if ($this->isPresent() && $this->isValid()) { $line_1 = $this->search($alias . '_line_1'); $city = $this->search($alias . '_city'); if (!$line_1->isPresent()) { $line_1->setError(new T_Form_Error('is missing')); } if (!$city->isPresent()) { $city->setError(new T_Form_Error('is missing')); } } // build address if ($this->isPresent() && $this->isValid()) { $data = array(); $data['line1'] = $this->search($alias . '_line_1')->getValue(); $data['line2'] = $this->search($alias . '_line_2')->getValue(); $data['city'] = $this->search($alias . '_city')->getValue(); $data['state'] = $this->search($alias . '_state')->getValue(); $data['postcode'] = $this->search($alias . '_postcode')->getValue(); if ($this->countries) { $code = $this->search($alias . '_country')->getValue(); $data['country'] = $this->countries->getByCode($code); } else { $data['country'] = null; } $address = $this->factory->like('T_Geo_Address', $data); // filter address try { foreach ($this->filters as $filter) { $address = _transform($address, $filter); } $this->setValue($address); } catch (T_Exception_Filter $e) { $this->setError(new T_Form_Error($e->getMessage())); return $this; } } elseif (!$this->isPresent() && $this->isRequired()) { $this->setError(new T_Form_Error('is missing')); } return $this; }
/** * Create user. * * @param array $row * @return T_User */ protected function toUser($row) { return $this->factory->like('T_User', $row); }
/** * Converts a row to a user role. * * @param array $row * @return T_Role */ protected function toRole($row) { $row['id'] = (int) $row['id']; return $this->factory->like('T_Role', $row); }
/** * Creates a country object from a table row. * * @param array $row * @return T_Geo_Country */ protected function fromRow($row) { $row['id'] = (int) $row['id']; return $this->factory->like('T_Geo_Country', $row); }