Example #1
0
 /**
  * возвращает HTML-код для дерева компаний и групп заданного рекламодателя
  *
  * @param integer id_entity код учетной записи выбранного рекламодателя
  * @param string e_mail адрес электронной почты рекламодателя
  * @param int $id_group группа, которую не стоит показывать
  * @return string HTML-код дерева
  */
 public function get_html_tree($id_entity, $e_mail, $id_group = 0, $campaign_type_filter = 'all')
 {
     $top = new jQTreeNode();
     $code_entity = type_to_str($id_entity, 'textcode');
     $top->setId('user' . $code_entity);
     $top->setOnClick("show_campaigns('{$code_entity}')");
     $campaigns = array();
     switch ($campaign_type_filter) {
         case 'cpm_flatrate':
             $this->db->where('campaigns.id_campaign_type', 'cpm_flatrate');
             $top->setCaption(__('All CPM/Flat Rate Campaigns'));
             break;
         default:
             $top->setCaption(__('All Campaigns'));
     }
     $this->db->select('id_group, groups.name AS group_name, campaigns.id_campaign AS id_campaign, campaigns.name AS campaign, id_campaign_type');
     $this->db->from('campaigns');
     $this->db->join('groups', 'campaigns.id_campaign = groups.id_campaign AND id_group <> ' . $this->db->escape($id_group) . ' AND groups.status != "deleted"', 'LEFT');
     $this->db->where(array('id_entity_advertiser' => $id_entity, 'campaigns.status !=' => 'deleted'));
     //$this->db->where("(groups.status != 'deleted' OR groups.status is NULL)", '', FALSE);
     $this->db->order_by('campaign ASC, group_name ASC');
     $res = $this->db->get();
     $this->EmptyTree = $res->num_rows() == 0;
     foreach ($res->result() as $row) {
         $code_campaign = type_to_str($row->id_campaign, 'textcode');
         $id_campaign_type = $row->id_campaign_type;
         $campaign_node = 'camp' . $code_campaign;
         if (!in_array($row->id_campaign, $campaigns)) {
             $campaigns[] = $row->id_campaign;
             ${$campaign_node} = new jQTreeNode();
             ${$campaign_node}->setCaption($row->campaign);
             ${$campaign_node}->setId($campaign_node);
             ${$campaign_node}->setOnClick("show_groups('{$code_campaign}', '{$id_campaign_type}')");
             ${$campaign_node}->setClass($row->id_campaign_type);
             $top->add(${$campaign_node});
         }
         if ($row->group_name != '') {
             $code_group = type_to_str($row->id_group, 'textcode');
             $group_node = 'group' . $code_group;
             ${$group_node} = new jQTreeNode();
             ${$group_node}->setCaption($row->group_name);
             ${$group_node}->setId($group_node);
             ${$group_node}->setOnClick("show_ads('{$code_group}', '', '{$id_campaign_type}')");
             ${$campaign_node}->add(${$group_node});
         }
     }
     $tree = new jQTree();
     $tree->setModel($top);
     $tree->setId('groups_tree');
     return $tree->getTree();
 }
Example #2
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();
 }