Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function actionVip()
- {
- $cats = Categories::model()->findAll();
- $list = '<select size="1" id="list">' . PHP_EOL . '<option value="0">Выберите категорию рекомендуемых:</option>' . PHP_EOL;
- foreach($cats as $item)
- $list .= '<option value="' . $item->id . '">' . $item->name . '</option>' . PHP_EOL;
- $list .= '</select>';
- $this->render('vip', array(
- 'list'=>$list,
- ));
- }
- public function actionGetvipcats()
- {
- $result = "";
- $cat_id = $_GET['id'];
- if ($cat_id > 0) {
- $criteria = new CDbCriteria(array('order'=>'position DESC'));
- $companies = Vip::model()->findAllByAttributes(array("category_id"=>$cat_id), $criteria);
- $places = Array();
- for($i = 0; $i < 15; $i++)
- $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>';
- foreach($companies as $item) {
- $company = Catalog::model()->findByPk($item->company_id);
- $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>';
- }
- $places[0] = str_replace("item", "item first", $places[0]);
- $places[14] = str_replace("item", "item last", $places[14]);
- $result = implode(PHP_EOL, $places);
- }
- echo $result;
- }
- public function actionGetvipcoms()
- {
- $companies = '<select name="company_id" size="1" id="coms"><option>Выберите категорию</option>';
- $coms = Catalog::model()->findAllByAttributes(array("category"=>$_GET['cat_id']));
- foreach($coms as $item)
- $companies .= '<option value="' . $item->id . '">' . $item->name . '</option>' . PHP_EOL;
- $companies .= '</select>';
- echo $companies;
- }
- public function actionVipedit()
- {
- $companies = '<select name="company_id" size="1" id="coms"><option>Выберите категорию</option>';
- $position = Vip::model()->find('position=' . $_GET['position'] . ' and category_id=' . $_GET['cat_id']);
- $id = $position === null ? 0 : $position->id;
- $real_cat = 0;
- $cats = Categories::model()->findAll();
- $categories = '<select size="1" id="cats" name="category_id">' . PHP_EOL;
- foreach($cats as $item)
- $categories .= '<option value="' . $item->id . '"' . ($item->id == $_GET['cat_id'] ? ' selected="selected"' : '') . '>' . $item->name . '</option>' . PHP_EOL;
- $categories .= '</select>';
- if ($id > 0) {
- $real_cat = Catalog::model()->find('id=' . $position->company_id)->category;
- $coms = Catalog::model()->findAllByAttributes(array("category"=>$real_cat));
- foreach($coms as $item)
- $companies .= '<option value="' . $item->id . '"' . ($id > 0 && $position->company_id == $item->id ? ' selected="selected"' : '') . '>' . $item->name . '</option>' . PHP_EOL;
- }
- $com_categories = '<select size="1" id="com_cats">' . ($real_cat == 0 ? '<option>Выберите категорию</option>' : '') . PHP_EOL;
- foreach($cats as $item)
- $com_categories .= '<option value="' . $item->id . '"' . ($item->id == $real_cat ? ' selected="selected"' : '') . '>' . $item->name . '</option>' . PHP_EOL;
- $com_categories .= '</select>';
- $companies .= '</select>';
- if (!empty($position->company_id)) {
- }
- $this->render('vipedit', array(
- 'com_categories'=>$com_categories,
- 'categories'=>$categories,
- 'companies'=>$companies,
- 'position'=>$_GET['position'],
- 'id'=>$id
- ));
- }
- public function actionVipsave()
- {
- $vip = Vip::model()->find('position=' . $_POST['position'] . ' and category_id=' . $_POST['category_id']);
- if ($vip === null) {
- $item = new Vip();
- $item->company_id = $_POST['company_id'];
- $item->category_id = $_POST['category_id'];
- $item->position = $_POST['position'];
- $item->save(false);
- } else {
- $vip->company_id = $_POST['company_id'];
- $vip->save(false);
- }
- $this->redirect(array('vip'));
- }
- public function actionVipdelete()
- {
- Vip::model()->find('position=' . $_GET['position'] . ' and category_id=' . $_GET['cat_id'])->delete();
- echo 'OK';
- }
- public function actionVipup()
- {
- $up = Vip::model()->find('position=' . ((int)$_GET['position'] - 1) . ' and category_id=' . $_GET['cat_id']);
- $now = Vip::model()->find('position=' . $_GET['position'] . ' and category_id=' . $_GET['cat_id']);
- if ($up !== null || $now !== null) {
- if ($up === null) {
- $now->position = ((int)$_GET['position'] - 1);
- if ($now->save())
- echo 'OK';
- } else {
- $up->position = $_GET['position'];
- $now->position = ((int)$_GET['position'] - 1);
- if ($now->save(false) && $up->save(false))
- echo 'OK';
- }
- }
- }
- public function actionVipdown()
- {
- $down = Vip::model()->find('position=' . ((int)$_GET['position'] + 1) . ' and category_id=' . $_GET['cat_id']);
- $now = Vip::model()->find('position=' . $_GET['position'] . ' and category_id=' . $_GET['cat_id']);
- if ($down !== null || $now !== null) {
- if ($down === null) {
- $now->position = ((int)$_GET['position'] + 1);
- if ($now->save())
- echo 'OK';
- } else {
- $down->position = $_GET['position'];
- $now->position = ((int)$_GET['position'] + 1);
- if ($now->save(false) && $down->save(false))
- echo 'OK';
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement