Gallery.php 1.68 KB
<?php
    /**
     * Created by PhpStorm.
     * User: beer
     * Date: 28.09.17
     * Time: 12:38
     */
    
    namespace common\models;
    
    use artbox\core\models\Image;
    
    /**
     * Stub class Gallery
     * for holding gallery
     *
     * @package common\models
     */
    class Gallery
    {
        /**
         * @return array
         */
        public function getImages(): array
        {
            return Image::find()
                        ->where(
                            [
                                'gallery' => true,
                            ]
                        )
                        ->all();
        }
        
        /**
         * @param array $images
         */
        public function saveImages(array $images)
        {
            if (empty($images)) {
                \Yii::$app->db->createCommand()
                              ->update(
                                  'ImageManager',
                                  [
                                      'gallery' => false,
                                  ],
                                  '1 = 1'
                              )
                              ->execute();
            } else {
                $condition = 'id IN (' . implode(',', $images) . ')';
                \Yii::$app->db->createCommand()
                              ->update(
                                  'ImageManager',
                                  [
                                      'gallery' => true,
                                  ],
                                  $condition
                              )
                              ->execute();
            }
        }
    }