Gallery.php 1.62 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($images)
        {
            \Yii::$app->db->createCommand()
                          ->update(
                              'ImageManager',
                              [
                                  'gallery' => false,
                              ],
                              '1 = 1'
                          )
                          ->execute();
            if (!empty($images)) {
                $condition = 'id IN (' . implode(',', $images) . ')';
                \Yii::$app->db->createCommand()
                              ->update(
                                  'ImageManager',
                                  [
                                      'gallery' => true,
                                  ],
                                  $condition
                              )
                              ->execute();
            }
        }
    }