public static function save($value, $type, $standard = null) { $var = $standard; if ($value !== null) { if ($type == VAR_DB || $type == VAR_ARR_DB) { $var = Sanitize::saveDb($value); } elseif ($type == VAR_HTML || $type == VAR_ARR_HTML) { $var = Sanitize::saveHTML($value); } elseif ($type == VAR_INT || $type == VAR_ARR_INT) { $var = Sanitize::saveInt($value); } elseif ($type == VAR_ALNUM || $type == VAR_ARR_ALNUM) { $var = Sanitize::saveAlNum($value, true); } elseif ($type == VAR_URI || $type == VAR_ARR_URI) { $var = Sanitize::saveAlNum($value, false); } else { $var = Sanitize::removeNullByte($value); } } else { if ($standard === null) { if ($type == VAR_DB || $type == VAR_ALNUM || $type == VAR_HTML || $type == VAR_URI) { $var = ''; } elseif ($type == VAR_INT) { $var = 0; } elseif ($type == VAR_ARR_INT || $type == VAR_ARR_DB || $type == VAR_ARR_ALNUM || $type == VAR_ARR_NONE || $type == VAR_ARR_HTML || $type == VAR_ARR_URI) { $var = array(); } else { $var = null; } } } return $var; }
public static function getAverageFields(CustomDataPosition $pos, array $params = array()) { $filter = new CustomDataFilter($pos); $filter->field(null); $fields = $pos->getFieldsForClassPath(self::$classPath); foreach ($fields as $field) { $fieldName = Sanitize::saveDb($field->getFieldName()); $filter->fieldCalculation($fieldName, "AVG({$fieldName})"); } foreach ($params as $field => $value) { $filter->condition($field, $value); } $result = $filter->execute(); if ($result) { $data = new CustomData($pos); $row = Database::getObject()->fetchAssoc($result); if ($row) { $data = new CustomData($pos); $data->set($row, true, $fields); return $data->getFields(array_keys($fields)); } } return array(); }