Inheritance: extends yii\base\Behavior, use trait nemmo\attachments\ModuleTrait
 public function init()
 {
     parent::init();
     if (empty($this->model)) {
         throw new InvalidConfigException("Property {model} cannot be blank");
     }
     $hasFileBehavior = false;
     foreach ($this->model->getBehaviors() as $behavior) {
         if (is_a($behavior, FileBehavior::className())) {
             $hasFileBehavior = true;
         }
     }
     if (!$hasFileBehavior) {
         throw new InvalidConfigException("The behavior {FileBehavior} has not been attached to the model.");
     }
 }
 public function run()
 {
     if (!$this->model) {
         return Html::tag('div', Html::tag('b', Yii::t('yii', 'Error')) . ': ' . $this->getModule()->t('attachments', 'The model cannot be empty.'), ['class' => 'alert alert-danger']);
     }
     $hasFileBehavior = false;
     foreach ($this->model->getBehaviors() as $behavior) {
         if (is_a($behavior, FileBehavior::className())) {
             $hasFileBehavior = true;
         }
     }
     if (!$hasFileBehavior) {
         return Html::tag('div', Html::tag('b', Yii::t('yii', 'Error')) . ': ' . $this->getModule()->t('attachments', 'The behavior FileBehavior has not been attached to the model.'), ['class' => 'alert alert-danger']);
     }
     Url::remember(Url::current());
     return GridView::widget(['dataProvider' => new ArrayDataProvider(['allModels' => $this->model->getFiles()]), 'layout' => '{items}', 'tableOptions' => $this->tableOptions, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['label' => $this->getModule()->t('attachments', 'File name'), 'format' => 'raw', 'value' => function ($model) {
         return Html::a("{$model->name}.{$model->type}", $model->getUrl());
     }], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{delete}', 'buttons' => ['delete' => function ($url, $model, $key) {
         return Html::a('<span class="glyphicon glyphicon-trash"></span>', ['/attachments/file/delete', 'id' => $model->id], ['title' => Yii::t('yii', 'Delete'), 'data-confirm' => Yii::t('yii', 'Are you sure you want to delete this item?'), 'data-method' => 'post']);
     }]]]]);
 }
Example #3
0
 /**
  * @inheritDoc
  */
 public function behaviors()
 {
     return [FileBehavior::className()];
 }
Example #4
0
 /**
  * @inheritdoc
  */
 public function behaviors()
 {
     return ['timestamp' => ['class' => TimestampBehavior::className(), 'createdAtAttribute' => 'created_at', 'updatedAtAttribute' => FALSE], 'fileBehavior' => ['class' => \nemmo\attachments\behaviors\FileBehavior::className()]];
 }
Example #5
0
 /**
  * @inheritdoc
  */
 public function behaviors()
 {
     return ['fileBehavior' => ['class' => \nemmo\attachments\behaviors\FileBehavior::className()]];
 }
Example #6
0
 public function behaviors()
 {
     return array_merge(parent::behaviors(), ['timestamp' => ['class' => 'yii\\behaviors\\TimestampBehavior', 'attributes' => [self::EVENT_BEFORE_INSERT => ['create_time', 'update_time'], self::EVENT_BEFORE_UPDATE => ['update_time']], 'value' => function () {
         return new Expression('CURRENT_TIMESTAMP');
     }], 'blameable' => ['class' => BlameableBehavior::className(), 'createdByAttribute' => 'create_by', 'updatedByAttribute' => false], 'attachments' => ['class' => \nemmo\attachments\behaviors\FileBehavior::className()], 'ip' => ['class' => IpBehavior::className(), 'attributes' => [self::EVENT_BEFORE_INSERT => ['ip']]]]);
 }