Exemple #1
0
 public function match(nc_routing_request $request, nc_routing_result $result)
 {
     $infoblock_id = $result->get_resource_parameter('infoblock_id');
     $folder_id = $result->get_resource_parameter('folder_id');
     if ($infoblock_id && !$this->infoblock_has_event_field($infoblock_id)) {
         return false;
     } else {
         if ($folder_id && !$this->folder_has_component_with_event_field($folder_id)) {
             return false;
         } else {
             if (!$infoblock_id && !$folder_id) {
                 return false;
             }
         }
     }
     foreach ($this->regexps as $regexp) {
         if (preg_match($regexp, $result->get_remainder(), $matches)) {
             $date = $matches['Y'] . ($matches['m'] ? "-{$matches['m']}" . ($matches['d'] ? "-{$matches['d']}" : "") : "");
             $result->set_resource_parameter('date', $date);
             $result->truncate_remainder(strlen($date));
             return true;
         }
     }
     return false;
 }
Exemple #2
0
 public function match(nc_routing_request $request, nc_routing_result $result)
 {
     if (!nc_preg_match($this->get_keyword_regexp(), $result->get_remainder(), $matches)) {
         return false;
         // --- RETURN ---
     }
     $possible_keywords = $this->get_possible_keywords($matches[1]);
     $infoblocks_in_folder = array();
     $infoblock_id = $result->get_resource_parameter('infoblock_id');
     // sic, not get_infoblock_id()
     $folder_id = $result->get_resource_parameter('folder_id');
     $infoblock_manager = nc_core::get_object()->sub_class;
     if ($infoblock_id) {
         $infoblocks_in_folder = array($infoblock_manager->get_by_id($infoblock_id));
     } else {
         if ($folder_id) {
             $infoblocks_in_folder = $infoblock_manager->get_by_subdivision_id($folder_id);
         }
     }
     foreach ($possible_keywords as $object_keyword) {
         foreach ($infoblocks_in_folder as $infoblock_settings) {
             list($object_id, $real_object_keyword) = (array) ObjectExists($infoblock_settings['Class_ID'], $infoblock_settings['sysTbl'], $infoblock_settings['Sub_Class_ID'], $object_keyword, $result->get_resource_parameter('date'), true);
             if ($object_id) {
                 $result->set_resource_parameter('infoblock_id', $infoblock_settings['Sub_Class_ID']);
                 $result->set_resource_parameter('object_keyword', $real_object_keyword);
                 $result->set_resource_parameter('object_id', $object_id);
                 $result->truncate_remainder(strlen($object_keyword));
                 return true;
                 // --- RETURN ---
             }
         }
     }
     return false;
     // --- RETURN ---
 }
Exemple #3
0
 public function match(nc_routing_request $request, nc_routing_result $result)
 {
     $folder_id = $result->get_resource_parameter('folder_id');
     $date = $result->get_resource_parameter('date');
     if ($folder_id && nc_preg_match($this->get_keyword_regexp(), $result->get_remainder(), $matches)) {
         // Сначала попробовать максимально возможное совпадение;
         // затем, если есть возможность частичного совпадения —
         // более короткие варианты (для того, чтобы, к примеру,
         // была возможность использовать символ подчёркивания в
         // ключевых словах или "-" в качестве разделителя частей
         // адреса)
         $keyword_parts = nc_preg_split($this->get_keyword_delimiter(), $matches[1], -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
         $possible_keywords = array();
         while (sizeof($keyword_parts)) {
             $possible_keywords[] = join('', $keyword_parts);
             array_pop($keyword_parts);
         }
         $infoblocks_in_folder = nc_core::get_object()->sub_class->get_by_subdivision_id($folder_id);
         foreach ($possible_keywords as $keyword) {
             foreach ($infoblocks_in_folder as $infoblock) {
                 if ($infoblock['EnglishName'] == $keyword) {
                     // KEYWORD MATCH!
                     if ($date) {
                         $has_event_field = nc_core::get_object()->get_component($infoblock['Class_ID'])->get_date_field();
                         if (!$has_event_field) {
                             continue;
                         }
                     }
                     $result->set_resource_parameter('infoblock_id', $infoblock['Sub_Class_ID']);
                     $result->truncate_remainder(strlen($keyword));
                     return true;
                 }
             }
         }
     }
     return false;
 }
Exemple #4
0
 public function match(nc_routing_request $request, nc_routing_result $result)
 {
     $infoblock_id = $result->get_infoblock_id();
     if ($infoblock_id && preg_match('/^(\\d+)/', $result->get_remainder(), $matches)) {
         $object_id = $matches[0];
         $infoblock_settings = nc_core::get_object()->sub_class->get_by_id($infoblock_id);
         list($object_id, $real_object_keyword) = (array) ObjectExistsByID($infoblock_settings['Class_ID'], $infoblock_settings['sysTbl'], $object_id, $result->get_resource_parameter('date'), true);
         if ($object_id) {
             $result->set_resource_parameter('object_id', $object_id);
             $result->set_resource_parameter('object_keyword', $real_object_keyword);
             $result->truncate_remainder(strlen($object_id));
             return true;
         }
     }
     return false;
 }