/** * Sets a value to the record * * @param string $column The column to set the value to * @param mixed $value The value to set * @return fActiveRecord This record, to allow for method chaining */ protected function set($column, $value) { if (!array_key_exists($column, $this->values)) { throw new fProgrammerException('The column specified, %s, does not exist', $column); } // We consider an empty string or a string of spaces to be equivalent to NULL if ($value === '' || is_string($value) && trim($value) === '') { $value = NULL; } $class = get_class($this); $value = fORM::objectify($class, $column, $value); // Float and int columns that look like numbers with commas will have the commas removed if (is_string($value)) { $table = fORM::tablize($class); $schema = fORMSchema::retrieve($class); $type = $schema->getColumnInfo($table, $column, 'type'); if (in_array($type, array('integer', 'float')) && preg_match('#^(\\d+,)+\\d+(\\.\\d+)?$#', $value)) { $value = str_replace(',', '', $value); } } self::assign($this->values, $this->old_values, $column, $value); return $this; }
/** * Sets the appropriate column values to the date the object was updated * * @internal * * @param fActiveRecord $object The fActiveRecord instance * @param array &$values The current values * @param array &$old_values The old values * @param array &$related_records Any records related to this record * @param array &$cache The cache array for the record * @return void */ public static function setDateUpdated($object, &$values, &$old_values, &$related_records, &$cache) { $class = get_class($object); foreach (self::$date_updated_columns[$class] as $column => $enabled) { fActiveRecord::assign($values, $old_values, $column, fORM::objectify($class, $column, date('Y-m-d H:i:s'))); // If the column has a corresponding timezone column, set that too if (isset(self::$timestamp_columns[$class][$column])) { fActiveRecord::assign($values, $old_values, self::$timestamp_columns[$class][$column], fTimestamp::getDefaultTimezone()); } } }