Advertisement
AndreyKlipikov

Vip tools

Jan 23rd, 2014
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.06 KB | None | 0 0
  1.     public function actionVip()
  2.     {
  3.         $cats = Categories::model()->findAll();
  4.         $list = '<select size="1" id="list">' . PHP_EOL . '<option value="0">Выберите категорию рекомендуемых:</option>' . PHP_EOL;
  5.         foreach($cats as $item)
  6.             $list .= '<option value="' . $item->id . '">' . $item->name . '</option>' . PHP_EOL;
  7.         $list .= '</select>';
  8.         $this->render('vip', array(
  9.             'list'=>$list,
  10.         ));
  11.     }
  12.    
  13.     public function actionGetvipcats()
  14.     {
  15.         $result = "";
  16.         $cat_id = $_GET['id'];
  17.         if ($cat_id > 0) {
  18.             $criteria = new CDbCriteria(array('order'=>'position DESC'));
  19.             $companies = Vip::model()->findAllByAttributes(array("category_id"=>$cat_id), $criteria);
  20.             $places = Array();
  21.             for($i = 0; $i < 15; $i++)
  22.                 $places[$i] = '<div class="item i' . $i . ' empty"><div class="panel"><a href="javascript:vipmove(' . $cat_id . ', ' . ($i + 1) . ', \'up\')" class="up"></a> <a href="javascript:vipmove(' . $cat_id . ', ' . ($i + 1) . ', \'down\')" class="down"></a> <a href="/admin/catalog/vipedit/?cat_id=' . $cat_id . '&position=' . ($i + 1) . '" class="edit"></a></div><div class="text">Пусто</div></div>';
  23.             foreach($companies as $item) {
  24.                 $company = Catalog::model()->findByPk($item->company_id);
  25.                 $places[$item->position - 1] = '<div class="item i' . ($item->position - 1) . ' busy"><div class="panel"><a href="javascript:vipmove(' . $cat_id . ', ' . $item->position . ', \'up\')" class="up"></a> <a href="javascript:vipmove(' . $cat_id . ', ' . $item->position . ', \'down\')" class="down"></a> <a href="/admin/catalog/vipedit/?cat_id=' . $cat_id . '&position=' . $item->position . '" class="edit"></a> <a href="javascript:vipdelete(' . $cat_id . ', ' . $item->position . ')" class="delete"></a></div><div class="image">' . (strlen($company->image_link) > 3 ? '<img src="/upload/' . ($company->id % 100) . '/' . $company->image_link . '" border="0" />' : '') . '</div><div class="text">' . $company->name . '</div></div>';
  26.             }
  27.             $places[0] = str_replace("item", "item first", $places[0]);
  28.             $places[14] = str_replace("item", "item last", $places[14]);
  29.             $result = implode(PHP_EOL, $places);
  30.         }
  31.         echo $result;
  32.     }
  33.    
  34.     public function actionGetvipcoms()
  35.     {
  36.         $companies = '<select name="company_id" size="1" id="coms"><option>Выберите категорию</option>';
  37.         $coms = Catalog::model()->findAllByAttributes(array("category"=>$_GET['cat_id']));
  38.         foreach($coms as $item)
  39.             $companies .= '<option value="' . $item->id . '">' . $item->name . '</option>' . PHP_EOL;
  40.         $companies .= '</select>';
  41.         echo $companies;
  42.     }
  43.    
  44.     public function actionVipedit()
  45.     {
  46.         $companies = '<select name="company_id" size="1" id="coms"><option>Выберите категорию</option>';
  47.         $position = Vip::model()->find('position=' . $_GET['position'] . ' and category_id=' . $_GET['cat_id']);
  48.         $id = $position === null ? 0 : $position->id;
  49.         $real_cat = 0;
  50.         $cats = Categories::model()->findAll();
  51.        
  52.         $categories = '<select size="1" id="cats" name="category_id">' . PHP_EOL;
  53.         foreach($cats as $item)
  54.             $categories .= '<option value="' . $item->id . '"' . ($item->id == $_GET['cat_id'] ? ' selected="selected"' : '') . '>' . $item->name . '</option>' . PHP_EOL;
  55.         $categories .= '</select>';
  56.        
  57.         if ($id > 0) {
  58.             $real_cat = Catalog::model()->find('id=' . $position->company_id)->category;
  59.             $coms = Catalog::model()->findAllByAttributes(array("category"=>$real_cat));
  60.             foreach($coms as $item)
  61.                 $companies .= '<option value="' . $item->id . '"' . ($id > 0 && $position->company_id == $item->id ? ' selected="selected"' : '') . '>' . $item->name . '</option>' . PHP_EOL;
  62.         }
  63.        
  64.         $com_categories = '<select size="1" id="com_cats">' . ($real_cat == 0 ? '<option>Выберите категорию</option>' : '') . PHP_EOL;
  65.         foreach($cats as $item)
  66.             $com_categories .= '<option value="' . $item->id . '"' . ($item->id == $real_cat ? ' selected="selected"' : '') . '>' . $item->name . '</option>' . PHP_EOL;
  67.         $com_categories .= '</select>';
  68.        
  69.         $companies .= '</select>';
  70.         if (!empty($position->company_id)) {
  71.            
  72.         }
  73.         $this->render('vipedit', array(
  74.             'com_categories'=>$com_categories,
  75.             'categories'=>$categories,
  76.             'companies'=>$companies,
  77.             'position'=>$_GET['position'],
  78.             'id'=>$id
  79.         ));
  80.     }
  81.    
  82.     public function actionVipsave()
  83.     {
  84.         $vip = Vip::model()->find('position=' . $_POST['position'] . ' and category_id=' . $_POST['category_id']);
  85.         if ($vip === null) {
  86.             $item = new Vip();
  87.             $item->company_id = $_POST['company_id'];
  88.             $item->category_id = $_POST['category_id'];
  89.             $item->position = $_POST['position'];
  90.             $item->save(false);
  91.         } else {
  92.             $vip->company_id = $_POST['company_id'];
  93.             $vip->save(false);
  94.         }
  95.         $this->redirect(array('vip'));
  96.     }
  97.    
  98.     public function actionVipdelete()
  99.     {
  100.         Vip::model()->find('position=' . $_GET['position'] . ' and category_id=' . $_GET['cat_id'])->delete();
  101.         echo 'OK';
  102.     }
  103.    
  104.     public function actionVipup()
  105.     {
  106.         $up = Vip::model()->find('position=' . ((int)$_GET['position'] - 1) . ' and category_id=' . $_GET['cat_id']);
  107.         $now = Vip::model()->find('position=' . $_GET['position'] . ' and category_id=' . $_GET['cat_id']);
  108.        
  109.         if ($up !== null || $now !== null) {
  110.             if ($up === null) {
  111.                 $now->position = ((int)$_GET['position'] - 1);
  112.                 if ($now->save())
  113.                     echo 'OK';
  114.             } else {
  115.                 $up->position = $_GET['position'];
  116.                 $now->position = ((int)$_GET['position'] - 1);
  117.                 if ($now->save(false) && $up->save(false))
  118.                     echo 'OK';
  119.             }
  120.         }
  121.     }
  122.    
  123.     public function actionVipdown()
  124.     {
  125.         $down = Vip::model()->find('position=' . ((int)$_GET['position'] + 1) . ' and category_id=' . $_GET['cat_id']);
  126.         $now = Vip::model()->find('position=' . $_GET['position'] . ' and category_id=' . $_GET['cat_id']);
  127.        
  128.         if ($down !== null || $now !== null) {
  129.             if ($down === null) {
  130.                 $now->position = ((int)$_GET['position'] + 1);
  131.                 if ($now->save())
  132.                     echo 'OK';
  133.             } else {
  134.                 $down->position = $_GET['position'];
  135.                 $now->position = ((int)$_GET['position'] + 1);
  136.                 if ($now->save(false) && $down->save(false))
  137.                     echo 'OK';
  138.             }
  139.         }
  140.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement