This repository has been archived by the owner on Jun 21, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
AControl.php
93 lines (79 loc) · 2.13 KB
/
AControl.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
83
84
85
86
87
88
89
90
91
92
93
<?php
/**
* For the full copyright and license information, please view
* the file license.txt that was distributed with this source code.
*
* @author Martin Štekl <martin.stekl@gmail.com>
* @since 2011.06.28
* @license MIT
* @copyright Copyright (c) 2011, 2012 Martin Štekl <martin.stekl@gmail.com>
*/
namespace stekycz\gallery;
use \Nette\Application\UI\Control;
use \Nette\ComponentModel\Container;
use \stekycz\gallery\Model\AGroup;
use \stekycz\gallery\Model\AItem;
use \ImageHelper;
/**
* Defines basic functionality for controls.
*/
abstract class AControl extends Control {
/**
* @var bool Show admin environment?
*/
protected $isAdmin = false;
/**
* @var string Path to file with component template
*/
protected $templateFile;
/**
* @var string Name of snippet in template
*/
protected $snippetName;
/**
* @var \ImageHelper Helps with work around pictures
*/
protected $imageHelper;
/**
* @var \stekycz\gallery\Model\AGroup
*/
protected $groupModel;
/**
* @var \stekycz\gallery\Model\AItem
*/
protected $itemModel;
/**
* @paramm ImageHelper $imageHelper
* @param \stekycz\gallery\Model\AGroup $groupModel
* @param \stekycz\gallery\Model\AItem $itemModel
* @param bool $isAdmin
*/
public function __construct(ImageHelper $imageHelper, AGroup $groupModel, AItem $itemModel, $isAdmin = false) {
$this->imageHelper = $imageHelper;
$this->groupModel = $groupModel;
$this->itemModel = $itemModel;
$this->isAdmin = $isAdmin;
}
protected function createTemplate($class = null) {
$template = parent::createTemplate($class);
$template->registerHelper('resize', callback($this->imageHelper, 'resize'));
$template->registerHelper('gallery', callback($this->imageHelper, 'gallery'));
return $template;
}
/**
* Setups template file and snippet name if is filled.
*
* @param string $templateFile
* @param string $snippetName
*/
public function setupTemplate($templateFile, $snippetName = null) {
$this->templateFile = $templateFile;
if ($snippetName !== null) {
$this->snippetName = $snippetName;
}
}
/**
* Renders control.
*/
abstract public function render();
}