public function action_getByName() { $search = $this->request->post('search'); if (Request::current()->is_ajax() && $search) { $criteria = new \DBCriteria(); $criteria->addSearchCondition('name', $search, true, 'AND', 'LIKE'); $data = \Model\Places::model()->findAll($criteria); $result = []; foreach ($data as $key => $value) { $result[$key]['item_id'] = $value->idplaces; $result[$key]['center_lat'] = $value->lat; $result[$key]['center_lng'] = $value->lng; } $this->response->body(json_encode(['data' => $result])); } }
/** * Validates the attribute of the object. * If there is any error, the error message is added to the object. * * @param \Model $object the object being validated * @param string $attribute the attribute being validated * * @throws \Kohana_Exception if given table does not have specified column name */ protected function validateAttribute($object, $attribute) { $value = $object->{$attribute}; if ($this->allowEmpty && $this->isEmpty($value)) { return; } if (is_array($value)) { // https://github.com/yiisoft/yii/issues/1955 $this->addError($object, $attribute, '{attribute} is invalid.'); return; } $className = $this->className === null ? get_class($object) : Yii::import($this->className); $attributeName = $this->attributeName === null ? $attribute : $this->attributeName; $finder = $this->getModel($className); $table = $finder->getTableSchema(); if (($column = $table->getColumn($attributeName)) === null) { throw new \Kohana_Exception('Table "{table}" does not have a column named "{column}".', ['{column}' => $attributeName, '{table}' => $table->name]); } $columnName = $column->rawName; $criteria = new DBCriteria(); if ($this->criteria !== []) { $criteria->mergeWith($this->criteria); } $tableAlias = empty($criteria->alias) ? $finder->getTableAlias(true) : $criteria->alias; $valueParamName = DbCriteria::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 : '{attribute} "{value}" is invalid.'; $this->addError($object, $attribute, $message, ['{value}' => CHtml::encode($value)]); } }
public function userCustomHistory($sender_id, $receiver_id, $session, $limit = false, $condition = false) { $criteria = new \DBCriteria(); $criteria->select = ' cht.sendtime, cht.message, usr1.fio as sender_fio, usr2.fio as receiver_fio, usr1.id as sender_id, usr2.id as receiver_id, usr1.photo as sender_photo, usr2.photo as receiver_photo '; $criteria->mergeWith(array('join' => 'INNER JOIN user AS usr1 ON usr1.id = cht.sender_id INNER JOIN user AS usr2 ON usr2.id = cht.receiver_id')); if ($limit) { $criteria->limit = $limit; } if (!$limit) { $criteria->limit = 200; $criteria->offset = $this->user_messages; } $criteria->order = ' cht.sendtime DESC '; if ($condition) { $criteria->condition = $condition; } else { $criteria->condition = ' ( cht.session = "' . $session . '" ) '; } $criteria->params = [':sender_id' => $sender_id, ':receiver_id' => $receiver_id]; $data = \Model\Chat::model()->findAll($criteria); // --------------Update Readed---------------// $criteria2 = new \DBCriteria(); $criteria2->condition = ' receiver_id = :receiver_id '; $criteria2->params = [':receiver_id' => $sender_id]; \Model\Chat::model()->updateAll(['read' => 1], $criteria2); return $data; }
public function yaestaenuso() { $criterio = new DBCriteria(); $criterio->addcondition("codservicio=:servi"); $criterio->paramas = array(":servi" => $this->codserv); $registro = Desolpe::model()->find($criterio); return is_null($registro) ? false : true; }