Ejemplo n.º 1
0
 /**
  * This is the default 'index' action that is invoked
  * when an action is not explicitly requested by users.
  */
 public function actionIndex()
 {
     // $cats = Category::model()->findAll(array('condition'=>'lft=1 and rgt=2 and level=1','order'=>'title'));
     $this->pageTitle = 'Быстрые отзывы покупателей о товарах и услугах';
     $cats = Category::getRubsByParentId();
     $lasts = Objects::model()->active()->findAll(array('order' => 'created_date DESC', 'limit' => 15));
     $last_array = array();
     if (!empty($lasts)) {
         foreach ($lasts as $last) {
             $last_array[] = $last->id;
         }
     }
     /*  $criteria = new CDbCriteria;
         $criteria->order = 'created_date DESC';
         $criteria->limit = 3;
         $criteria->addNotInCondition('org_id', $last_array);
         $lasts_poll = PollChoice::model()->findAll($criteria);
         if(!empty($lasts_poll)){
             foreach ($lasts_poll as $last_poll) {
                 if(!in_array($last_poll->org->id, $last_array)){
                     $last_array[] = $last_poll->org->id;
                     $lasts[] = $last_poll->org;
                 }
                 
             }
         } */
     $this->render('index', array('cats' => $cats, 'lasts' => $lasts));
 }
Ejemplo n.º 2
0
    public function actionIndex() {

    	$this->active_link = 'dashboard';
    	//count users
    	$users = User::model()->count('status != '.User::STATUS_DELETED);
        $objects = Objects::model()->active()->count(array('select'=>'id'));
        $objectsNew = Objects::model()->active()->count(array('select'=>'id','condition'=>'verified = false'));
        $polls = PollChoice::model()->count();
        $photos = ObjectsImages::model()->count();
        $videos = ObjectsHttp::model()->count(array('condition'=>'type='.ObjectsHttp::TYPE_VIDEO));
        $this->render('dashboard',array('users'=>$users,'objects'=>$objects,
            'objectsNew'=>$objectsNew, 'polls'=>$polls,'photos'=>$photos,
            'videos'=>$videos

        ));
    }
Ejemplo n.º 3
0
<?php

echo '<div class="">';
$num = substr($data['id'], 0, 1);
$id = substr_replace($data['id'], '', 0, 1);
$id = (int) $id;
if ($num == 2) {
    $data['uploaded_by'] = $this->user->id;
    $bl = $this->renderPartial('_lastimages', array('model' => $data, 'addClass' => 'col-sm-3 col-xs-6'), true);
} elseif ($num == 1) {
    $comment = Comment::model()->with('obj')->findByPk($id);
    $bl = $this->renderPartial('_itemmain', array('model' => $comment, 'org' => $comment->obj), true);
} else {
    $object = Objects::model()->findByPk($id);
    $bl = $this->renderPartial('_objects_view', array('data' => $object), true);
}
echo $bl;
echo '</div>';
Ejemplo n.º 4
0
<?php

$user = User::model()->findByPk($model['uploaded_by']);
$org = Objects::model()->findByPk($model['org']);
$url = Yii::app()->createAbsoluteUrl('/fastreview/item', array( 'id'=>$org->id, 'dash'=>'-', 'itemurl'=>$org->url));
if(!empty($user)){
	$user_avatar = $user->getAvatar();
	$user_name = $user->fullname;
} else {
	$user_avatar = '/img/avatar.png';
	$user_name = 'Аноним';
}
?>
<div class="oblects_view">
<div class="media">
<div class="pull-left">
<div class="iAvatar">
<img class="lv-img-lg" src="<?php echo $user_avatar; ?>" alt="">
	</div>
	
</div>
<div class="media-body">
<div class="iAuthor">
		<span style="color:#333;font-size:17px;font-weight:300;display:block;line-height:1.3em;"><?php echo $user_name; ?></span>
		<span class="c-gray f-11" style="display:block;"><?php echo Yii::app()->dateFormatter->format('d MMMM yyyy', $model['date']); ?></span>
	</div>
<span style="font-weight:bold;"><?php 
echo CHtml::link($org->title,$url,array('class'=>'nocolor')); 
?></span>

<div class="lightbox row lastimages">
Ejemplo n.º 5
0
 protected function _loadItem($id = null)
 {
     if (!$id && !$url) {
         throw new CHttpException(404, 'Страница не найдена.');
     }
     if ($id) {
         $model = Objects::model()->active()->findByPk($id);
     }
     if (!$model) {
         throw new CHttpException(404, 'Страница не найдена.');
     }
     // $model->saveCounters(array('views_count'=>1));
     return $model;
 }
Ejemplo n.º 6
0
 protected function beforeDelete()
 {
     if (!parent::beforeDelete()) {
         return false;
     }
     Comment::model()->updateAll(array('user_id' => 0), array('condition' => 'user_id=' . $this->id));
     ObjectsImages::model()->updateAll(array('uploaded_by' => null), array('condition' => 'uploaded_by=' . $this->id));
     Objects::model()->updateAll(array('author' => null), array('condition' => 'author=' . $this->id));
     $this->deleteModelDir();
     // удалили модель? удаляем и файл и всю папку
     return true;
 }
Ejemplo n.º 7
0
 public function actionObjectsFiles($id){
      $id   = (int)$id;
      $model = Objects::model()->findByPk($id); 
      if(!$model)
          throw new CHttpException(404, Yii::t('site','Page not found'));
      $uploadPath = $model->getFileFolder();
      if($model->images){
      foreach($model->images as $file){ //get an array which has the names of all the files and loop through it 
          $obj['id'] = $file->id; //get the filename in array
          $obj['name'] = $file->realname;
          if(file_exists($uploadPath.$file->filename)){
          	$obj['size'] = filesize($uploadPath.$file->filename); //get the flesize in array
          } else {
          	$obj['size'] = '0';
          }
          $result[] = $obj; // copy it to another array
        }
         header('Content-Type: application/json');
         echo json_encode($result); // now you have a json response which you can use in client side 
     }
 }
Ejemplo n.º 8
0
	public function getViewUrlAdmin()
	{
		
                $model = Objects::model()->findByPk($this->object_pk);
   				
                if($model){
                	$ret = '';
                	if(get_class($model) == 'Objects'){
					$ret .= Yii::app()->createUrl("/catalog/admin/company/update", array("id"=>$model->id));
					} 
                	return Yii::app()->createAbsoluteUrl($ret);  
                }
  
	}
Ejemplo n.º 9
0
    public function actionUpdate($obj, $id=null)
    {
    //  $this->layout = '//layouts/new_item';
      $object = Objects::model()->active()->findByPk($obj);
      if(!$object)
        throw new CHttpException(404, 'Страница не найдена.');

      $model = null;
      if($id)
      {
        $new = false;
        $this->action_title = 'РЕДАКТИРОВАТЬ СТАТЬЮ';
        $this->pageTitle = 'Редактировать обзор';
        if(Yii::app()->user->isGuest){
           $this->redirect(Yii::app()->createAbsoluteUrl('/catalog/article/new',array('obj'=>$object->id)));
           Yii::app()->end();
        }
        $model = Article::model()->findByPk($id,'author='.Yii::app()->user->id);
        if(!$model)
          $this->redirect(Yii::app()->createAbsoluteUrl('/catalog/article/new',array('obj'=>$object->id)));
      } 
      if(!$model)
      {
        $new = true;
        $this->action_title = 'ДОБАВИТЬ СТАТЬЮ';
        $this->pageTitle = 'Добавление нового обзора - '.Yii::app()->name;
        $model = new Article;
      } 
    if(isset($_POST['Article']))
    {
      $model->attributes = $_POST['Article'];
      $model->object_id = $object->id;
      
      
      /*
      if(!$model->categories_ar || !is_array($model->categories_ar) || (isset($model->categories_ar[0]) && empty($model->categories_ar[0]))){
        $model->categories_ar = array();
        $model->categorie = null;
      } else {
        $model->categorie = 1;
      }*/

      // Uncomment the following line if AJAX validation is needed
    if(isset($_POST['ajax']) && $_POST['ajax']==='article-form')
    {
      
      $errors = CActiveForm::validate($model);
      
      if ($errors !== '[]') {
             $errors = CJSON::decode($errors);
             echo CJSON::encode(array('success'=>false, 'message'=>$errors));
             Yii::app()->end();
      } 

    }
    if(isset($_POST['preview']) && $_POST['preview'] == 1){

            $message = $this->renderPartial('_article_listview_preview',array('data'=>$model),true);
            echo CJSON::encode(array(
                'flag' => true,
                'preview' => true,
                'message'=>$message
            ));
            
            Yii::app()->end();
        }
    
      $model->status_org = Article::STATUS_ACTIVE;
      $model->verified = false;
      $model->mywork = false;
      if(isset($_POST['Article']['mywork'])){
        $model->mywork = true;
      }
     


      if($model->save()){
       // $model->setCategories($model->categories_ar);
        
        $model->addDropboxLogoFiles($this->uploadlogosession);
        Yii::app()->session->remove($this->uploadlogosession);

        $model->addDropboxFiles($this->uploadsession);
        Yii::app()->session->remove($this->uploadsession);

        $replace = $model->getOrigFilePath();
        $model->description = str_replace ( '/uploads/tmp/' , $replace , $model->description  );
        $model->save('false',array('description'));

        $article_url = Yii::app()->createAbsoluteUrl('/fastreview/item', array( 'id'=>$object->id, 'dash'=>'-', 'itemurl'=>$object->url));
        if(Yii::app()->request->isAjaxRequest){
          
            echo CJSON::encode(array('success'=>true, 'message'=>array('url'=>$article_url)));
            Yii::app()->end();
        } else {
            $this->redirect($article_url);
        }
      } 
    }

     /* $categories_ar  = array();
        $categories = $model->categories;
        if($categories){
            foreach($categories as $cats){
                $categories_ar[] = $cats->id;
            }
        }*/

      $this->render('_form', array(
        'model'=>$model,
        'object'=>$object
       // 'categories_ar'=>$categories_ar
        ));
    }
Ejemplo n.º 10
0
	protected function checkUniqueUrl($unique){
        // Check if url available
            if($this->isNewRecord) {
                $test = Objects::model()
                    ->withUrl($unique)
                    ->count();
            } else {
                $test = Objects::model()
                    ->withUrl($unique)
                    ->count('id!=:id', array(':id'=>$this->id));
            }
            return $test;
    }
Ejemplo n.º 11
0
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer $id the ID of the model to be loaded
  * @return City the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model=Objects::model()->findByPk($id);
     if($model===null)
         throw new CHttpException(404,'The requested page does not exist.');
     return $model;
 }
Ejemplo n.º 12
0
    /**
     * 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 Article;
        else
        {
            $id = (int)$_GET['id'];
            $model=$this->loadModel($id);
        }
        if($model->verified !== true){
            $this->active_link = 'new_article';
        }
        $firms = array(); $ar_url = array(); $error = false; $ids = array();

        if(!empty($_POST['Article']['article_ar'])){
        	$ars = $_POST['Article']['article_ar'];
        	if(isset($ars['firmname']) && !empty($ars['firmname'])){
        		foreach ($ars['firmname'] as $key => $value) {
        			$value = trim(strip_tags($value));
        			$firms[$key]['firmname'] = $value;
        		}
        	}

        	if(isset($ars['firmphotoh']) && !empty($ars['firmphotoh'])){
        		foreach ($ars['firmphotoh'] as $key => $value) {
        			$firms[$key]['firmphotoh'] = $value;
        		}
        	}
        	if(isset($ars['firmurl']) && !empty($ars['firmurl'])){
        		$ids = 0;
        		foreach ($ars['firmurl'] as $key => $value) {
        			$value = trim(strip_tags($value));
        			if(!empty($value)){
	        			$stri = stristr($value, Yii::app()->params['serverName']);
						if($stri === FALSE) {
							if (is_numeric($value)) { 
								$ids = (int) $value;
							} else {
								$this->addFlashMessage('Фирма '. ($key+1) .', url - неверная ссылка', 'error');
								$error = true;
								break;
							}
						} else {
							$id_url = explode('/',$stri);

							if(isset($id_url[1])){
								$ids = $id_url[1];
							}
						}
					}
					$ids_check = Objects::model()->findByPk($ids);
					if(!$ids_check){
						$this->addFlashMessage('Объект '. ($key+1) .', url - не найден', 'error');
						$error = true;
						break;
					}

        			$firms[$key]['firmurl'] = (int)$ids;

        		}
        	}
        	if(isset($ars['firmdescription']) && !empty($ars['firmdescription'])){
        		foreach ($ars['firmdescription'] as $key => $value) {
        			$value = trim(strip_tags($value));
        			$firms[$key]['firmdescription'] = $value;
        			if(!empty($value)){
        				
        			} else {
        				$this->addFlashMessage('Фирма '. ($key+1) .'  - нет описания', 'error');
						$error = true;
						break;
        			}

        		}
        	}
        } 

        // Uncomment the following line if AJAX validation is needed
        // $this->performAjaxValidation($model, 'orgs-form');
         
       /*  if(isset($_POST['Article']['articleorg_ar']) && 
         	!empty($_POST['Article']['articleorg_ar']) && 
            is_array($_POST['Article']['articleorg_ar'])) 
         { 
			$ar_url = $_POST['Article']['articleorg_ar'];

				for($i=0;$i<count($ar_url);$i++)
				{
					if(empty($ar_url[$i]))
						continue;
					$model->articleorg = $ar_url[$i];
					if($model->validate(array('articleorg')))
					{
						$ar_url[$i] = $model->articleorg;
					} else {
						$this->addFlashMessage($model->errors, 'error');
						$error = true;
						break;
					}
					
					$stri = stristr($ar_url[$i], Yii::app()->params['serverName']);
					if($stri === FALSE) {
						if (is_numeric($ar_url[$i])) { 
							$ids[] = (int) $ar_url[$i];
						} else {
							$this->addFlashMessage('Фирма, url - неверная ссылка', 'error');
							$error = true;
							break;
						}
					} else {
						$id_url = explode('/',$stri);

						if(isset($id_url[1])){
							$ids[] = $id_url[1];
						}
					}
				}
				
		 }
		 */
		 if(isset($_POST['Article'])){
		 	 
		 	// VarDumper::dump($_POST); die(); 
		}
		
        if(isset($_POST['Article']) && !$error)
        {

            $model->attributes=$_POST['Article'];
              
            if(!$model->categories_ar || !is_array($model->categories_ar) || (isset($model->categories_ar[0]) && empty($model->categories_ar[0]))){
                $model->categories_ar = array();
                $model->categorie = null;
            } else {
                $model->categorie = $model->categories_ar[0];
            }

            if($model->save()){
            
                
                
                $model->setCategories($model->categories_ar);
            //	$model->articleorg_ar = $ids;
           // 	$model->setArticleOrg($model->articleorg_ar);

                $model->addDropboxLogoFiles($this->uploadlogosession);
                Yii::app()->session->remove($this->uploadlogosession);

                $model->addDropboxFiles($this->uploadsession);
                Yii::app()->session->remove($this->uploadsession);

                $replace = $model->getOrigFilePath();
                $model->description = str_replace ( '/uploads/tmp/' , $replace , $model->description  );
                $model->save('false',array('description'));
                
                if(!empty($firms)){

              	    $dontDelete = array();
                	foreach ($firms as $key => $firm) {
                		 
                		 $found = Article::model()->findByAttributes(array(
							'part_org'=>$firm['firmurl'],
							'part'=>$model->id
						 ));
						 // если не было части - делаем
						 if(!$found){
	                		 $modelPart = new Article;
	                		 $modelPart->scenario = 'part';
	                		 $modelPart->title = $firm['firmname'];
	                		 $modelPart->description = $firm['firmdescription'];
	                		 $modelPart->part = $model->id;
	                		 $modelPart->part_order = $key;
	                		 $modelPart->part_org = $firm['firmurl'];
	                		 $modelPart->created_date = date('Y-m-d H:i:s');
	                		 if($modelPart->save()){
	                		 	//$modelPart->articleorg_ar = array($firm->firmurl);
	                		 	//$modelPart->setArticleOrg($modelPart->articleorg_ar);
	                		 	$modelPart->tmpLogotip = array($firm['firmphotoh']);
	                		 	$modelPart->addDropboxLogoFiles($this->uploadsession);
	                            
	                		 }
                		} else { // изменяем, если что-то поменялось.

		 					

							if($found->title != $firm['firmname'] or $found->description != $firm['firmdescription']
								or $found->part_order != $key){
								$found->title = $firm['firmname'];
								$found->description = $firm['firmdescription'];
								$found->part_order = $key;
								$found->save(false,array('title','description','part_order'));
							}
							$found->tmpLogotip = array($firm['firmphotoh']);
                			$found->addDropboxLogoFiles($this->uploadsession);
						}
                		$dontDelete[] = $firm['firmurl'];
                	}
                	// Удаляем все части, которых не было в массиве
					if(sizeof($dontDelete) > 0){
						$cr = new CDbCriteria;
						$cr->addNotInCondition('part_org', $dontDelete);

						Article::model()->deleteAllByAttributes(array(
							'part'=>$model->id,
						), $cr);
					} else { // удаляем все части, т.к. пустой массив
						// Delete all relations
						Article::model()->deleteAllByAttributes(array(
							'part'=>$model->id,
						));
					}
                }

                Yii::app()->session->remove($this->uploadsession);
           

                if(Yii::app()->request->isAjaxRequest){
                    
                } else {
                    $text = $new? "Статья {$model->title} добавлена" : "Статья {$model->title} отредактирована";
                    $this->addFlashMessage($text,'success');
                    $this->redirect(Yii::app()->createAbsoluteUrl('catalog/admin/article'));
                }

            } else {
                $this->addFlashMessage($model->errors,'error');
            }
        }

        $categories_ar = $articleorg_ar = array();
        $categories = $model->categories;
        $orgs = $model->orgs;

        if($categories){
            foreach($categories as $cats){
                $categories_ar[] = $cats->id;
            }
        }
       /* if($orgs){
            foreach($orgs as $org){
                $articleorg_ar[] = $org->id;
            }
        }*/
        $this->render('update',array(
            'model'=>$model,
            'categories_ar'=>$categories_ar,
          //  'articleorg_ar'=>$articleorg_ar
        ));
    }