Пример #1
0
 /**
  * возвращает фильтрованный по таргетингу список континентов/стран в виде дерева
  *
  * @param integer $id_targeting_group код группы таргетинга
  * @param boolean $allowed фильтр (true - возвращает разрешенные страны, false - запрещенные)
  * @param boolean $all_denied случай, когда запрещены все страны
  * @return string HTML-код дерева списка
  */
 public function get_tree($id_targeting_group, $allowed, $all_denied)
 {
     $values_count = $this->get_targeting_count($id_targeting_group);
     if ($values_count == 0) {
         if ($all_denied) {
             if ($allowed) {
                 return '';
             }
         } else {
             if (!$allowed) {
                 return '';
             }
         }
         $res = $this->db->select('iso, c.name AS country, c.unicode_name, con.name AS continent, con.id_continent')->from('countries c')->join('continents con', 'c.id_continent=con.id_continent')->where('banned <>', 'true')->order_by('continent')->order_by('country')->get();
     } else {
         $not = $allowed ? ' NOT' : '';
         $res = $this->db->select('iso, c.name AS country, c.unicode_name, con.name AS continent, con.id_continent')->from('countries c')->join('continents con', 'c.id_continent=con.id_continent')->join('targeting_group_values tgv', "c.iso=tgv.value AND tgv.id_targeting_group={$id_targeting_group} AND tgv.group='countries'", 'LEFT')->where('banned <>', 'true')->where("id_targeting_group_value IS{$not} NULL")->order_by('continent')->order_by('country')->get();
     }
     $type = $allowed ? 'allowed' : 'denied';
     $top = new jQTreeNode();
     $top->setCaption(__('All Countries'));
     $top->setId($type . '_all_countries');
     $top->setOnClick("");
     $countries = array();
     foreach ($res->result() as $row) {
         $countries[$row->id_continent]['name'] = $row->continent;
         $name = $row->country;
         if ("" != $row->unicode_name) {
             $name .= " (" . $row->unicode_name . ")";
         }
         $countries[$row->id_continent]['list'][$row->iso] = $name;
     }
     foreach ($countries as $id_continent => $continent) {
         $continent_node = new jQTreeNode();
         $continent_node->setCaption(_($continent['name']));
         $id = $continent['name'] == 'Unknown' ? $type . '_country_UN' : $type . "_continent_" . $id_continent;
         $continent_node->setId($id);
         $continent_node->setOnClick("countries_switch_selection('{$id}')");
         $top->add($continent_node);
         foreach ($continent['list'] as $iso => $name) {
             if ($name == 'Unknown') {
                 continue;
             }
             $country_node = new jQTreeNode();
             $country_node->setCaption($name);
             $id = $type . '_country_' . $iso;
             $country_node->setID($id);
             $country_node->setOnClick("countries_switch_selection('{$id}')");
             $continent_node->add($country_node);
         }
     }
     $tree = new jQTree();
     $tree->setModel($top);
     $tree->setId($type . '_country_tree');
     return $tree->getTree();
 }