/**
  * Get the path for the given ImageManager_id record
  * @param int $ImageManager_id ImageManager record for which the path needs to be generated
  * @param int $width Thumbnail image width
  * @param int $height Thumbnail image height
  * @param string $thumbnailMode Thumbnail mode
  * @return null|string Full path is returned when image is found, null if no image could be found
  */
 public function getImagePath($ImageManager_id, $width = 400, $height = 400, $thumbnailMode = "outbound")
 {
     //default return
     $return = null;
     $mImageManager = ImageManager::findOne($ImageManager_id);
     //check if not empty
     if ($mImageManager !== null) {
         //set crop mode
         $mode = $thumbnailMode == "outbound" ? "outbound" : "inset";
         $sMediaPath = null;
         if ($this->mediaPath !== null) {
             $sMediaPath = $this->mediaPath;
         }
         $sFileExtension = pathinfo($mImageManager->fileName, PATHINFO_EXTENSION);
         //get image file path
         $sImageFilePath = $sMediaPath . '/' . $mImageManager->id . '_' . $mImageManager->fileHash . '.' . $sFileExtension;
         //check file exists
         if (file_exists($sImageFilePath)) {
             $return = \Yii::$app->imageresize->getUrl($sImageFilePath, $width, $height, $mode, null, $mImageManager->fileName);
         } else {
             $return = null;
             //isset(\Yii::$app->controller->module->assetPublishedUrl) ? \Yii::$app->controller->module->assetPublishedUrl. "/img/img_no-image.png" : null;
         }
     }
     return $return;
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = ImageManager::find();
     // add conditions that should always apply here
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pagesize' => 100], 'sort' => ['defaultOrder' => ['created' => SORT_DESC]]]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->orFilterWhere(['like', 'fileName', $this->globalSearch])->orFilterWhere(['like', 'created', $this->globalSearch])->orFilterWhere(['like', 'modified', $this->globalSearch]);
     return $dataProvider;
 }
 /**
  * @inheritdoc
  */
 public function run()
 {
     //default
     $ImageManager_id = null;
     $mImageManager = null;
     $sFieldId = null;
     //start input group
     $field = "<div class='image-manager-input'>";
     $field .= "<div class='input-group'>";
     //set input fields
     if ($this->hasModel()) {
         //get field id
         $sFieldId = Html::getInputId($this->model, $this->attribute);
         $sFieldNameId = $sFieldId . "_name";
         //get filename from selected file
         $ImageManager_id = $this->model->{$this->attribute};
         $ImageManager_fileName = null;
         $mImageManager = ImageManager::findOne($ImageManager_id);
         if ($mImageManager !== null) {
             $ImageManager_fileName = $mImageManager->fileName;
         }
         //create field
         $field .= Html::textInput($this->attribute, $ImageManager_fileName, ['class' => 'form-control', 'id' => $sFieldNameId, 'readonly' => true]);
         $field .= Html::activeHiddenInput($this->model, $this->attribute, $this->options);
     } else {
         $field .= Html::textInput($this->name . "_name", null, ['readonly' => true]);
         $field .= Html::hiddenInput($this->name, $this->value, $this->options);
     }
     //end input group
     $sHideClass = $ImageManager_id === null ? 'hide' : '';
     $field .= "<a href='#' class='input-group-addon btn btn-primary delete-selected-image " . $sHideClass . "' data-input-id='" . $sFieldId . "' data-show-delete-confirm='" . ($this->showDeletePickedImageConfirm ? "true" : "false") . "'><i class='glyphicon glyphicon-remove' aria-hidden='true'></i></a>";
     $field .= "<a href='#' class='input-group-addon btn btn-primary open-modal-imagemanager' data-aspect-ratio='" . $this->aspectRatio . "' data-crop-view-mode='" . $this->cropViewMode . "' data-input-id='" . $sFieldId . "'>";
     $field .= "<i class='glyphicon glyphicon-folder-open' aria-hidden='true'></i>";
     $field .= "</a></div>";
     //show preview if is true
     if ($this->showPreview == true) {
         $sHideClass = $mImageManager == null ? "hide" : "";
         $sImageSource = isset($mImageManager->id) ? \Yii::$app->imagemanager->getImagePath($mImageManager->id, 500, 500, 'inset') : "";
         $field .= '<div class="image-wrapper ' . $sHideClass . '">' . '<img id="' . $sFieldId . '_image" alt="Thumbnail" class="img-responsive img-preview" src="' . $sImageSource . '">' . '</div>';
     }
     //close image-manager-input div
     $field .= "</div>";
     echo $field;
     $this->registerClientScript();
 }
 /**
  * Finds the ImageManager model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return ImageManager the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = ImageManager::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }