/
grid_slot.php
executable file
·88 lines (75 loc) · 1.94 KB
/
grid_slot.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
<?php
/**
* @author Palasthotel <rezeption@palasthotel.de>
* @copyright Copyright (c) 2014, Palasthotel
* @license http://www.gnu.org/licenses/gpl-2.0.html GPLv2
* @package Palasthotel\Grid
*/
use Grid\Constants\Hook;
class grid_slot extends grid_base {
public $grid;
public $slotid;
public $style;
public $classes = array();
public $boxes;
public $dimension;
public function __construct()
{
$this->boxes=array();
}
public function render($editmode, $container)
{
$this->storage->fireHook(Hook::WILL_RENDER_SLOT, (object) array( "container"=>$container, "slot" => $this, 'editmode'=>$editmode) );
$boxes=array();
if(count($this->boxes)>0)
{
$this->boxes[0]->classes[]="grid-box-first";
$this->boxes[count($this->boxes)-1]->classes[]="grid-box-last";
}
foreach($this->boxes as $box)
{
$boxes[]=$box->render($editmode, $container, $this);
}
ob_start();
$found = FALSE;
if( is_array( $this->storage->templatesPaths) )
{
foreach ($this->storage->templatesPaths as $templatesPath) {
$template_path = rtrim($templatesPath.'/grid-slot.tpl.php', "/");
if( file_exists($template_path) ){
include $template_path;
$found = TRUE;
break;
}
}
}
if(!$found)
{
include dirname(__FILE__).'/../templates/frontend/grid-slot.tpl.php';
}
$output=ob_get_clean();
$this->storage->fireHook(Hook::DID_RENDER_SLOT, (object) array( "container"=>$container, "slot" => $this, 'editmode'=>$editmode) );
return $output;
}
public function addBox($idx,$box)
{
$list=$this->boxes;
array_splice($list, $idx,0,array($box));
$this->boxes=$list;
$this->storage->storeSlotOrder($this);
return true;
}
public function removeBox($idx)
{
$list=$this->boxes;
array_splice($list, $idx,1);
$this->boxes=$list;
$this->storage->storeSlotOrder($this);
return true;
}
public function setStyle($style)
{
$this->style=$style;
return $this->storage->persistSlot($this);
}
}