/
FolderService.php
49 lines (39 loc) · 1.45 KB
/
FolderService.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
<?php
namespace Concrete\Core\Page\Stack\Folder;
use Concrete\Core\Application\Application;
use Concrete\Core\Database\Connection\Connection;
use Concrete\Core\Page\Type\Type;
class FolderService
{
protected $connection;
protected $application;
public function __construct(Application $application, Connection $connection)
{
$this->connection = $connection;
$this->application = $application;
}
public function getByPath($path)
{
$c = \Page::getByPath(STACKS_PAGE_PATH . '/' . trim($path, '/'));
if ($c->getCollectionTypeHandle() == STACK_CATEGORY_PAGE_TYPE) {
return $this->application->make('Concrete\Core\Page\Stack\Folder\Folder', array($c));
}
}
public function getByID($cID)
{
$c = \Page::getByID($cID);
if ($c->getCollectionTypeHandle() == STACK_CATEGORY_PAGE_TYPE) {
return $this->application->make('Concrete\Core\Page\Stack\Folder\Folder', array($c));
}
}
public function add($name, Folder $folder = null)
{
// $site = \Core::make('site')->getActiveSiteForEditing();
$type = Type::getByHandle(STACK_CATEGORY_PAGE_TYPE);
$parent = $folder ? $folder->getPage() : \Page::getByPath(STACKS_PAGE_PATH);
$data = array();
$data['name'] = $name;
$page = $parent->add($type, $data);
return $this->application->make('Concrete\Core\Page\Stack\Folder\Folder', array($page));
}
}