Esempio n. 1
0
    /**
     * @inheritdoc
     * 
     * FIXME hide input
     */
    public function run()
    {
        $folderurl = \yii\helpers\Url::to($this->folderurl);
        //		$this->options['data-url'] = \yii\helpers\Url::to($this->uploadurl);
        $picid = $this->model->{$this->attribute};
        $picture = null;
        if ($picid) {
            $picture = Picture::find()->where(['id' => $picid])->one();
        }
        if (!$picture) {
            $picture = new Picture();
        }
        $id = $this->options['id'];
        $js = [];
        $view = $this->getView();
        /*        CKEditorWidgetAsset::register($view);
        
                $id = $this->options['id'];
        
                $options = $this->clientOptions !== false && !empty($this->clientOptions)
                    ? Json::encode($this->clientOptions)
                    : '{}';
        
                $js[] = "CKEDITOR.replace('$id', $options);";*/
        $js[] = <<<JS
\tjQuery('#{$id}-select').fileselect({
\t\ttitle:\t\t"Выбор изображения",
\t\tcallback:\tfunction(id){alert(id)}
\t});
\t
JS;
        $this->registerClientScript();
        $view->registerJs(implode("\n", $js));
        return $this->render('picSelect', ['widget' => $this, 'picture' => $picture]);
    }
Esempio n. 2
0
 /**
  * Lists all Picture models.
  * @return mixed
  */
 public function actionJson()
 {
     $all = Picture::find()->all();
     $ret = [];
     foreach ($all as $img) {
         $ret['images'][] = ['preview' => $img->url('preview'), 'url' => $img->url('full'), 'title' => $img->name];
     }
     echo json_encode($ret);
 }
Esempio n. 3
0
 /**
  * Load picture by id
  * 
  * If picture not found returned default picture
  * 
  * Default picture 
  * @param integer $id
  * @param array|id|null $default
  * @return \simplator\medialib\models\Picture
  */
 public static function getPicture($id, $default = 'id')
 {
     $pic = Picture::find()->where(['id' => $id])->one();
     if (!$pic) {
         $pic = Picture::find()->where(['id' => \Yii::$app->settings->get('default.' . $default, 'medialib')])->one();
     }
     if (!$pic) {
         $pic = Picture::find()->where(['id' => \Yii::$app->settings->get('default.id', 'medialib')])->one();
     }
     if (!$pic) {
         $pic = new Picture();
     }
     return $pic;
 }