Source for file places.component.php

  1. <?php
  2.  
  3.  
  4. /**
  5.  * $Id: places.component.php 691 2008-04-07 13:55:39Z serov $
  6.  *
  7.  * @package Mediadaily.ru
  8.  * @author Vendelev Artiom
  9.  */
  10.  
  11. class places_component extends component_view {
  12.  
  13.     /**
  14.     * Current place id.
  15.     * @var integer 
  16.     */
  17.     protected $current_place;
  18.     
  19.     protected function init({
  20.         $this->tree $this->obj->places->tree;
  21.     }
  22.     
  23.     public function GetCountry($params{//exit;
  24.         $name    trim(urldecode($params['params'][0]));
  25.         $placeId $params['params'][1];
  26.         $limit   $params['params'][3];
  27.         $page    $params['params'][4];
  28.         if (!$name{
  29.             $results $this->obj->places->GetPopularCountries(0$page$limit$limit);
  30.  
  31.             $result=array();
  32.             foreach($results as $res){
  33.                 $result[]=$res;
  34.             }
  35.             $data['data']  $result;
  36.             $num_rows $this->obj->places->getChildNodesCount(1);
  37.             if($num_rows){
  38.                 $num_rows+=$limit;
  39.             }
  40.         else {
  41.             $result        $this->obj->places->GetCountry($placeId$name$page$limittrue);
  42.             $data['data']  $result['data'];
  43.             $num_rows $result['num_rows'];
  44.         }
  45.  
  46.         $data['pages'Core::PageLister($limit$num_rows$page);
  47.         $this->GetSuggest($params$data);
  48.     }
  49.     
  50.     public function GetRegion($params{
  51.         $name    trim(urldecode($params['params'][0]));
  52.         $placeId $params['params'][1];
  53.         $limit   $params['params'][3];
  54.         $page    $params['params'][4];
  55.  
  56.         $result        $this->obj->places->GetRegion($placeId$name$page$limittrue);
  57.         $data['data']  $result['data'];
  58.         $data['pages'Core::PageLister($limit$result['num_rows']$page);
  59.         $this->GetSuggest($params$data);
  60.     }
  61.     
  62.     public function GetCity($params{
  63.         $name     trim(urldecode($params['params'][0]));
  64.         $placeId  $params['params'][1];
  65.         $limit    $params['params'][3];
  66.         $page     $params['params'][4];
  67.         
  68.         $result        $this->obj->places->GetCity($placeId$name$page$limittrue);
  69.         $data['data']  $result['data'];
  70.         $data['pages'Core::PageLister($limit$result['num_rows']$page);
  71.         $this->GetSuggest($params$data);
  72.     }
  73.     
  74.  
  75.   public function GetRegionCities($params{
  76.     $url explode('/' CFG_COMPONENT_PARAMS);
  77.     array_shift($url)array_shift($url);
  78.             $places_data $this->obj->places->GetLevel($this->current_place);
  79.             $places_cnt count($places_data1;
  80.             $region array_shift($places_data);
  81.             $places array (
  82.                 'cnt_records' => $places_cnt,
  83.                 'records' => array (
  84.                     $region['place_full_name'=> $places_data
  85.                 )
  86.             );
  87.             $type '';//not need
  88.             $template 'region';
  89.  
  90.         $this->obj->tpl->Assign(array (
  91.             'current_title' => _('Choose a city'),
  92.             'places' => $places,
  93.             'type' => $type,
  94.             'cols' => $this->obj->places->PrepareColCount($places['cnt_records']),
  95.             'component_params' => implode('/'$url)
  96.         ));
  97.  
  98.         $this->obj->tpl->Display'places/' $template '.tpl');
  99.   }
  100.   public function GetAllCities($params{
  101.     include_once (CFG_APP_ROOT."/config/cities_config.php");
  102.     global $main_cities;
  103.     $url explode('/' CFG_COMPONENT_PARAMS);
  104.     array_shift($url)array_shift($url);
  105.  
  106.     $type = isset($url[0]$url[0'abc';
  107.     if $type === 'abc'){
  108.       //$places = $this->obj->places->GetCitiesSortByAbc();
  109.       if $alphabet $this->GetAlphabet()){
  110.         $arr array ('current_title' => _('Choose a city by alphabet')'alphabet' => $alphabet);
  111.         $this->obj->tpl->Assign(array ('current_title' => _('Choose a city by alphabet') ) );
  112.         $this->obj->tpl->Assign(array ('alphabet' => $alphabet ) );
  113.         if in_arrayurldecode($url[1]$alphabet) ){
  114.           $places $this->obj->places->GetCitiesSortBySymbol(urldecode($url[1]));
  115.           $arr['current_symbol'urldecode($url[1]);
  116.           array_shift($url);
  117.         else {
  118.           $places $this->obj->places->GetCitiesSortBySymbol($alphabet[0]);
  119.           $arr['current_symbol'$alphabet[0];
  120.         }
  121.         $this->obj->tpl->Assign$arr );
  122.         $template 'allplaces';
  123.       }
  124.     else {
  125.       $template 'region_places';
  126.       $places $this->obj->places->GetCitiesSortByRegion();
  127.       $this->obj->tpl->Assign(array ('current_title' => _('Choose a city by region')));
  128.     }
  129.     array_shift($url);
  130.     $this->obj->tpl->Display('places/' $template '.tpl'array(
  131.       'places' => $places['records'],
  132.       'main_cities' => $main_cities,
  133.       'cnt_places' => $places['cnt_records'],
  134.       'type' => $type,
  135.       'component_params' => implode('/'$url)
  136.     ));
  137.   }
  138.   
  139.   public function GetPopularCountries($params{
  140.         $page $params['params'][0];
  141.         $limit $params['params'][1];
  142.         $country_id $params['params'][2];
  143.         $selected_place $params['params'][2];
  144.         $search_name trim(urldecode(@$params['params'][3]));
  145.         $auto @$params['params'][4];
  146.         $add_limit 5;
  147.         $num_rows $this->obj->places->getChildNodesCount(1);
  148.         if (!$search_name{
  149.             $pages Core::PageLister($limit$num_rows$page5$add_limit($num_rows ($add_limit $limit)) true false);
  150.             $countries $this->obj->places->GetPopularCountries($country_id$page$limit@$pages['query_limit'$pages['query_limit'0);
  151.         else 
  152.             $countries $this->obj->places->GetCountry(1$search_name$page$limittrue0);
  153.             $num_rows $countries['num_rows'];
  154.             $pages Core::PageLister($limit$num_rows$page5$add_limitfalse);
  155.             $countries $this->obj->places->GetCountry(1$search_name$page$limitfalse@$pages['query_limit'$pages['query_limit'0);
  156.         }
  157.         $selected_place (count($countries== 1$countries[array_pop(array_keys($countries))]['id'$selected_place;
  158.         $this->obj->tpl->Assign(array(
  159.             'countries' => $countries,
  160.             'block_type' => 'country',
  161.             'block_type_plural' => 'Countries',
  162.             'country_id' => $country_id,
  163.             'selected_place' => $selected_place,
  164.             'search_name' => $search_name,
  165.             'data' => array('pages' => $pages),
  166.         ));
  167.         $content $this->obj->tpl->Fetch('sch_users/registration/registration_school-choice__select-place.tpl');
  168.         
  169.         $js '';
  170.         if ($auto != && $selected_place)
  171.             $js 'changecountry('.$selected_place.');';
  172.         if (count($countries== 1)
  173.             $js .= ' changecountry('.$countries[array_pop(array_keys($countries))]['id'].', 2);';
  174.             
  175.         $this->Ajax('top_countries'$content$js);
  176.       
  177.   }
  178.   public function GetPopularRegions($params{
  179.         if (sizeof($params['params']3)
  180.             return ;
  181.         $page = (int)$params['params'][0];
  182.         $limit = (int)$params['params'][1];
  183.         $country_id = (int)$params['params'][2];
  184.         $selected_place @$params['params'][3];
  185.         $search_name trim(urldecode(@$params['params'][4]));
  186.         $auto @$params['params'][5];
  187.         $add_limit 5;
  188.         $num_rows $this->obj->places->getChildNodesCount($country_id);
  189.         if (!$search_name){
  190.             $pages Core::PageLister($limit$num_rows$page5$add_limit($num_rows ($add_limit $limit)) true false);
  191.             $regions $this->obj->places->GetPopularRegions($country_id$page$limit$selected_place@$pages['query_limit'$pages['query_limit'0);
  192.         }
  193.         else {
  194.             $regions $this->obj->places->GetRegion((int)$country_id$search_name$page$limittrue0);
  195.             $num_rows $regions['num_rows'];
  196.             $pages Core::PageLister($limit$num_rows$page5$add_limitfalse);
  197.             $regions $this->obj->places->GetRegion((int)$country_id$search_name$page$limitfalse@$pages['query_limit'$pages['query_limit'0);
  198.         }
  199.         $selected_place (count($regions== 1$regions[array_pop(array_keys($regions))]['id'$selected_place;
  200.         $this->obj->tpl->Assign(array(
  201.             'countries' => $regions,
  202.             'block_type' => 'region',
  203.             'block_type_plural' => 'Regions',
  204.             'country_id' => $country_id,
  205.             'selected_place' => $selected_place,
  206.             'search_name' => $search_name,
  207.             'data' => array('pages' => $pages),
  208.         ));
  209.         $content $this->obj->tpl->Fetch('sch_users/registration/registration_school-choice__select-place.tpl');
  210.         
  211.         //$content = print_r($params['params'], true);
  212.         $js ($auto != && $selected_place'changeregion('.$selected_place.');' '';
  213.         if (count($regions== 1)
  214.             $js .= ' changeregion('.$regions[array_pop(array_keys($regions))]['id'].', 2);';
  215.         
  216.  
  217.         $this->Ajax('top_regions'$content$js);
  218.   }
  219.   public function GetPopularCities($params{
  220.         if (sizeof($params['params']3)
  221.             return ;
  222.         $page $params['params'][0];
  223.         $limit $params['params'][1];
  224.         $region_id $params['params'][2];
  225.         $selected_place @$params['params'][3];
  226.         $search_name trim(urldecode(@$params['params'][4]));
  227.         $add_limit 5;
  228.         $num_rows $this->obj->places->getChildNodesCount($region_id);
  229.         if (!$search_name{
  230.             $pages Core::PageLister($limit$num_rows$page5$add_limit($num_rows ($add_limit $limit)) true false);
  231.             $cities $this->obj->places->GetPopularCities($region_id$page$limit$selected_place@$pages['query_limit'$pages['query_limit'0);
  232.         }
  233.         else {
  234.             $cities $this->obj->places->GetCity((int)$region_id$search_name$page$limittrue0);
  235.             $num_rows $cities['num_rows'];
  236.             $pages Core::PageLister($limit$num_rows$page5$add_limitfalse);
  237.             $cities $this->obj->places->GetCity((int)$region_id$search_name$page$limitfalse@$pages['query_limit'$pages['query_limit'0);
  238.         }
  239.         $selected_place (count($cities== 1$cities[array_pop(array_keys($cities))]['id'$selected_place;
  240.         $this->obj->tpl->Assign(array(
  241.             'countries' => $cities,
  242.             'block_type' => 'city',
  243.             'block_type_plural' => 'Cities',
  244.             'country_id' => $region_id,
  245.             'selected_place' => $selected_place,
  246.             'search_name' => $search_name,
  247.             'data' => array('pages' => $pages),
  248.         ));
  249.         $content $this->obj->tpl->Fetch('sch_users/registration/registration_school-choice__select-place.tpl');
  250.         
  251.         //$content = print_r($cities, true);
  252.         $js $selected_place 'changecity('.$selected_place.');' '';
  253.         if (count($cities== 1)
  254.             $js .= ' changecity('.$cities[array_pop(array_keys($cities))]['id'].', 2);';
  255.         
  256.  
  257.         $this->Ajax('top_cities'$content$js);
  258.   }
  259.   
  260. }
  261. ?>

Documentation generated on Thu, 03 Mar 2011 20:12:09 +0300 by phpDocumentor 1.4.3