/
StackCategory.php
96 lines (83 loc) · 2.18 KB
/
StackCategory.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
94
95
96
<?php
namespace Concrete\Core\Page\Stack;
use Concrete\Core\Multilingual\Page\Section\Section;
use Concrete\Core\Page\Type\Type;
use Core;
use Page;
class StackCategory
{
protected $page;
public function __construct($page)
{
$this->setPage($page);
}
/**
* @return mixed
*/
public function getPage()
{
return $this->page;
}
/**
* @param mixed $page
*/
public function setPage($page)
{
$this->page = $page;
}
/**
* @param Section $section
*
* @return StackCategory
*/
public static function getCategoryFromMultilingualSection(Section $section)
{
$sc = null;
if ($section->isDefaultMultilingualSection()) {
return static::getFromDefaultMultilingualSection();
} else {
// we find the stack category located at /paths/locale
$text = Core::make('helper/text');
$locale = $section->getLocale();
$path = STACKS_PAGE_PATH . '/' . $locale;
$page = \Page::getByPath($path);
if (is_object($page) && !$page->isError()) {
$sc = new self($page);
}
}
return $sc;
}
/**
* @return StackCategory
*/
public static function getFromDefaultMultilingualSection()
{
$sc = new self(Page::getByPath(STACKS_PAGE_PATH));
return $sc;
}
public function copyToTargetCategory(StackCategory $category)
{
$list = new StackList();
$list->filterByStackCategory($this);
$stacks = $list->get();
foreach ($stacks as $stack) {
$stack->duplicate($category->getPage());
}
}
/**
* @param Section $section
*
* @return StackCategory
*/
public static function createFromMultilingualSection(Section $section)
{
$parent = \Page::getByPath(STACKS_PAGE_PATH);
$data = array();
$data['name'] = $section->getLocale();
$data['cHandle'] = $section->getLocale();
$type = Type::getByHandle(STACK_CATEGORY_PAGE_TYPE);
$page = $parent->add($type, $data);
$sc = new self($page);
return $sc;
}
}