public function checkexists($attribute, $params) { if (!$this->hasErrors()) { $value = (string) $this->login_or_email; if (strpos($this->login_or_email, "@")) { // $user = User::model()->findByAttributes(array('email' => $this->login_or_email)); $user = User::model()->find(array('condition' => 'LOWER(email)=:email', 'params' => array(':email' => MHelper::String()->toLower($value)))); if ($user) { $this->user_id = $user->id; } } else { // $user = User::model()->findByAttributes(array('username' => $this->login_or_email)); $user = User::model()->find(array('condition' => 'LOWER(username)=:username', 'params' => array(':username' => MHelper::String()->toLower($value)))); if ($user) { $this->user_id = $user->id; } } if ($user === null) { if (strpos($value, "@")) { $this->addError("login_or_email", UsersModule::t("Email is incorrect.")); } else { $this->addError("login_or_email", UsersModule::t("Username is incorrect.")); } } } }
/** * Authenticates a user. * The example implementation makes sure if the username and password * are both 'demo'. * In practical applications, this should be changed to authenticate * against some persistent user identity storage (e.g. database). * @return boolean whether authentication succeeds. */ public function authenticate() { if (strpos($this->username, "@")) { $user = User::model()->find(array('condition' => 'LOWER(email)=:email', 'params' => array(':email' => MHelper::String()->toLower($this->username)))); } else { $user = User::model()->find(array('condition' => 'LOWER(username)=:username', 'params' => array(':username' => MHelper::String()->toLower($this->username)))); // $user = User::model()->notsafe()->findByAttributes(array('username' => $this->username)); } if ($user === null) { if (strpos($this->username, "@")) { $this->errorCode = self::ERROR_EMAIL_INVALID; } else { $this->errorCode = self::ERROR_USERNAME_INVALID; } } else { if (Yii::app()->getModule('users')->encrypting($this->password) !== $user->password) { $this->errorCode = self::ERROR_PASSWORD_INVALID; } else { if ($user->status == 0 && Yii::app()->getModule('users')->loginNotActiv == false) { $this->errorCode = self::ERROR_STATUS_NOTACTIV; } else { $this->_id = $user->id; $this->username = $user->username; $this->errorCode = self::ERROR_NONE; } } } return !$this->errorCode; }
public function renderSummary() { if (($count = $this->dataProvider->getItemCount()) <= 0) { return; } echo '<div class="' . $this->summaryCssClass . '">'; if ($this->enablePagination) { if (($summaryText = $this->summaryText) === null) { $summaryText = Yii::t('zii', 'Displaying {start}-{end} of {count} result(s).'); } $pagination = $this->dataProvider->getPagination(); $total = $this->dataProvider->getTotalItemCount(); $start = $pagination->currentPage * $pagination->pageSize + 1; $end = $start + $count - 1; if ($end > $total) { $end = $total; $start = $end - $count + 1; } echo strtr($summaryText, array('{start}' => $start, '{end}' => $end, '{count}' => $total, '{page}' => $pagination->currentPage + 1, '{pages}' => $pagination->pageCount)); echo MHelper::String()->plural($total, $this->declentionwords[0], $this->declentionwords[1], $this->declentionwords[2]); } else { if (($summaryText = $this->summaryText) === null) { $summaryText = Yii::t('zii', 'Total {count} result(s).'); } echo strtr($summaryText, array('{count}' => $count, '{start}' => 1, '{end}' => $count, '{page}' => 1, '{pages}' => 1)); echo MHelper::String()->plural($count, $this->declentionwords[0], $this->declentionwords[1], $this->declentionwords[2]); } echo '</div>'; }
public static function cleanUrl($text, $tolower = true) { $text = filter_var($text, FILTER_SANITIZE_URL); // $text = preg_replace('/[^A-Za-z0-9_\-]/', '', $text); if ($tolower) { $text = MHelper::String()->toLower($text); } return $text; }
/** * Displays a particular model. */ public function actionView($url) { // if(Yii::app()->user->isGuest) // Yii::app()->user->loginRequired(); $this->modules = 'userprofile'; // $this->layout = '//layouts/zazadun'; $this->breadcrumbs = array('Account'); /* if($url == Yii::app()->user->username){ $this->actionViewProfile(); Yii::app()->end(); } */ $user = User::model()->active()->find(array('condition' => 'username=:username', 'params' => array(':username' => $url))); if (!$user) { $user = User::model()->active()->find(array('condition' => 'LOWER(username)=:username', 'params' => array(':username' => MHelper::String()->toLower($url)))); } if (!$user) { throw new CHttpException(404, Yii::t('site', 'Page not found')); } $this->pageTitle = Yii::app()->name . ' - '; $this->pageTitle .= $user->fullname ? $user->fullname : $user->username; $this->user = $user; /* if(!$user->status == User::STATUS_DELETED){ $this->render('accountdeleted'); Yii::app()->end(); } */ // Load last comments // $comments = Comment::getLastComments(10, null, $user->id); // $lastImages = OrgsImages::getLastImages(10, null, $user->id); /* $comments = Comment::model() ->with('obj') ->approved() ->orderByCreatedDesc() ->findAll(array('condition'=>'t.id_parent is null and t.user_id='.$user->id,'limit'=>10)); $sql = "SELECT uploaded_by, org, max(date_uploaded) as date FROM orgs_images LEFT OUTER JOIN orgs o ON (o.id=orgs_images.org) WHERE orgs_images.uploaded_by = {$user->id} GROUP BY uploaded_by, cast(date_trunc('day',date_uploaded) as text), org ORDER BY date DESC LIMIT 10 "; $command = Yii::app()->db->createCommand($sql); $lastImages = $command->queryALL(); */ $need_status = Objects::STATUS_ACTIVE; $need_status_c = Comment::STATUS_APPROVED; $count = "SELECT count(id) FROM\n\t\t\t\t(SELECT\n\t\t\t\t CAST(CAST (1 AS TEXT) || CAST (T .id AS TEXT) AS NUMERIC (24, 0)) AS id, \n\t\t\t\t t.object_pk as org, t.name, t.text, t.created as date,\n\t\t\t\t t.yes, t.no, t.rating, null as filename\n\t\t\t\t FROM comments t\n\t\t\t\t LEFT OUTER JOIN objects organizations \n\t\t\t\t ON (organizations.id = t.object_pk)\n\t\t\t\t WHERE\tT .status = {$need_status_c} AND t.user_id = {$user->id} AND (organizations.status = {$need_status})\n\t\t\t\t \n\t\t\t\tUNION\n\t\t\t\t\t(SELECT \n\t\t\t\t CAST (CAST (2 AS TEXT) || CAST (max(i.id) AS TEXT) AS NUMERIC (24, 0)) AS id, \n\t\t\t\t i.object, null, null, max(i.date_uploaded) as date,\n\t\t\t\t null, null, null, \n\t\t\t\t array_to_string(array_agg(filename), ',') as filename\n\t\t\t\t FROM objects_images i\n\t\t\t\t LEFT OUTER JOIN objects organizations \n\t\t\t\t ON (organizations.id = i.object)\n\t\t\t\t\tWHERE i.uploaded_by = {$user->id} and (organizations.status = {$need_status} )\n\t\t\t\t GROUP BY i.uploaded_by, cast(date_trunc('day',i.date_uploaded) as text),i.object\n\t\t\t\t ORDER BY date DESC)\n UNION \n (SELECT\n CAST (CAST (3 AS TEXT) || CAST (o.id AS TEXT) AS NUMERIC (24, 0)) AS id,\n o.id, null, null, o.created_date as date,\n null, null, null, null\n FROM objects o\n WHERE o.status={$need_status} and o.author = {$user->id}\n ORDER BY date DESC)\n\t\t\t\t) ss\n\n\t\t\t\t\t"; $sql = "SELECT * FROM\n\t\t\t\t(SELECT\n\t\t\t\t CAST(CAST (1 AS TEXT) || CAST (T .id AS TEXT) AS NUMERIC (24, 0)) AS id, \n\t\t\t\t t.object_pk as org, t.name, t.text, t.created as date,\n\t\t\t\t t.yes, t.no, t.rating, null as filename\n\t\t\t\t FROM comments t\n\t\t\t\t LEFT OUTER JOIN objects organizations \n\t\t\t\t ON (organizations.id = t.object_pk)\n\t\t\t\t WHERE\tT .status = {$need_status_c} AND t.user_id = {$user->id} AND (organizations.status = {$need_status} )\n\t\t\t\t \n\t\t\t\tUNION\n\t\t\t\t\t(SELECT \n\t\t\t\t CAST (CAST (2 AS TEXT) || CAST (max(i.id) AS TEXT) AS NUMERIC (24, 0)) AS id, \n\t\t\t\t i.object, null, null, max(i.date_uploaded) as date,\n\t\t\t\t null, null, null, \n\t\t\t\t array_to_string(array_agg(filename), ',') as filename\n\t\t\t\t FROM objects_images i\n\t\t\t\t LEFT OUTER JOIN objects organizations \n\t\t\t\t ON (organizations.id = i.object)\n\t\t\t\t\tWHERE i.uploaded_by = {$user->id} and (organizations.status = {$need_status} )\n\t\t\t\t GROUP BY i.uploaded_by, cast(date_trunc('day',i.date_uploaded) as text),i.object\n\t\t\t\t ORDER BY date DESC)\n UNION \n (SELECT\n CAST (CAST (3 AS TEXT) || CAST (o.id AS TEXT) AS NUMERIC (24, 0)) AS id,\n o.id, null, null, o.created_date as date,\n null, null, null, null\n FROM objects o\n WHERE o.status={$need_status} and o.author = {$user->id}\n ORDER BY date DESC)\n\t\t\t\t) ss\n\n\t\t\t\t\tORDER BY ss.date DESC"; $total = Yii::app()->db->createCommand($count)->queryScalar(); $provider = new CSqlDataProvider($sql, array('totalItemCount' => $total, 'pagination' => array('pageSize' => 10))); /*$command = Yii::app()->db->createCommand($sql); $blocks = $command->queryALL(); $total = count($blocks); $pages = new CPagination($total); $pages->setPageSize(2);*/ $this->render('view', array('user' => $user, 'provider' => $provider)); }
public function checkEmail($attribute, $params) { $dbEmail = User::model()->find(array('condition'=>'LOWER(email)=:email','params'=>array('email'=>MHelper::String()->toLower($this->email)))); if(!$dbEmail) { return true; } else{ $this->addError($attribute, 'Email занят'); } return false; }
public function actionIndex() { $users = new User('search'); $users->unsetAttributes(); $criteria = new CDbCriteria(); $criteria->condition = 'status != ' . User::STATUS_DELETED; if (Yii::app()->request->getQuery('s')) { $s = MHelper::String()->toLower(Yii::app()->request->getQuery('s')); $s = addcslashes($s, '%_'); // escape LIKE's special characters $criteria->condition = 'status != ' . User::STATUS_DELETED . ' AND ((LOWER(email) LIKE :s)OR(LOWER(username) LIKE :s)OR(LOWER(fullname) LIKE :s))'; $criteria->params = array(':s' => "%{$s}%"); } $dataProvider = new CActiveDataProvider('User', array('criteria' => $criteria, 'sort' => array('attributes' => array('id', 'username', 'fullname'), 'defaultOrder' => 'id ASC'), 'pagination' => array('pageSize' => 50))); $this->render('index', array('dataProvider' => $dataProvider)); }
public function checkEmail($attribute, $params) { if ($this->email != '') { $dbEmail = User::model()->find('LOWER(email)=?', array(MHelper::String()->toLower($this->email))); if ($dbEmail == null) { return true; // $this->addError($attribute, 'Email does not exist in the database.'); } elseif ($dbEmail->email != $this->email) { $this->addError($attribute, Yii::t('site', 'Email is not available')); } elseif ($dbEmail->email == $this->email) { $this->addError($attribute, Yii::t('site', 'Email is not available')); } } else { $this->addError($attribute, Yii::t('site', 'Email is empty')); } return false; }
public function actionAutoCompleteUrl($term) { if(isset($_GET['term'])) { $arr = array(); $criteria = new CDbCriteria(); $criteria->compare('LOWER(url)',MHelper::String()->toLower($_GET['term']),true); $criteria->limit = 50; $model = new City; foreach($model->findAll($criteria) as $m) { $arr[] = $m->url; } } echo CJSON::encode($arr); Yii::app()->end(); }
public static function addNewCity($city) { $trueCity = null; if(!empty($city)){ // добавляем город $trueCity = new City; $trueCity->title = $city; $trueCity->alternative_title = $city; $address_city = $city; $params = array( 'geocode' => $address_city, // координаты 'format' => 'json', // формат ответа 'results' => 1, // количество выводимых результатов 'kind'=>'locality' // 'key' => '...', // ваш api key ); $trueRegion = $result_region = null; $response = json_decode(@file_get_contents('http://geocode-maps.yandex.ru/1.x/?' . http_build_query($params, '', '&'))); if ($response && $response->response->GeoObjectCollection->metaDataProperty->GeocoderResponseMetaData->found > 0) { $result = $response->response->GeoObjectCollection->featureMember[0]->GeoObject->Point->pos; if($result){ $exp_str1 = explode(" ", $result); $trueCity->latitude = $exp_str1[1]; $trueCity->longitude = $exp_str1[0]; } $result = $response->response->GeoObjectCollection->featureMember[0]->GeoObject->name; if($result){ $trueCity->title = $result; $trueCity->alternative_title = $result; } $result_region = $response->response->GeoObjectCollection->featureMember[0]->GeoObject->metaDataProperty->GeocoderMetaData->AddressDetails->Country->AdministrativeArea->AdministrativeAreaName; if($result_region){ $trueRegion = Region::model()->find('LOWER(title)=:title',array(':title'=>MHelper::String()->toLower($result_region))); if(!$trueRegion){ $trueRegion = new Region; $trueRegion->title = $result_region; $trueRegion->save(); } } } if($trueCity->latitude) { // склонение $params = array( 'format' => 'json', // формат ответа 'name'=>$trueCity->title ); $response = CJSON::decode(@file_get_contents('http://export.yandex.ru/inflect.xml?' . http_build_query($params, '', '&'))); if ($response) { if(isset($response[2])) $trueCity->rodpad = $response[2]; if(isset($response[6])) $trueCity->mestpad = $response[6]; } if($trueRegion){ $trueCity->region = $trueRegion->id; } $trueCity->pos = 0; $trueCityCheck = City::model()->find('LOWER(title)=:title or LOWER(alternative_title)=:alternative_title',array(':title'=>MHelper::String()->toLower($trueCity->title),':alternative_title'=>MHelper::String()->toLower($trueCity->title))); if($trueCityCheck) // потому-что ввести могут что угодно, а город обозначится только после запроса к яндексу. return $trueCityCheck; if($trueCity->save()){ } else { if($trueCity->errors && isset($trueCity->errors['title'])){ if($trueCity->errors['title'][0] == 'Город с таким названием уже существует.'){ $trueCity = City::model()->find('LOWER(title)=:title or LOWER(alternative_title)=:alternative_title',array(':title'=>MHelper::String()->toLower($trueCity->title),':alternative_title'=>MHelper::String()->toLower($trueCity->title))); } } } } } return $trueCity; }
</div> <?php } else { ?> <div data-droplevel="2" class="eluidba62844c col-md-6 col-sm-6 zn_sortable_content zn_content "> <div class="box image-boxes imgboxes_style4 kl-title_style_bottom eluid3e112a5a "> <div style="width:100%;" class="imgboxes-wrapper"> <a style="width:100%;" href="<?php echo $url; ?>"> <div style="display:block;width:100%;height:57%;padding-bottom: 57%;background-image:url('<?php echo $im; ?>');" class="cover-bg imgbox_image"></div> <img height="" width="" class="hide img-responsive imgbox_image" alt="" src="<?php echo $im; ?>"> <span class="imgboxes-border-helper"></span> <h3 class="m_title imgboxes-title"><div class="trunk_1"> <?php echo CHtml::encode($last->title); ?></div> </h3></a> </div> <div class="trunk_2" style="margin-bottom:20px;"> <?php echo MHelper::String()->purifyFromIm($last->description); ?> </div> </div><!-- end span --> </div> <?php } ?> <?php } ?>
public function actionItem($id) { $model = $this->_loadItem($id); $trunc_text = MHelper::String()->truncate($model->title, 400, '..', true, true, false); $this->pageTitle = $trunc_text . ' - Быстрые отзывы покупателей'; $this->pageTitle = trim(preg_replace('/\\s+/', ' ', $this->pageTitle)); $cr = new CDbCriteria(); $cr->condition = 'object_id=' . $model->id; $cr->order = 'created_date DESC'; $articlesProvider = new CActiveDataProvider(Article::model()->fullactive(), array('criteria' => $cr, 'pagination' => array('pageSize' => 10))); $pohs = Objects::model()->active()->findAll(array('condition' => 'categorie=' . $model->categorie . ' and id!=' . $id, 'limit' => 5, 'order' => 'created_date DESC')); if (!empty($_POST['Comment'])) { Yii::import('application.modules.comments.CommentsModule'); Yii::import('application.modules.comments.models.Comment'); $comment = new Comment(); if (isset($_POST['ajax']) && $_POST['ajax'] === 'comment-create-form') { $comment->attributes = Yii::app()->request->getPost('Comment'); $comment->status = Comment::STATUS_WAITING; if (!Yii::app()->user->isGuest) { $comment->name = Yii::app()->user->getShowname(); $comment->email = Yii::app()->user->email; } $errors = CActiveForm::validate($comment); if ($errors !== '[]') { echo $errors; } else { // Load module $module = Yii::app()->getModule('comments'); // Validate and save comment on post request $comment = $module->processRequest($model); echo '[]'; } Yii::app()->end(); } } if (isset($_POST['Objects']) && isset($_POST['itemData']) && $_POST['itemData'] == 1) { if (isset($_POST['ajax']) && $_POST['ajax'] === 'pinboard-form') { $errors = CActiveForm::validate($model); if ($errors !== '[]') { echo $errors; Yii::app()->end(); } } $model->attributes = $_POST['Objects']; if ($model->validate()) { if (isset(Yii::app()->session['deleteObjectsFiles'])) { $sessAr = unserialize(Yii::app()->session['deleteObjectsFiles']); if (isset($sessAr['id']) && $sessAr['id'] == $model->id && isset($sessAr['files']) && is_array($sessAr['files'])) { $files = $model->images; if ($files) { foreach ($files as $file) { if (in_array($file->id, $sessAr['files'])) { $file->delete(); } } } } } $model->addDropboxFiles($this->uploadsession); Yii::app()->session->remove($this->uploadsession); if (isset(Yii::app()->session['deleteObjectsFiles'])) { unset(Yii::app()->session['deleteObjectsFiles']); } if (Yii::app()->request->isAjaxRequest) { echo CJSON::encode(array('flag' => true, 'message' => 'done')); Yii::app()->end(); } else { $this->refresh(); Yii::app()->end(); } } } if (isset($_POST['Objects']) && isset($_POST['itemData']) && $_POST['itemData'] == 2) { if (isset($_POST['ajax']) && $_POST['ajax'] === 'pinboard-video-form') { $errors = CActiveForm::validate($model); if ($errors !== '[]') { echo $errors; Yii::app()->end(); } } $model->attributes = $_POST['Objects']; if (!empty($model->video_link) && $model->validate()) { $model->video = array($model->video_link); $model->video_comments = array(''); $model->setHttp($model->video, $model->video_comments, false, ObjectsHttp::TYPE_VIDEO); echo CJSON::encode(array('flag' => true, 'message' => 'done')); Yii::app()->end(); } echo '[]'; Yii::app()->end(); } $this->render('item', array('model' => $model, 'pohs' => $pohs, 'articlesProvider' => $articlesProvider)); }
public function search() { $criteria=new CDbCriteria; $criteria->compare('org_id',$this->org_id); $criteria->compare('type',$this->type); $criteria->compare('status',$this->status); $criteria->compare('LOWER(label)',MHelper::String()->toLower($this->label),true); return new CActiveDataProvider($this, array( 'criteria'=>$criteria, 'pagination' => array( 'pageSize' => 30, ), )); }
$events = '['; if (!empty($model)) { foreach ($model as $evt) { $events .= "{title:'" . trim(preg_replace('/\\s+/', ' ', $evt->title)) . "',"; // $events[]['title'] = $evt->title; $src = $time = $vozrast = ''; if ($evt->image) { // $src = $evt->getOrigFilePath().$evt->image; $src = Yii::app()->createAbsoluteUrl($evt->getUrl('260x260')); } $events .= "image:'" . $src . "',"; $events .= "lector:'" . trim(preg_replace('/\\s+/', ' ', MHelper::String()->truncate($evt->lector, 100))) . "',"; if ($evt->vozrast) { $vozrast = $evt->vozrast . '+'; } $events .= "vozrast:'" . $evt->vozrast . "',"; $events .= "description:'" . trim(preg_replace('/\\s+/', ' ', MHelper::String()->truncate($evt->description, 200))) . "',"; if ($evt->date) { $events .= "start:'" . Yii::app()->dateFormatter->format('yyyy-MM-dd', $evt->date) . 'T' . Yii::app()->dateFormatter->format('HH:mm', $evt->date) . ':00' . "',"; $events .= "time:'" . Yii::app()->dateFormatter->format('dd/MM/yyyy HH:mm', $evt->date) . "',"; } // $events[]['start'] = Yii::app()->dateFormatter->format('yyyy-MM-dd', $evt->date).'T'.Yii::app()->dateFormatter->format('HH:mm', $evt->date).':00'; // $events[]['url'] = Yii::app()->createAbsoluteUrl('lectures/view',array('id'=>$evt->id)); $events .= "url:'" . Yii::app()->createAbsoluteUrl('lectures/view', array('id' => $evt->id)) . "'"; $events .= '},'; } } $events = rtrim($events, ','); $events .= ']'; $script = "\n(function() {\n var currentLangCode = 'ru';\n\n function renderCalendar() {\n \$('#calendar').fullCalendar({\n header: {\n left: '',\n center: '',\n right: 'title prev,next'\n },\n views: {\n month: { // name of view\n titleFormat: 'MMMM'\n // other view-specific options here\n }\n },\n defaultDate: '" . Yii::app()->dateFormatter->format('yyyy-MM-dd', time()) . "',\n lang: currentLangCode,\n // buttonIcons: false, // show the prev/next text\n weekNumbers: false,\n editable: false,\n eventLimit: true, // allow more link when too many events\n events: " . $events . ",\n eventClick: function(event, jsEvent, view) {\n\n \$('#calcImage').css('background-image', 'url(' + event.image + ')' );\n \$('#calcModalLabel').html(event.title);\n \$('#calcModalBody').html(event.description);\n \$('.calcEventUrl').attr('href',event.url);\n \$('#calcModal').modal();\n return false;\n }\n });\n }\n\n renderCalendar();\n \n})();\n"; Yii::app()->clientScript->registerScript("calendar", $script, CClientScript::POS_END);
// Display comments if(!empty($comments)) { foreach($comments as $row) { ?> <div class="comment mainly" id="comment_<?php echo $row->id; ?>"> <span class="username"><?php if(!empty($row->user_id)){ echo CHtml::link(CHtml::image($row->user->getAvatar(60),$row->user->username,array('width' => 30),array('style'=>'margin-right:5px;vertical-align:top')),Yii::app()->createUrl('/account/'.$row->user->username)); echo CHtml::link(CHtml::encode($row->user->username),Yii::app()->createUrl('/account/'.$row->user->username)); } else { echo MHelper::String()->wordwrap(nl2br(CHtml::encode($row->name)),39,"\n",true); } ?></span> <span class="created">(<?php echo $row->created; ?>)</span> <?php //echo CHtml::link('#', Yii::app()->request->getUrl().'#comment_'.$row->id) ?> <div class="message"> <?php echo MHelper::String()->wordwrap(nl2br(CHtml::encode($row->text)),39,"\n",true); ?> </div> </div> <?php } } ?> </div>
/** * 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($additionalCriteria = null) { // @todo Please modify the following code to remove attributes that should not be searched. $criteria = new CDbCriteria(); // $criteria->with=array('userization'=>array('together'=>true)); if ($additionalCriteria !== null) { $criteria->mergeWith($additionalCriteria); } if ($this->id) { $this->id = (int) $this->id; } $criteria->compare('t.id', $this->id); $criteria->compare('LOWER(t.title)', MHelper::String()->toLower($this->title), true); $criteria->compare('t.description', $this->description, true); $criteria->compare('t.lft', $this->lft); $criteria->compare('t.rgt', $this->rgt); $criteria->compare('t.status_id', $this->status_id); $criteria->compare('t.level', $this->level); $criteria->compare('t.url', $this->url, true); $criteria->compare('t.icon', $this->icon, true); $criteria->compare('LOWER(t.keywords)', MHelper::String()->toLower($this->keywords), true); return new CActiveDataProvider($this, array('criteria' => $criteria, 'sort' => Category::getCSort(), 'pagination' => array('pageSize' => 50))); }
$lectorus = Lectures::model()->findAll(array('condition' => 'DATE(date)=DATE(CURDATE())')); if ($lectorus) { if (count($lectorus) > 1) { ?> <div id="goToNextSlideLectore"></div> <?php } ?> <ul id="main-lectorus-slider"> <?php foreach ($lectorus as $lectoria) { $src = $lectoria->getOrigFilePath() . $lectoria->image; echo '<li style="width:100%;height:100%;"> <a href="' . Yii::app()->createUrl('lectures/view', array('id' => $lectoria->id)) . '" class="a-lectures-slider"><div class="lect_img" style="background-image:url(' . $src . ')"></div> <div class="lect_txt"><div class="lect_txt_zag">' . MHelper::String()->truncate($lectoria->title, 25) . '</div><div class="m-t-5">' . MHelper::String()->truncate($lectoria->short_desc, 90) . '</div></div></a></li>'; } ?> </ul> <?php } else { echo '<div class="text-center" style="padding-top:22px;"><strong>Лекций на сегодня нет</strong></div>'; } ?> </div> <!--<img src="/img/lectorii.png" style="right:10px;" />--> <div class="v-center-div" id="main_v_lectorii"> </div> </div>
/** * 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($params = array(), $additionalCriteria = null, $pagination = true) { // @todo Please modify the following code to remove attributes that should not be searched. $criteria=new CDbCriteria; if($additionalCriteria !== null) $criteria->mergeWith($additionalCriteria); if($this->id) $this->id = (int)$this->id; $criteria->compare('t.id',$this->id); if($this->title){ $criteria->compare('LOWER(t.title)',MHelper::String()->toLower($this->title),true); } $criteria->compare('LOWER(t.description)',MHelper::String()->toLower($this->description),true); $criteria->compare('LOWER(t.address)',MHelper::String()->toLower($this->address),true); $criteria->compare('LOWER(t.street)',MHelper::String()->toLower($this->street),true); $criteria->compare('LOWER(t.dom)',MHelper::String()->toLower($this->dom),true); $criteria->compare('t.city_id',$this->city_id); $criteria->compare('t.link',$this->link,true); $criteria->compare('t.url',$this->url,true); $criteria->compare('t.created_date',$this->created_date,true); $criteria->compare('t.status',$this->status); $criteria->compare('t.categorie', $this->categorie); $criteria->compare('t.author', $this->author); if($pagination){ return new CActiveDataProvider($this, array( 'criteria' => $criteria, 'sort' => Objects::getCSort(), 'pagination' => array( 'pageSize'=>50, ) )); } else { return new CActiveDataProvider($this, array( 'criteria' => $criteria, 'sort' => Objects::getCSort('t.id'), 'pagination' => false )); } }
public function checkUniqueLabel($attribute,$params) { if(!$this->$attribute) return true; $name = MHelper::String()->simple_ucfirst($this->$attribute); if($this->group_id == null){ $condition = 'LOWER('.$attribute.')=:label AND group_id is null'; $params = array( ':label'=>MHelper::String()->toLower($name), ); } else { $condition = 'LOWER('.$attribute.')=:label AND group_id=:group_id'; $params = array( ':label'=>MHelper::String()->toLower($name), ':group_id'=>$this->group_id ); } if($this->id){ $condition .= ' AND id!='.$this->id; } $cnt = EavOptions::model()->count($condition, $params); if($cnt > 0) { $this->addError($attribute, $this->getAttributeLabel($attribute).' уже существует'); return false; } else { return true; } }
public function beforeSave() { if(parent::beforeSave()) { $reurl = false; if($this->isNewRecord) { $this->_newRec = true; $this->author = (Yii::app()->user)?Yii::app()->user->id:null; } else { $this->_curr = self::findByPk($this->id,array('select'=>'status_org')); if($this->_curr) { if($this->title != $this->_curr->title) $reurl = true; } } // Create slug Yii::import('ext.SlugHelper.SlugHelper'); if(!$this->url || $reurl){ // $this->url = SlugHelper::run(preg_replace('/\s{2,}/', ' ', $this->synonim)); $this->url = SlugHelper::run($this->title, 'yandex'); } else { $this->url = SlugHelper::run($this->url, 'yandex'); } $this->description = trim(MHelper::String()->purifyFromScript($this->description)); $this->updated_date = date('Y-m-d H:i:s'); return true; } else return false; }
/** * @access protected * @param $attributes * @return CDbCriteria */ protected function getFindByEavAttributesCriteria($attributes) { $criteria = new CDbCriteria(); $pk = $this->getModelTableFk(); $conn = $this->getOwner()->getDbConnection(); $i = 0; foreach ($attributes as $attribute => $values) { // If search models with attribute name with specified values. if (is_string($attribute)) { // Get attribute compare operator $attribute = $conn->quoteValue($attribute); if (!is_array($values)) { $values = array($values); } /*foreach ($values as $value) { $value = $conn->quoteValue($value); $criteria->join .= "\nJOIN {$this->tableName} eavb$i" . "\nON t.{$pk} = eavb$i.{$this->entityField}" . "\nAND eavb$i.{$this->attributeField} = $attribute" . "\nAND eavb$i.{$this->valueField} = $value"; $i++; }*/ $valueTmpArr = array(); foreach ($values as $value) { $valueTmpArr[] = $conn->quoteValue($value); } $valueInCondition = implode(',', $valueTmpArr); $criteria->join .= "\nJOIN {$this->tableName} eavb{$i}" . "\nON t.{$pk} = eavb{$i}.{$this->entityField}" . "\nAND eavb{$i}.{$this->attributeField} = {$attribute}"; if (!empty($valueInCondition)) { $criteria->join .= "\nAND eavb{$i}.{$this->valueField} IN ({$valueInCondition})"; } $i++; } elseif (is_int($attribute)) { $criteria->join .= "\nJOIN {$this->tableName} eavb{$i}" . "\nON t.{$pk} = eavb{$i}.{$this->entityField}" . "\nAND eavb{$i}.{$this->attributeField} = {$attribute}"; if (!empty($values) && !is_array($values) && is_int($values)) { // $values = $conn->quoteValue($values); $values = (int) $values; $values = "'" . $values . "'"; $criteria->join .= "\nAND eavb{$i}.{$this->valueField} = {$values}"; } elseif (!empty($values)) { if (!is_array($values)) { $values = array($values); } $valueTmpArr = array(); foreach ($values as $value) { $value = MHelper::String()->toLower($value); $value = "'" . $value . "'"; $valueTmpArr[] = $value; } $valueInCondition = implode(',', $valueTmpArr); if (!empty($valueInCondition)) { $criteria->join .= "\nAND LOWER(eavb{$i}.{$this->valueField}) IN ({$valueInCondition})"; } } else { $values = $conn->quoteValue(MHelper::String()->toLower($values)); $criteria->join .= "\nAND LOWER(eavb{$i}.{$this->valueField}) = {$values}"; } $i++; } } $criteria->distinct = TRUE; $criteria->group .= "t.{$pk}"; return $criteria; }
public function actionSearch() { // $this->layout = '//layouts/zazadun'; if(Yii::app()->request->isPostRequest && Yii::app()->request->getPost('q') && Yii::app()->request->getPost('pereparam')){ $this->redirect(Yii::app()->request->addUrlParam('catalog/article/search', array('q'=>Yii::app()->request->getPost('q')))); } $model = new Article; $count_items = 0; if (($term = Yii::app()->getRequest()->getQuery('q')) !== null) { $this->pageTitle = CHtml::encode($term); $query = $term; $s = MHelper::String()->toLower(trim($term)); $resultsPr = null; if(!empty($s)){ $s = addcslashes($s, '%_'); // escape LIKE's special characters $criteria = new CDbCriteria; $criteria->scopes='fullactive'; $criteria->condition ='(( (LOWER(t.title) LIKE :s) or (LOWER(t.description) LIKE :s) ))'; $criteria->params = array(':s'=>"%$s%"); $dataProvider = new CActiveDataProvider('Article', array( 'criteria' => $criteria, 'sort' => array( 'defaultOrder' => 't.created_date DESC', ), 'pagination' => array( 'pageSize' => 25, 'pageVar'=>'page' ), )); // VarDumper::dump($dataProvider); die(); // Ctrl + X Delete line } $count_items = 0; if ($dataProvider && $dataProvider->totalItemCount) { $count_items = $dataProvider->totalItemCount; } if(!empty($term) && !isset($_GET['page'])){ $searchquery = new Searchqueries; $searchquery->query = $term; $searchquery->quantity = $count_items; $searchquery->ip_address = MHelper::Ip()->getIp(); $searchquery->save(); } $dtitle = $query.' '; $this->render('search', compact('term', 'query','dataProvider','count_items','model','dtitle')); } else { $term = $query = ''; $dtitle = $query; $dataProvider = null; $this->render('search', compact('term', 'query','dataProvider','count_items','model','dtitle')); } }
/** * Получает конечные активные рубрики, в которых имеются активные фирмы по городу * @param $city_id int * @return array */ public static function getRubs($city_id, $descendantsroot = null, $query = null, $root_id = null, $depth=null, $except = null) { $connection=Yii::app()->db; $sql = 'SELECT DISTINCT "t"."id" AS "id", "t"."title" AS "title", "t"."url" AS "url" FROM "category_article" "t" LEFT OUTER JOIN "article_category" "categorization" ON ("categorization"."category"="t"."id") LEFT OUTER JOIN "article" "organizations" ON ("categorization"."org"="organizations"."id") WHERE (t.status_id = 1) AND (categorization.category=t.id) AND (organizations.city_id='.$city_id.') AND (organizations.status_org = '.Article::STATUS_ACTIVE.')'; if($descendantsroot){ $sql .= " AND (t.lft > {$descendantsroot->lft}) AND (t.rgt < {$descendantsroot->rgt} AND (t.root = {$descendantsroot->root}))"; if($depth){ $sql .= " AND (t.level <= {$descendantsroot->level} + ".$depth.") "; } } if($root_id){ $sql .= " AND (t.id={$root_id})"; } if($query){ $query = MHelper::String()->toLower($query); $query = addcslashes($query, '%_'); // escape LIKE's special characters $sql .= " AND (LOWER(t.title) LIKE '%$query%')"; } if($except){ $sql .= " AND (t.id!={$except})"; } $sql .= ' ORDER BY t.title '; $command=$connection->cache(4000)->createCommand($sql); $rows=$command->queryAll(); return $rows; }
/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id the ID of the model to be updated */ public function actionUpdate($new = false) { if ($new === true){ $model = new Objects; } else { $id = (int)$_GET['id']; $model=$this->loadModel($id); if($model->verified == true){ $this->pageTitle = 'Объекты'; $this->active_link = 'objects'; } else if($model->verified == false){ $this->pageTitle = 'Новые объекты'; $this->active_link = 'new_objects'; } $old_mesto = $model->address; } // Uncomment the following line if AJAX validation is needed $this->performAjaxValidation($model, 'objects-form'); if(isset($_POST['Objects'])) { $typeAttributes = Yii::app()->getRequest()->getPost('EavOptions', array()); if(!empty($typeAttributes)){ $er = $ers = null; foreach ($typeAttributes as $attribute => $value) { if (null == $value || (is_array($value) && empty($value))) { continue; } //сохраняем значения if(!is_array($value)){ $modelE = new EavProductVariant(); $er = $modelE->store($attribute, $value, $model, $forcheck = true); if($er == false){ $ers = $modelE->errors; break; } } else { foreach ($value as $val) { $modelE = new EavProductVariant(); $er = $modelE->store($attribute, $val, $model, $forcheck = true); if($er == false){ $ers = $modelE->errors; break 2; } } } } if(!empty($ers)){ $this->addFlashMessage($ers,'error'); $this->refresh(); } } $model->attributes=$_POST['Objects']; if(!$model->categories_ar || !is_array($model->categories_ar)){ $model->categories_ar = array(); $model->categorie = null; } else { $model->categorie = $model->categories_ar[0]; } if($new || (!empty($old_mesto) && $old_mesto != $model->address)){ $words = explode(',',$model->address,2); if(!empty($words)){ $city = trim($words[0]); $trueCity = City::model()->find('LOWER(title)=:title or LOWER(alternative_title)=:title',array(':title'=>MHelper::String()->toLower($city))); if(!$trueCity) $trueCity = City::addNewCity($city); if($trueCity) $model->city_id = $trueCity->id; } if(isset($words[1])){ $words = explode(',',$words[1],2); if(isset($words[0]) && !empty($words[0])){ $model->street = trim($words[0]); } if(isset($words[1]) && !empty($words[1])){ $model->dom = trim($words[1]); } } } if($model->saveData(array(), $typeAttributes, array(), array(), $model->video)){ if(isset(Yii::app()->session['deleteObjectsFiles'])) { $sessAr = unserialize(Yii::app()->session['deleteObjectsFiles']); if(isset($sessAr['id']) && $sessAr['id'] == $model->id && isset($sessAr['files']) && is_array($sessAr['files'])) { $files = $model->images; if($files) { foreach ($files as $file) { if(in_array($file->id,$sessAr['files'])){ $file->delete(); } } } } } $model->addDropboxFiles($this->uploadsession); Yii::app()->session->remove($this->uploadsession); if(isset(Yii::app()->session['deleteObjectsFiles'])) unset(Yii::app()->session['deleteObjectsFiles']); if(Yii::app()->request->isAjaxRequest){ } else { $text = $new? "Объект {$model->title} добавлен" : "Объект {$model->title} отредактирован"; $this->addFlashMessage($text,'success'); if($model->verified == true) { $this->redirect(Yii::app()->createAbsoluteUrl('catalog/admin/objects')); } else if($model->verified == false){ $this->redirect(Yii::app()->createAbsoluteUrl('catalog/admin/objects/new_objects')); } } } else { $this->addFlashMessage($model->errors,'error'); $this->refresh(); } } $categories_ar[] = $model->categorie; $video = $model->objectsVideo; $this->render('update',array( 'model'=>$model, 'categories_ar'=>$categories_ar, 'video'=>$video, )); }
if(!empty($data->logotip)) { $alt = $data->title; $im = $data->getUrl('180x180','adaptiveResize',false,'logotip'); } ?> <a class="oblects_view" href="<?php echo $url; ?>"> <div class="media"> <div class="pull-left"> <img alt="" src="<?php echo $im; ?>" class="lv-img-lg" /> </div> <div class="media-body m-t-5"> <p class="m-b-5 t-uppercase nocolor"><?php echo CHtml::encode($data->title); ?></p> <?php if(!empty($data->description)){ echo '<p class="object_descr m-b-5 trunk_8">'.MHelper::String()->purifyFromIm($data->description).'</p>'; } ?> <div class="pull-left" style="width:48%"> <?php $this->widget('application.modules.poll.widgets.Poll', array('org_id'=>$data->id, 'type'=>PollChoice::TYPE_PLUS)); ?> </div> <div class="pull-right" style="width:48%"> <?php $this->widget('application.modules.poll.widgets.Poll', array('org_id'=>$data->id, 'type'=>PollChoice::TYPE_MINUS)); ?> </div> <div class="clearfix"></div> </div> </div> </a> <div class="clearfix"></div>
/** * 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($additionalCriteria = null) { // @todo Please modify the following code to remove attributes that should not be searched. $criteria = new CDbCriteria; if($additionalCriteria !== null) $criteria->mergeWith($additionalCriteria); if($this->id) $this->id = (int)$this->id; $criteria->compare('t.id', $this->id); $criteria->compare('LOWER(t.title)',MHelper::String()->toLower($this->title),true); $criteria->compare('t.lft', $this->lft); $criteria->compare('t.rgt', $this->rgt); $criteria->compare('t.created_date', $this->created_date, true); $criteria->compare('t.level',$this->level); $criteria->compare('t.url',$this->url,true); return new CActiveDataProvider($this, array( 'criteria' => $criteria, 'sort' => Category::getCSort(), 'pagination' => array( 'pageSize' => 30, ), )); }
<div class="error-page"> <div class="error-code">403</div> <div class="error-text"> <?php if(isset($error['message'])){ echo MHelper::String()->toUpper($error['message']); } else { echo 'YOU HAVEN\'T ACCESS TO THIS PAGE'; } ?> </div> <!-- / .error-text --> </div>
<?php $lastJournal = $model->oneJournalFirst(); if($lastJournal) { $url = Yii::app()->createAbsoluteUrl('/catalog/catalogue/item', array('city'=>$this->city->url,'id'=>$lastJournal->id,'itemurl'=>$lastJournal->url,'dash'=>'-')); ?> <div class="org_rubrics" style="padding-left:32px;margin-top:20px;margin-bottom:20px;"> <span class="org_rubrics_title" style="margin-bottom:10px;">Регулярные каталоги товаров и акций</span><br> <p><a href="<?php echo $url; ?>"><?php echo MHelper::String()->truncate($lastJournal->title,26); ?></a></p> <?php $imgs = $lastJournal->images; if($imgs) { echo CHtml::link(CHtml::image($lastJournal->getOrigFilePath().$imgs[0]->filename,'',array('style'=>'max-width:225px;height:auto;')),$url); } ?> </div> <?php } ?>
public function beforeSave() { if (parent::beforeSave()) { $reurl = false; if ($this->isNewRecord) { $this->_newRec = true; $this->author = Yii::app()->user ? Yii::app()->user->id : null; } else { $this->_curr = self::findByPk($this->id); if ($this->_curr) { if ($this->title != $this->_curr->title) { $reurl = true; } } } // Create slug Yii::import('ext.SlugHelper.SlugHelper'); if (!$this->url || $reurl) { // $this->url = SlugHelper::run(preg_replace('/\s{2,}/', ' ', $this->synonim)); $this->url = SlugHelper::run($this->title, 'yandex'); } else { $this->url = SlugHelper::run($this->url, 'yandex'); } $unique = $this->url; $addsuffix = 0; while ($this->checkUniqueUrl($unique) > 0) { $unique = $this->url . $suffix . '-' . $addsuffix; $addsuffix++; } $this->url = $unique; $this->description = trim(MHelper::String()->purifyFromScript($this->description)); $this->updated_date = date('Y-m-d H:i:s'); return true; } else { return false; } }
public function actionSearch() { if(Yii::app()->request->isPostRequest && Yii::app()->request->getPost('q') && Yii::app()->request->getPost('pereparam')){ $this->redirect(Yii::app()->request->addUrlParam('catalog/catalog/search', array('q'=>Yii::app()->request->getPost('q')))); } $this->layout = '//layouts/zazadun'; $count_items = 0; if (($term = Yii::app()->getRequest()->getQuery('q')) !== null) { $this->pageTitle = CHtml::encode($term).' в '.$this->city->mestpad; $query = $term; $s = MHelper::String()->toLower(trim($term)); $resultsPr = null; if(!empty($s)){ $s = addcslashes($s, '%_'); // escape LIKE's special characters $criteria = new CDbCriteria; $criteria->scopes='active'; $criteria->with = array( 'categorization', 'categories'=>array( 'together'=>true ), 'city'=>array('together'=>true) ); // $criteria->together = true; /* $criteria->compare('t.city_id',$this->city_id); $criteria->compare('LOWER(t.title)',$s,true); $criteria->compare('LOWER(t.description)',$s,true,'OR'); $criteria->compare('LOWER(t.synonim)',$s,true,'OR'); $criteria->compare('LOWER(categories.title)', $s, true, 'OR'); $criteria->compare('LOWER(categories.keywords)', $s, true, 'OR'); */ $criteria->condition ='(t.city_id = '.$this->city->id.' and ( (LOWER(t.title) LIKE :s) or (LOWER(t.synonim) LIKE :s) or (LOWER(t.description) LIKE :s) or (LOWER(categories.title) LIKE :s) or (LOWER(categories.keywords) LIKE :s)))'; $criteria->params = array(':s'=>"%$s%"); $resultsPr = new CActiveDataProvider('Orgs', array( 'criteria' => $criteria, 'sort' => array( 'defaultOrder' => 't.title', ), 'pagination' => array( 'pageSize' => 20, 'pageVar'=>'page' ), )); // VarDumper::dump($resultsPr); die(); // Ctrl + X Delete line } if ($resultsPr && $resultsPr->totalItemCount) { $count_items = $resultsPr->totalItemCount; } if(!empty($term) && !isset($_GET['page'])){ $searchquery = new Searchqueries; $searchquery->query = $term; $searchquery->city_id = $this->city->id; $searchquery->quantity = $count_items; $searchquery->ip_address = MHelper::Ip()->getIp(); $searchquery->save(); } // $this->render('search', compact('term', 'query','resultsPr','count_items')); $dtitle = $term . ' '. $this->city->rodpad; $this->render('view',array( 'provider'=>$resultsPr, 'dtitle'=>$dtitle, 'itemView'=>'_organizations_view', 'count_items'=>$count_items )); } else { $term = $query = ''; $resultsPr = null; $dtitle = 'Поиск'; $this->render('view',array( 'provider'=>$resultsPr, 'dtitle'=>$dtitle, 'itemView'=>'_organizations_view', 'count_items'=>$count_items )); } }