/** * Retrieves a list of models based on the current search/filter conditions. * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions. */ public function search($prefix = null) { // Warning: Please modify the following code to remove attributes that // should not be searched. $criteria = new CDbCriteria(array('join' => 'INNER JOIN user ON user.id = t.user_id AND user.status = ' . UserAccount::STATUS_ACTIVE)); $criteria->mergeWith(self::getCriteriaFindByName($this->name, $prefix)); $criteria->compare('birth_place', $this->birth_place, true); if ($this->birth_day) { $date = new DateTime($this->birth_day); $criteria->compare('birth_day', $date->format('Y-m-d')); $this->ageFrom = null; $this->ageTo = null; } else { if ($this->ageFrom) { $criteria->compare('birth_day', '<=' . $this->calculateStartDate($this->ageFrom)->format('Y-m-d')); } if ($this->ageTo) { $criteria->compare('birth_day', '>=' . $this->calculateStartDate($this->ageTo)->format('Y-m-d')); } } $criteria->compare('gender', $this->gender); if ($this->applyScopes) { $scopes = $this->applyScopes; foreach ($scopes as $scopeName => $params) { $criteria->mergeWith($this->getScope($scopeName, $params)); } } return new CActiveDataProvider(new Profile(), array('criteria' => $criteria)); }
public function actionIndex() { $dbCriteria = new CDbCriteria(array('condition' => 't.status = :status', 'params' => array(':status' => News::STATUS_PUBLISHED), 'limit' => $this->module->perPage, 'order' => 't.creation_date DESC', 'with' => array('user'))); if (!Yii::app()->user->isAuthenticated()) { $dbCriteria->mergeWith(array('condition' => 'is_protected = :is_protected', 'params' => array(':is_protected' => News::PROTECTED_NO))); } if ($this->isMultilang()) { $dbCriteria->mergeWith(array('condition' => 't.lang = :lang', 'params' => array(':lang' => Yii::app()->language))); } $dataProvider = new CActiveDataProvider('News', array('criteria' => $dbCriteria)); $this->render('index', array('dataProvider' => $dataProvider)); }
public function actionIndex() { $dbCriteria = new CDbCriteria(['condition' => 't.status = :status', 'params' => [':status' => News::STATUS_PUBLISHED], 'order' => 't.create_time DESC', 'with' => ['user']]); if (!Yii::app()->user->isAuthenticated()) { $dbCriteria->mergeWith(['condition' => 'is_protected = :is_protected', 'params' => [':is_protected' => News::PROTECTED_NO]]); } if ($this->isMultilang()) { $dbCriteria->mergeWith(['condition' => 't.lang = :lang', 'params' => [':lang' => Yii::app()->language]]); } $dataProvider = new CActiveDataProvider('News', ['criteria' => $dbCriteria, 'pagination' => ['pageSize' => $this->module->perPage]]); $this->render('index', ['dataProvider' => $dataProvider]); }
public function doRestList() { $criteria = new CDbCriteria(array('condition' => 't.user_id = ' . $this->plainFilter['user_id'])); if (!empty($this->plainFilter['name'])) { $criteria->mergeWith(array('condition' => 'election.name LIKE :electionName', 'params' => array(':electionName' => '%' . $this->plainFilter['name'] . '%'))); } if (!empty($this->plainFilter['status'])) { $criteria->mergeWith(Candidate::getCriteriaWithStatusOnly($this->plainFilter['status'])); } $results = $this->getModel()->with($this->nestedRelations)->limit($this->restLimit)->offset($this->restOffset)->findAll($criteria); $this->outputHelper('Records Retrieved Successfully', $results, $this->getModel()->with($this->nestedRelations)->count($criteria)); }
public function doRestList() { if (empty($this->plainFilter['election_id'])) { throw new Exception('Election id filter property missed'); } $election = Election::model()->findByPk($this->plainFilter['election_id']); if (!$election) { throw new Exception('Election was not found'); } $criteria = new CDbCriteria(array('condition' => 't.election_id = ' . $election->id)); if (isset($this->plainFilter['user_id'])) { $criteria->mergeWith(array('condition' => 't.user_id = ' . (int) $this->plainFilter['user_id'])); } if (isset($this->plainFilter['candidate_id'])) { $criteria->mergeWith(array('condition' => 't.candidate_id = ' . (int) $this->plainFilter['candidate_id'])); } if (isset($this->plainFilter['accepted_only']) && $this->plainFilter['accepted_only']) { $criteria->addCondition('t.status = ' . Vote::STATUS_PASSED); } $peopleSearch = new PeopleSearch(); if ($name = $this->plainFilter['name']) { $peopleSearch->name = $name; } if ($ageFrom = $this->plainFilter['ageFrom']) { $peopleSearch->ageFrom = $ageFrom; } if ($ageTo = $this->plainFilter['ageTo']) { $peopleSearch->ageTo = $ageTo; } if ($birth_place = $this->plainFilter['birth_place']) { $peopleSearch->birth_place = $birth_place; } if ($gender = $this->plainFilter['gender']) { $peopleSearch->gender = $gender; } $arProvCriteria = $peopleSearch->search('profile')->criteria; if ($arProvCriteria) { $originalCriteria = clone $criteria; $criteria->mergeWith($arProvCriteria); } $results = $this->getModel()->with($this->nestedRelations)->limit($this->restLimit)->offset($this->restOffset)->findAll($criteria); $totalCount = $this->getModel()->with($this->nestedRelations)->count($criteria); $extraData = $totalCount; if (isset($this->plainFilter['candidate_id'])) { if (isset($originalCriteria)) { $criteria = $originalCriteria; } $acceptedCountCritetia = clone $criteria; $acceptedCount = $this->getModel()->with($this->nestedRelations)->count($acceptedCountCritetia->addCondition('t.status = ' . Vote::STATUS_PASSED)); $extraData = array('totalCount' => $totalCount, 'acceptedCount' => $acceptedCount); } $this->outputHelper('Records Retrieved Successfully', $results, $extraData); }
/** * @param StoreCategory $category * @param CDbCriteria $mergeWith * @return array|mixed|null */ public function getForCategory(StoreCategory $category, CDbCriteria $mergeWith) { $criteria = new CDbCriteria(['order' => 't.sort ASC', 'join' => 'LEFT JOIN {{store_product}} AS products ON products.producer_id = t.id', 'distinct' => true]); $criteria->addInCondition('products.category_id', [$category->id]); $criteria->mergeWith($mergeWith); return Producer::model()->findAll($criteria); }
/** * Duplicated from the admin controller to give a user list. * * @TODO: There's a method on the UserController that could be used, so would be worth consolidating) */ public function actionUserFind() { $res = array(); if (\Yii::app()->request->isAjaxRequest && !empty($_REQUEST['search'])) { $criteria = new \CDbCriteria(); $criteria->compare('LOWER(username)', strtolower($_REQUEST['search']), true, 'OR'); $criteria->compare('LOWER(first_name)', strtolower($_REQUEST['search']), true, 'OR'); $criteria->compare('LOWER(last_name)', strtolower($_REQUEST['search']), true, 'OR'); $words = explode(' ', $_REQUEST['search']); if (count($words) > 1) { // possibly slightly verbose approach to checking first and last name combinations // for searches $first_criteria = new \CDbCriteria(); $first_criteria->compare('LOWER(first_name)', strtolower($words[0]), true); $first_criteria->compare('LOWER(last_name)', strtolower(implode(' ', array_slice($words, 1, count($words) - 1))), true); $last_criteria = new \CDbCriteria(); $last_criteria->compare('LOWER(first_name)', strtolower($words[count($words) - 1]), true); $last_criteria->compare('LOWER(last_name)', strtolower(implode(' ', array_slice($words, 0, count($words) - 2))), true); $first_criteria->mergeWith($last_criteria, 'OR'); $criteria->mergeWith($first_criteria, 'OR'); } foreach (\User::model()->findAll($criteria) as $user) { $res[] = array('id' => $user->id, 'label' => $user->getFullNameAndTitle(), 'value' => $user->getFullName(), 'username' => $user->username); } } echo \CJSON::encode($res); }
/** * Validates the attribute of the object. * If there is any error, the error message is added to the object. * @param CModel $object the object being validated * @param string $attribute the attribute being validated */ protected function validateAttribute($object, $attribute) { $value = $object->{$attribute}; if ($this->allowEmpty && $this->isEmpty($value)) { return; } $className = $this->className === null ? get_class($object) : Yii::import($this->className); $attributeName = $this->attributeName === null ? $attribute : $this->attributeName; $finder = CActiveRecord::model($className); $table = $finder->getTableSchema(); if (($column = $table->getColumn($attributeName)) === null) { throw new CException(Yii::t('yii', 'Table "{table}" does not have a column named "{column}".', array('{column}' => $attributeName, '{table}' => $table->name))); } $columnName = $column->rawName; $criteria = new CDbCriteria(); if ($this->criteria !== array()) { $criteria->mergeWith($this->criteria); } $tableAlias = empty($criteria->alias) ? $finder->getTableAlias(true) : $criteria->alias; $valueParamName = CDbCriteria::PARAM_PREFIX . CDbCriteria::$paramCount++; $criteria->addCondition($this->caseSensitive ? "{$tableAlias}.{$columnName}={$valueParamName}" : "LOWER({$tableAlias}.{$columnName})=LOWER({$valueParamName})"); $criteria->params[$valueParamName] = $value; if (!$finder->exists($criteria)) { $message = $this->message !== null ? $this->message : Yii::t('yii', '{attribute} "{value}" is invalid.'); $this->addError($object, $attribute, $message, array('{value}' => CHtml::encode($value))); } }
public function actionView($slug) { $category = Category::model()->getByAlias($slug); if (is_null($category)) { throw new CHttpException(404, Yii::t('NewsModule.news', 'Requested page was not found!')); } $dbCriteria = new CDbCriteria(['condition' => 't.status = :status AND t.category_id = :category_id', 'params' => [':status' => News::STATUS_PUBLISHED, ':category_id' => $category->id], 'order' => 't.date DESC']); if (!Yii::app()->getUser()->isAuthenticated()) { $dbCriteria->mergeWith(['condition' => 'is_protected = :is_protected', 'params' => [':is_protected' => News::PROTECTED_NO]]); } if ($this->isMultilang()) { $dbCriteria->mergeWith(['condition' => 't.lang = :lang', 'params' => [':lang' => Yii::app()->language]]); } $dataProvider = new CActiveDataProvider('News', ['criteria' => $dbCriteria, 'pagination' => ['pageSize' => $this->getModule()->perPage]]); $this->render('view', ['dataProvider' => $dataProvider, 'category' => $category]); }
protected function validateAttribute($object, $attribute) { $value = $object->{$attribute}; if ($this->allowEmpty && $this->isEmpty($value)) { return; } $className = $this->className === null ? get_class($object) : Yii::import($this->className); $attributeName = $this->attributeName === null ? $attribute : $this->attributeName; $finder = CActiveRecord::model($className); $table = $finder->getTableSchema(); if (!is_array($attributeName)) { $attributeName = array($attributeName); } $condition = array(); foreach ($attributeName as $aN) { if (($column = $table->getColumn($aN)) === null) { throw new CException(Yii::t('yii', 'Table "{table}" does not have a column named "{column}".', array('{column}' => $aN, '{table}' => $table->name))); } $condition[] = $column->rawName . '=:vp'; } $criteria = array('condition' => implode(' OR ', $condition), 'params' => array(':vp' => $value)); if ($this->criteria !== array()) { $criteria = new CDbCriteria($criteria); $criteria->mergeWith($this->criteria); } if (!$finder->exists($criteria)) { $message = $this->message !== null ? $this->message : Yii::t('yii', '{attribute} "{value}" is invalid.'); $this->addError($object, $attribute, $message, array('{value}' => $value)); } }
public function doRestList() { $model = $this->getModel(); if (empty($this->plainFilter['election_id'])) { throw new Exception('Election id filter property missed'); } $election = Election::model()->findByPk($this->plainFilter['election_id']); if (!$election) { throw new Exception('Election was not found'); } $criteria = new CDbCriteria(array('condition' => 't.election_id = ' . $election->id)); $peopleSearch = new PeopleSearch(); if ($name = $this->plainFilter['name']) { $peopleSearch->name = $name; } if ($ageFrom = $this->plainFilter['ageFrom']) { $peopleSearch->ageFrom = $ageFrom; } if ($ageTo = $this->plainFilter['ageTo']) { $peopleSearch->ageTo = $ageTo; } if ($birth_place = $this->plainFilter['birth_place']) { $peopleSearch->birth_place = $birth_place; } if ($gender = $this->plainFilter['gender']) { $peopleSearch->gender = $gender; } $arProvCriteria = $peopleSearch->search('')->criteria; if ($arProvCriteria) { $criteria->mergeWith($arProvCriteria); } $results = $model->with($this->nestedRelations)->filter($this->restFilter)->orderBy($this->restSort)->limit($this->restLimit)->offset($this->restOffset)->findAll($criteria); $forCount = $this->getModel()->filter($this->restFilter); $this->outputHelper('Records Retrieved Successfully', $results, $forCount->with($this->nestedRelations)->count($criteria)); }
/** * Register Form */ public function actionRegister() { $register = new RegisterForm(ControllerCore::REQUIRE_CAPTCHA_SCENARIO); if (isset($_POST[CHtml::modelName($register)])) { $register->attributes = $_POST[CHtml::modelName($register)]; if ($register->save()) { $form = new LoginUser(); $form->username = $register->email; $form->password = $_POST[CHtml::modelName($register)]['password']; $form->rememberMe = 0; /** * Generate random Assignment for newly registered user */ $user = $register->user; $criteria = new CDbCriteria(); $criteria->with = ['corpusParseTreeConsensus']; $criteria->order = 'rand()'; $ratio = ['definitive' => 5, 'challenge' => ['limit' => 15, 'range' => [1000, 2000]], 'corpus' => ['Tutorial' => 5]]; $criteriaGolden = new CDbCriteria(); $criteriaGolden->mergeWith($criteria); $criteriaGolden->addCondition('corpusParseTreeConsensus.corpusParseTreeStringID is not null'); $criteriaGolden->limit = $ratio['definitive']; $stringsGolden = CorpusParseTreeString::model()->findAll($criteriaGolden); $criteriaChallenge = new CDbCriteria(); $criteriaChallenge->mergeWith($criteria); $criteriaChallenge->addCondition('corpusParseTreeConsensus.corpusParseTreeStringID is null'); $criteriaChallenge->addCondition('ID >= :min and ID <= :max'); $criteriaChallenge->params = [':min' => $ratio['challenge']['range'][0], ':max' => $ratio['challenge']['range'][1]]; $criteriaChallenge->limit = $ratio['challenge']['limit']; $stringsChallenge = CorpusParseTreeString::model()->findAll($criteriaChallenge); $stringsTutorial = []; foreach ($ratio['corpus'] as $corpusName => $limit) { $criteriaTutorial = new CDbCriteria(); $criteriaTutorial->mergeWith($criteria); $criteriaTutorial->with[] = 'corpusParseTree'; $criteriaTutorial->limit = $limit; $criteriaTutorial->compare('corpusParseTree.name', $corpusName); $stringsTutorial = array_merge($stringsTutorial, CorpusParseTreeString::model()->findAll($criteriaTutorial)); } foreach ([$stringsTutorial, $stringsGolden, $stringsChallenge] as $parts) { foreach ($parts as $string) { /* @var $string CorpusParseTreeString */ $assigned = new StringAssigned(); $assigned->userID = $user->ID; $assigned->corpusParseTreeStringID = $string->ID; $assigned->save(); } } /** * End Generate random Assignment */ if ($form->validate() && $form->login()) { $this->emailVerify($register->user); $this->redirect(['/parser']); } } } $this->render('register', ['register' => $register]); }
public function getCategorys($exCriteria) { $criteria = new CDbCriteria(); $criteria->condition = "type='" . lcfirst(get_class($this->owner)) . "'"; $criteria->order = "weight asc"; $criteria->mergeWith($exCriteria); return Category::model()->findAll($criteria); }
function print_task($tasks) { $id = 1; foreach ($tasks as $task) { $childcount = Task::model()->count(array('condition' => 'parent_id=' . $task->id . ' AND deleted=0')); $assignment = TaskAssignment::model()->find(array('condition' => 'task_id=' . $task->id . ' AND deleted=0')); if ($childcount > 0) { $childtasks = Task::model()->findAll(array('condition' => 'parent_id=' . $task->id . ' AND deleted=0')); echo 'g.AddTaskItem(new JSGantt.TaskItem("' . $task->id . '", "' . $task->title . '", "' . date('m/d/Y', strtotime($task->start_date)) . '", "' . date('m/d/Y', strtotime($task->due_date)) . '", "659af7", "#", 0, "' . (isset($assignment) ? $assignment->member->username : '') . '", 0, 1, ' . ($task->has_parent ? $task->parent_id : 0) . ', 0));'; print_task($childtasks); } else { echo 'g.AddTaskItem(new JSGantt.TaskItem("' . $task->id . '", "' . $task->title . '", "' . date('m/d/Y', strtotime($task->start_date)) . '", "' . date('m/d/Y', strtotime($task->due_date)) . '", "659af7", "#", 0, "' . (isset($assignment) ? $assignment->member->username : '') . '", 0, 0, ' . ($task->has_parent ? $task->parent_id : 0) . ', 0));'; // set criteria for tasklog $criteria = new CDbCriteria(); $criteria->with = array('taskAssignment.task'); $criteria->order = 'date ASC'; $criteria->condition = 'type="Project" AND task.id=' . $task->id . ' AND t.deleted=0 and task.deleted=0'; $criteria2 = new CDbCriteria(); $criteria2->with = array('taskAssignment.task'); $criteria2->condition = 'type="Non-project" AND t.member_id=' . $assignment->member_id . ' AND t.deleted=0 AND t.date BETWEEN "' . $task->start_date . '" AND "' . $task->due_date . '"'; $criteria3 = new CDbCriteria(); $criteria3->with = array('taskAssignment.task'); $criteria3->condition = 'type="Project" AND t.member_id=' . $assignment->member_id . ' AND t.deleted=0 AND t.date BETWEEN "' . $task->start_date . '" AND "' . $task->due_date . '"'; // Merge criteria $criteria->mergeWith($criteria2, 'OR'); $criteria->mergeWith($criteria3, 'OR'); // Get tasklog based on criteria $tasklog = TaskLog::model()->findAll($criteria); if ($tasklog) { echo 'g.AddTaskItem(new JSGantt.TaskItem("' . $task->id . '.1", "' . $task->title . ' - REAL", "", "", "fe7e7e", "#", 0, "-", 0, 1, ' . ($task->has_parent ? $task->parent_id : 0) . ', 0));'; foreach ($tasklog as $item) { if ($item->type == "Non-project") { echo 'g.AddTaskItem(new JSGantt.TaskItem("' . $task->id . '.' . $item->id . '", "' . $item->date . ' - ' . $item->task_title . ' (Non-project)", "' . date('m/d/Y', strtotime($item->date)) . '", "' . date('m/d/Y', strtotime($item->date)) . '", "737070", "#", 0, "' . $item->member->username . '", 0, 0, "' . $task->id . '.1", "' . $task->title . '-REAL", 0));'; } else { if ($item->type == "Project" && $item->taskAssignment->task->id != $task->id) { echo 'g.AddTaskItem(new JSGantt.TaskItem("' . $task->id . '.' . $item->id . '", "' . $item->date . ' - ' . $item->taskAssignment->task->title . ' (Different project)", "' . date('m/d/Y', strtotime($item->date)) . '", "' . date('m/d/Y', strtotime($item->date)) . '", "737070", "#", 0, "' . $item->member->username . '", 0, 0, "' . $task->id . '.1", "' . $task->title . '-REAL", 0));'; } else { echo 'g.AddTaskItem(new JSGantt.TaskItem("' . $task->id . '.' . $item->id . '", "' . $item->date . '", "' . date('m/d/Y', strtotime($item->date)) . '", "' . date('m/d/Y', strtotime($item->date)) . '", "fe7e7e", "#", 0, "' . $item->member->username . '", 0, 0, "' . $task->id . '.1", "' . $task->title . '-REAL", 0));'; } } } } } } }
public function count($condition = '', $params = array()) { $criteria = new CDbCriteria(); $criteria->join .= " inner join ttsk_task on tcmn_ttsk_id = ttsk_id "; $criteria->join .= " inner join ccmp_company on ttsk_ccmp_id = ccmp_id "; $criteria->compare('ccmp_sys_ccmp_id', Yii::app()->sysCompany->getActiveCompany()); $criteria->mergeWith($condition); return parent::count($criteria, $params); }
public function getSimilarPosts(Post $post, $limit = 10) { $criteria = new CDbCriteria(); $criteria->limit = $limit; $criteria->order = 'publish_time DESC'; $criteria->addNotInCondition('t.id', [$post->id]); $criteria->mergeWith(Post::model()->public()->published()->getFindByTagsCriteria($post->getTags())); return Post::model()->findAll($criteria); }
public function run() { $criteria = new CDbCriteria(); $criteria->limit = $this->limit; $criteria->order = 'publish_date DESC'; $criteria->addNotInCondition('t.id', array($this->post->id)); $criteria->mergeWith(Post::model()->public()->published()->getFindByTagsCriteria($this->post->getTags())); $posts = Post::model()->findAll($criteria); $this->render($this->view, array('posts' => $posts)); }
/** * Retrieves a list of models based on the current search/filter conditions. * * Typical usecase: * - Initialize the model fields with values from filter form. * - Execute this method to get CActiveDataProvider instance which will filter * models according to data in model fields. * - Pass data provider to CGridView, CListView or any similar widget. * * @return CActiveDataProvider the data provider that can return the models * based on the search/filter conditions. */ public function search($merge = null) { $criteria = new CDbCriteria(); $criteria->compare('id_discipline', $this->id_discipline); $criteria->compare('title', $this->title, true); if ($merge !== null) { $criteria->mergeWith($merge); } return new CActiveDataProvider($this, array('criteria' => $criteria)); }
function updateset($lid) { $clang = Yii::app()->lang; // Get added and deleted languagesid arrays if ($_POST['languageids']) { $postlanguageids = sanitize_languagecodeS($_POST['languageids']); } if ($_POST['label_name']) { $postlabel_name = sanitize_labelname($_POST['label_name']); } $newlanidarray = explode(" ", trim($postlanguageids)); $oldlangidsarray = array(); $labelset = Labelsets::model()->findByAttributes(array('lid' => $lid)); $oldlangidsarray = explode(' ', $labelset->languages); $addlangidsarray = array_diff($newlanidarray, $oldlangidsarray); $dellangidsarray = array_diff($oldlangidsarray, $newlanidarray); // If new languages are added, create labels' codes and sortorder for the new languages $result = Label::model()->findAllByAttributes(array('lid' => $lid), array('order' => 'code, sortorder, assessment_value')); if ($result) { foreach ($result as $row) { $oldcodesarray[$row['code']] = array('sortorder' => $row['sortorder'], 'assessment_value' => $row['assessment_value']); } } if (isset($oldcodesarray) && count($oldcodesarray) > 0) { foreach ($addlangidsarray as $addedlangid) { foreach ($oldcodesarray as $oldcode => $olddata) { $sqlvalues[] = array('lid' => $lid, 'code' => $oldcode, 'sortorder' => $olddata['sortorder'], 'language' => $addedlangid, 'assessment_value' => $olddata['assessment_value']); } } } if (isset($sqlvalues)) { foreach ($sqlvalues as $sqlvalue) { $label = new Label(); foreach ($sqlvalue as $name => $value) { $label->setAttribute($name, $value); } $label->save(); } } // If languages are removed, delete labels for these languages $criteria = new CDbCriteria(); $criteria->addColumnCondition(array('lid' => $lid)); $langcriteria = new CDbCriteria(); foreach ($dellangidsarray as $dellangid) { $langcriteria->addColumnCondition(array('language' => $dellangid), 'OR'); } $criteria->mergeWith($langcriteria); if (!empty($dellangidsarray)) { $result = Label::model()->deleteAll($criteria); } // Update the label set itself $labelset->label_name = $postlabel_name; $labelset->languages = $postlanguageids; $labelset->save(); }
/** * Retrieves a list of models based on the current search/filter conditions. * * Typical usecase: * - Initialize the model fields with values from filter form. * - Execute this method to get CActiveDataProvider instance which will filter * models according to data in model fields. * - Pass data provider to CGridView, CListView or any similar widget. * * @return CActiveDataProvider the data provider that can return the models * based on the search/filter conditions. */ public function search($merge = null) { // @todo Please modify the following code to remove attributes that should not be searched. $criteria = new CDbCriteria(); $criteria->compare('id_discipline', $this->id_discipline); $criteria->compare('id_user', $this->id_user); if ($merge !== null) { $criteria->mergeWith($merge); } return new CActiveDataProvider($this, array('criteria' => $criteria)); }
public function searchFilter() { $criteria1 = new CDbCriteria(); $criteria1->compare('receiver_id', Yii::app()->user->id, false, 'OR'); $criteria1->compare('sender_id', Yii::app()->user->id, false, 'OR'); $criteria = new CDbCriteria(); $criteria->mergeWith($criteria1); $criteria->compare('type_id', 2); $criteria->addNotInCondition('read_id', array(6)); $criteria->order = 'sender_date DESC'; return new CActiveDataProvider(get_class($this), array('criteria' => $criteria, 'pagination' => array('pageSize' => 5))); }
public function getTagCriteria($tag, $criteria = NULL) { if ($criteria == NULL) { $criteria = new CDbCriteria(); } $criteriaChild = new CDbCriteria(); $criteriaChild->join = "LEFT JOIN tags ON tags.pk = t.id AND tags.model = '{$this->owner->tableName()}'" . " LEFT JOIN tags_item ON tags_item.tags_id = tags.id"; $criteriaChild->addCondition(TUtil::qc('tags_item.tag_name') . " = :tag"); $criteriaChild->params = array(':tag' => $tag); $criteria->mergeWith($criteriaChild); return $criteria; }
public function doRestList() { if (empty($this->plainFilter['election_id'])) { throw new Exception('Election id filter property missed'); } $election = Election::model()->findByPk($this->plainFilter['election_id']); if (!$election) { throw new Exception('Election was not found'); } $criteria = new CDbCriteria(array('condition' => 't.election_id = ' . $election->id)); if (!empty($this->plainFilter['name'])) { $criteria->mergeWith(PeopleSearch::getCriteriaFindByName($this->plainFilter['name'], 'profile')); } if (!empty($this->plainFilter['status'])) { $criteria->mergeWith(Candidate::getCriteriaWithStatusOnly($this->plainFilter['status'])); } if (in_array($election->status, array(Election::STATUS_ELECTION, Election::STATUS_FINISHED))) { $criteria->mergeWith(array('with' => 'acceptedVotesCount')); } $results = $this->getModel()->with($this->nestedRelations)->limit($this->restLimit)->offset($this->restOffset)->findAll($criteria); $this->outputHelper('Records Retrieved Successfully', $results, $this->getModel()->with($this->nestedRelations)->count($criteria)); }
/** * Retrieves a list of models based on the current search/filter conditions. * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions. */ public function search($merge = null) { // Warning: Please modify the following code to remove attributes that // should not be searched. $criteria = new CDbCriteria(); $criteria->compare('id', $this->id); $criteria->compare('srid', $this->srid); $criteria->compare('username', $this->username); if ($merge !== null) { $criteria->mergeWith($merge); } return new CActiveDataProvider($this, array('criteria' => $criteria)); }
/** * Retrieves a list of models based on the current search/filter conditions. * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions. */ public function search($merge = null) { // Warning: Please modify the following code to remove attributes that // should not be searched. $criteria = new CDbCriteria(); $criteria->compare('id', $this->id); $criteria->compare('geometry_zone', $this->geometry_zone); $criteria->compare('parameter', $this->parameter, true); $criteria->compare('value', $this->value, true); if ($merge !== null) { $criteria->mergeWith($merge); } return new CActiveDataProvider($this, array('criteria' => $criteria)); }
public function searchPlat($idPlat) { $criteria = new CDbCriteria(); //$criteria->select = "id"; // $criteria->alias = "t"; $criteria->mergeWith(array('join' => 'LEFT JOIN characteristic_platforms as cp ON t.id = cp.id_characteristic', 'condition' => 'cp.id_platform = ' . $idPlat)); Characteristic::model()->findAll($criteria); // $criteria->addCondition(array("condtion"=>"id_app = $id_ap")); $criteria->compare('id', $this->id); $criteria->compare('name', $this->name, true); $criteria->compare('id_criteria', $this->id_criteria); return new CActiveDataProvider($this, array('criteria' => $criteria, 'pagination' => false)); }
/** * Retrieves a list of models based on the current search/filter conditions. * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions. */ public function search($merge = null) { // Warning: Please modify the following code to remove attributes that // should not be searched. $criteria = new CDbCriteria(); $criteria->compare('id', $this->id); $criteria->compare('wr_id', $this->wr_id); $criteria->compare('geom', $this->geom, true); $criteria->compare('altitude', $this->elevation, true); if ($merge !== null) { $criteria->mergeWith($merge); } return new CActiveDataProvider($this, array('criteria' => $criteria)); }
/** * Loads the requested data model. * * @param integer $id the model ID * * @return CActiveRecord the model instance. * @throws CHttpException if the model cannot be found */ protected function loadModel($id) { $finder = CActiveRecord::model($this->modelName); if ($this->additionalCriteriaOnLoadModel) { $c = new CDbCriteria($this->additionalCriteriaOnLoadModel); $c->mergeWith(array('condition' => $finder->tableSchema->primaryKey . '=:id', 'params' => array(':id' => $id))); $model = $finder->find($c); } else { $model = $finder->findByPk($id); } if (!$model) { throw new CHttpException(404, 'Unable to find the requested object.'); } return $model; }
/** * Retrieves a list of models based on the current search/filter conditions. * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions. */ public function search($merge = null) { // Warning: Please modify the following code to remove attributes that // should not be searched. $criteria = new CDbCriteria(); $criteria->compare('id', $this->id); $criteria->compare('wr_geometry_id', $this->wr_geometry_id); $criteria->compare('zone_name', $this->zone, true); $criteria->compare('pe', $this->pe); $criteria->compare('water_demand', $this->water_demand); if ($merge !== null) { $criteria->mergeWith($merge); } return new CActiveDataProvider($this, array('criteria' => $criteria)); }
/** * @param StoreCategory $category * @return Attribute[] */ public function getForCategory(StoreCategory $category) { $criteria = new CDbCriteria(['condition' => 't.is_filter = 1 AND t.type != :type', 'params' => [':type' => Attribute::TYPE_TEXT], 'join' => 'LEFT JOIN {{store_type_attribute}} ON t.id = {{store_type_attribute}}.attribute_id LEFT JOIN {{store_type}} ON {{store_type_attribute}}.type_id = {{store_type}}.id LEFT JOIN {{store_product}} AS products ON products.type_id = {{store_type}}.id', 'distinct' => true]); $categories = $category->getChildsArray(); if (!empty($categories)) { $categoriesCriteria = new CDbCriteria(['condition' => 'products.category_id = :category', 'params' => [':category' => $category->id]]); $categoriesCriteria->addInCondition('products.category_id', $categories, 'OR'); $criteria->mergeWith($categoriesCriteria, 'AND'); } else { $criteria->addCondition('products.category_id = :category'); $criteria->params[':category'] = $category->id; } return Attribute::model()->findAll($criteria); }