public function actionAddData()
	{
		die();
		$settings = 0;
		if(isset($_REQUEST['Settings']))
			$settings = $_REQUEST['Settings'];

		$criteria=new CDbCriteria;
		$criteria->limit = 1000;
		$criteria->offset = $settings;
		$criteria->order = 'id';

		$orgs = Orgs::model()->findAll($criteria);
		$cnt = 0;
		if($orgs){
			foreach($orgs as $org){

				/* $logcheck = ActionLog::model()->find(array('condition'=>'model_name=:model_name and model_id=:model_id and event=:event','params'=>array(':model_name'=>'Orgs',':model_id'=>$org->id,':event'=>ActionLog::ACTION_CREATE)));
				if(!$logcheck){
					$log = new ActionLog;
					$log->event = ActionLog::ACTION_CREATE;
					$log->user_id = $org->author;
			        $log->model_name = 'Orgs';
			       // $log->model_title = $org->title;
			        $log->datetime = $org->created_date;
			        $log->model_id = $org->id;
			        if($log->save()){
			        	$cnt++;
			        } 
		    	} */
		    /*	$lastUpdateDate = ActionLog::model()->find(array('condition'=>'model_name=:model_name and model_id=:model_id and (event=:event or event=:event2)','params'=>array(':model_name'=>'Orgs',':model_id'=>$org->id,':event'=>ActionLog::ACTION_CREATE, ':event2'=>ActionLog::ACTION_UPDATE),'order'=>'datetime DESC'));
				if($lastUpdateDate){
	        		$now = strtotime($org->updated_date); 
				    $last_date = strtotime($lastUpdateDate->datetime);
				    if($now > $last_date){
					    $datediff = $now - $last_date;
					    if(floor($datediff/(60*60*24)) > 30 ){ // more 30 days left
					    	$log = new ActionLog;
							$log->event = ActionLog::ACTION_UPDATE;
							$log->user_id = $org->lasteditor?$org->lasteditor:$org->author;
					        $log->model_name = 'Orgs';
					       // $log->model_title = $org->title;
					        $log->datetime = $org->updated_date;
					        $log->model_id = $org->id;
					        if($log->save()){
					        	$cnt++;
					        } 
					    }
					}
	        	} */
			}
		}
		echo 'Добавлено '.$cnt;
		$sleeper = 2;
		$settings += 1000;
		if($settings < 23300){
	    	  echo '<META HTTP-EQUIV=Refresh CONTENT="'.$sleeper.'; URL='.Yii::app()->createUrl("/logger/admin/default/adddata",array('Settings'=>$settings)).'">';
	    	  exit;
		}
	}
  	public function actionAddReview($id)
    {

        $id = (int)$id;
        $review = Orgs::model()->active()->findByPk($id);
        if(!$review)
            Yii::app()->end();
        if(isset($_POST['Comment'])) {

            $model = new Comment;
            $model->scenario = 'subcomment';
            $model->object_pk = $review->id;

            if(!Yii::app()->user->isGuest)
            {
                $model->user_id = Yii::app()->user->id;

            } else {

                 Yii::app()->end();
            }
            $model->setAttribute('status', Comment::STATUS_APPROVED);
            $this->performAjaxValidation($model, 'comments-form');
            	$model->attributes=$_POST['Comment'];
            if(empty($model->id_parent))
                $model->id_parent = null;

            

            if($model->validate()){
                
                if($model->save()){
                	if(isset($_POST['type']) && $_POST['type']==1){
                		$this->renderPartial('_comment_super',array('model'=>$model,'supermodel'=>$review));
                	} else{
                		// $this->renderPartial('_comment',array('model'=>$model));
                	}
                    
                } 
                
            } 

        }
        Yii::app()->end();
    }
示例#3
0
	public function starRating($id, $ratingAjax) {

      $id = (int)$id;
      $org = Orgs::model()->findByPk($id);
      if($org){

          $rating = OrgsRating::model()->findByAttributes(array(
            'org'=>$id
          ));
          // если не было категории - делаем
          if(!$rating)
          {
            $rating = new OrgsRating;
            $rating->org = $id;
            $rating->vote_count = 1;
            $rating->vote_sum = $ratingAjax;
            $rating->vote_average = round($rating->vote_sum / $rating->vote_count,2);
            $rating->save(false);

            $org->rating_id = $rating->id;
            $org->save(false,array('rating_id'));                    
          } else {
            $rating->vote_count = $rating->vote_count + 1;
            $rating->vote_sum = $rating->vote_sum + $ratingAjax;
            $rating->vote_average = round($rating->vote_sum / $rating->vote_count,2);
            if(!$rating->save()){
                VarDumper::dump($rating->errors); die(); // Ctrl + X  Delete line
            }
          }
          
    }
    return true;
    }
<?php
$ar = array();

 if($data->categories){
 	$org = Orgs::model()->findByPk($data->id);
 	$allrubrics = $org->categories;
 	if($allrubrics){
	 	foreach ($allrubrics as $cat){

	 	//	$cat_url = Yii::app()->createAbsoluteUrl($data->city->url.'/catalog/'.$cat->url);
	 	//	echo CHtml::link($cat->title, $cat_url, array('class'=>'parentCategoryElement'));
	 	$ar[] = $cat->title;
	 	}
	 }
 }
 if(!empty($ar)){
 	echo implode(', ',$ar);
 }
 ?>
示例#5
0
                <?php echo $form->textArea($model, 'description', 
                array(
                    'class'=>'form-control',
                   // 'id'=>'Issue_description',
                   // 'rows'=>10
                )); 
                ?>
            </div>


            </div>
        </div> <!-- / .form-group -->
         <?php
        if($articleorg_ar){
                    foreach($articleorg_ar as $key=>$phon){
                    	$org = Orgs::model()->findByPk($phon);
                        if($key == 0){
                            $buttn = '<button type="button" class="btn btn-success addPhone"><span class="btn-label icon fa fa-plus-square"></span></button>';
                        } else {
                            $buttn = '<button type="button" class="btn btn-danger remPhone"><span class="btn-label icon fa fa-minus-square"></span></button>';
                        }
                        ?>
                   <div class="form-group">
                    <?php  echo $form->label($model, 'articleorg_ar', array('class'=>'col-lg-2 col-md-12 col-sm-12 control-label')); ?>
                    <div class="col-lg-10 col-md-12 col-sm-12">
                    <div class="input-group">
                        <input type="text" value="<?php echo Yii::app()->createAbsoluteUrl('catalog/catalog/item',array('city'=>$org->city->url, 'id'=>$org->id, 'itemurl'=>$org->url)); ?>"  name="Article[articleorg_ar][]"  placeholder="http://moscow.zazadun.ru/12345/sometitle" maxlength="255" class="form-control">
                        <span class="input-group-btn">
                            <?php echo $buttn; ?>
                        </span>
                    </div>
  protected function _loadItem($id=null, $url)
  {
       // $id = null;
       // $expl = explode('-',$url,2);
       // if(!empty($expl) && is_int($expl[0]))
  		if(!$id && !$url)
  			throw new CHttpException(404, 'Страница не найдена.');

  		if($id)
        {
        	
        	// $id = $expl[0];
        	$model = Orgs::model()
		        ->active()
		        ->with('images','city')
		        ->findByPk($id);

		 //   if(isset($expl[1]))
		 //   {
		    	// if($model->url != $expl[1] || $model->city_id != $this->city->id)

		   // }
        }
        else 
        {
        	$model = Orgs::model()
		        ->active()
		        ->with('images','city')
		        ->withUrl($url)
		        ->find(array(
		        'limit'=>1
		       ));
		    if(!$model) // try search by name
		    {
		    	$redo = new Redo404;
				$model = $redo->detranslit($url,$this->city);
		    }
        }	
        
        if (!$model)
         throw new CHttpException(404, 'Страница не найдена.');

		if(!$id || $model->url != $url || $model->city_id != $this->city->id)
    	{

    		if($model->city_id)
    			$red = Yii::app()->createAbsoluteUrl('/catalog/catalog/item', array('city'=>$model->city->url, 'id'=>$model->id,  'itemurl'=>$model->url));
    		else
    			$red = Yii::app()->createAbsoluteUrl('/catalog/catalog/itemnocity', array('id'=>$model->id));
    		 $this->redirect($red, TRUE, 301);
    	}

     $model->saveCounters(array('views_count'=>1));

    return $model;
}
示例#7
0
     protected function beforeDelete(){
        if(!parent::beforeDelete())
            return false;

        OrgsImages::model()->updateAll(array('uploaded_by'=>null),array('condition'=>'uploaded_by='.$this->id));
        Orgs::model()->updateAll(array('author'=>null),array('condition'=>'author='.$this->id));

        $this->deleteModelDir(); // удалили модель? удаляем и файл и всю папку
        return true;
    }
示例#8
0
 public function actionFeedbackUpdate()
 {
     $model = new FormFeedbackUpdate();
     // if it is ajax validation request
     if (isset($_POST['ajax']) && $_POST['ajax'] === 'form-feedback-update') {
         $model->attributes = Yii::app()->request->getPost('FormFeedbackUpdate');
         $errors = CActiveForm::validate($model);
         if ($errors !== '[]') {
             echo $errors;
         } else {
             if ($model->validate()) {
                 $org = Orgs::model()->findByPk($model->org);
                 $url = Yii::app()->createAbsoluteUrl('/catalog/catalog/item', array('city' => $org->city->url, 'id' => $org->id, 'itemurl' => $org->url));
                 $subject = 'Обновление: ' . $org->title;
                 $content = 'Обновить данные <a href="' . $url . '">' . $org->title . '</a><br><br>';
                 $content .= $model->content . '<br><br>';
                 if (!Yii::app()->user->isGuest) {
                     $content .= 'Пользователь: ' . Yii::app()->user->username;
                 } else {
                     $content .= "Пользователь: Аноним";
                 }
                 // $mailto = '*****@*****.**';
                 $mailto = '*****@*****.**';
                 $send = SendMail::send($mailto, $subject, $content, true);
                 if (!isset($send->ErrorInfo) && !empty($send->ErrorInfo)) {
                     VarDumper::dump($send->ErrorInfo);
                     die;
                     // Ctrl + X    Delete line
                 }
                 if ($send) {
                     $message = 'Ваше сообщение успешно отправлено.';
                     if (Yii::app()->request->isAjaxRequest) {
                         echo CJSON::encode(array('flag' => true, 'message' => $message));
                     } else {
                         Yii::app()->user->setFlash('success', $message);
                         $this->refresh();
                     }
                 } else {
                     $message = 'Ошибка отправки сообщения.';
                     // $message .= $send->ErrorInfo;
                     if (Yii::app()->request->isAjaxRequest) {
                         echo CJSON::encode(array('flag' => false, 'message' => $message));
                     } else {
                         Yii::app()->user->setFlash('error', $message);
                         $this->refresh();
                     }
                 }
                 Yii::app()->end();
             }
         }
     }
     Yii::app()->end();
 }