-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathEditorWidget.php
More file actions
84 lines (72 loc) · 2.03 KB
/
EditorWidget.php
File metadata and controls
84 lines (72 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/
namespace humhub\modules\drawio\widgets;
use humhub\helpers\Html;
use humhub\modules\file\libs\FileHelper;
use humhub\modules\file\models\File;
use humhub\widgets\JsWidget;
use Yii;
use yii\helpers\Url;
/**
* Description of EditorWidget
*
* @author Luke
*/
class EditorWidget extends JsWidget
{
/**
* @var File the file
*/
public $file;
/**
* @inheritdoc
*/
public $jsWidget = 'drawio.Editor';
/**
* @inheritdoc
*/
public $init = true;
/**
* @inheritdoc
*/
public function getData()
{
$user = Yii::$app->user->getIdentity();
return [
'file-guid' => $this->file->guid,
'file-name' => Html::encode($this->file->fileName),
'file-extension' => Html::encode(strtolower(FileHelper::getExtension($this->file))),
'file-content' => file_get_contents($this->file->store->get()) ?: null,
'file-save-url' => Url::to(['/drawio/open/update', 'guid' => $this->file->guid]),
'user-guid' => ($user) ? Html::encode($user->guid) : '',
'user-first-name' => ($user) ? Html::encode($user->profile->firstname) : 'Anonymous',
'user-last-name' => ($user) ? Html::encode($user->profile->lastname) : 'User',
'user-language' => ($user) ? $user->language : 'en',
];
}
/**
* @inheritdoc
*/
public function getAttributes()
{
return [
'style' => 'height:100%;border-radius: 8px 8px 0px 0px;background-color:#F4F4F4',
];
}
/**
* @inheritdoc
*/
public function run()
{
$url = Yii::$app->getModule('drawio')->getServerUrl() . '/?embed=1&spin=1&proto=json&stealth=1&splash=0&ui=atlas';
return $this->render('editor', [
'file' => $this->file,
'options' => $this->getOptions(),
'drawioUrl' => $url,
]);
}
}