-
Notifications
You must be signed in to change notification settings - Fork 2
/
GalleryManager.php
82 lines (68 loc) · 2.9 KB
/
GalleryManager.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
76
77
78
79
80
81
82
<?php
/**
* Widget to manage gallery.
* Requires Twitter Bootstrap styles to work.
*
* @author Bogdan Savluk <[email protected]>
*/
class GalleryManager extends CWidget
{
/** @var Gallery Model of gallery to manage */
public $gallery;
/** @var string Route to gallery controller */
public $controllerRoute = false;
public $assets;
public function init()
{
$this->assets = Yii::app()->getAssetManager()->publish(dirname(__FILE__) . '/assets');
}
public $htmlOptions = array();
/** Render widget */
public function run()
{
/** @var $cs CClientScript */
$cs = Yii::app()->clientScript;
$cs->registerCssFile($this->assets . '/galleryManager.css');
$cs->registerCoreScript('jquery');
$cs->registerCoreScript('jquery.ui');
if (YII_DEBUG) {
$cs->registerScriptFile($this->assets . '/jquery.iframe-transport.js');
$cs->registerScriptFile($this->assets . '/jquery.galleryManager.js');
} else {
$cs->registerScriptFile($this->assets . '/jquery.iframe-transport.min.js');
$cs->registerScriptFile($this->assets . '/jquery.galleryManager.min.js');
}
if ($this->controllerRoute === null)
throw new CException('$controllerRoute must be set.', 500);
$photos = array();
foreach ($this->gallery->galleryPhotos as $photo) {
$photos[] = array(
'id' => $photo->id,
'rank' => $photo->rank,
'name' => (string)$photo->name,
'description' => (string)$photo->description,
'preview' => $photo->getPreview(),
);
}
$opts = array(
'hasName' => $this->gallery->name ? true : false,
'hasDesc' => $this->gallery->description ? true : false,
'uploadUrl' => Yii::app()->createUrl($this->controllerRoute . '/ajaxUpload', array('gallery_id' => $this->gallery->id)),
'deleteUrl' => Yii::app()->createUrl($this->controllerRoute . '/delete'),
'updateUrl' => Yii::app()->createUrl($this->controllerRoute . '/changeData'),
'arrangeUrl' => Yii::app()->createUrl($this->controllerRoute . '/order'),
'nameLabel' => Yii::t('galleryManager.main', 'Name'),
'descriptionLabel' => Yii::t('galleryManager.main', 'Description'),
'photos' => $photos,
);
if (Yii::app()->request->enableCsrfValidation) {
$opts['csrfTokenName'] = Yii::app()->request->csrfTokenName;
$opts['csrfToken'] = Yii::app()->request->csrfToken;
}
$opts = CJavaScript::encode($opts);
$cs->registerScript('galleryManager#' . $this->id, "$('#{$this->id}').galleryManager({$opts});");
$this->htmlOptions['id'] = $this->id;
$this->htmlOptions['class'] = 'GalleryEditor';
$this->render('galleryManager');
}
}