本文整理汇总了PHP中CDbCriteria::mergeWith方法的典型用法代码示例。如果您正苦于以下问题:PHP CDbCriteria::mergeWith方法的具体用法?PHP CDbCriteria::mergeWith怎么用?PHP CDbCriteria::mergeWith使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CDbCriteria
的用法示例。
在下文中一共展示了CDbCriteria::mergeWith方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: search
/**
* 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));
}
示例2: actionIndex
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));
}
示例3: actionIndex
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]);
}
示例4: doRestList
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));
}
示例5: doRestList
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);
}
示例6: getForCategory
/**
* @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);
}
示例7: actionUserFind
/**
* 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);
}
示例8: validateAttribute
/**
* 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)));
}
}
示例9: actionView
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]);
}
示例10: validateAttribute
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));
}
}
示例11: doRestList
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));
}
示例12: actionRegister
/**
* 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]);
}
示例13: getCategorys
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);
}
示例14: print_task
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));';
}
}
}
}
}
}
}
示例15: count
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);
}