public function actionList() { $criteria = new CDbCriteria(); $sort = new CSort('AdminAdvert'); $sort->defaultOrder = 't.id asc'; $sort->applyOrder($criteria); $models = AdminAdvert::model()->findAll($criteria); $this->render('list', array('models' => $models, 'sort' => $sort)); }
/** * Tests for acceptance of fields with dots in * CSort::attributes. * * @return void */ function testGetDirectionsWithDots() { $_GET['sort'] = 'comments.id'; $criteria = new CDbCriteria(); $criteria->with = 'comments'; $sort = new CSort('TestPost'); $sort->attributes = array('id', 'comments.id' => array('asc' => 'comments.id', 'desc' => 'comments.id desc')); $sort->applyOrder($criteria); $directions = $sort->getDirections(); $this->assertTrue(isset($directions['comments.id'])); }
/** * Tests for acceptance of arrays for asc/desc keys in * CSort::attributes. * * @return void */ function testGetDirectionsWithArrays() { $_GET['sort'] = 'comments.id'; $criteria = new CDbCriteria(); $criteria->with = 'comments'; $sort = new CSort('TestPost'); $sort->attributes = array('id', 'comments.id' => array('asc' => array('comments.id', 'id'), 'desc' => array('comments.id desc', 'id desc'))); $sort->applyOrder($criteria); $directions = $sort->getDirections(); $this->assertEquals($criteria->order, 'comments.id, id'); }
public function run() { $criteria = new CDbCriteria(); $pages = new CPagination(EavAttributeExtended::model()->count()); $pages->pageSize = $this->getController()->getModule()->getItemsPerPage(); $pages->applyLimit($criteria); $sort = new CSort('EavAttributeExtended'); $sort->attributes = array('id', 'name', 'label', 'type', 'data_type'); $sort->applyOrder($criteria); $model = EavAttributeExtended::model()->findAll($criteria); $this->controller->render('index', array('model' => $model, 'sort' => $sort, 'pages' => $pages)); }
/** * Manages all models. */ public function actionAdmin() { $criteria = new CDbCriteria(); $criteria->addSearchCondition('companyId', Yii::app()->user->getState('selectedCompanyId')); $pages = new CPagination(ChangeLog::model()->count($criteria)); $pages->pageSize = Yii::app()->user->getState('NumberRecordsPerPage'); $pages->applyLimit($criteria); $sort = new CSort('ChangeLog'); $sort->applyOrder($criteria); $models = ChangeLog::model()->findAll($criteria); $this->render('admin', array('models' => $models, 'pages' => $pages, 'sort' => $sort)); }
/** * Index action */ public function actionIndex() { // Did we submit the form and selected items? if (isset($_POST['bulkoperations']) && $_POST['bulkoperations'] != '') { // Perms if (!Yii::app()->user->checkAccess('op_custompages_managepages')) { throw new CHttpException(403, Yii::t('error', 'Sorry, You don\'t have the required permissions to enter this section')); } // Did we choose any values? if (isset($_POST['record']) && count($_POST['record'])) { // What operation we would like to do? switch ($_POST['bulkoperations']) { case 'bulkdelete': // Perms if (!Yii::app()->user->checkAccess('op_custompages_deletepages')) { throw new CHttpException(403, Yii::t('error', 'Sorry, You don\'t have the required permissions to enter this section')); } // Load records and delete them $records = CustomPages::model()->deleteByPk(array_keys($_POST['record'])); // Done Yii::app()->user->setFlash('success', Yii::t('admincustompages', '{count} pages deleted.', array('{count}' => $records))); break; case 'bulkapprove': // Load records $records = CustomPages::model()->updateByPk(array_keys($_POST['record']), array('status' => 1)); // Done Yii::app()->user->setFlash('success', Yii::t('admincustompages', '{count} pages approved.', array('{count}' => $records))); break; case 'bulkunapprove': // Load records $records = CustomPages::model()->updateByPk(array_keys($_POST['record']), array('status' => 0)); // Done Yii::app()->user->setFlash('success', Yii::t('admincustompages', '{count} pages Un-Approved.', array('{count}' => $records))); break; default: // Nothing break; } } } // Load members and display $criteria = new CDbCriteria(); $count = CustomPages::model()->count(); $pages = new CPagination($count); $pages->pageSize = self::PAGE_SIZE; $pages->applyLimit($criteria); $sort = new CSort('CustomPages'); $sort->defaultOrder = 'dateposted DESC'; $sort->applyOrder($criteria); $sort->attributes = array('title' => 'title', 'alias' => 'alias', 'author' => 'authorid', 'dateposted' => 'dateposted', 'language' => 'language', 'status' => 'status'); $rows = CustomPages::model()->with(array('author', 'lastauthor'))->findAll($criteria); $this->render('index', array('count' => $count, 'rows' => $rows, 'pages' => $pages, 'sort' => $sort)); }
/** * Manages all models. */ public function actionAdmin() { $this->processAdminCommand(); $criteria = new CDbCriteria(); $pages = new CPagination(Failedemail::model()->count($criteria)); $pages->pageSize = self::PAGE_SIZE; $pages->applyLimit($criteria); $sort = new CSort('Failedemail'); $sort->applyOrder($criteria); $models = Failedemail::model()->findAll($criteria); $this->render('admin', array('models' => $models, 'pages' => $pages, 'sort' => $sort)); }
/** * Manages all networks. */ public function actionAdmin() { $this->breadCrumbs = array('Управление сайтом' => array('/users/default/siteManagment')); $criteria = new CDbCriteria(); $criteria->addColumnCondition(array('userId' => Yii::app()->user->id)); $pages = new CPagination(User::model()->count()); $pages->applyLimit($criteria); $sort = new CSort('Network'); $sort->defaultOrder = 'network'; $sort->applyOrder($criteria); $nw = Network::model()->findAll($criteria); $this->widget('FormWindow'); $this->renderAjax('admin', array('pages' => $pages, 'networks' => $nw, 'sort' => $sort)); }
public function actionList() { $criteria = new CDbCriteria(); $criteria->limit = param('adminLinkCountOfPage'); $sort = new CSort('Link'); $sort->defaultOrder = 'orderid asc, id asc'; $sort->applyOrder($criteria); $pages = new CPagination(AdminLink::model()->count($criteria)); $pages->pageSize = $criteria->limit; $pages->applyLimit($criteria); $models = AdminLink::model()->findAll($criteria); $data = array('models' => $models, 'sort' => $sort, 'pages' => $pages); $this->render('list', $data); }
public function actionList($adid) { $adid = (int) $adid; $advert = AdminAdvert::model()->findByPk($adid); if ($advert === null) { throw new CHttpException(404, t('advert_is_not_exist', 'admin')); } $criteria = new CDbCriteria(); $criteria->addColumnCondition(array('ad_id' => $adid)); $sort = new CSort('AdminAdcode'); $sort->defaultOrder = 't.state desc, t.id asc'; $sort->applyOrder($criteria); $models = AdminAdcode::model()->findAll($criteria); $this->render('list', array('models' => $models, 'sort' => $sort, 'advert' => $advert)); }
/** * Manages all models. */ public function actionAdmin() { $this->processAdminCommand(); $criteria = new CDbCriteria(); //属于用户的分类 $criteria->condition = 'uid=:uid'; $criteria->params = array(':uid' => Yii::app()->user->id); $pages = new CPagination(FriendGroup::model()->count($criteria)); $pages->pageSize = self::PAGE_SIZE; $pages->applyLimit($criteria); $sort = new CSort('FriendGroup'); $sort->applyOrder($criteria); $models = FriendGroup::model()->findAll($criteria); $this->render('admin', array('models' => $models, 'pages' => $pages, 'sort' => $sort)); }
public function getModel($className) { if ($this->_model == null) { $this->_model = parent::getModel($className); } return $this->_model; }
/** * Show all users */ public function actionIndex() { // Load members and display $criteria = new CDbCriteria(); $count = Members::model()->count($criteria); $pages = new CPagination($count); $pages->pageSize = self::PAGE_SIZE; $pages->applyLimit($criteria); $sort = new CSort('Members'); $sort->defaultOrder = 'joined DESC'; $sort->applyOrder($criteria); $sort->attributes = array('username' => 'username', 'joined' => 'joined', 'role' => 'role'); $sort->route = '/users/index'; $sort->params = array('lang' => false); $rows = Members::model()->findAll($criteria); $this->render('index', array('rows' => $rows, 'sort' => $sort, 'pages' => $pages)); }
/** * Index action */ public function actionIndex() { // Did we submit the form and selected items? if (isset($_POST['bulkoperations']) && $_POST['bulkoperations'] != '') { // Did we choose any values? if (isset($_POST['record']) && count($_POST['record'])) { // What operation we would like to do? switch ($_POST['bulkoperations']) { case 'read': // Load records $records = ContactUs::model()->updateByPk(array_keys($_POST['record']), array('sread' => 1)); // Done Yii::app()->user->setFlash('success', Yii::t('contactus', '{count} items marked as read.', array('{count}' => $records))); break; case 'notread': // Load records $records = ContactUs::model()->updateByPk(array_keys($_POST['record']), array('sread' => 0)); // Done Yii::app()->user->setFlash('success', Yii::t('contactus', '{count} items marked as not read.', array('{count}' => $records))); break; case 'delete': // Load records $records = ContactUs::model()->deleteByPk(array_keys($_POST['record'])); // Done Yii::app()->user->setFlash('success', Yii::t('contactus', '{count} items deleted.', array('{count}' => $records))); break; default: // Nothing break; } } } // Load items and display $criteria = new CDbCriteria(); $count = ContactUs::model()->count(); $pages = new CPagination($count); $pages->pageSize = self::PAGE_SIZE; $pages->applyLimit($criteria); $sort = new CSort('ContactUs'); $sort->defaultOrder = 'postdate DESC'; $sort->applyOrder($criteria); $sort->attributes = array('name' => 'name', 'email' => 'email', 'postdate' => 'postdate', 'subject' => 'subject', 'sread' => 'sread'); $items = ContactUs::model()->findAll($criteria); $this->render('index', array('rows' => $items, 'pages' => $pages, 'sort' => $sort, 'count' => $count)); }
private static function fetchList($criteria = null, $sort = true, $pages = true) { $criteria = $criteria === null ? new CDbCriteria() : $criteria; $criteria->limit = param('adminPostCountOfPage'); $criteria->order = 'id desc'; if ($sort) { $sort = new CSort('Post'); $sort->defaultOrder = 'id desc'; $sort->applyOrder($criteria); } if ($pages) { $count = Post::model()->count($criteria); $pages = new CPagination($count); } $models = Post::model()->findAll($criteria); $data = array('models' => $models, 'sort' => $sort, 'pages' => $pages); return $data; }
function actionIndex() { /*$posts = Post::model()->findAll(); $this->render( 'index', array( 'posts' => $posts, ) );*/ $criteria = new CDbCriteria(); $count = Post::model()->count($criteria); $pages = new CPagination($count); // elements per page $pages->pageSize = 5; $pages->applyLimit($criteria); // sorting $sort = new CSort('Post'); $sort->attributes = array('id', 'title'); $sort->applyOrder($criteria); $models = Post::model()->findAll($criteria); $this->render('index', array('models' => $models, 'pages' => $pages, 'sort' => $sort)); }
public static function getApartments($limit = 10, $usePagination = 1, $all = 1, $criteria = null) { $pages = array(); Yii::app()->getModule('apartments'); if ($criteria === null) { $criteria = new CDbCriteria(); } if (!$all) { $criteria->addCondition('t.deleted = 0'); $criteria->addCondition('t.active = ' . Apartment::STATUS_ACTIVE); if (param('useUserads')) { $criteria->addCondition('owner_active = ' . Apartment::STATUS_ACTIVE); } } $sort = new CSort('Apartment'); $sort->attributes = array('price' => 'price', 'date_created' => 'date_created'); if (!$criteria->order) { $sort->defaultOrder = 't.date_up_search DESC, t.sorter DESC'; } $sort->applyOrder($criteria); $sorterLinks = self::getSorterLinks($sort); $criteria->addCondition('t.owner_id = 1 OR t.owner_active = 1'); $criteria->addInCondition('t.type', Apartment::availableApTypesIds()); $criteria->addInCondition('t.price_type', array_keys(Apartment::getPriceArray(Apartment::PRICE_SALE, true))); // find count $apCount = Apartment::model()->count($criteria); if ($usePagination) { $pages = new CPagination($apCount); $pages->pageSize = $limit; $pages->applyLimit($criteria); } else { $criteria->limit = $limit; } if (issetModule('seo')) { $criteria->with = array('seo'); } // $apartments = Apartment::model() // ->cache(param('cachingTime', 1209600), Apartment::getImagesDependency()) // ->with(array('images')) // ->findAll($criteria); return array('pages' => $pages, 'sorterLinks' => $sorterLinks, 'apCount' => $apCount, 'criteria' => $criteria); }
/** * Index action */ public function actionIndex() { // Did we submit the form and selected items? if (isset($_POST['bulkoperations']) && $_POST['bulkoperations'] != '') { // Perms if (!Yii::app()->user->checkAccess('op_users_bulk_users')) { throw new CHttpException(403, Yii::t('error', 'Sorry, You don\'t have the required permissions to enter this section')); } // Did we choose any values? if (isset($_POST['user']) && count($_POST['user'])) { // What operation we would like to do? switch ($_POST['bulkoperations']) { case 'bulkdelete': // Perms if (!Yii::app()->user->checkAccess('op_users_delete_users')) { throw new CHttpException(403, Yii::t('error', 'Sorry, You don\'t have the required permissions to enter this section')); } // Load members and delete them $members_deleted = Members::model()->deleteByPk(array_keys($_POST['user'])); // Done Yii::app()->user->setFlash('success', Yii::t('adminmembers', '{count} users deleted.', array('{count}' => $members_deleted))); break; default: // Nothing break; } } } // Load members and display $criteria = new CDbCriteria(); $count = Members::model()->count(); $pages = new CPagination($count); $pages->pageSize = self::PAGE_SIZE; $pages->applyLimit($criteria); $sort = new CSort('Members'); $sort->defaultOrder = 'joined DESC'; $sort->applyOrder($criteria); $sort->attributes = array('id' => 'ID', 'username' => 'username', 'joined' => 'joined', 'email' => 'email', 'role' => 'role'); $members = Members::model()->findAll($criteria); $this->render('index', array('count' => $count, 'members' => $members, 'pages' => $pages, 'sort' => $sort)); }
public function getOrderBy($criteria = null) { $order = parent::getOrderBy($criteria); if ($this->alwaysApplyDefaultOrder && $this->defaultOrder && $order !== $this->defaultOrder) { if ($order) { $order .= ', ' . $this->defaultOrder; } else { $order = $this->defaultOrder; } } return $order; }
public static function fetchList($criteria = null, $sort = true, $pages = true) { $criteria = $criteria === null ? new CDbCriteria() : $criteria; if ($criteria->limit <= 0) { $criteria->limit = param('adminUserCountOfPage'); } if ($sort) { $sort = new CSort(__CLASS__); $sort->defaultOrder = 't.id desc'; $sort->applyOrder($criteria); } if ($pages) { $count = self::model()->count($criteria); $pages = new CPagination($count); $pages->setPageSize($criteria->limit); $pages->applyLimit($criteria); } $models = self::model()->findAll($criteria); $data = array('models' => $models, 'sort' => $sort, 'pages' => $pages); return $data; }
/** * Show all books. */ public function actionList() { $criteria = new CDbCriteria(); $criteria->with = 'author'; $searchForm = new SearchForm(); if (isset($_POST['SearchForm'])) { $searchForm->setAttributes($_POST['SearchForm']); $criteria = $searchForm->apllyFilter($criteria); } $pages = new CPagination(Books::model()->count()); $pages->applyLimit($criteria); $sort = new CSort('Books'); $sort->attributes = array('name', 'date', 'date_update', 'author' => array('asc' => 'author.lastname, author.firstname', 'desc' => 'author.lastname DESC, author.firstname DESC', 'label' => 'Автор')); $sort->defaultOrder = 'name'; $sort->applyOrder($criteria); $books = Books::model()->findAll($criteria); $formWidget = $this->createWidget('FormWindow'); $formWidget->afterClose = '$("#ui-datepicker-div").remove();$("#content").load("#");'; $formWidget->run(); $this->renderAjax('list', array('pages' => $pages, 'models' => $books, 'sort' => $sort, 'searchForm' => $searchForm)); }
public function actionIndex() { //commits from github $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, "https://api.github.com/repos/nodejs/node-v0.x-archive/commits?per_page=25&page=1"); curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13'); $cont = curl_exec($curl); $commits = json_decode($cont); curl_close($curl); //echo count($commits); //die; //add to database foreach ($commits as $item) { $commit = new Commit(); $commit->sha = $item->sha; $commit->url = $item->html_url; $commit->committer = $item->author->login; $commit->save(); } $criteria = new CDbCriteria(); //$criteria->addCondition('status=1'); //counts $count = Commit::model()->count($criteria); $pages = new CPagination($count); $pageSize = isset(Yii::app()->params['commitsPerPage']) ? Yii::app()->params['commitsPerPage'] : 25; $pages->pageSize = $pageSize; $pages->applyLimit($criteria); //sorting $sort = new CSort('Commit'); $sort->defaultOrder = array('committer' => CSort::SORT_ASC); $sort->attributes = array('id' => array('asc' => "id", 'desc' => "id DESC"), 'sha' => array('asc' => "sha", 'desc' => "sha DESC"), 'committer' => array('asc' => "committer", 'desc' => "committer DESC")); $sort->applyOrder($criteria); $items = Commit::model()->findAll($criteria); $this->render('index', array('items' => $items, 'pages' => $pages, 'sort' => $sort, 'commits' => $commits)); }
public static function fetchList(CDbCriteria $criteria = null, $pages = true, $sort = false) { if ($criteria === null) { $criteria = new CDbCriteria(); } if ($pages) { $limit = $criteria->limit <= 0 ? param('adminSpecialCountOfPage') : $criteria->limit; $pages = new CPagination(self::model()->count($criteria)); $pages->setPageSize($limit); $pages->applyLimit($criteria); $data['pages'] = $pages; } if ($sort) { $sort = new CSort('AdminSpecial'); $sort->defaultOrder = 'create_time desc'; $sort->applyOrder($criteria); $data['sort'] = $sort; } else { $criteria->order = 'create_time desc'; } $data['models'] = self::model()->findAll($criteria); return $data; }
/** * Print out array of models for the jqGrid rows. */ public function actionGridData() { if (!Yii::app()->request->isPostRequest) { throw new CHttpException(400, Yii::t('http', 'Invalid request. Please do not repeat this request again.')); exit; } // specify request details $jqGrid = $this->processJqGridRequest(); // specify filter parameters $company = isset($_GET['company']) ? $_GET['company'] : null; if ($company !== 'all' && !ctype_digit($company)) { $company = 'all'; } $paymentMethod = isset($_GET['paymentMethod']) ? $_GET['paymentMethod'] : null; if ($paymentMethod !== 'all' && $paymentMethod !== (string) CompanyPayment::CASH && $paymentMethod !== (string) CompanyPayment::CHECK && $paymentMethod !== (string) CompanyPayment::CREDIT_CARD && $paymentMethod !== (string) CompanyPayment::PAYPAL && $paymentMethod !== (string) CompanyPayment::WIRE) { $paymentMethod = 'all'; } // criteria $criteria = new CDbCriteria(); $criteria->group = "`t`.`id`"; // required by together() $criteria->select = "`t`.amount, `t`.paymentDate, `t`.paymentMethod, `t`.paymentNumber"; //$criteria->select="`t`.`amount`, `t`.`paymentDate`, `t`.`paymentMethod`, `t`.`paymentNumber`"; // uncomment in yii-1.1.2 if ($jqGrid['searchField'] !== null && $jqGrid['searchString'] !== null && $jqGrid['searchOper'] !== null) { $field = array('amount' => "`t`.`amount`", 'paymentDate' => "`t`.`paymentDate`", 'paymentMethod' => "`t`.`paymentMethod`", 'paymentNumber' => "`t`.`paymentNumber`", 'company' => "`CompanyPayment_Company`.`title`"); $operation = $this->getJqGridOperationArray(); $keywordFormula = $this->getJqGridKeywordFormulaArray(); if (isset($field[$jqGrid['searchField']]) && isset($operation[$jqGrid['searchOper']])) { $criteria->condition = '(' . $field[$jqGrid['searchField']] . ' ' . $operation[$jqGrid['searchOper']] . ' :keyword)'; $criteria->params = array(':keyword' => str_replace('keyword', $jqGrid['searchString'], $keywordFormula[$jqGrid['searchOper']])); // search by special field types if ($jqGrid['searchField'] === 'createTime' && ($keyword = strtotime($jqGrid['searchString'])) !== false) { $criteria->params = array(':keyword' => str_replace('keyword', $keyword, $keywordFormula[$jqGrid['searchOper']])); if (date('H:i:s', $keyword) === '00:00:00') { // visitor is looking for a precision by day, not by second $criteria->condition = '(TO_DAYS(FROM_UNIXTIME(' . $field[$jqGrid['searchField']] . ',"%Y-%m-%d")) ' . $operation[$jqGrid['searchOper']] . ' TO_DAYS(FROM_UNIXTIME(:keyword,"%Y-%m-%d")))'; } } } } if ($company !== 'all') { $criteria->addCondition("`CompanyPayment_Company`.`id`=:companyId"); $criteria->params[':companyId'] = $company; } if ($paymentMethod === (string) CompanyPayment::CASH) { $criteria->addCondition("`t`.`paymentMethod`=:cash"); $criteria->params[':cash'] = CompanyPayment::CASH; } else { if ($paymentMethod === (string) CompanyPayment::CHECK) { $criteria->addCondition("`t`.`paymentMethod`=:check"); $criteria->params[':check'] = CompanyPayment::CHECK; } else { if ($paymentMethod === (string) CompanyPayment::CREDIT_CARD) { $criteria->addCondition("`t`.`paymentMethod`=:creditCard"); $criteria->params[':creditCard'] = CompanyPayment::CREDIT_CARD; } else { if ($paymentMethod === (string) CompanyPayment::PAYPAL) { $criteria->addCondition("`t`.`paymentMethod`=:paypal"); $criteria->params[':paypal'] = CompanyPayment::PAYPAL; } else { if ($paymentMethod === (string) CompanyPayment::WIRE) { $criteria->addCondition("`t`.`paymentMethod`=:wire"); $criteria->params[':wire'] = CompanyPayment::WIRE; } } } } } if (User::isClient()) { $criteria->addCondition("`Company_User2Company`.`userId`=:clientId AND `Company_User2Company`.`position`=:clientPosition"); $criteria->params[':clientId'] = Yii::app()->user->id; $criteria->params[':clientPosition'] = Company::OWNER; } // pagination $with = array(); if (strpos($criteria->condition, 'CompanyPayment_Company') !== false) { $with[] = 'company'; } if (strpos($criteria->condition, 'Company_User2Company') !== false) { $with[] = 'company.allUser2Company'; } if (count($with) >= 1) { $pages = new CPagination(CompanyPayment::model()->with($with)->count($criteria)); } else { $pages = new CPagination(CompanyPayment::model()->count($criteria)); } $pages->pageSize = $jqGrid['pageSize'] !== null ? $jqGrid['pageSize'] : self::GRID_PAGE_SIZE; $pages->applyLimit($criteria); // sort $sort = new CSort('CompanyPayment'); $sort->attributes = array('amount' => array('asc' => "`t`.`amount`", 'desc' => "`t`.`amount` desc", 'label' => CompanyPayment::model()->getAttributeLabel('amount')), 'paymentDate' => array('asc' => "`t`.`paymentDate`", 'desc' => "`t`.`paymentDate` desc", 'label' => CompanyPayment::model()->getAttributeLabel('Date')), 'paymentMethod' => array('asc' => "`t`.`paymentMethod`", 'desc' => "`t`.`paymentMethod` desc", 'label' => CompanyPayment::model()->getAttributeLabel('Method')), 'paymentNumber' => array('asc' => "`t`.`paymentNumber`", 'desc' => "`t`.`paymentNumber` desc", 'label' => CompanyPayment::model()->getAttributeLabel('Number')), 'company' => array('asc' => "`CompanyPayment_Company`.`title`", 'desc' => "`CompanyPayment_Company`.`title` desc", 'label' => CompanyPayment::model()->getAttributeLabel('companyId'))); $sort->defaultOrder = "`t`.`paymentDate` DESC"; $sort->applyOrder($criteria); // find all $with = array('company' => array('select' => 'title')); if (strpos($criteria->condition, 'Company_User2Company') !== false) { $with['company.allUser2Company'] = array('select' => 'id'); } $together = strpos($criteria->condition, 'Company_User2Company') !== false; if ($together) { $models = CompanyPayment::model()->with($with)->together()->findAll($criteria); } else { $models = CompanyPayment::model()->with($with)->findAll($criteria); } // create resulting data array $data = array('page' => $pages->getCurrentPage() + 1, 'total' => $pages->getPageCount(), 'records' => $pages->getItemCount(), 'rows' => array()); foreach ($models as $model) { $data['rows'][] = array('id' => $model->id, 'cell' => array(isset($model->company->id) ? CHtml::link(CHtml::encode($model->company->title), array('company/show', 'id' => $model->company->id)) : '', CHtml::encode(MDate::format($model->paymentDate, 'medium', null)), CHtml::encode($model->amount), CHtml::encode($model->getAttributeView('paymentMethod')), CHtml::encode($model->paymentNumber), CHtml::link('<span class="ui-icon ui-icon-zoomin"></span>', array('show', 'id' => $model->id), array('class' => 'w3-ig w3-link-icon w3-border-1px-transparent w3-first ui-corner-all', 'title' => Yii::t('link', 'Show'))) . CHtml::link('<span class="ui-icon ui-icon-pencil"></span>', array('update', 'id' => $model->id), array('class' => 'w3-ig w3-link-icon w3-border-1px-transparent w3-last ui-corner-all', 'title' => Yii::t('link', 'Edit'))))); } $this->printJson($data); }
/** * Print out array of models for the jqGrid rows. */ public function actionGridData() { if (!Yii::app()->request->isPostRequest) { throw new CHttpException(400, Yii::t('http', 'Invalid request. Please do not repeat this request again.')); exit; } // specify request details $jqGrid = $this->processJqGridRequest(); // specify filter parameters $company = isset($_GET['company']) ? $_GET['company'] : null; if ($company !== 'all' && !ctype_digit($company)) { $company = 'all'; } $priority = isset($_GET['priority']) ? $_GET['priority'] : null; if ($priority !== 'all' && $priority !== (string) Project::PRIORITY_HIGHEST && $priority !== (string) Project::PRIORITY_HIGH && $priority !== (string) Project::PRIORITY_MEDIUM && $priority !== (string) Project::PRIORITY_LOW && $priority !== (string) Project::PRIORITY_LOWEST) { $priority = 'all'; } $state = isset($_GET['state']) ? $_GET['state'] : null; if ($state !== 'all' && $state !== 'closed' && $state !== 'open') { $state = 'all'; } // criteria $criteria = new CDbCriteria(); $criteria->group = "`t`.`id`"; // required by together() $criteria->select = "`t`.closeDate, `t`.hourlyRate, `t`.openDate, `t`.priority, `t`.title"; //$criteria->select="`t`.`closeDate`, `t`.`hourlyRate`, `t`.`openDate`, `t`.`priority`, `t`.`title`"; // uncomment in yii-1.1.2 if ($jqGrid['searchField'] !== null && $jqGrid['searchString'] !== null && $jqGrid['searchOper'] !== null) { $field = array('closeDate' => "`t`.`closeDate`", 'hourlyRate' => "`t`.`hourlyRate`", 'openDate' => "`t`.`openDate`", 'priority' => "`t`.`priority`", 'title' => "`t`.`title`", 'company' => "`Project_Company`.`title`"); $operation = $this->getJqGridOperationArray(); $keywordFormula = $this->getJqGridKeywordFormulaArray(); if (isset($field[$jqGrid['searchField']]) && isset($operation[$jqGrid['searchOper']])) { $criteria->condition = '(' . $field[$jqGrid['searchField']] . ' ' . $operation[$jqGrid['searchOper']] . ' :keyword)'; $criteria->params = array(':keyword' => str_replace('keyword', $jqGrid['searchString'], $keywordFormula[$jqGrid['searchOper']])); // search by special field types if ($jqGrid['searchField'] === 'createTime' && ($keyword = strtotime($jqGrid['searchString'])) !== false) { $criteria->params = array(':keyword' => str_replace('keyword', $keyword, $keywordFormula[$jqGrid['searchOper']])); if (date('H:i:s', $keyword) === '00:00:00') { // visitor is looking for a precision by day, not by second $criteria->condition = '(TO_DAYS(FROM_UNIXTIME(' . $field[$jqGrid['searchField']] . ',"%Y-%m-%d")) ' . $operation[$jqGrid['searchOper']] . ' TO_DAYS(FROM_UNIXTIME(:keyword,"%Y-%m-%d")))'; } } } } if ($company !== 'all') { $criteria->addCondition("`Project_Company`.`id`=:companyId"); $criteria->params[':companyId'] = $company; } if ($priority === (string) Project::PRIORITY_HIGHEST) { $criteria->addCondition("`t`.`priority`=:priorityHighest"); $criteria->params[':priorityHighest'] = Project::PRIORITY_HIGHEST; } else { if ($priority === (string) Project::PRIORITY_HIGH) { $criteria->addCondition("`t`.`priority`=:priorityHigh"); $criteria->params[':priorityHigh'] = Project::PRIORITY_HIGH; } else { if ($priority === (string) Project::PRIORITY_MEDIUM) { $criteria->addCondition("`t`.`priority`=:priorityMedium"); $criteria->params[':priorityMedium'] = Project::PRIORITY_MEDIUM; } else { if ($priority === (string) Project::PRIORITY_LOW) { $criteria->addCondition("`t`.`priority`=:priorityLow"); $criteria->params[':priorityLow'] = Project::PRIORITY_LOW; } else { if ($priority === (string) Project::PRIORITY_LOWEST) { $criteria->addCondition("`t`.`priority`=:priorityLowest"); $criteria->params[':priorityLowest'] = Project::PRIORITY_LOWEST; } } } } } if ($state === 'closed') { $criteria->addCondition("`t`.`closeDate` IS NOT NULL"); } else { if ($state === 'open') { $criteria->addCondition("(`t`.`closeDate` IS NULL OR TO_DAYS('" . MDate::formatToDb(time(), 'date') . "') < TO_DAYS(`t`.`closeDate`))"); } } if (User::isClient()) { $criteria->addCondition("`Company_User2Company`.`userId`=:clientId AND `Company_User2Company`.`position`=:clientPosition"); $criteria->params[':clientId'] = Yii::app()->user->id; $criteria->params[':clientPosition'] = Company::OWNER; } if (User::isConsultant()) { $criteria->addCondition("`Task_Consultant`.`id`=:consultantId"); $criteria->params[':consultantId'] = Yii::app()->user->id; } // pagination $with = array(); if (strpos($criteria->condition, 'Project_Company') !== false) { $with[] = 'allCompany'; } if (strpos($criteria->condition, 'Company_User2Company') !== false) { $with[] = 'allCompany.allUser2Company'; } if (strpos($criteria->condition, 'Task_Consultant') !== false) { $with[] = 'allTask.allConsultant'; } if (count($with) >= 1) { $pages = new CPagination(Project::model()->with($with)->count($criteria)); } else { $pages = new CPagination(Project::model()->count($criteria)); } $pages->pageSize = $jqGrid['pageSize'] !== null ? $jqGrid['pageSize'] : self::GRID_PAGE_SIZE; $pages->applyLimit($criteria); // sort $sort = new CSort('Project'); $sort->attributes = array('closeDate' => array('asc' => "`t`.`closeDate`", 'desc' => "`t`.`closeDate` desc", 'label' => Project::model()->getAttributeLabel('Closed')), 'hourlyRate' => array('asc' => "`t`.`hourlyRate`", 'desc' => "`t`.`hourlyRate` desc", 'label' => Project::model()->getAttributeLabel('Rate')), 'openDate' => array('asc' => "`t`.`openDate`", 'desc' => "`t`.`openDate` desc", 'label' => Project::model()->getAttributeLabel('Opened')), 'priority' => array('asc' => "`t`.`priority`", 'desc' => "`t`.`priority` desc", 'label' => Project::model()->getAttributeLabel('priority')), 'title' => array('asc' => "`t`.`title`", 'desc' => "`t`.`title` desc", 'label' => Project::model()->getAttributeLabel('title')), 'company' => array('asc' => "`Project_Company`.`title`", 'desc' => "`Project_Company`.`title` desc", 'label' => Company2Project::model()->getAttributeLabel('companyId'))); $sort->defaultOrder = "`t`.`closeDate` ASC, `t`.`priority` ASC, `t`.`createTime` DESC"; $sort->applyOrder($criteria); // find all $with = array('allCompany' => array('select' => 'title')); if (strpos($criteria->condition, 'Company_User2Company') !== false) { $with['allCompany.allUser2Company'] = array('select' => 'id'); } if (strpos($criteria->condition, 'Task_Consultant') !== false) { $with['allTask.allConsultant'] = array('select' => 'id'); } $together = strpos($criteria->condition, 'Project_Company') !== false || strpos($criteria->order, 'Project_Company') !== false || strpos($criteria->condition, 'Company_User2Company') !== false || strpos($criteria->condition, 'Task_Consultant') !== false; if ($together) { $models = Project::model()->with($with)->together()->findAll($criteria); } else { $models = Project::model()->with($with)->findAll($criteria); } // create resulting data array $data = array('page' => $pages->getCurrentPage() + 1, 'total' => $pages->getPageCount(), 'records' => $pages->getItemCount(), 'rows' => array()); foreach ($models as $model) { $data['rows'][] = array('id' => $model->id, 'cell' => array(isset($model->allCompany[0]->id) ? CHtml::link(CHtml::encode($model->allCompany[0]->title), array('company/show', 'id' => $model->allCompany[0]->id)) : '', CHtml::encode($model->title), CHtml::encode($model->hourlyRate), CHtml::encode($model->getAttributeView('priority')), CHtml::encode(MDate::format($model->openDate, 'medium', null)), CHtml::encode(MDate::format($model->closeDate, 'medium', null)), CHtml::link('<span class="ui-icon ui-icon-zoomin"></span>', array('show', 'id' => $model->id), array('class' => 'w3-ig w3-link-icon w3-border-1px-transparent w3-first ui-corner-all', 'title' => Yii::t('link', 'Show'))) . CHtml::link('<span class="ui-icon ui-icon-pencil"></span>', array('update', 'id' => $model->id), array('class' => 'w3-ig w3-link-icon w3-border-1px-transparent w3-last ui-corner-all', 'title' => Yii::t('link', 'Edit'))))); } $this->printJson($data); }
/** * Manages all models. */ public function actionAdmin() { $this->processAdminCommand(); if (isset($_POST['Export'])) { return; } //we just sent a file. Send more and we mess up the file. $criteria = new CDbCriteria(); $this->editinglanguage = ""; if (isset($_POST['langcode'])) { $this->editinglanguage = $_POST['langcode']; } if (strlen($this->editinglanguage) == 0) { $langs = Message::model()->findAll(array('select' => 'distinct language')); if (isset($langs) && count($langs) > 0) { $this->editinglanguage = $langs[0]->language; } else { $this->editinglanguage = "en_US"; } } $criteria->addSearchCondition('language', $this->editinglanguage); $pages = new CPagination(Message::model()->count($criteria)); $pages->pageSize = Yii::app()->user->getState('NumberRecordsPerPage'); $pages->applyLimit($criteria); $sort = new CSort('Message'); $sort->applyOrder($criteria); $models = Message::model()->findAll($criteria); $_GET['langcode'] = $this->editinglanguage; $version = ""; $foundOption = Options::model()->find('name=:name AND userId=:id AND companyId=:compid', array(':name' => "Language.Version." . $_GET['langcode'], ':id' => 0, ':compid' => 0)); if ($foundOption !== null) { $version = $foundOption->datavalue; } $this->render('admin', array('models' => $models, 'pages' => $pages, 'sort' => $sort, 'language' => $this->editinglanguage, 'version' => $version)); }
/** * Index action */ public function actionIndex() { // New subscriber form $model = new Newsletter(); if (isset($_POST['Newsletter'])) { $model->attributes = $_POST['Newsletter']; if ($model->save()) { Yii::app()->user->setFlash('success', Yii::t('newsletter', 'Email Added.')); } } // Send newsletter if (isset($_POST['sendnewsletter']) && $_POST['sendnewsletter']) { // Make sure content exists if (isset($_POST['content']) && $_POST['content'] != '') { // Make sure there are enough email $emails = Newsletter::model()->findAll(); if ($emails) { $sent = 0; // Loop and send foreach ($emails as $row) { $email = Yii::app()->email; $email->subject = isset($_POST['subject']) ? $_POST['subject'] : 'Newsletter'; $email->to = $row->email; $email->from = Yii::app()->params['emailout']; $email->replyTo = Yii::app()->params['emailout']; $email->message = $_POST['content']; $email->send(); $sent++; } Yii::app()->user->setFlash('success', Yii::t('newsletter', '{count} Newsletter emails sent.', array('{count}' => $sent))); } else { Yii::app()->user->setFlash('error', Yii::t('newsletter', 'There are no subscribers to send the newsletter to.')); } } else { Yii::app()->user->setFlash('error', Yii::t('newsletter', 'You must provide a valid content to email.')); } } // Did we submit the form and selected items? if (isset($_POST['bulkoperations']) && $_POST['bulkoperations'] != '') { // Did we choose any values? if (isset($_POST['record']) && count($_POST['record'])) { // What operation we would like to do? switch ($_POST['bulkoperations']) { case 'delete': // Load records $records = Newsletter::model()->deleteByPk(array_keys($_POST['record'])); // Done Yii::app()->user->setFlash('success', Yii::t('newsletter', '{count} items deleted.', array('{count}' => $records))); break; default: // Nothing break; } } } // Load items and display $criteria = new CDbCriteria(); $count = Newsletter::model()->count(); $pages = new CPagination($count); $pages->pageSize = self::PAGE_SIZE; $pages->applyLimit($criteria); $sort = new CSort('Newsletter'); $sort->defaultOrder = 'joined DESC'; $sort->applyOrder($criteria); $sort->attributes = array('email' => 'email', 'joined' => 'joined'); $items = Newsletter::model()->findAll($criteria); $this->render('index', array('model' => $model, 'rows' => $items, 'pages' => $pages, 'sort' => $sort, 'count' => $count)); }
/** * Manages all models. */ public function actionAdmin() { $this->processAdminCommand(); $criteria = new CDbCriteria(); $criteria->addSearchCondition('companyId', Yii::app()->user->getState('selectedCompanyId')); $criteria->addSearchCondition('periodId', Yii::app()->user->getState('selectedPeriodId')); $pages = new CPagination(Trans::model()->count($criteria)); $pages->pageSize = Yii::app()->user->getState('NumberRecordsPerPage'); $pages->applyLimit($criteria); $sort = new CSort('Trans'); $sort->applyOrder($criteria); $models = Trans::model()->findAll($criteria); $trans = TempTrans::model()->findAll(array('condition' => 'userId=' . Yii::app()->user->id, 'order' => 'rownum')); $existsOldTrans = false; if ($trans !== null) { $existsOldTrans = count($trans) > 1 || isset($trans[0]) && strlen($trans[0]->notesheader) > 0 || isset($trans[0]) && strlen($trans[0]->amountdebit) > 0 || isset($trans[0]) && strlen($trans[0]->amountcredit) > 0 || isset($trans[0]) && strlen($trans[0]->fileInfo) > 0 || isset($trans[0]) && strlen($trans[0]->notes) > 0 || isset($trans[0]) && $trans[0]->customerId != 0; } $this->render('admin', array('models' => $models, 'pages' => $pages, 'sort' => $sort, 'existsOldTrans' => $existsOldTrans)); }
/** * Displayes the authitem manage page */ public function actionManage() { $this->processAdminCommand(); $page = Yii::app()->getRequest()->getParam("page", ""); if (Yii::app()->request->isAjaxRequest || $page != "") { $selectedType = Yii::app()->request->getParam('selectedType', Yii::app()->user->getState("selectedType")); } else { $selectedType = ""; } Yii::app()->user->setState("selectedType", $selectedType); $criteria = new CDbCriteria(); if ($selectedType != "") { $criteria->condition = "type = " . $selectedType; } if (!Yii::app()->request->isAjaxRequest) { Yii::app()->user->setState("currentPage", Yii::app()->request->getParam('page', 0) - 1); } $pages = new CPagination(AuthItem::model()->count($criteria)); $pages->route = "manage"; $pages->pageSize = $this->module->pageSize; $pages->applyLimit($criteria); $pages->setCurrentPage(Yii::app()->user->getState('currentPage')); $sort = new CSort('AuthItem'); $sort->applyOrder($criteria); $models = AuthItem::model()->findAll($criteria); $full = Yii::app()->request->getParam("full"); if (Yii::app()->request->isAjaxRequest && !$full) { $this->renderPartial('manage/list', array('models' => $models, 'pages' => $pages, 'sort' => $sort, 'full' => $full), false, true); } else { if (Yii::app()->request->isAjaxRequest && $full) { $this->renderPartial('manage/manage', array('models' => $models, 'pages' => $pages, 'sort' => $sort, 'full' => $full), false, true); } else { $this->render('manage/manage', array('models' => $models, 'pages' => $pages, 'sort' => $sort, 'full' => $full)); } } }
/** * Manages all posts. */ public function actionAdmin() { $this->breadCrumbs = array('Управление сайтом' => array('/users/default/siteManagment')); $this->changeUserData(); $criteria = new CDbCriteria(); $pages = new CPagination(User::model()->count()); $pages->applyLimit($criteria); $sort = new CSort('User'); $sort->defaultOrder = 'email'; $sort->applyOrder($criteria); $users = User::model()->findAll($criteria); $this->widget('FormWindow'); $this->renderAjax('admin', array('pages' => $pages, 'users' => $users, 'sort' => $sort)); }