/** @brief Adds new sort parameter or substitutes existing one. * * @param $current_value [in] current sort order value. * @param $sort_param [in] new sort parameter * @param $order [in] sort order * * @return copy of current query. */ private function internal_add_sort($current_value, $sort_param, $order, $feed = null) { if ($sort_param == '') { $sort_param = null; } if (!is_null($sort_param)) { if (strncmp('afs:', $sort_param, 4) == 0) { AfsSortBuiltins::check_value($sort_param, 'Invalid sort parameter: '); } elseif (1 != preg_match('/^[a-zA-Z][a-zA-Z0-9_-]*$/', $sort_param)) { throw new Exception('Invalid sort parameter provided: ' . $sort_param); } AfsSortOrder::check_value($order, 'Invalid sort order provided: '); $new_value = $current_value; if (is_null($new_value)) { $new_value = array(); } $new_value[] = new AfsSortParameter($sort_param, $order, $feed); } else { $new_value = array(); } $this->sort = $new_value; }