Esempio n. 1
0
 public function afterDelete()
 {
     // 删除关系表
     AttachmentIndex::deleteAll(['attachment_id' => $this->primaryKey]);
     try {
         $media = MediaItem::createFromAttachment($this);
         if ($media->isImage()) {
             $this->deleteThumbs();
         }
         $this->deleteFile();
     } catch (\Exception $ex) {
     }
 }
Esempio n. 2
0
 /**
  * @inheritdoc
  */
 public function run()
 {
     Yii::$app->response->format = Response::FORMAT_JSON;
     $attachments = Attachment::findAll(["author_id" => $this->authorId]);
     $list = [];
     foreach ($attachments as $attachment) {
         $mediaItem = MediaItem::createFromAttachment($attachment);
         if ($mediaItem->getFileType() === MediaItem::FILE_TYPE_IMAGE) {
             $list[] = ['title' => $attachment->title, 'thumb' => $attachment->getUrl(), 'image' => $attachment->getUrl()];
         } elseif ($mediaItem->getFileType() === MediaItem::FILE_TYPE_DOCUMENT) {
             $list[] = ['title' => $attachment->title, 'name' => $attachment->title, 'link' => $attachment->getUrl(), 'size' => $attachment->size];
         } else {
             $list[] = $url;
         }
     }
     return $list;
 }
Esempio n. 3
0
use hass\attachment\assets\AttachmentUpdateAsset;
use hass\attachment\helpers\MediaItem;
/* @var $this yii\web\View */
/* @var $searchModel \hass\attachment\models\AttachmentSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
/* @var $model yii\db\ActiveRecord */
$this->title = Yii::t('hass/attachment', '编辑附件');
$this->params['breadcrumbs'][] = ["label" => "附件首页", "url" => ["index"]];
$this->params['breadcrumbs'][] = $this->title;
/** @var \hass\attachment\assets\AttachmentUpdateAsset $bundle */
$bundle = AttachmentUpdateAsset::register($this);
?>
<div class="row">
	<div class="col-md-9">
		<?php 
$media = MediaItem::createFromAttachment($model);
echo $this->render("_update_" . $media->getFileType(), ['model' => $model, "media" => $media, "bundle" => $bundle]);
?>
	</div>
	<div class="col-md-3">
		<?php 
$form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data', 'class' => 'model-form']]);
?>
		<div class="box box-solid">
			<div class="box-body">
				<?php 
echo $this->render("_info", ["model" => $model]);
?>
				<?php 
echo $form->field($model, 'title')->textInput(['class' => 'form-control']);
?>