1 <?php
2
3 4 5 6 7 8 9 10
11
12 namespace Icybee\Modules\Images;
13
14 use Brickrouge\Element;
15
16 class PopImage extends \Icybee\Modules\Nodes\PopNode
17 {
18 const THUMBNAIL_VERSION = '#popimage-thumbnail-version';
19
20 static protected function add_assets(\Brickrouge\Document $document)
21 {
22 parent::add_assets($document);
23
24 $document->js->add(DIR . 'public/module.js');
25 $document->css->add(DIR . 'public/module.css');
26 }
27
28 public function __construct($attributes=array())
29 {
30 parent::__construct
31 (
32 $attributes + array
33 (
34 self::T_CONSTRUCTOR => 'images',
35 self::THUMBNAIL_VERSION => '$popimage',
36
37 'placeholder' => 'Sélectionner une image',
38
39 'data-adjust' => 'adjust-image'
40 )
41 );
42 }
43
44 protected function alter_dataset(array $dataset)
45 {
46 return parent::alter_dataset
47 (
48 $dataset + array
49 (
50 'widget-constructor' => 'PopImage',
51 'thumbnail-version' => $this[self::THUMBNAIL_VERSION]
52 )
53 );
54 }
55
56 protected function getEntry($model, $value)
57 {
58 return $model->where('path = ? OR title = ? OR slug = ?', $value, $value, $value)->order('created_at DESC')->one;
59 }
60
61 protected function getPreview($record)
62 {
63 if (!$record)
64 {
65 return new Element('img');
66 }
67
68 return $record->thumbnail($this[self::THUMBNAIL_VERSION])->to_element(array(
69
70 'data-nid' => $record->nid,
71 'data-path' => $record->url('get')
72
73 ));
74 }
75 }