public function getImages()
 {
     /**
      * @var $object \app\models\Object
      * @var $model \app\properties\HasProperties | \yii\db\ActiveRecord
      * @return \yii\db\ActiveQueryInterface
      */
     $model = $this;
     $object = $model->object;
     return $model->hasMany(Image::className(), ['object_model_id' => 'id'])->andWhere(['object_id' => $object->id])->addOrderBy(['sort_order' => SORT_ASC, 'id' => SORT_ASC]);
 }
예제 #2
0
 public function actionEdit($id)
 {
     $model = OpenGraphObject::findOne($id);
     /** @var OpenGraphObject $model */
     if (Yii::$app->request->isPost) {
         $model->load(Yii::$app->request->post());
         $model->relation_data = json_encode(Yii::$app->request->post('data'));
         if ($model->save()) {
             $this->refresh();
         }
     }
     $openGraphFields = [['key' => 'title', 'label' => Yii::t('app', 'Title'), 'required' => true], ['key' => 'image', 'label' => Yii::t('app', 'Image'), 'required' => true], ['key' => 'description', 'label' => Yii::t('app', 'Description'), 'required' => true]];
     $relationLinks = [['class' => \app\modules\image\models\Image::className(), 'relationName' => 'getImages']];
     return $this->render('form', ['openGraphFields' => $openGraphFields, 'relationLinks' => $relationLinks, 'model' => $model]);
 }
 public function run()
 {
     $cacheKey = static::className() . ':' . implode("_", [$this->model->object->id, $this->model->id, $this->viewFile, $this->limit, $this->offset, $this->thumbnailOnDemand ? '1' : '0', $this->thumbnailWidth, $this->thumbnailHeight, $this->useWatermark]);
     $result = Yii::$app->cache->get($cacheKey);
     if ($result === false) {
         if ($this->offset > 0 || !is_null($this->limit)) {
             $images = $this->model->getImages()->limit($this->limit)->offset($this->offset)->all();
         } else {
             $images = $this->model->images;
         }
         if ($this->noImageOnEmptyImages === true && count($images) === 0) {
             return $this->render('noimage', ['model' => $this->model, 'thumbnailOnDemand' => $this->thumbnailOnDemand, 'thumbnailWidth' => $this->thumbnailWidth, 'thumbnailHeight' => $this->thumbnailHeight, 'useWatermark' => $this->useWatermark, 'additional' => $this->additional]);
         }
         $result = $this->render($this->viewFile, ['model' => $this->model, 'images' => $images, 'thumbnailOnDemand' => $this->thumbnailOnDemand, 'thumbnailWidth' => $this->thumbnailWidth, 'thumbnailHeight' => $this->thumbnailHeight, 'useWatermark' => $this->useWatermark, 'additional' => $this->additional]);
         Yii::$app->cache->set($cacheKey, $result, 86400, new TagDependency(['tags' => [ActiveRecordHelper::getCommonTag(Image::className()), ActiveRecordHelper::getCommonTag($this->model->className())]]));
     }
     return $result;
 }
예제 #4
0
use kartik\icons\Icon;
use app\backend\widgets\BackendWidget;
use yii\helpers\ArrayHelper;
$this->title = Yii::t('app', 'Settings');
$this->params['breadcrumbs'][] = 'Google Feed';
\app\backend\assets\YmlAsset::register($this);
$formName = 'YmlSettings';
$currencies = ArrayHelper::map(\app\modules\shop\models\Currency::find()->select('iso_code')->orderBy(['is_main' => SORT_DESC, 'sort_order' => SORT_ASC, 'iso_code' => SORT_ASC])->asArray()->all(), 'iso_code', 'iso_code');
?>

<?php 
echo app\widgets\Alert::widget(['id' => 'alert']);
?>

<?php 
$feed_relations = ['getImage' => \app\modules\image\models\Image::className(), 'getMainCategory' => \app\modules\shop\models\Category::className()];
$feed_settings = [];
$feed_settings['product_fields'] = (new \app\modules\shop\models\Product())->attributeLabels();
$feed_settings['relations_keys'] = array_combine(array_keys($feed_relations), array_keys($feed_relations));
$feed_settings['relations_map'] = [];
foreach ($feed_relations as $key => $value) {
    $_fields = (new $value())->attributeLabels();
    $feed_settings['relations_map'][$key] = ['fields' => $_fields, 'html' => array_reduce($_fields, function ($result, $i) {
        $result .= '<option value="' . addslashes(htmlspecialchars($i)) . '">' . addslashes(htmlspecialchars($i)) . '</option>';
        return $result;
    }, '')];
}
if (true === isset($feed_settings['relations_map']['getImage'])) {
    $feed_settings['relations_map']['getImage']['fields']['file'] = Yii::t('app', 'File');
    $feed_settings['relations_map']['getImage']['html'] .= '<option value="file">' . Yii::t('app', 'File') . '</option>';
}
예제 #5
0
 public function getImage()
 {
     $result = $this->hasOne(Image::className(), ['object_model_id' => 'id']);
     $object = Object::getForClass($this->className());
     return $result->andWhere(['object_id' => $object->id]);
 }
예제 #6
0
 protected static function loadClassNames()
 {
     if (is_null(static::$classNames)) {
         static::$classNames = [Image::className() => Yii::t('app', 'Image'), Thumbnail::className() => Yii::t('app', 'Thumbnail'), Watermark::className() => Yii::t('app', 'Watermark')];
     }
 }