-
Notifications
You must be signed in to change notification settings - Fork 0
/
DicomThumbnail.php
75 lines (63 loc) · 2.4 KB
/
DicomThumbnail.php
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
<?php
namespace jonmer09\dicom;
use kartik\helpers\Html;
use yii\helpers\ArrayHelper;
/**
* Description of DicomThumbnail
* Jun 30, 2016 2:43:32 PM
* @author Jonmer Carpio <jonmer09@gmail.com>
*
*/
class DicomThumbnail extends \yii\base\Widget {
public $imageId;
public $_stack;
public $options;
public $description;
public $single;
public function registerPlugin() {
$id = $this->getId();
$this->imageId = ["currentImageIdIndex" => 0, 'imageIds' => !is_array($this->imageId) ? [$this->imageId] : $this->imageId];
$this->_stack = json_encode($this->imageId);
$js = <<<EOF
$(document).ready(function() {
var element = document.getElementById('$id');
var stack = eval($this->_stack);
cornerstone.enable(element);
cornerstone.loadImage(stack.imageIds[0]).then(function(image) {
cornerstone.displayImage(element, image);
cornerstone.fitToWindow(element);
});
});
EOF;
$this->view->registerJs($js);
}
public function init() {
$this->setId('dicom_th_' . time() . $this->id);
DicomAsset::register($this->view);
$this->registerPlugin();
parent::init();
}
public function run() {
$linkOpts = ArrayHelper::getValue($this->options, 'link', []);
$divOpts = ArrayHelper::getValue($this->options, 'div', []);
$dOpts = ArrayHelper::merge([
'id' => $this->getId(),
"class" => "dicom_thumbnail",
"oncontextmenu" => "return false;",
"unselectable" => "on",
"onselectstart" => "return false;",
"onmousedown" => "return false;"
], $divOpts);
$div = Html::tag('div', "", $dOpts);
$div2 = Html::tag('div', "{$this->description}", ['class' => 'text-center small']);
$aOpts = ArrayHelper::merge([
'class' => '',
"oncontextmenu" => "return false",
"unselectable" => "on",
"onselectstart" => "return false;",
"onmousedown" => "return false;",
"role" => "button",
], $linkOpts);
return Html::a("{$div}{$div2}", null, $aOpts);
}
}