/** * Get a value. * * @param string $name Name of the field. * * @return mix Value of the var. */ public function __get($name) { $name = Phprojekt_ActiveRecord_Abstract::convertVarToSql($name); if (!is_null($this->_metadata) && isset($this->_metadata->{$name})) { return $this->_metadata->{$name}; } return null; }
/** * Make a where clause. * * @param string $field Field for filter. * @param string $rule Rule for apply the filter. * @param string $value Value used for filter. * @param string $operator AND/OR operator for concatenate the where clause. * * @return void */ public function addFilter($field, $rule, $value, $operator = 'AND') { $identifier = Phprojekt_ActiveRecord_Abstract::convertVarToSql($field); if (in_array($identifier, $this->_cols)) { $rule = $this->_convertRule($field, $identifier, $rule, $value); if (null !== $this->_userWhere) { $this->_userWhere .= $operator . " "; } $this->_userWhere .= sprintf('(%s) ', $rule); } }
/** * Initialize a new user filter on an active record. * It uses the table name and the database adapter from the Active Record. * * @param Phprojekt_ActiveRecord_Abstract $record An active record. * @param string $identifier The identifier usually the column to filter. * @param mixed $value The value to filter. * * @return void */ public function __construct(Phprojekt_ActiveRecord_Abstract $record, $identifier, $value) { $info = $record->info(); $cols = $info['cols']; $identifier = Phprojekt_ActiveRecord_Abstract::convertVarToSql($identifier); if (!in_array($identifier, $cols)) { throw new InvalidArgumentException('Identifier not found'); } $this->_identifier = $identifier; $this->_value = $value; parent::__construct($record->getAdapter()); }
/** * Get a value of a var. * Is the var is a float, return the locale float. * * @param string $varname Name of the var to assign. * * @return mixed Value of the var. */ public function __get($varname) { $info = $this->info(); $value = parent::__get($varname); $varForInfo = Phprojekt_ActiveRecord_Abstract::convertVarToSql($varname); if (true == isset($info['metadata'][$varForInfo])) { $type = $info['metadata'][$varForInfo]['DATA_TYPE']; $value = Phprojekt_Converter_Value::get($type, $value); } return $value; }
/** * Validates a value using the database type of the field. * * @param Phprojekt_Model_Interface $class Model object. * @param string $varname Name of the field. * @param mix $value Value to validate. * * @return boolean True for valid. */ public function validateValue(Phprojekt_Model_Interface $class, $varname, $value) { $info = $class->info(); $varForInfo = Phprojekt_ActiveRecord_Abstract::convertVarToSql($varname); $valid = true; if (isset($info['metadata'][$varForInfo]) && !empty($value)) { $type = $info['metadata'][$varForInfo]['DATA_TYPE']; switch ($type) { case 'int': $valid = Cleaner::validate('integer', $value, false); break; case 'float': $valid = Cleaner::validate('float', $value, false); break; case 'date': $valid = Cleaner::validate('date', $value, false); break; case 'time': // $valid = Cleaner::validate('timestamp', $value, false); break; case 'timestamp': case 'datetime': $valid = Cleaner::validate('timestamp', $value, false); break; default: $valid = Cleaner::validate('string', $value, true); break; } } return $valid !== false; }
/** * Apply rules for tableField. * * @param string $value Name of the field in the table. * * @return string Converted name. */ public static function convertTableField($value) { return Phprojekt_ActiveRecord_Abstract::convertVarToSql($value); }