Example #1
0
 public function actionIndex($style = null, $order = null, $manufacturer = null, $attribute = null)
 {
     if (isset($_GET['q'])) {
         $with = array();
         $category = array();
         $criteria = new CDbCriteria();
         $criteria->condition = "name like :search or description like :search";
         $criteria->params = array(':search' => "%{$_GET['q']}%");
         if (isset($_GET['category']) && $_GET['category'] > 0) {
             $category = Category::model()->findByPk($_GET['category']);
             $criteria->addCondition("category_id = {$category->id}");
         }
         $template = "type/_grid";
         if ($style == "list") {
             $template = 'type/_' . $style;
         }
         switch ($order) {
             case "price":
                 $criteria->order = "price";
                 break;
             case "created":
                 $criteria->order = "created DESC";
                 break;
             default:
                 $criteria->order = "name";
                 break;
         }
         if ($manufacturer) {
             $criteria->addInCondition("manufacturer_id", explode(',', trim($manufacturer)));
         }
         if ($attribute) {
             $crtr = new CDbCriteria();
             $crtr->addInCondition("id", explode(',', trim($attribute)));
             $opt = EntityAttributeOption::model()->findAll($crtr);
             $attrs = CHtml::listData($opt, 'id', 'option');
             $criteria->addInCondition("entityAttributeOptions.option", $attrs);
             $with = array('entityAttributeOptions' => array('together' => true));
         }
         $products = new Product();
         $total = $products->with($with)->count($criteria);
         $pages = new Pagination($total);
         $pages->pageSize = 4;
         $pages->applyLimit($criteria);
         $list = $products->with($with)->findAll($criteria);
         if (Yii::app()->request->isAjaxRequest) {
             $this->widget("ProductList", array('pages' => $pages, 'products' => $list, 'template' => $template));
             Yii::app()->end();
         }
         $this->render('index', array('models' => $list, 'pages' => $pages, 'q' => $_GET['q'], 'template' => $template, 'category' => $category));
     } else {
         throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.');
     }
 }
 /**
  * List action: list of elements
  * 
  * @param array $aParams array of input params
  * @return ActionResponse 
  */
 public function actionList($aParams = array())
 {
     $aConfig = $this->config('List');
     $limit = 10;
     $aFindParams = array();
     if (count($aParams) && $this->sMapperAlias) {
         foreach ($aParams as $key => $param) {
             if ($this->mapper()->isRealFieldExists($key)) {
                 $aFindParams['Criteria'][$key] = $param;
             }
         }
     }
     $page = isset($_GET['page']) ? intval($_GET['page']) - 1 : 0;
     $aFindParams['Limit'] = $limit;
     $aFindParams['Offset'] = $page * $limit;
     $sort_field = isset($_GET['sort_field']) ? $_GET['sort_field'] : 'Id';
     $sort_direction = isset($_GET['sort_direction']) ? $_GET['sort_direction'] : 'ASC';
     $aFindParams['Order'] = array();
     //echo '<pre>', print_r($aFindParams, true), '</pre>'; die();
     if (isset($aConfig['Component']['FindParams'])) {
         $aFindParams = ArrayHelper::merge($aFindParams, $aConfig['Component']['FindParams']);
     }
     if (!count($aFindParams['Order'])) {
         $aFindParams['Order'] = array($sort_field => $sort_direction);
     }
     $mResult = false;
     if ($aConfig) {
         if (!isset($aConfig['View']) || isset($aConfig['View']) && $aConfig['View'] != false) {
             $mResult = $this->view(array(), $aConfig['View']);
         } else {
             if (isset($aConfig['Component'])) {
                 $sComponentModule = $aConfig['Component']['Component'][0];
                 $sComponentAlias = $aConfig['Component']['Component'][1];
                 $aComponentParams = isset($aConfig['Component']['Params']) ? $aConfig['Component']['Params'] : array();
                 // Проверка доступа
                 $this->checkActionAccess('List');
                 $aComponentParams['Data'] = $this->getListData($aFindParams);
                 $count = $this->getListDataCount($aFindParams);
                 $oPagination = new Pagination($count);
                 $oPagination->setPageSize($aFindParams['Limit']);
                 $oPagination->applyLimit(@$aFindParams['Criteria']);
                 $aComponentParams['Pagination'] = $oPagination;
                 $mResult = $this->component($sComponentModule, $sComponentAlias, $aComponentParams);
             } else {
                 $mResult = false;
             }
         }
     } else {
         $mResult = $this->view('List');
     }
     return $mResult;
 }
Example #3
0
 /**
  * Lists all schemata.
  */
 public function actionList()
 {
     // Create list for sideBar usage
     if ($this->request->getParam('sideBar')) {
         $schemata = array();
         foreach (Schema::model()->findAll() as $schema) {
             $schemata[] = $schema->SCHEMA_NAME;
         }
         $this->sendJSON($schemata);
     } else {
         $criteria = new CDbCriteria();
         // Pagination
         $pages = new Pagination(Schema::model()->count($criteria));
         $pages->setupPageSize('pageSize', 'schemata');
         $pages->applyLimit($criteria);
         $pages->route = '#schemata';
         // Sort
         $sort = new CSort('Schema');
         $sort->attributes = array('name' => 'SCHEMA_NAME', 'tableCount' => 'tableCount', 'collation' => 'DEFAULT_COLLATION_NAME');
         $sort->defaultOrder = 'SCHEMA_NAME ASC';
         $sort->route = '#schemata';
         $sort->applyOrder($criteria);
         $criteria->group = 'SCHEMA_NAME';
         $criteria->select = 'SCHEMA_NAME, DEFAULT_COLLATION_NAME, COUNT(*) AS tableCount';
         $schemaList = Schema::model()->with(array('tables' => array('select' => 'COUNT(tables.TABLE_NAME) AS tableCount')))->together()->findAll($criteria);
         $this->render('list', array('schemaList' => $schemaList, 'schemaCount' => $pages->getItemCount(), 'schemaCountThisPage' => min($pages->getPageSize(), $pages->getItemCount() - $pages->getCurrentPage() * $pages->getPageSize()), 'pages' => $pages, 'sort' => $sort));
     }
 }
Example #4
0
 public function actionSchemata()
 {
     // Create criteria
     $criteria = new CDbCriteria();
     $criteria->condition = 'Host = :host AND User = :user';
     $criteria->params = array(':host' => $this->host, ':user' => $this->user);
     // Pagination
     $pages = new Pagination(User::model()->count($criteria));
     $pages->setupPageSize('pageSize', 'privileges.userSchemata');
     $pages->applyLimit($criteria);
     $pages->route = '#privileges/users/' . base64_encode($this->user . '@' . $this->host) . '/schemata';
     // Sort
     $sort = new CSort('User');
     $sort->attributes = array('User' => 'username', 'Host' => 'host', 'Password = \'\'' => 'password');
     $sort->defaultOrder = 'User ASC';
     $sort->route = '#privileges/users/' . base64_encode($this->user . '@' . $this->host) . '/schemata';
     $sort->applyOrder($criteria);
     // Fetch schemata
     $schemata = SchemaPrivilege::model()->findAll($criteria);
     // Render
     $this->render('userSchemata', array('schemata' => $schemata, 'user' => $this->user, 'host' => $this->host, 'pages' => $pages, 'sort' => $sort));
 }