/**
  * Displays a particular model.
  * @param integer $id the ID of the model to be displayed
  */
 public function actionView($id)
 {
     $user = $this->loadModel($id);
     if ($user->occupation_id == 5) {
         //avto
         if (Yii::app()->getRequest()->getParam('class') != '') {
             $avto = Avto::model()->findAllByAttributes(array('uid' => $id, 'class' => Yii::app()->getRequest()->getParam('class')));
         } else {
             $avto = Avto::model()->findAllByAttributes(array('uid' => $id));
         }
         $this->render('view_avto', array('model' => $user, 'avto' => $avto));
     } elseif ($user->occupation_id == 6) {
         //flo
         $flo = Flo::model()->findAllByAttributes(array('uid' => $id));
         $this->render('view_flo', array('model' => $user, 'flo' => $flo));
     } elseif ($user->occupation_id == 17) {
         //studio
         //$cond_hals='type="photo" and source="hall" and visible=1';
         $hals = StudioHals::model()->with('files')->findAllByAttributes(array('uid' => $id, 'visible' => 1));
         $banners = StudioBanners::model()->findByAttributes(array('uid' => $id));
         if (isset($_GET['calendar'])) {
             $this->render('view_studio_calendar', array('model' => $user));
         } elseif (isset($_GET['equip'])) {
             $this->render('view_studio_equip', array('model' => $user, 'equips' => StudioEquip::model()->findAllByAttributes(array('uid' => $id, 'visible' => 1))));
         } elseif (isset($_GET['prices'])) {
             $this->render('view_studio_prices', array('model' => $user, 'prices' => StudioHals::model()->findAllByAttributes(array('uid' => $id, 'visible' => 1))));
         } elseif (isset($_GET['rent'])) {
             $this->render('view_studio_rent', array('model' => $user, 'rent' => StudioRent::model()->findAllByAttributes(array('uid' => $id, 'visible' => 1))));
         } elseif (isset($_GET['halls'])) {
             if (isset($_GET['hid'])) {
                 $hals = StudioHals::model()->findAllByAttributes(array('uid' => $id, 'visible' => 1));
                 $hall = StudioHals::model()->with('files')->findByAttributes(array('id' => intval($_GET['hid']), 'uid' => $id, 'visible' => 1));
                 $this->render('view_studio_hals', array('model' => $user, 'hall' => $hall, 'hals' => $hals));
             } else {
                 $this->render('view_studio', array('model' => $user, 'hals' => $hals, 'banners' => $banners));
             }
         } else {
             $this->render('view_studio', array('model' => $user, 'hals' => $hals, 'banners' => $banners));
         }
     } elseif ($user->genre_id == '') {
         //other users without genres
         $flo = Flo::model()->findAllByAttributes(array('uid' => $id));
         $this->render('view_user', array('model' => $user, 'flo' => $flo));
     } else {
         if ($user->occupation_id == 2) {
             //video operator
             /*$portfolio=Files::model()->findAllByAttributes(array('uid'=>$id,'type'=>'video','source'=>'portfolio'));
                     $this->render('view_video',array(
             			'model'=>$this->loadModel($id),
                         'portfolio'=>$portfolio,
             		));*/
             $portfolio = Video::model()->findAllByAttributes(array('uid' => $id));
             $this->render('view_video', array('model' => $this->loadModel($id), 'portfolio' => $portfolio));
         } else {
             $portfolio = Portfolio::model()->findAllByAttributes(array('uid' => $id));
             $this->render('view', array('model' => $this->loadModel($id), 'portfolio' => $portfolio));
         }
     }
 }
<?php

$this->widget('application.extensions.tooltipster.tooltipster', array('identifier' => '#show_tooltip', 'options' => array('position' => 'bottom')));
foreach ($model as $item) {
    $c = StudioHals::model()->findByPk($item->portfolio_id);
    if ($c->picture == $item->file) {
        $chk = 'checked';
    } else {
        $chk = '';
    }
    $top = View::model()->findByAttributes(array('uid' => Yii::app()->user->id, 'photo' => $item->file));
    if (is_object($top)) {
        if ($top->photo == $item->file) {
            $class = 'cabinet__photo__item-selected';
            $del = 'yes';
        } else {
            $class = 'cabinet__photo__item-select';
            $del = 'no';
        }
    } else {
        $class = 'cabinet__photo__item-select';
        $del = 'no';
    }
    ?>
    <div class="data_<?php 
    echo $item->id;
    ?>
">
        <figure class="cabinet__photo__item2">
            <a href="/users/<?php 
    echo Yii::app()->user->id;
 public function actionUpdate($id)
 {
     $model = $this->loadModel($id);
     if ($model->occupation->templ == 'members') {
         $model->scenario = 'genre';
     }
     // Uncomment the following line if AJAX validation is needed
     $this->performAjaxValidation($model);
     if (isset($_POST['Users'])) {
         if ($_POST['member'] == 0) {
             $model->name = $_POST['Users']['name'];
             Yii::app()->user->name = $model->name;
             $model->gender = $_POST['Users']['gender'];
             $model->date_birth = $_POST['year_b'] . '-' . $_POST['month_b'] . '-' . $_POST['day_b'];
             $model->birth_public = $_POST['Users']['birth_public'];
             $model->city_id = $_POST['Users']['city_id'];
             $model->email = $_POST['Users']['email'];
             $model->about = $_POST['Users']['about'];
             $model->phone = $_POST['Users']['phone'];
             $model->phone2 = $_POST['Users']['phone2'];
             $model->phone3 = $_POST['Users']['phone3'];
             if ($model->validate() && $model->save()) {
                 Yii::app()->user->setFlash('success_save', '1');
                 $this->redirect(array('index'));
             }
             /*else { 
                   echo CHtml::errorSummary($model);
                   //exit();
               }*/
         }
         if ($_POST['member'] == 1) {
             //$model->attributes=$_POST['Users'];
             if (isset($_POST['Users']['name_studio'])) {
                 $_POST['Users']['name'] = $_POST['Users']['name_studio'];
                 //unset($_POST['Users']['name_studio']);
                 $model->setScenario('studio_update');
             }
             foreach ($_POST['Users'] as $k => $v) {
                 if ($k == 'photo') {
                     if ($v != '') {
                         $model->photo = CUploadedFile::getInstance($model, 'photo');
                     }
                 } elseif ($k == 'url') {
                     $v = str_replace('http://', '', $v);
                     $model->{$k} = $v;
                 } else {
                     $model->{$k} = $v;
                 }
             }
             if (!isset($_POST['Users']['phone2'])) {
                 $model->phone2 = '';
             }
             if (!isset($_POST['Users']['phone3'])) {
                 $model->phone3 = '';
             }
             if (isset($_POST['year_b'])) {
                 $model->date_birth = $_POST['year_b'] . '-' . $_POST['month_b'] . '-' . $_POST['day_b'];
             }
             Yii::app()->user->name = $model->name;
             //echo '<pre>';
             //print_r($_POST);
             //echo '</pre>';
             //exit();
             if (isset($_POST['Users']['genre_id'])) {
                 $model->genre_id = serialize($_POST['Users']['genre_id']);
             }
             if ($model->save()) {
                 if (isset($_POST['Users']['genre_id'])) {
                     Yii::import('application.modules.my.models.Portfolio');
                     Yii::import('application.modules.my.models.Video');
                     Yii::import('application.modules.my.models.Genre');
                     $keys = array();
                     $data = '';
                     $data = Portfolio::model()->findAllByAttributes(array('uid' => Yii::app()->user->id));
                     //print_r($data); exit();
                     if (is_array($data) && !empty($data)) {
                         //Portfolio::model()->deleteAllByAttributes(array('uid'=>Yii::app()->user->id));
                         //exit();
                         foreach ($_POST['Users']['genre_id'] as $genre) {
                             $item = Portfolio::model()->findByAttributes(array('uid' => Yii::app()->user->id, 'title' => Genre::getName($genre)));
                             if (count($item) > 0) {
                                 $keys[] = $item->id;
                             } else {
                                 $mod = new Portfolio();
                                 $mod->title = Genre::getName($genre);
                                 $mod->uid = Yii::app()->user->id;
                                 $mod->save();
                                 $keys[] = $mod->id;
                             }
                         }
                         $del = new Portfolio();
                         $criteria = new CDbCriteria();
                         $criteria->condition = 'uid=' . Yii::app()->user->id;
                         $criteria->addNotInCondition('id', $keys);
                         $del->deleteAll($criteria);
                     } else {
                         foreach ($_POST['Users']['genre_id'] as $genre) {
                             $mod = new Portfolio();
                             $mod->title = Genre::getName($genre);
                             $mod->uid = Yii::app()->user->id;
                             $mod->save();
                             //print_r($mod);
                         }
                         //exit();
                     }
                     //////////VIDEO/////////////////////////
                     $keys = array();
                     $data = '';
                     $data = Video::model()->findAllByAttributes(array('uid' => Yii::app()->user->id));
                     //print_r($data); exit();
                     if (is_array($data) && !empty($data)) {
                         //Portfolio::model()->deleteAllByAttributes(array('uid'=>Yii::app()->user->id));
                         //exit();
                         foreach ($_POST['Users']['genre_id'] as $genre) {
                             $item = Video::model()->findByAttributes(array('uid' => Yii::app()->user->id, 'title' => Genre::getName($genre)));
                             if (count($item) > 0) {
                                 $keys[] = $item->id;
                             } else {
                                 $mod = new Video();
                                 $mod->title = Genre::getName($genre);
                                 $mod->uid = Yii::app()->user->id;
                                 $mod->save();
                                 $keys[] = $mod->id;
                             }
                         }
                         $del = new Video();
                         $criteria = new CDbCriteria();
                         $criteria->condition = 'uid=' . Yii::app()->user->id;
                         $criteria->addNotInCondition('id', $keys);
                         $del->deleteAll($criteria);
                     } else {
                         foreach ($_POST['Users']['genre_id'] as $genre) {
                             $mod = new Video();
                             $mod->title = Genre::getName($genre);
                             $mod->uid = Yii::app()->user->id;
                             $mod->save();
                             //print_r($mod);
                         }
                         //exit();
                     }
                 } elseif (isset($_POST['Users']['hals'])) {
                     StudioHals::model()->deleteAllByAttributes(array('uid' => Yii::app()->user->id));
                     $h = 1;
                     while ($h <= $_POST['Users']['hals']) {
                         $mod = new StudioHals();
                         $mod->title = 'Зал ' . $h;
                         $mod->uid = Yii::app()->user->id;
                         $mod->save();
                         $h++;
                     }
                 }
                 Yii::app()->user->setFlash('success_save', '1');
                 $this->redirect(array('index'));
             }
             /*else { 
                   $this->render('index',array('model'=>$model));
                   //echo CHtml::errorSummary($model);
                   //exit();
               } */
         }
     }
     //if(empty($_POST['Users']['genre_id']))
     //    $model->addError('genre_id','Необходимо указать жанр, в котром Вы работаете.');
     $this->render('index', array('model' => $model));
 }
 public function actionPriceedit($id)
 {
     $m = StudioHals::model()->findByPk($id);
     if ($m->uid == Yii::app()->user->id) {
         if (isset($_POST['StudioHals'])) {
             $m->attributes = $_POST['StudioHals'];
             if ($m->save()) {
                 $this->redirect('/my/studio/prices');
             }
         }
         $this->render('/studioHals/update', array('model' => Users::model()->findByPk(Yii::app()->user->id), 'm' => $m));
     } else {
         throw new CHttpException(404, 'The requested element does not exist.');
     }
 }