public function prepareValue($value) { if (is_bool($value)) { return $value ? 1 : 0; } elseif (is_int($value)) { return $value; } elseif (is_float($value)) { // convert the decimal separator back to english notation if changed by locale $localeconv = localeconv(); return str_replace($localeconv['decimal_point'], '.', $value); } elseif (is_string($value)) { return "'" . $this->escapeString($value) . "'"; } elseif ($value === null) { return 'NULL'; } elseif ($value instanceof SisField) { return $value->getFullName(); } else { Sis::error('Invalid data type!', array('value' => $value)); return false; } }
public function __construct($type, $op, $params) { if (!self::isValid($type)) { Sis::error('Invalid condition type!', array('type' => $type)); } $this->type = self::resolveAliases($type); $this->op = $op; $this->params = $params; // Operations starting with "field" accept an array shorthand for // operating on multiple fields. if (substr($this->type, 0, 6) == 'field_' && is_array($params[0])) { $subConds = array(); foreach ($params[0] as $fieldName => $value) { $subConds[] = new self($this->type, $op, array($fieldName, $value)); } $this->type = 'merge_and'; $this->op = $op; $this->params = $subConds; // This is an optimization - we skip prepare_merge_and because // we already know our subconditions are not registered with // the operation object. return; } // some conditions need preparation $method = 'prepare_' . $this->type; if (method_exists(__CLASS__, $method)) { self::$method($this->op, $this->params); } }