Example #1
0
 /**
  * @return nc_search_rule|NULL
  */
 public function get_rule()
 {
     if ($this->get('rule_id')) {
         try {
             $rule = new nc_search_rule();
             return $rule->load($this->get('rule_id'));
         } catch (Exception $e) {
             return null;
         }
     }
     return null;
 }
Example #2
0
 /**
  * @param string|int|array $area_string  строка, описывающая область поиска
  *    ^\d$:  load *rule* with that ID from the database
  *     subX., subX, subX*, -subX etc; siteX etc; allsites
  *     /path, /path/*, /path., site.com;
  *   array of nc_search_area_part: set area parts
  * @param integer $site_id (для резолвинга неполных путей)
  * @throws nc_search_exception
  */
 public function __construct($area_string = null, $site_id = null)
 {
     // Если на входе одно число, рассматривать его как ID *правила*
     if (ctype_digit($area_string) || is_int($area_string)) {
         $this->set('rule_id', (int) $area_string);
         $rule = new nc_search_rule();
         $rule->load($area_string);
         $this->set_area($rule->get_area_string(), $rule->get('site_id'));
     } elseif (is_string($area_string)) {
         $this->set_area($area_string, $site_id);
     } elseif (is_array($area_string)) {
         $this->parts = $area_string;
     } else {
         // if ($area_string instanceof self) { // actually that's an error!
         // we could gracefully copy another area properties, but we won't!
         throw new nc_search_exception("Wrong \$area_string parameter");
     }
 }