public static function load_from_row($row, $recurse_limit = 1, $current_level = 0, $altPrefix = null) { // When PHP 5.3.0 is in, we can shift this over too and just redefine it // if needed (eg. loading child objects) $class = __CLASS__; $object = new $class(); $fields = self::fields_array(); $fields[] = array("created_at", "datetime"); $fields[] = array("updated_at", "datetime"); $fields[] = array("deleted", "bool"); $prefix = self::table; if ($altPrefix) { $prefix = $altPrefix; } foreach ($fields as $field) { $property = $field[0]; if (isset($field[2])) { $property = $field[2]; } if (isset($row["{$prefix}.{$field[0]}"])) { if ($field[1] == "datetime") { $object->{$property} = strtotime($row["{$prefix}.{$field[0]}"]); } else { $object->{$property} = $row["{$prefix}.{$field[0]}"]; } } else { $object->{$property} = null; } } $object->password_confirmation = $object->password; $object->is_new = false; // Load child objects here if ($current_level < $recurse_limit) { $current_level++; $object->profile = UserProfile::load_from_row($row, $recurse_limit, $current_level); $object->referer = User::load_from_row($row, $recurse_limit, $current_level, 'referer'); $object->aclgroup = ACLGroup::load_from_row($row, $recurse_limit, $current_level); $object->country = Country::load_from_row($row, $recurse_limit, $current_level); } $object->hash = $object->calculateHash(); return $object; }
public static function load_from_row($row, $recurse_limit = 1, $current_level = 0) { // When PHP 5.3.0 is in, we can shift this over too and just redefine it // if needed (eg. loading child objects) $class = __CLASS__; $object = new $class(); $fields = self::fields_array(); $fields[] = array("created_at", "datetime"); $fields[] = array("updated_at", "datetime"); $fields[] = array("deleted", "bool"); foreach ($fields as $field) { $property = $field[0]; if (isset($field[2])) { $property = $field[2]; } if (isset($row[self::table . ".{$field[0]}"])) { if ($field[1] == "datetime") { $object->{$property} = strtotime($row[self::table . ".{$field[0]}"]); } else { $object->{$property} = $row[self::table . ".{$field[0]}"]; } } else { $object->{$property} = null; } } $object->is_new = false; // Load child objects here if ($current_level < $recurse_limit) { $current_level++; $object->group = ACLGroup::load_from_row($row, $recurse_limit, $current_level); $object->acl = ACL::load_from_row($row, $recurse_limit, $current_level); } return $object; }