1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Superdesk Web Publisher MultiTenancy Bundle. |
5
|
|
|
* |
6
|
|
|
* Copyright 2016 Sourcefabric z.ú. and contributors. |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please see the |
9
|
|
|
* AUTHORS and LICENSE files distributed with this source code. |
10
|
|
|
* |
11
|
|
|
* @copyright 2016 Sourcefabric z.ú |
12
|
|
|
* @license http://www.superdesk.org/license |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace SWP\Bundle\MultiTenancyBundle\Factory; |
16
|
|
|
|
17
|
|
|
use Doctrine\Common\Persistence\ObjectManager; |
18
|
|
|
use Doctrine\ODM\PHPCR\HierarchyInterface; |
19
|
|
|
use SWP\Component\MultiTenancy\Factory\OrganizationFactoryInterface; |
20
|
|
|
|
21
|
|
|
class OrganizationFactory implements OrganizationFactoryInterface |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var OrganizationFactoryInterface |
25
|
|
|
*/ |
26
|
|
|
protected $decoratedFactory; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var ObjectManager |
30
|
|
|
*/ |
31
|
|
|
protected $documentManager; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var string|null |
35
|
|
|
*/ |
36
|
|
|
protected $rootPath; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* OrganizationFactory constructor. |
40
|
|
|
* |
41
|
|
|
* @param OrganizationFactoryInterface $decoratedFactory |
42
|
|
|
* @param ObjectManager $documentManager |
43
|
|
|
* @param null $rootPath |
44
|
|
|
*/ |
45
|
|
|
public function __construct( |
46
|
|
|
OrganizationFactoryInterface $decoratedFactory, |
47
|
|
|
ObjectManager $documentManager, |
48
|
|
|
$rootPath = null |
49
|
|
|
) { |
50
|
|
|
$this->decoratedFactory = $decoratedFactory; |
51
|
|
|
$this->documentManager = $documentManager; |
52
|
|
|
$this->rootPath = $rootPath; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* {@inheritdoc} |
57
|
|
|
*/ |
58
|
|
|
public function create() |
59
|
|
|
{ |
60
|
|
|
return $this->decoratedFactory->create(); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* {@inheritdoc} |
65
|
|
|
*/ |
66
|
|
|
public function createWithCode() |
67
|
|
|
{ |
68
|
|
|
$organization = $this->decoratedFactory->createWithCode(); |
69
|
|
|
|
70
|
|
|
if ($organization instanceof HierarchyInterface) { |
71
|
|
|
$organization->setParentDocument($this->documentManager->find(null, $this->rootPath)); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
return $organization; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|