/** * Создаёт стандартные маршруты на указанном сайте. * * @param int $site_id * @return bool */ public static function create($site_id) { if (!nc_core::get_object()->catalogue->get_by_id($site_id, 'Catalogue_ID')) { return false; } // Пути по умолчанию в порядке убывания приоритета $all_patterns = array("folder /{folder}/{date}/", "folder /{folder}/{date}", "folder /{folder}/", "folder /{folder}", "infoblock /{folder}/{infoblock_action}_{infoblock_keyword}.{format}", "infoblock /{folder}/{date}/{infoblock_action}_{infoblock_keyword}.{format}", "object /{folder}/{date}/{object_action}_{object_keyword}.{format}", "object /{folder}/{object_action}_{object_keyword}.{format}", "object /{folder}/{date}/{object_action}_{infoblock_keyword}_{object_id}.{format}", "object /{folder}/{object_action}_{infoblock_keyword}_{object_id}.{format}", "object /{folder}/{date}/{object_keyword}.{format}", "object /{folder}/{object_keyword}.{format}", "object /{folder}/{date}/{infoblock_keyword}_{object_id}.{format}", "object /{folder}/{infoblock_keyword}_{object_id}.{format}", "infoblock /{folder}/{infoblock_keyword}.{format}", "infoblock /{folder}/{date}/{infoblock_keyword}.{format}"); $all_patterns = array_reverse($all_patterns); foreach ($all_patterns as $pattern_data) { list($resource_type, $pattern) = explode(" ", $pattern_data, 2); $route = new nc_routing_route(array('site_id' => $site_id, 'description' => '', 'is_builtin' => true, 'pattern' => $pattern, 'resource_type' => $resource_type, 'enabled' => true)); $route->save(); } return true; }
/** * (POST only) * params: route_id, priority */ protected function action_change_priority() { $input = $this->input; $route = new nc_routing_route($input->fetch_post('route_id')); $old_priority = (int) $route->get('priority'); $new_priority = (int) $input->fetch_post('priority'); if ($new_priority && $old_priority != $new_priority) { if ($new_priority < $old_priority) { // moving upward $direction = '+'; $min = $new_priority; $max = $old_priority; } else { // moving downward $direction = '-'; $min = $old_priority; $max = $new_priority; } nc_db()->query("UPDATE `{$route->get_table_name()}`\n SET `Priority` = `Priority` {$direction} 1\n WHERE `Site_ID` = " . (int) $route->get('site_id') . "\n AND `Priority` BETWEEN {$min} AND {$max}"); $route->set('priority', $new_priority)->save(); } exit; }