Advertisement
Guest User

Untitled

a guest
Apr 21st, 2015
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.92 KB | None | 0 0
  1. <?php
  2. /**
  3.  *
  4.  */
  5. function new_search_show_found() {
  6.     $query = db_select('node', 'n')
  7.       ->fields('n', array('nid', 'title', 'type'));
  8.     $query = $query->extend('PagerDefault');
  9.     if ($_GET['search']) {
  10.         $output = ('<h1>' . t('Search results') . '<span>"' . $_GET['search'] . '"</span></h1>');
  11.  
  12.         $query->leftJoin('field_revision_field_promo', 'p', 'p.entity_id = n.nid');
  13.         $or = db_or();
  14.         $or->condition('field_promo_value', $_GET['search']);
  15.         $or->condition('title', '%' . $_GET['search'] . '%', 'LIKE');
  16.         $query->condition('type', 'page', '!=');
  17.         $query->condition($or);
  18.     } else {
  19.         $output = ('<h1>' . t('All promo') . '</h1>');
  20.         $query->condition('type', 'promo');
  21.     }
  22.     $query->orderBy('nid', 'DESC');
  23.     $query->limit(10);
  24.     $query = $query->execute();
  25.     $num = 1;
  26.     $output .= '<div class="akcia search">
  27.             <div class="items">';
  28.  
  29.     while($item = $query->fetchAssoc()){
  30.         if ($item['type'] == 'promo') {
  31.             $promo = node_load($item['nid']);
  32.             $shop = node_load($promo->field_promo_shop['und'][0]['nid']);
  33.             $output .= '<div class="item">';
  34.             $output .= '
  35.                    <div class="left">
  36.                         ' . theme_image(array('path' => $shop->field_shop_logo['und'][0]['uri'])) . '
  37.                         ' . l(t('Shop actions'), 'node/' . $shop->nid) . '
  38.                     </div>
  39.                     <div class="center">';
  40.                         //echo '<pre>';
  41.                         //print_r($promo);
  42.                         //echo '<pre>';
  43.                         // set taxonomy term id for Pop-Up
  44.                         $tid_popup = 133;
  45.                         // set taxonomy term id for iFrame
  46.                         $tid_iframe = 134;
  47.                         $nalias = drupal_get_path_alias('node/'.$promo->nid);
  48.                         if (isset($promo->field_promo_link_type['und'][0]['tid'])
  49.                           && intval($promo->field_promo_link_type['und'][0]['tid']) == $tid_popup){
  50.                             $output .= '<a href="http://promokoder.com.ua/'.$nalias.'?display=pop-up" class="pop-up-title-link" target="_blank"><h4>'.$promo->title.'</h4></a>';
  51.                         }else{
  52.                             if (isset($promo->field_promo_link_type['und'][0])
  53.                               && $promo->field_promo_link_type['und'][0]['tid']
  54.                               && intval($promo->field_promo_link_type['und'][0]['tid']) == $tid_iframe){
  55.                                 $output .= '<a href="http://promokoder.com.ua/'.$nalias.'?display=iframe" target="_blank"><h4>'.$promo->title.'</h4></a>';
  56.                             }else{
  57.                                 if (!isset($promo->field_promo_link_type['und'][0])){
  58.                                     $output .= '<a href="http://promokoder.com.ua/'.$nalias.'?display=pop-up" class="pop-up-title-link" target="_blank"><h4>'.$promo->title.'</h4></a>';
  59.                                 }
  60.                             }                  
  61.                         }
  62.            
  63.                         if (isset($promo->field_promo_to_date['und'][0]['value'])
  64.                           && strtotime($promo->field_promo_to_date['und'][0]['value']) >= time()){
  65.                             $output .= '<div class="close">
  66.                                 <span class="to-date">Окончание акции: <small>';
  67.                                
  68.                                 $getd = strtotime($promo->field_promo_to_date['und'][0]['value']);
  69.                                 $conv = date("d m Y", $getd);
  70.                                 $expl = explode(" ", $conv);
  71.                                 switch($expl[1]){
  72.                                     case 01:
  73.                                         $expl[1] = "января";
  74.                                         break;
  75.                                     case 02:
  76.                                         $expl[1] = "февраля";
  77.                                         break;
  78.                                     case 03:
  79.                                         $expl[1] = "марта";
  80.                                         break;
  81.                                     case 04:
  82.                                         $expl[1] = "апреля";
  83.                                         break;
  84.                                     case 05:
  85.                                         $expl[1] = "мая";
  86.                                         break;
  87.                                     case 06:
  88.                                         $expl[1] = "июня";
  89.                                         break;
  90.                                     case 07:
  91.                                         $expl[1] = "июля";
  92.                                         break;
  93.                                     case 08:
  94.                                         $expl[1] = "августа";
  95.                                         break;
  96.                                     case 09:
  97.                                         $expl[1] = "сентября";
  98.                                         break;
  99.                                     case 10:
  100.                                         $expl[1] = "октября";
  101.                                         break;
  102.                                     case 11:
  103.                                         $expl[1] = "ноября";
  104.                                         break;
  105.                                     case 12:
  106.                                         $expl[1] = "декабря";
  107.                                         break;
  108.                                    
  109.                                 }
  110.                                 $output .= '<div style="font-size: 14px; display: inline-block;">'.$expl[0].' '.$expl[1].', '.$expl[2].'</div>';
  111.                                
  112.                                 $output .= '</small></span>
  113.                             </div>';
  114.                         }
  115.             $output .= '       
  116.                         </div>
  117.                     <div class="right">';
  118.                         /*<div class="link">' . l(t('Show promo'), 'node/' . $promo->nid) . '</div>
  119.                         <span></span>
  120.                         <div class="hide"></div>*/
  121.                        
  122.                         if (isset($promo->field_promo_to_date['und'][0]['value'])
  123.                             && strtotime($promo->field_promo_to_date['und'][0]['value']) >= time()) {
  124.                             $tid_promocode = 131;
  125.                             $tid_action = 132;
  126.                             if (isset($promo->field_type_of_content['und'][0]['tid'])
  127.                             && intval($promo->field_type_of_content['und'][0]['tid']) == $tid_action){
  128.                                 $btn_text = "Перейти <br/>на акцию";
  129.                             }else{
  130.                                 if (isset($promo->field_type_of_content['und'][0]['tid'])
  131.                                 && intval($promo->field_type_of_content['und'][0]['tid']) == $tid_promocode){
  132.                                     $btn_text = "Показать промокод";
  133.                                 }else{
  134.                                     if (!isset($promo->field_type_of_content['und'][0])){
  135.                                         $btn_text = "Показать промокод";
  136.                                     }
  137.                                 }
  138.                             }      
  139.                                 $output .= '<div class="link">';
  140.                                     // set taxonomy term id for Pop-Up
  141.                                     $tid_popup = 133;
  142.                                     // set taxonomy term id for iFrame
  143.                                     $tid_iframe = 134;
  144.                                     $nalias = drupal_get_path_alias('node/'.$promo->nid);
  145.                                     if (isset($promo->field_promo_link_type['und'][0]['tid'])
  146.                                   && intval($promo->field_promo_link_type['und'][0]['tid']) == $tid_popup){
  147.                                         $output .= '<a href="http://promokoder.com.ua/'.$nalias.'?display=pop-up" target="_blank" class="pop-up-window">'.$btn_text.'</a>';    
  148.                                     }else{
  149.                                         if (isset($promo->field_promo_link_type['und'][0]['tid'])
  150.                                   && intval($promo->field_promo_link_type['und'][0]['tid']) == $tid_iframe){
  151.                                             $output .= '<a href="http://promokoder.com.ua/'.$nalias.'?display=iframe" target="_blank">'.$btn_text.'</a>';
  152.                                         }else{
  153.                                             if (!isset($promo->field_promo_link_type['und'][0])){
  154.                                                 $output .= '<a href="http://promokoder.com.ua/'.$nalias.'?display=pop-up" target="_blank" class="pop-up-window">'.$btn_text.'</a>';
  155.                                             }
  156.                                         }                  
  157.                                     }
  158.                                     if(!empty($promo->field_promo_count_reviews['und'][0]['value'])){
  159.                                         $vcount = ($promo->field_promo_count_reviews['und'][0]['value']);
  160.                                     }else{
  161.                                         $vcount = 1;
  162.                                     }
  163.                                 $output .= '
  164.                                     </div>
  165.                                 <span></span>
  166.                                 <div class="hide"><div class="reviews-counter"><p class="views-title">Воспользовались:</p><img src="'.base_path().'sites/all/themes/promo/img/person.png" class="i-promo"><div class="counter">'.$vcount.'</div></div></div>';
  167.                         }else{
  168.                         if(!empty($promo->field_promo_count_reviews['und'][0]['value'])){
  169.                                         $vcount = ($promo->field_promo_count_reviews['und'][0]['value']);
  170.                                     }else{
  171.                                         $vcount = 1;
  172.                                     }
  173.                             $output .= '
  174.                                 <div class="end">
  175.                                     <div class="over-text">'.t('Action is over').'</div>
  176.                                     <div class="reviews-counter"><p class="views-title">Воспользовались:</p><img src="'.base_path().'sites/all/themes/promo/img/person.png" class="i-promo"><div class="counter">'.$vcount.'</div></div>
  177.                                 </div>';
  178.                         }
  179.                        
  180.                        
  181.             $output .= '
  182.                     </div>
  183.                     </div>';
  184.         } else if ($item['type'] == 'brand'){
  185.             $output .= '
  186.            <div class="text">' .
  187.                 l($item['title'], drupal_get_path_alias('node/' . $item['nid'])) .
  188.                 '
  189.                </div>';
  190.         } else {
  191.             $output .= '
  192.            <div class="text">' .
  193.               l($item['title'], 'node/' . $item['nid']) .
  194.               '
  195.              </div>';
  196.         }
  197.         ++$num;
  198.     }
  199.     $output = $output . theme('pager', array('show_next' => TRUE), $quantity = 5) . '
  200.    </div>
  201.    </div>';
  202.     return $output;
  203. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement