示例#1
0
 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>';
 }
示例#2
0
 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."));
             }
         }
     }
 }
示例#3
0
 public function actionUpload()
 {
     Yii::import("ext.MyAcrop.qqFileUploader");
     $folder = 'uploads/tmp';
     // folder for uploaded files
     // $allowedExtensions = array("jpg","jpeg","gif","png");
     $allowedExtensions = array();
     $sizeLimit = Yii::app()->params['storeImages']['maxFileSize'];
     $uploader = new qqFileUploader($allowedExtensions, $sizeLimit, $this->uploadlogosession);
     $uploader->inputName = 'photo';
     $result = $uploader->handleUpload($folder);
     $datasession = Yii::app()->session->itemAt($this->uploadlogosession);
     if (!empty($datasession)) {
         end($datasession);
         $key = key($datasession);
         $result['tmpFile'] = $datasession[$key];
         $tmpFile = Yii::getPathOfAlias('webroot') . '/uploads/tmp/' . $result['tmpFile'];
         if (file_exists($tmpFile)) {
             $thumbTo = array(160, 160);
             $folder = Yii::getPathOfAlias('webroot') . '/uploads/tmp/';
             $uploadDirectoryUpload = rtrim($folder, '/');
             $check = MHelper::File()->getUniqueTargetPath($uploadDirectoryUpload, $result['tmpFile']);
             $target = $uploadDirectoryUpload . '/' . $check;
             // if (copy($tmpFile, $target)){
             Yii::import('ext.phpthumb.PhpThumbFactory');
             $thumb = PhpThumbFactory::create($tmpFile);
             $sizes = Yii::app()->params['storeImages']['sizes'];
             $method = $sizes['resizeThumbMethod'];
             $thumb->{$method}($thumbTo[0], $thumbTo[1])->save($target);
             if (copy($target, $tmpFile)) {
                 unlink($target);
                 //delete tmp file
             }
             /* $result['tmpFile'] = $check;
                     
             
                                 $data_sess = array();
             
                                 if(Yii::app()->session->itemAt($this->uploadlogosession)){
                                     $data = Yii::app()->session->itemAt($this->uploadlogosession);
                                     if(!is_array($data)){
                                         $data_sess[$key] = $check;
                                     } else {
                                         $data[$key] = $check;
                                         $data_sess = $data;
                                     }
                                 } else {
                                     $data_sess[$key] = $check;
                                 }
                                 Yii::app()->session->remove($this->uploadlogosession);
                                 Yii::app()->session->add($this->uploadlogosession, $data_sess);
                                 
                                 unlink($tmpFile); //delete tmp file
                                 */
             // }
         }
     }
     $result = htmlspecialchars(json_encode($result), ENT_NOQUOTES);
     echo $result;
 }
示例#4
0
 /**
  * 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;
 }
示例#5
0
 public static function array_merge_recursive_simple()
 {
     if (func_num_args() < 2) {
         trigger_error(__FUNCTION__ . ' needs two or more array arguments', E_USER_WARNING);
         return;
     }
     $arrays = func_get_args();
     $merged = array();
     while ($arrays) {
         $array = array_shift($arrays);
         if (!is_array($array)) {
             trigger_error(__FUNCTION__ . ' encountered a non array argument', E_USER_WARNING);
             return;
         }
         if (!$array) {
             continue;
         }
         foreach ($array as $key => $value) {
             if (is_string($key)) {
                 if (is_array($value) && array_key_exists($key, $merged) && is_array($merged[$key])) {
                     $merged[$key] = MHelper::array_merge_recursive_simple($merged[$key], $value);
                 } else {
                     $merged[$key] = $value;
                 }
             } else {
                 $merged[] = $value;
             }
         }
     }
     return $merged;
 }
示例#6
0
    public function actionTovote (){
        $id = (int)$_POST['id'];
        $voter = (int)$_POST['vote'];
        $ret = array();
        // check
        $ip = MHelper::Ip()->getIp();
        $vote = PollVote::model()->find(array('condition'=>'choice_id=:id and ip_address=:ip','params'=>array(':id'=>$id,':ip'=>$ip)));
        if(!$vote){
            $vote = new PollVote;
            $vote->vote = $voter;
            $vote->choice_id = $id;
            $vote->ip_address = $ip;
            if(!Yii::app()->user->isGuest){
              $vote->user_id = Yii::app()->user->id; 
            }
            if(!$vote->save()){
            	VarDumper::dump($vote->errors); die(); // Ctrl + X	Delete line
            }
            $weight = '';
            $sql = "SELECT COUNT(*) FROM poll_vote WHERE choice_id={$id} and vote={$voter}";
            $numClients = Yii::app()->db->createCommand($sql)->queryScalar();
            $review = PollChoice::model()->findByPk($id);
            if($voter == 1){
            	$review->yes = $numClients;
            	$diff = $review->yes - $review->no;
	            $sum = $review->yes + $review->no; 
				if($diff>0){
					$weight = round(($diff)*100/$sum);
				}
            	$review->weight =  $weight;
            	$review->votes =  $diff;
            	$review->save(false,array('yes','weight','votes'));

            } else {
            	$review->no = $numClients;
            	$diff = $review->yes - $review->no;
	            $sum = $review->yes + $review->no; 
				if($diff>0){
					$weight = round(($diff)*100/$sum);
				}
				$review->weight =  $weight;
				$review->votes =  $diff;
            	$review->save(false,array('no','weight','votes'));
            }

            
            $ret['flag'] = true;
            $ret['count'] = $numClients;
            $ret['yes'] = $review->yes;
            $ret['no'] = $review->no;
            $ret['type'] = $review->type;
            $ret['id'] = $review->id;

            $ret['weight'] = $weight;
            $ret['weight_text'] = (!empty($weight))?'считают '.$weight.'%':'';
            echo CJSON::encode($ret);
        }
    }
示例#7
0
 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;
 }
示例#8
0
 /**
  * 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 run() {

        $controller = $this->getController();


         // get the Model Name
    	// $model_class = ucfirst($controller->getId());
 
    	// create the Model
    	// $model = new $model_class();
    	Yii::import("ext.MyAcrop.qqFileUploader");
        $folder='uploads/tmp';// folder for uploaded files
       // $allowedExtensions = array("jpg","jpeg","gif","png");
        $allowedExtensions = array();
        $sizeLimit = Yii::app()->params['storeImages']['maxFileSize'];
        $uploader = new qqFileUploader($allowedExtensions, $sizeLimit, 'articlefiles');
        $uploader->inputName = 'tmpFiles';
        $result = $uploader->handleUpload($folder);

        $datasession = Yii::app()->session->itemAt('articlefiles');

        if(!empty($datasession)){
                end($datasession);
                $key = key($datasession);
                $result['tmpFile'] = $datasession[$key];

                $tmpFile = Yii::getPathOfAlias('webroot').'/uploads/tmp/'.$result['tmpFile'];

        if(file_exists($tmpFile)) {

            $thumbTo = array(720,400);
            $folder = Yii::getPathOfAlias('webroot').'/uploads/tmp/';
            $uploadDirectoryUpload = rtrim($folder,'/');
            $check = MHelper::File()->getUniqueTargetPath($uploadDirectoryUpload, $result['tmpFile']);
            $target = $uploadDirectoryUpload.'/'.$check;
                
                Yii::import('ext.phpthumb.PhpThumbFactory');
                $thumb  = PhpThumbFactory::create($tmpFile);
                $sizes  = Yii::app()->params['storeImages']['sizes'];
               // $method = $sizes['resizeThumbMethod'];
               // $thumb->$method($thumbTo[0],$thumbTo[1])->save($target);
                $thumb->resize(1000)->save($target);

               if (copy($target, $tmpFile)){
                    unlink($target); //delete tmp file
               }
           }
       }
        $result = htmlspecialchars(json_encode($result), ENT_NOQUOTES);

        echo $result;

    }
 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));
 }
示例#12
0
 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;
 }
示例#13
0
<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>

			</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 
 
} ?>

			

示例#15
0
 protected function moveUploadedTmp($fromUrl)
 {
     $filename = MHelper::File()->getUniqueTargetPath($this->folderPath, $fromUrl);
     $tmpFolder = Yii::getPathOfAlias(Yii::app()->params['storeImages']['tmp']);
     if (copy($tmpFolder . DIRECTORY_SEPARATOR . $fromUrl, $this->folderPath . DIRECTORY_SEPARATOR . $filename)) {
         unlink($tmpFolder . DIRECTORY_SEPARATOR . $fromUrl);
         $this->owner->saveAttributes(array($this->attribute => $filename));
         return true;
     }
     return false;
 }
示例#16
0
    'dataProvider'=>$dataProvider,
    'itemView'=>'application.modules.catalog.views.article._article_listview2',
    'id'=>'article_listview',       // must have id corresponding to js above
    'itemsCssClass'=>'item-article-list one-column',
    'template'=>"{items}"
));

} 
*/

if(!empty($blocks)){ ?>
<div class="row">
<div id="main_list_grid_m1"  data-columns>
<?php

	usort($blocks, MHelper::get('Array')->sortFunction('time'));
	$blocks = array_reverse($blocks);
	foreach ($blocks as $k=>$block) { 

		echo '<div class="item item-article-list one-column col-lg-4 col-md-6 col-sm-6 col-xs-12">';
		echo $block['html'];
		echo '</div>';
		
	 } ?>
</div> 
</div>
<?php } ?>

<div style="font-size:20px;font-weight:300;margin-left:26px;margin-bottom:18px;" class="rootCategory">
Каталог организаций
</div>
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>


// Validate and save comment on post request
//$comment = $module->processRequestArticle($model);
// Load model comments
$provider = CommentArticle::getObjectComments($model);

$themeUrl = Yii::app()->theme->baseUrl;

// Display comments
if($provider) {
 ?>
 <div class="clearfix"></div>
<div id="comment_module" class="woocommerce" style="margin-top:20px;margin-bottom:0px;">
<div id="reviews">
<div id="comments">
<?php
$ip = MHelper::Ip()->getIp();
			$this->widget('zii.widgets.CListView', array(
            'dataProvider'=>$provider,
            'ajaxUpdate'=>true,
            'template'=>"{items}\n{pager}",
            'itemView'=>'application.modules.comments.views.comment._item',
            'itemsTagName'=>'ol',
            'itemsCssClass'=>'commentlist',
           // 'viewData'=>array(),
            'emptyText'=>'',
            'pager'=>array(
              'maxButtonCount'=>5,
              'header' => '',
              'firstPageLabel'=>'<<',
              'lastPageLabel'=>'>>',
              'nextPageLabel' => '>',
 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));
 }
示例#20
0
 /**
  * @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;
 }
示例#21
0
  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,
        ),
    ));
  }
示例#22
0
	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;
	}
示例#23
0
 public function chickPhoto()
 {
     $photo = $this->photo;
     if (true === strpos($this->photo, '://')) {
         $save = MHelper::File()->getRemoteImg($photo, true);
         $tmpFile = Yii::getPathOfAlias('webroot') . '/uploads/tmp/' . $save;
         if (file_exists($tmpFile)) {
             $thumbTo = array(160, 160);
             $folder = $this->getFileFolder();
             $check = MHelper::File()->getUniqueTargetPath($uploadDirectoryUpload, $save);
             $target = $uploadDirectoryUpload . '/' . $check;
             if (copy($tmpFile, $target)) {
                 $thumb = PhpThumbFactory::create($target);
                 $sizes = Yii::app()->params['storeImages']['sizes'];
                 $method = $sizes['resizeThumbMethod'];
                 $thumb->{$method}($thumbTo[0], $thumbTo[1])->save($target);
                 $this->photo = $check;
                 $this->save(true, array('photo'));
                 unlink($tmpFile);
                 //delete tmp file
             }
         }
     }
     return true;
 }
示例#24
0
<div class="comment" id="comment_<?php echo $model->id; ?>">
    <div class="iTable">
    <div class="iAvatar" style="height: 30px;">
    <img class="comment-avatar" alt="" src="<?php echo $model->user->getAvatar(); ?> ">
    </div>
    <div class="iAuthor" style="min-height: 30px;">
    <div class="comment-heading">
          <?php echo $model->user->fullname; ?>
          <span><?php echo MHelper::Date()->timeAgo($model->created, array('short'=>true)); ?></span>
    </div>
    </div>    
    </div>
    <div class="clearfix"></div> 
      <div class="comment-text">
 	<?php echo nl2br(CHtml::encode($model->text)); ?>
      </div>
  </div> <!-- / .comment -->
示例#25
0
    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'));
        }
        
    }
示例#26
0
          'hideIconOnBalloonOpen'=> false,
        ),
      );
    }

?>
<div class="header-map" id="header-map">
	<div class="main-map">
	
	<div class="main-map-view">
	<div class="map-text">
	<?php 

	if(!empty($model->nearest_metro) && !empty($model->nearest_metro_distance) && $model->nearestmetro){

		$size = MHelper::Ip()->size($model->nearest_metro_distance);
		echo 'до '.$model->nearestmetro->metro_name.' - '.$size;
	}
	?>
	</div>
	<?php
	$truemap = false;
	if(($model->lat && $model->lng) || ($model->city->latitude && $model->city->longitude)){
		 if($model->lat && $model->lng){
		 	$lat = $model->lat;
		 	$lng = $model->lng;
		 	$zoom = 14;
		 } else if($model->city->latitude && $model->city->longitude){
		 	$lat = $model->city->latitude;
		 	$lng = $model->city->longitude;
		 	$zoom = 12;
示例#27
0
	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;
    }
示例#28
0
    /**
      * Получает конечные активные рубрики, в которых имеются активные фирмы по городу
      * @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;

    }
示例#29
0
 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;
     }
 }
示例#30
0
<?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
}
?>