-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProccessMapDataTrait.php
44 lines (35 loc) · 1023 Bytes
/
ProccessMapDataTrait.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
<?php
namespace ImageMapField\Traits;
use SilverStripe\View\ArrayData;
use SilverStripe\ORM\ArrayList;
use ImageMapField\Models\Area;
trait ProcessMapDataTrait
{
public function getImageMapView()
{
$data = $this->getImageMapViewableData();
if ($data) {
return $data->renderWith(['ImageMapTemplate']);
}
return null;
}
/**
* @return ArrayData with 2 props - Image and ImageMapAreas
*/
public function getImageMapViewableData()
{
$data = json_decode($this->ProcessMapData, true);
$arrayList = ArrayList::create();
if (is_array($data)) {
foreach ($data as $value) {
$arrayList->push(Area::create($value));
}
}
$arrayData = ArrayData::create([
'Image' => $this->ProcessMapImage(),
'ImageMapAreas' => $arrayList,
'ProcessMapCaption' => $this->ProcessMapCaption,
]);
return $arrayData;
}
}