model() public static méthode

Returns the static model of the specified AR class.
public static model ( string $className = __CLASS__ ) : Gallery
$className string
Résultat Gallery the static model class
 /** @return Gallery Returns gallery associated with model */
 public function getGallery()
 {
     if (empty($this->_gallery)) {
         $this->_gallery = Gallery::model()->findByPk($this->getOwner()->{$this->idAttribute});
     }
     return $this->_gallery;
 }
Exemple #2
0
 public function actionShow($id)
 {
     $model = Gallery::model()->findByPk((int) $id);
     if (is_null($model)) {
         throw new CHttpException(404, Yii::t('gallery', 'Страница не найдена!'));
     }
     $image = new Image();
     if (Yii::app()->request->isPostRequest && isset($_POST['Image'])) {
         $transaction = Yii::app()->db->beginTransaction();
         try {
             $image = $image->create($_POST['Image']);
             if (!$image->hasErrors()) {
                 if ($model->addImage($image)) {
                     Yii::app()->user->setFlash(YFlashMessages::NOTICE_MESSAGE, Yii::t('gallery', 'Фотография добавлена!'));
                 }
                 $transaction->commit();
                 $this->redirect(array('/gallery/gallery/show/', 'id' => $model->id));
             }
             throw new CDbException(Yii::t('gallery', 'При добавлении изображения произошла ошибка!'));
         } catch (Exception $e) {
             $transaction->rollback();
             Yii::app()->user->setFlash(YFlashMessages::ERROR_MESSAGE, Yii::t('gallery', $e->getMessage()));
         }
     }
     $dataProvider = new CActiveDataProvider('ImageToGallery', array('criteria' => array('condition' => 'galleryId = :galleryId', 'params' => array(':galleryId' => $model->id), 'limit' => self::GALLERY_PER_PAGE, 'order' => 't.creation_date DESC', 'with' => 'image'), 'pagination' => array('pageSize' => self::GALLERY_PER_PAGE)));
     $this->render('show', array('image' => $image, 'model' => $model, 'dataProvider' => $dataProvider));
 }
 /**
  * @param $id
  * @throws CDbException
  * @throws CHttpException
  */
 public function actionView($id)
 {
     if (($gallery = Gallery::model()->published()->findByPk($id)) === null) {
         throw new CHttpException(404, Yii::t('GalleryModule.gallery', 'Page was not found!'));
     }
     $image = new Image();
     if (Yii::app()->getRequest()->getIsPostRequest() && !empty($_POST['Image'])) {
         try {
             $transaction = Yii::app()->db->beginTransaction();
             $image->attributes = $_POST['Image'];
             if ($image->save() && $gallery->addImage($image)) {
                 $transaction->commit();
                 Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('GalleryModule.gallery', 'Photo was created!'));
                 $this->redirect(['/gallery/gallery/view', 'id' => $gallery->id]);
             }
         } catch (Exception $e) {
             $transaction->rollback();
             Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::ERROR_MESSAGE, $e->getMessage());
         }
     }
     if ($gallery->status == Gallery::STATUS_PRIVATE && $gallery->owner != Yii::app()->user->id) {
         throw new CHttpException(404);
     }
     $this->render('view', ['image' => $image, 'model' => $gallery]);
 }
 public function actionIndex()
 {
     $criteria = new CDbCriteria();
     $criteria->condition = "status = 1";
     $criteria->order = "sort_order asc,gallery_id asc";
     $model = Gallery::model()->findAll($criteria);
     $this->render('index', array('gallery' => $model));
 }
 /**
  * Index Page, for now just render all static content.
  */
 public function actionView($id)
 {
     $gallery = Gallery::model()->with('galleryImages')->findByPk($id);
     if (empty($gallery)) {
         $gallery = new Gallery();
     }
     $this->render('view', array('gallery' => $gallery));
 }
 public function loadModel($id)
 {
     $model = Gallery::model()->findByPk($id);
     if (!$model) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
 public function actionIndex()
 {
     $dependency = new CDbCacheDependency('SELECT MAX(UNIX_TIMESTAMP(updated_at)), COUNT(0) FROM {{gallery}} WHERE status = :status');
     $dependency->params = array('status' => ActiveRecord::STATUS_ON);
     $model = Gallery::model()->cache(3600 * 24, $dependency, 2)->opened();
     $dataProvider = new CActiveDataProvider($model, array('criteria' => array('order' => 'sort'), 'pagination' => array('pageSize' => (int) config('gallery.limit'), 'pageVar' => 'page')));
     $this->render('//gallery', array('dataProvider' => $dataProvider));
 }
Exemple #8
0
 public static function LoadGallery($id)
 {
     $id = _xls_number_only($id);
     if ($id > 1000) {
         $id = 1000;
     }
     $gallery = Gallery::model()->findByPk($id);
     if (!$gallery) {
         $gallery = new Gallery();
         $gallery->id = $id;
         $gallery->name = true;
         $gallery->description = true;
         $gallery->versions = array('small' => array('resize' => array(200, null)), 'medium' => array('resize' => array(800, null)));
         $gallery->save();
     }
     return $gallery;
 }
 public function run()
 {
     if (Yii::app()->request->isAjaxRequest && isset($_GET['q'])) {
         $title = Yii::app()->request->getParam('q', '');
         $limit = Yii::app()->request->getParam('limit', 50);
         $limit = min($limit, 50);
         $criteria = new CDbCriteria();
         $criteria->condition = "title LIKE :sterm";
         $criteria->params = array(":sterm" => "%{$title}%");
         $criteria->limit = $limit;
         $array = Gallery::model()->findAll($criteria);
         $result = '';
         foreach ($array as $val) {
             $result .= $val->getAttribute('title') . '|' . $val->getAttribute('id') . "\n";
         }
         echo $result;
     }
 }
Exemple #10
0
echo $getTranslateWorld['gallery'];
?>
</h1>
                    <div id="slider_container" style="position:relative;margin:0 auto;top:0px;left:0px;width:800px;height:456px;background:#191919;">
                        <div u="loading" style="position:absolute;top:0px;left:0px;">
                            <div style="filter:alpha(opacity=70);opacity:0.7;position:absolute;display:block;background-color:#000000;top:0px;left:0px;width:100%;height:100%;">
                            </div>
                            <div style="position:absolute;display:block;background:url(<?php 
echo Yii::app()->request->baseUrl;
?>
/css/xeon/img/loading.gif) no-repeat center center;top:0px;left:0px;width:100%;height:100%;">
                            </div>
                        </div>
                        <div u="slides" style="cursor:move;position:absolute;left:0px;top:0px;width:800px;height:356px;overflow:hidden;">
                            <?php 
$gallery = Gallery::model()->findAll();
if (!empty($gallery)) {
    foreach ($gallery as $key => $value) {
        ?>
                                    <div>
                                        <a href=''><img u = "image" src = "<?php 
        echo Yii::app()->request->baseUrl . '/css/xeon/images/gallery/' . $value->image_big;
        ?>
"></a>
                                        <img u = "thumb" src = "<?php 
        echo Yii::app()->request->baseUrl . '/css/xeon/images/gallery/' . $value->image_small;
        ?>
">
                                    </div>
                                    <?php 
    }
 /**
  * Возвращает модель по указанному идентификатору
  * Если модель не будет найдена - возникнет HTTP-исключение.
  *
  * @param integer идентификатор нужной модели
  *
  * @return Gallery $model
  *
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     if (($model = Gallery::model()->findByPk($id)) === null) {
         throw new CHttpException(404, Yii::t('GalleryModule.gallery', 'Requested page was not found.'));
     }
     return $model;
 }
Exemple #12
0
 public static function getSelectedGallery($id)
 {
     return Gallery::model()->findByPk($id);
 }
Exemple #13
0
 public function getGalleryList()
 {
     $result = array();
     if ($galleries = Gallery::model()->findAll()) {
         foreach ($galleries as $gallery) {
             $result[$gallery->id] = $gallery->title;
         }
     }
     return $result;
 }
 public static function getGallery($id)
 {
     return !empty($id) ? Gallery::model()->with('photos')->findByPk($id) : new Gallery();
 }
Exemple #15
0
 /**
  * Load model for our gallery.
  * Sets @var $this->gmodel.
  * Sets order of pictures
  * Sets @var $this->imgsOrder.
  */
 public function loadGallery()
 {
     $this->gmodel = Gallery::model()->find(array('condition' => "pid='{$this->pid}'"));
     $this->imgsOrder = unserialize($this->gmodel->imgsOrder);
 }
Exemple #16
0
 /**
  * Returns the static model of the specified AR class.
  * @param string $className active record class name.
  * @return AGallery the static model class
  */
 public static function model($className = __CLASS__)
 {
     return parent::model($className);
 }
Exemple #17
0
 /**
  * set gallery id
  *
  * @param mixed $value - value for setter
  *
  * @return bool
  **/
 public function setGalleryId($value = null)
 {
     if ($this->scenario === 'search' || !Yii::app()->hasModule('gallery')) {
         return $this->_galleryId = $value;
     }
     if ($this->gallery instanceof Gallery) {
         $this->galleryRell->delete();
     }
     if (($gallery = Gallery::model()->loadModel($value)) === null) {
         return $value;
     }
     return $gallery->addImage($this);
 }
Exemple #18
0
 protected function beforeDelete()
 {
     if (parent::beforeDelete()) {
         if ($this->id == $this->gallery->cover_photo_id) {
             $gallery = Gallery::model()->findByPk($this->gallery_id);
             $gallery->cover_photo_id = null;
             $gallery->save();
         }
         return true;
     } else {
         return false;
     }
 }