public function run() { $voting = null; if (is_numeric(HU::post('id_voting'))) { $voting = Voting::model()->onlyActive()->with('answer')->findByPk(HU::post('id_voting')); } if ($voting == null) { //echo CHtml::encode($this->controller->widget('vote.widgets.VoteWidget', null, true)); return; } if (Yii::app()->vote->check($voting->id_voting)) { $answers = $_POST['VotingAnswer']['name']; $cr = new CDbCriteria(); $cr->addColumnCondition(array('id_voting' => $voting->id_voting)); if (is_array($answers)) { $cr->addInCondition('id_voting_answer', $answers); } else { if (is_numeric($answers)) { $cr->addColumnCondition(array('id_voting_answer' => $answers)); } } VotingAnswer::model()->updateCounters(array('count' => 1), $cr); VisitSite::saveCurrentVisit(Voting::ID_OBJECT, $voting->id_voting); Yii::app()->user->setState('vote_' . $voting->id_voting, time()); // перегружаем голосовалку, чтоб обновились показатели счетчиков $voting = Voting::model()->onlyActive()->with('answer')->findByPk($voting->id_voting); } $voteCount = $voting->getSumVote(); echo CHtml::encode($this->controller->renderPartial("vote.widgets.views.statistic", array('voting' => $voting, 'voteCount' => $voteCount)), null, true); }
public function run() { $this->controller->_seoTitle = '交易记录 - ' . $this->controller->_setting['site_name']; $this->controller->loadModel(); $model = new UserTrade(); $criteria = new CDbCriteria(); //查询条件 $create_time_start = Yii::app()->request->getParam('create_time_start'); $create_time_end = Yii::app()->request->getParam('create_time_end'); $trade_type = Yii::app()->request->getParam('trade_type'); $trade_status = Yii::app()->request->getParam('trade_status'); $create_time_start && $criteria->addBetweenCondition('time_create', strtotime($create_time_start), strtotime($create_time_end)); if ($trade_type && $trade_type != 'all') { $criteria->addColumnCondition(['type' => $trade_type]); } if ($trade_status && $trade_status != 'all') { $criteria->addColumnCondition(['status' => $trade_status]); } $criteria->addColumnCondition(array('user_id' => Yii::app()->user->id)); $count = $model->count($criteria); $pages = new CPagination($count); $pages->pageSize = 10; $pages->applyLimit($criteria); $lists = $model->findAll($criteria); //加载css js Yii::app()->clientScript->registerScriptFile($this->controller->_static_public . "/js/jquery/jquery.js"); Yii::app()->clientScript->registerScriptFile($this->controller->_static_public . "/js/My97DatePicker/WdatePicker.js", CClientScript::POS_END); $this->controller->render('list_trade', array('lists' => $lists, 'pages' => $pages, 'create_time_start' => $create_time_start, 'create_time_end' => $create_time_end, 'trade_type' => $trade_type, 'trade_status' => $trade_status)); }
public function run() { $model = new Comment(); //条件 $criteria = new CDbCriteria(); $type = trim(Yii::app()->request->getParam('type')); $type && $criteria->addColumnCondition(array('type' => $type)); $status = trim(Yii::app()->request->getParam('status')); $status && $criteria->addColumnCondition(array('status' => $status)); $title = trim(Yii::app()->request->getParam('content')); $title && $criteria->addSearchCondition('content', $title); $criteria->order = 't.id DESC'; $count = $model->count($criteria); //分页 $pages = new CPagination($count); $pages->pageSize = 10; $pages->applyLimit($criteria); //查询 $result = $model->findAll($criteria); //全部类型 $model_types = ModelType::model()->findAll(); Yii::app()->clientScript->registerCssFile($this->controller->_static_public . "/js/kindeditor/code/prettify.css"); Yii::app()->clientScript->registerScriptFile($this->controller->_static_public . "/js/kindeditor/code/prettify.js", CClientScript::POS_END); $this->controller->render('index', array('model' => $model, 'model_types' => $model_types, 'datalist' => $result, 'pagebar' => $pages)); }
public static function check($idObject, $idInstance, $type, $ip, $expired, $countRepeats = 1) { $validIp = true; if ($expired > 0) { $expired = time() - $expired; $digitalIp = $ip; if (is_string($ip)) { $digitalIp = ip2long($ip); } $criteria = new CDbCriteria(); $criteria->addCondition('date>:date'); $criteria->params = array(':date' => $expired); $criteria->addColumnCondition(array('type_visit' => $type, 'ip' => $digitalIp, 'id_object' => $idObject)); if ($idInstance != null) { $criteria->addColumnCondition(array('id_instance' => $idInstance)); } $count = self::model()->count($criteria); if ($count < $countRepeats) { $validIp = true; } else { $validIp = false; } } return $validIp; }
public function search() { $criteria = new CDbCriteria(); if ($this->comment_id) { if ($this->comment_id) { $criteria->addColumnCondition(array('t.id' => $this->comment_id)); } } else { if ($this->post_id) { $criteria->addColumnCondition(array('t.post_id' => $this->post_id)); } if ($this->user_id) { $criteria->addColumnCondition(array('t.user_id' => $this->user_id)); } if ($this->user_name) { $criteria->addColumnCondition(array('t.user_name' => $this->user_name)); } if ($this->keyword) { $criteria->addSearchCondition('t.content', $this->keyword); } if ($this->start_create_time || $this->end_create_time) { $criteria->addCondition(array('and', 't.create_time > :starttime', 't.create_time < :endtime')); $starttime = (int) $this->start_create_time ? strtotime($this->start_create_time) : 0; $endtime = (int) $this->end_create_time ? strtotime($this->end_create_time) : $_SERVER['REQUEST_TIME']; $params = array(':starttime' => $starttime, ':endtime' => $endtime); $criteria->params = array_merge($criteria->params, $params); } } $data = $criteria->condition ? AdminComment::fetchList($criteria) : null; return $data; }
public function byUnicName($unicName) { $criteria = new CDbCriteria(); $criteria->addColumnCondition(array('unique_name' => $unicName)); $this->getDbCriteria()->mergeWith($criteria); return $this; }
public function run() { $model = new Catalog(); //一级分类条件 $criteria = new CDbCriteria(); $type = intval(Yii::app()->request->getParam('type')); $type && $criteria->addColumnCondition(array('type' => $type)); $criteria->addColumnCondition(array('parent_id' => 0)); $count = $model->count($criteria); //分页 $pages = new CPagination($count); $pages->pageSize = 20; $pages->applyLimit($criteria); $result = $model->findAll($criteria); $this->controller->render('index', array('model' => $model, 'datalist' => $result, 'pages' => $pages)); }
public function run() { $model = new User(); //审核状态 $user_status = array('all' => '所有', User::STATUS_AUDIT => '待审核', User::STATUS_DISABLE => '禁用', User::STATUS_NORMAL => '正常'); //条件 $criteria = new CDbCriteria(); $groupid = intval(Yii::app()->request->getParam('groupid')); $username = trim(Yii::app()->request->getParam('username')); $status = Yii::app()->request->getParam('status', 'all'); $groupid > 0 && $criteria->addColumnCondition(array('groupid' => $groupid)); if ($status != 'all') { $criteria->addSearchCondition('status', $status); } $criteria->addSearchCondition('username', $username); $criteria->order = 'uid ASC'; $count = $model->count($criteria); //分页 $pages = new CPagination($count); $pages->pageSize = 10; $pages->applyLimit($criteria); //查询 $result = $model->findAll($criteria); $this->controller->render('index', array('datalist' => $result, 'pagebar' => $pages, 'status' => $status, 'user_status' => $user_status)); }
public function getRootNode() { $criteria = new CDbCriteria(); $criteria->addColumnCondition(array('decisiontree_id' => $this->id, 'parent_id' => null)); $node = OphCoTherapyapplication_DecisionTreeNode::model()->find($criteria); return $node; }
/** * Search the local authorities and return both their address and the address of their social security department * * @param $term */ public function actionAutoComplete($term) { $crit = new \CDbCriteria(); // NOTE: have commented out the address eager loading here due to column ambiguity issues with the relation definitions. // need to investigate if this can be solved with the cunning use of scopes on the Contact model or not. $crit->with = array('contact' => array('alias' => 'service_contact'), 'commissioning_body', 'commissioning_body.contact', 'type' => array('alias' => 'service_type'), 'commissioning_body.type' => array('alias' => 'body_type')); $crit->compare('LOWER(t.name)', strtolower($term), true); $crit->compare('LOWER(commissioning_body.name)', strtolower($term), true, 'OR'); $crit->addColumnCondition(array('service_type.shortname' => 'SSD')); $crit->addColumnCondition(array('body_type.shortname' => 'LA')); $crit->order = 'commissioning_body.name, t.name'; $results = array(); $found_bodies = array(); foreach (\CommissioningBodyService::model()->findAll($crit) as $cbs) { $body = $cbs->commissioning_body; $found_bodies[] = $body->id; $results[] = array('id' => 'service' . $cbs->id, 'value' => $cbs->name . " ({$body->name})", 'service' => array('id' => $cbs->id, 'name' => $cbs->name, 'address' => $cbs->getLetterAddress(array('delimiter' => ",\n")), 'telephone' => $cbs->contact->primary_phone), 'body' => array('id' => $body->id, 'name' => $body->name, 'address' => $body->getLetterAddress(array('delimiter' => ",\n")), 'telephone' => $body->contact->primary_phone)); } $body_crit = new \CDbCriteria(); $body_crit->with = array('type', 'contact', 'contact.correspondAddress'); $body_crit->compare('LOWER(t.name)', strtolower($term), true); $body_crit->addNotInCondition('t.id', $found_bodies); $body_crit->addColumnCondition(array('type.shortname' => 'LA')); foreach (\CommissioningBody::model()->findAll($body_crit) as $body) { $results[] = array('id' => 'body' . $body->id, 'value' => $body->name, 'body' => array('id' => $body->id, 'name' => $body->name, 'address' => $body->getLetterAddress(array('delimiter' => ",\n")), 'telephone' => $body->contact->primary_phone)); } echo json_encode($results); }
private function fetchPosts() { $criteria = new CDbCriteria(); $criteria->select = array('id', 'category_id', 'topic_id', 'title', 'create_time', 'comment_nums', 'digg_nums', 'visit_nums', 'state'); $criteria->order = 'create_time desc'; $criteria->limit = $this->count; if ($this->cid) { $criteria->addColumnCondition(array('category_id' => $this->cid)); } if ($this->tid) { $criteria->addColumnCondition(array('topic_id' => $this->tid)); } $criteria->addColumnCondition(array('t.state' => POST_STATE_ENABLED)); $models = Post::model()->findAll($criteria); return (array) $models; }
public function run() { $controller = $this->getController(); $controller->_seoTitle = Yii::t('common', 'User Center') . ' - ' . Yii::t('common', 'My Replys') . ' - ' . $controller->_setting['site_name']; //我的回复 $uid = Yii::app()->user->id; $comment_mod = new Comment(); $reply_mod = new Reply(); $criteria = new CDbCriteria(); $criteria->addColumnCondition(array('t.user_id' => $uid)); $criteria->order = 't.id DESC'; //分页 $count = $reply_mod->count($criteria); $pages = new CPagination($count); $pages->pageSize = 15; $pages->applyLimit($criteria); $datalist = $reply_mod->findAll($criteria); foreach ((array) $datalist as $k => $v) { $reply = $comment_mod->findByPk($v->cid); if ($reply) { $c_mod_class = $controller->_content_models[$reply->type]; $c_mod_name = strtolower($c_mod_class); $content_mod = new $c_mod_class(); $content = $content_mod->findByPk($reply->content_id); $datalist[$k]['title'] = $content->title; $datalist[$k]['url'] = $controller->createUrl($c_mod_name . '/view', array('id' => $reply->content_id)); } } $controller->render('my_replys', array('datalist' => $datalist, 'pages' => $pages)); }
public function actionVerify() { $criteria = new CDbCriteria(); $criteria->addColumnCondition(array('state' => Post::STATE_DISABLED)); $data = self::fetchList($criteria); $this->render('list', $data); }
public function search() { $criteria = new CDbCriteria(); if ($this->postid) { $criteria->addColumnCondition(array('t.id' => $this->postid)); } else { if ($this->author) { $criteria->addColumnCondition(array('t.contributor' => $author, 't.user_name' => $this->author), 'OR'); } if ($this->keyword) { $criteria->addSearchCondition('t.title', $this->keyword); } } $data = $criteria->condition ? AdminPost::fetchList($criteria) : null; return $data; }
public function byParent($idParent) { $criteria = new CDbCriteria(); $criteria->addColumnCondition(array('id_parent' => $idParent)); $criteria->order = "sequence ASC"; $this->getDbCriteria()->mergeWith($criteria); return $this; }
/** * [clearContacts description] * @return [type] */ public function clearContacts() { $criteria = new CDbCriteria(); $criteria->addColumnCondition([$this->relationAttribute => $this->owner->id]); $numberOfContacts = (int) Yii::app()->db->getCommandBuilder()->createCountCommand("{{{$this->relationTable}}}", $criteria)->queryScalar(); $rowsAffected = Yii::app()->db->createCommand()->delete("{{{$this->relationTable}}}", "{$this->relationAttribute} = :owner", [':owner' => $this->owner->id]); return $numberOfContacts === $rowsAffected; }
public function byInstance(DaActiveRecord $model) { $criteria = new CDbCriteria(); $criteria->addColumnCondition(array('id_photogallery_object' => $model->getIdObject(), 'id_photogallery_instance' => $model->getPrimaryKey())); $criteria->order = "sequence ASC"; $this->getDbCriteria()->mergeWith($criteria); return $this; }
public function init() { $criteria = new CDbCriteria(); $criteria->order = 'sequence'; $criteria->addColumnCondition(array('id_banner_place' => $this->idBannerPlace)); $this->banners = Banner::model()->with('bannerFile')->findAll($criteria); parent::init(); }
public function actionForbidden() { $criteria = new CDbCriteria(); $criteria->addColumnCondition(array('state' => USER_STATE_FORBIDDEN)); $data = AdminUser::fetchList($criteria); $this->adminTitle = t('forbidden_user', 'admin'); $this->render('list', $data); }
public static function fetchSubList($pid) { $pid = (int) $pid; $criteria = new CDbCriteria(); $criteria->addColumnCondition(array('parent_id' => $pid)); $criteria->order = 'order asc, id asc'; $models = self::model()->find($criteria); return $models; }
private function fetchPosts() { $criteria = new CDbCriteria(); $criteria->select = array('id', 'category_id', 'topic_id', 'title', 'create_time', 'comment_nums', 'digg_nums', 'visit_nums', 'state'); $criteria->order = 'comment_nums desc, id desc'; $criteria->limit = $this->count; $criteria->addCondition('create_time > :createtime'); $createtime = $_SERVER['REQUEST_TIME'] - 3600 * 24 * $this->days; if ($this->cid) { $criteria->addColumnCondition(array('category_id' => $this->cid)); } if ($this->tid) { $criteria->addColumnCondition(array('topic_id' => $this->tid)); } $criteria->addColumnCondition(array('t.state' => POST_STATE_ENABLED)); $criteria->params = array_merge($criteria->params, array(':createtime' => $createtime)); $models = Post::model()->findAll($criteria); return (array) $models; }
public function onlyActive($order = null) { $criteria = new CDbCriteria(); $criteria->addColumnCondition(array('is_active' => '1')); if ($order != null) { $criteria->order = $order; } $this->getDbCriteria()->mergeWith($criteria); return $this; }
public function run() { $model = new Ad(); //条件 $criteria = new CDbCriteria(); $title = trim(Yii::app()->request->getParam('title')); $position_id = intval(Yii::app()->request->getParam('position_id')); $title && $criteria->addColumnCondition(array('title' => $title)); $position_id && $criteria->addColumnCondition(array('position_id', $position_id)); $criteria->order = 't.id ASC'; $count = $model->count($criteria); //分页 $pages = new CPagination($count); $pages->pageSize = 10; $pages->applyLimit($criteria); //查询 $result = $model->findAll($criteria); $this->controller->render('index', array('model' => $model, 'datalist' => $result, 'pagebar' => $pages)); }
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(); }
public function uniqueForUser($attribute, $params) { if (!$this->hasErrors()) { $cri = new CDbCriteria(); $cri->addColumnCondition(array('userId' => Yii::app()->user->id, 'network' => $this->{$attribute})); $r = $this->findAll($cri); if (count($r) > 0) { $this->addError($attribute, 'Социальная сеть ' . $this->network . ' уже привязана!'); } } }
/** * Get all the queue set resources that are part of the given category. * * @param PatientTicketing_QueueSetCategory $qscr * * @return array */ public function getQueueSetsForCategory(PatientTicketing_QueueSetCategory $qscr) { $class = self::$primary_model; $criteria = new \CDbCriteria(); $criteria->addColumnCondition(array('category_id' => $qscr->getId())); $res = array(); foreach ($class::model()->active()->with('permissioned_users')->findAll($criteria) as $qs) { $res[] = $this->modelToResource($qs); } return $res; }
public function actionIncome() { $model = new UserTrade(); $criteria = new CDbCriteria(); //搜索 $username = trim(Yii::app()->request->getParam('username')); if ($username) { $criteria->addColumnCondition(['user.username' => $username]); } $criteria->addColumnCondition(['t.type' => UserTrade::TYPE_INCOME]); $criteria->with = ['withdraw', 'user']; $criteria->order = 't.id DESC'; $count = $model->count($criteria); $pages = new CPagination($count); $pages->pageSize = 13; $criteria->limit = $pages->pageSize; $criteria->offset = $pages->currentPage * $pages->pageSize; $result = $model->findAll($criteria); $this->render('income', array('datalist' => $result, 'pagebar' => $pages)); }
public function run() { $model = new Image(); //条件 $criteria = new CDbCriteria(); $title = trim(Yii::app()->request->getParam('title')); $catalogId = intval(Yii::app()->request->getParam('catalogId')); $criteria->addColumnCondition(array('type' => $this->controller->_type)); $title && $criteria->addSearchCondition('title', $title); $catalogId && $criteria->addColumnCondition(array('catalog_id' => $catalogId)); $criteria->order = 't.id DESC'; $criteria->with = array('catalog'); $count = $model->count($criteria); //分页 $pages = new CPagination($count); $pages->pageSize = 10; $pages->applyLimit($criteria); $result = $model->findAll($criteria); $this->controller->render('index', array('model' => $model, 'datalist' => $result, 'pagebar' => $pages)); }
private static function fetchHotList($pid) { if (null === $criteria) { $criteria = new CDbCriteria(); } $criteria->order = 'id desc'; $criteria->limit = param('commentCountOfPage'); $criteria->addColumnCondition(array('post_id' => $pid, 'state' => Comment::STATE_ENABLED))->addCondition('up_nums > :hot_nums'); $comments = Comment::model()->findAll($criteria, array(':hot_nums' => param('upNumsOfCommentIsHot'))); return $comments; }
public function search() { $criteria = new CDbCriteria(); if ($this->postid) { $criteria->addColumnCondition(array('post_id' => $this->postid)); } if ($this->userid) { $criteria->addColumnCondition(array('user_id' => $this->userid)); } if ($this->fileType) { $criteria->addColumnCondition(array('file_type' => $this->fileType)); } if ($this->keyword) { $criteria->addSearchCondition('desc', $this->keyword); } if ($this->fileUrl) { $criteria->addSearchCondition('url', $this->fileUrl); } $data = $criteria->condition ? AdminUpload::fetchList($criteria) : null; return $data; }