/**
  * Метод добавления одной фотографии:
  *
  * @param RealtyGalleryImage $image - инстанс изображения
  * @param mixed $imageData - POST-массив данных
  * @param RealtyGallery $realtyGallery - инстанс галереи
  *
  * @return void
  **/
 private function _addImage(RealtyGalleryImage $image, array $imageData, RealtyGallery $realtyGallery)
 {
     try {
         $transaction = Yii::app()->getDb()->beginTransaction();
         $image->setAttributes($imageData);
         $image->item_id = $realtyGallery->id;
         $criteria = new CDbCriteria();
         $criteria->select = new CDbExpression('MAX(sort) as sort');
         $criteria->condition = 't.item_id = :item_id';
         $criteria->params = [':item_id' => $realtyGallery->id];
         $max = $image->find($criteria);
         $image->sort = $max->sort + 100;
         if ($image->save()) {
             $transaction->commit();
             if (Yii::app()->getRequest()->getPost('ajax') === null) {
                 Yii::app()->getUser()->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('RealtyModule.realty', 'Photo was created!'));
                 $this->redirect(['/realty/realtyGalleryImageBackend/index', 'item_id' => $realtyGallery->id]);
             }
         }
     } catch (Exception $e) {
         $transaction->rollback();
         Yii::app()->getUser()->setFlash(yupe\widgets\YFlashMessages::ERROR_MESSAGE, $e->getMessage());
     }
 }