Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class CatalogController extends Controller {
- public $defaultAction = 'view';
- /**
- * Lists all models.
- */
- public function actionView($id) {
- $cat = Category::model()->findByPK($id);
- if ($cat !== null) {
- $min = (isset($_GET['min']))?(int)$_GET['min']:0;
- $max = (isset($_GET['max']))?(int)$_GET['max']:100000;
- $cc = $cat->children()->findAll();
- $childrens = array();
- foreach ($cc as $key=>$child) {
- if($child->children()) {
- $child_childrens = $child->getChildrens();
- if($child_childrens) {
- foreach ($child_childrens as $child_children) {
- if($child_children->itemsCount) {
- $childrens[] = $child;
- break;
- }
- }
- } else {
- if($child->itemsCount) {
- $childrens[] = $child;
- }
- }
- }
- }
- $cc = $childrens;
- $parents = $cat->ancestors()->findAll();
- if($cc) {
- $dataProvider = new CArrayDataProvider($cc,
- array(
- 'pagination'=>array(
- 'pageSize'=>20,
- 'pageVar' =>'page',
- ),
- )
- );
- $this->render('indexCat', array(
- 'dataProvider' => $dataProvider,
- 'cat' => $cat,
- 'parents' => $parents,
- 'id' => $id,
- 'min' => $min,
- 'max' => $max,
- ));
- } else {
- $dataProvider = new CActiveDataProvider(Items::model()->active()->category($id)->price($min,$max)->cache(86000),
- array(
- 'pagination'=>array(
- 'pageSize'=>21,
- 'pageVar' =>'page',
- ),
- )
- );
- $this->render('index', array(
- 'dataProvider' => $dataProvider,
- 'cat' => $cat,
- 'cat_children' => $cc,
- 'parents' => $parents,
- 'id' => $id,
- 'min' => $min,
- 'max' => $max,
- ));
- }
- } else {
- $this->redirect('/');
- }
- }
- public function actionFilter() {
- $id = (int)$_POST['id'];
- $min = (int)$_POST['min'];
- $max = (int)$_POST['max'];
- if($id == 0) $id = (int)$_POST['this_id'];
- if($min < 0) $min = 0;
- if($max == 0) $max = 100000;
- $this->redirect(
- $this->createUrl('catalog/view',
- array(
- 'id'=>$id,
- 'min'=>$min,
- 'max'=>$max,
- )
- )
- );
- }
- /**
- * Returns the data model based on the primary key given in the GET variable.
- * If the data model is not found, an HTTP exception will be raised.
- * @param integer $id the ID of the model to be loaded
- * @return Catalog the loaded model
- * @throws CHttpException
- */
- public function loadModel($id) {
- $model = Catalog::model()->findByPk($id);
- if ($model === null)
- throw new CHttpException(404, 'The requested page does not exist.');
- return $model;
- }
- /**
- * Performs the AJAX validation.
- * @param Catalog $model the model to be validated
- */
- protected function performAjaxValidation($model) {
- if (isset($_POST['ajax']) && $_POST['ajax'] === 'catalog-form') {
- echo CActiveForm::validate($model);
- Yii::app()->end();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement