/** * Search sites according to specified criteria * * @return void */ public function search_sites() { //load nessesary components $this->load->model('pagination_post'); $filter_mode = $this->input->post('filter_mode'); $this->load->helper('periods_helper'); $siteModel = new Sppc_SiteModel(); //initialize table builder $this->table_builder->clear(); $this->table_builder->init_sort_vars('search_sites_cpc', 'url', 'asc'); $col_index = 0; $col_alias = array('url' => $col_index++, 'impressions' => $col_index++, 'clicks' => $col_index++, 'min_bid' => $col_index++, 'min_bid_image' => $col_index++, 'action' => $col_index++); $this->table_builder->sorted_column($col_alias['url'], 'url', "Site", 'asc'); $this->table_builder->sorted_column($col_alias['impressions'], 'impressions', "Monthly Traffic Volume", 'asc'); $this->table_builder->sorted_column($col_alias['clicks'], 'clicks', "Clicks", 'asc'); $this->table_builder->sorted_column($col_alias['min_bid'], 'min_cpc', "Min Bid Text", 'asc'); $this->table_builder->sorted_column($col_alias['min_bid_image'], 'min_cpc_image', "Min Bid Image", 'asc'); $this->table_builder->set_cell_content(0, $col_alias['action'], __('Action')); $this->table_builder->cell(0, $col_alias['action'])->add_attribute('class', 'simpleTitle'); // set table attributes $this->table_builder->add_attribute('class', 'xTable'); //or set style here $this->table_builder->add_row_attribute(0, 'class', 'th f9px'); $this->table_builder->add_col_attribute($col_alias['action'], 'class', 'center'); $this->table_builder->insert_empty_cells = false; // initialize page browser $this->pagination_post->clear(); $this->pagination_post->set_form_name('search_sites_cpc'); //initialize from config $form_data = array("name" => "search_sites_cpc_form", "view" => "advertiser/manage_ads/campaigns/creation/select_sites/jframe_search_sites.html", "action" => $this->site_url . $this->index_page . "advertiser/create_campaign_step_select_sites/search_sites", 'fields' => array('filter_mode' => array('id_field_type' => 'string', 'form_field_type' => 'hidden', 'default' => $filter_mode))); //initialize search filter object $dateRange = data_range(array('mode' => 'select', 'period' => 'lastmonth')); $statStartDate = new Zend_Date($dateRange['from'], Zend_Date::TIMESTAMP); $statEndDate = new Zend_Date($dateRange['to'], Zend_Date::TIMESTAMP); $searchFilter = new Sppc_Site_SearchFilter(); $searchFilter->setConnectToStats(true, $statStartDate, $statEndDate)->setHasCpc(true); // according to filter mode configure search filter object switch ($filter_mode) { case 'all': //show all active sites break; case 'by_category': // search sites by category $categories = array(); $id_category = $this->input->post('id_category'); $include_subcats = $this->input->post('include_subcats'); if ($id_category) { $categoryModel = new Sppc_CategoryModel(); $category = $categoryModel->findObjectById($id_category); if (!is_null($category)) { $categories[] = $category; if ($include_subcats == 'true') { $categories = array_merge($categories, $category->getChildCategories(true)); } } $this->table_builder->insert_empty_cells = false; $form_data['fields']['id_category'] = array('id_field_type' => 'int', 'form_field_type' => 'hidden', 'default' => $id_category); $form_data['fields']['include_subcats'] = array('id_field_type' => 'string', 'form_field_type' => 'hidden', 'default' => $include_subcats); } $searchFilter->setCategories($categories); break; case 'by_name': // search sites by id $siteIds = array(); $id_site = $this->input->post('id_site'); if ($id_site) { $form_data['fields']['id_site'] = array('id_field_type' => 'string', 'form_field_type' => 'hidden', 'default' => $id_site); $id_site = explode(',', $id_site); foreach ($id_site as $site) { $siteIds[] = type_cast($site, 'textcode'); } } $searchFilter->setSiteId($siteIds); break; case 'by_price': // search sites by bid $bid = $this->input->post('price'); $cpcBidType = $this->input->post('cpc_bid_type'); $cpcBidType = in_array($cpcBidType, array('text', 'image')) ? $cpcBidType : false; if ($bid && $cpcBidType) { $form_data['fields']['price'] = array('id_field_type' => 'positive_float', 'form_field_type' => 'hidden', 'default' => type_to_str($bid, 'float')); $form_data['field']['cpc_bid_type'] = array('id_field_type' => 'string', 'form_field_type' => 'hidden', 'default' => $cpcBidType); switch ($cpcBidType) { case 'text': $searchFilter->setMaximumTextBid($bid); break; case 'image': $searchFilter->setMaximumImageBid($bid); break; } } break; } $sitesCount = $siteModel->getCount($searchFilter); $this->pagination_post->set_total_records($sitesCount); $this->pagination_post->read_variables('search_sites_cpc', 1, 10); $sites = $siteModel->search($searchFilter, $this->table_builder->sort_field . ' ' . $this->table_builder->sort_direction, $this->pagination_post->get_per_page(), $this->pagination_post->get_page()); $rowsCount = count($sites); if ($rowsCount > 0) { $rowCounter = 1; foreach ($sites as $site) { // url $this->table_builder->set_cell_content($rowCounter, $col_alias['url'], array('name' => $site->getUrl(), 'href' => 'http://' . $site->getUrl(), 'extra' => 'target="_blank"'), 'link'); $this->table_builder->add_cell_content($rowCounter, $col_alias['url'], '<br>' . limit_str_and_hint($site->getName(), 30)); // last month traffic $this->table_builder->set_cell_content($rowCounter, $col_alias['impressions'], type_to_str($site->getImpressions(), 'impressions')); // Clicks $this->table_builder->set_cell_content($rowCounter, $col_alias['clicks'], type_to_str($site->getClicks(), 'clicks')); // Min bid for text ads $cellContent = ' <span class="min_bid_text">' . type_to_str($site->getMinCpc(), 'money') . ' <span class="hide min_bid_value">' . type_to_str($site->getMinCpc(), 'float') . '</span> </span>'; $this->table_builder->set_cell_content($rowCounter, $col_alias['min_bid'], $cellContent); // Min bid for image ads $cellContent = ' <span class="min_image_bid_text">' . type_to_str($site->getMinCpcImage(), 'money') . ' <span class="hide min_image_bid_value">' . type_to_str($site->getMinCpcImage(), 'float') . ' </span> </span>'; $this->table_builder->set_cell_content($rowCounter, $col_alias['min_bid_image'], $cellContent); // Actions $this->table_builder->set_cell_content($rowCounter, $col_alias['action'], array('name' => __('Add'), 'href' => '#', 'extra' => 'value="{@Add@}" title="{@Add@}" class="guibutton floatl ico ico-plusgreen" jframe="no" onclick="return addSiteToGroup(\'' . type_to_str($site->getId(), 'textcode') . '\');"'), 'link'); // add attribute for row $this->table_builder->add_row_attribute($rowCounter, 'id_site', type_to_str($site->getId(), 'textcode')); $rowCounter++; } } else { $this->table_builder->set_cell_content(1, 0, __('Records not found')); $this->table_builder->cell(1, 0)->add_attribute('colspan', count($col_alias)); $this->table_builder->cell(1, 0)->add_attribute('class', 'nodata'); } // Устанавливаем возможность выбора колонок $this->table_builder->use_select_columns(); $invariable_columns = array($col_alias['url'], $col_alias['action']); $this->table_builder->set_invariable_columns($invariable_columns); $sites_table = $this->table_builder->get_sort_html(); $this->template = "common/parent/jq_iframe.html"; $form_content = $this->form->get_form_content('create', $form_data, $this->input, $this); $form_content = str_replace('<%SITES_TABLE%>', $sites_table, $form_content); $form_content = str_replace('<%COLUMNS%>', $this->table_builder->get_columns_html(), $form_content); $form_content = str_replace('<%PAGINATION%>', $this->pagination_post->create_form(), $form_content); $this->_set_content($form_content); $this->_display(); }