_gallery_view.php 6.43 KB
<?php
    
    /**
     * @var View $this
     */
    
    use artbox\core\assets\GalleryAsset;
    use artbox\core\components\imagemanager\assets\ImageManagerInputAsset;
    use artbox\core\helpers\ImageHelper;
    use yii\helpers\Html;
    use yii\helpers\Json;
    use yii\helpers\Url;
    use yii\web\View;
    
    ImageManagerInputAsset::register($this);
    
    //set baseUrl from image manager
    $sBaseUrl = Url::to([ '/imagemanager/manager' ]);
    //set base url
    $this->registerJs("imageManagerInput.baseUrl = '" . $sBaseUrl . "';");
    $this->registerJs(
        "imageManagerInput.message = " . Json::encode(
            [
                'detachWarningMessage' => Yii::t('core', 'Are you sure you want to detach the image?'),
            ]
        ) . ";"
    );
    
    GalleryAsset::register($this);

?>
  
  <div class="row">
    <div class="gw-container">
        <?php if (empty($images)) { ?>
          <div class="col-md-2 gw-item">
              <?php
                  $hash = rand(10000, 99999);
                  
                  echo Html::hiddenInput(
                      'images[' . $hash . ']',
                      null,
                      [
                          'id'    => $hash,
                          'class' => 'gw-image-input',
                          'data'  => [
                              'img'  => $hash . '_img',
                              'name' => $hash . '_name',
                          ],
                      ]
                  );
              ?>
            <div class="image_gall">
                <?php
                    echo Html::img(
                        '',
                        [
                            'class' => 'img-rounded',
                            'id'    => $hash . '_img',
                        ]
                    );
                ?>
            </div>
              <?php
                  
                  echo Html::tag(
                      'p',
                      '',
                      [
                          'class' => 'text-info',
                          'id'    => $hash . '_name',
                      ]
                  );
                  
                  echo Html::button(
                      Html::tag(
                          'i',
                          '',
                          [
                              'class' => 'fa fa-folder-open',
                          ]
                      ),
                      [
                          'class' => 'open-modal-imagemanager btn btn-primary',
                          'data'  => [
                              'aspect-ratio'   => '',
                              'crop-view-mode' => 1,
                              'input-id'       => $hash,
                          ],
                      ]
                  );
                  
                  echo Html::button(
                      Html::tag(
                          'i',
                          '',
                          [
                              'class' => 'fa fa-trash',
                          ]
                      ),
                      [
                          'class' => 'remove-img btn btn-danger',
                      ]
                  );
              ?>
          </div>
        <?php } else {
            foreach ($images as $image) {
                /**
                 * @var \artbox\core\models\Image $image
                 */
                ?>
              
              <div class="col-md-2 gw-item">
                  <?php
                      $hash = rand(10000, 99999);
                      
                      echo Html::hiddenInput(
                          'images[' . $hash . ']',
                          $image->id,
                          [
                              'id'    => $hash,
                              'class' => 'gw-image-input',
                              'data'  => [
                                  'img'  => $hash . '_img',
                                  'name' => $hash . '_name',
                              ],
                          ]
                      );
                  ?>
                <div class="image_gall">
                    <?php
                        echo ImageHelper::set($image->getPath())
                                        ->resize(400, 400)
                                        ->renderImage(
                                            [
                                                'id' => $hash . '_img',
                                            ]
                                        );
                    ?>
                </div>
                  <?php
                      
                      echo Html::tag(
                          'p',
                          $image->fileName,
                          [
                              'class' => 'text-info',
                              'id'    => $hash . '_name',
                          ]
                      );
                      
                      echo Html::button(
                          Html::tag(
                              'i',
                              '',
                              [
                                  'class' => 'fa fa-folder-open',
                              ]
                          ),
                          [
                              'class' => 'open-modal-imagemanager btn btn-primary',
                              'data'  => [
                                  'aspect-ratio'   => '',
                                  'crop-view-mode' => 1,
                                  'input-id'       => $hash,
                              ],
                          ]
                      );
                      
                      echo Html::button(
                          Html::tag(
                              'i',
                              '',
                              [
                                  'class' => 'fa fa-trash',
                              ]
                          ),
                          [
                              'class' => 'remove-img btn btn-danger',
                          ]
                      );
                  ?>
              </div>
            
            <?php }
        } ?>
    </div>
  </div>

<?= Html::button(
    Html::tag(
        'li',
        '',
        [
            'class' => 'fa fa-plus',
        ]
    ) . ' Add',
    [
        'id'    => 'add-image',
        'class' => 'btn btn-success',
    ]
) ?>