1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* YAWIK |
5
|
|
|
* |
6
|
|
|
* @filesource |
7
|
|
|
* @license MIT |
8
|
|
|
* @copyright 2013 - 2017 Cross Solution <http://cross-solution.de> |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Organizations\Controller; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
use Auth\Exception\UnauthorizedAccessException; |
15
|
|
|
use Core\Entity\Exception\NotFoundException; |
16
|
|
|
use Jobs\Repository\Job as JobRepository; |
17
|
|
|
use Organizations\Entity\Organization; |
18
|
|
|
use Organizations\Repository\Organization as OrganizationRepository; |
19
|
|
|
use Zend\Http\Response; |
20
|
|
|
use Zend\I18n\Translator\TranslatorInterface; |
21
|
|
|
use Zend\Mvc\Controller\AbstractActionController; |
22
|
|
|
use Zend\View\Model\ViewModel; |
23
|
|
|
use Organizations\ImageFileCache\Manager as ImageFileCacheManager; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Class ProfileController |
27
|
|
|
* |
28
|
|
|
* @author Anthonius Munthi <[email protected]> |
29
|
|
|
* @package Organizations\Controller |
30
|
|
|
* @since 0.30.1 |
31
|
|
|
*/ |
32
|
|
|
class ProfileController extends AbstractActionController |
33
|
|
|
{ |
34
|
|
|
/** |
35
|
|
|
* @var OrganizationRepository |
36
|
|
|
*/ |
37
|
|
|
private $repo; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var JobRepository |
41
|
|
|
*/ |
42
|
|
|
private $jobRepo; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var TranslatorInterface |
46
|
|
|
*/ |
47
|
|
|
private $translator; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @var ImageFileCacheManager |
51
|
|
|
*/ |
52
|
|
|
private $imageFileCacheManager; |
53
|
|
|
|
54
|
|
|
public function __construct( |
55
|
|
|
OrganizationRepository $repo, |
56
|
|
|
JobRepository $jobRepository, |
57
|
|
|
TranslatorInterface $translator, |
58
|
|
|
ImageFileCacheManager $imageFileCacheManager |
59
|
|
|
) |
60
|
|
|
{ |
61
|
|
|
$this->repo = $repo; |
62
|
|
|
$this->translator = $translator; |
63
|
|
|
$this->imageFileCacheManager = $imageFileCacheManager; |
64
|
|
|
$this->jobRepo = $jobRepository; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* List organization |
69
|
|
|
* |
70
|
|
|
* @return ViewModel |
71
|
|
|
*/ |
72
|
|
View Code Duplication |
public function indexAction() |
|
|
|
|
73
|
|
|
{ |
74
|
|
|
|
75
|
|
|
$result = $this->pagination([ |
|
|
|
|
76
|
|
|
'paginator' => [ |
77
|
|
|
'Organizations/Organization', |
78
|
|
|
'as' => 'organizations', |
79
|
|
|
'params' => [ |
80
|
|
|
'type' => 'profile', |
81
|
|
|
] |
82
|
|
|
], |
83
|
|
|
'form' => [ |
84
|
|
|
'Core/Search', |
85
|
|
|
[ |
86
|
|
|
'text_name' => 'text', |
87
|
|
|
'text_placeholder' => /*@translate*/ 'Search for organizations', |
88
|
|
|
'button_element' => 'text', |
89
|
|
|
], |
90
|
|
|
'as' => 'form' |
91
|
|
|
] |
92
|
|
|
]); |
93
|
|
|
return new ViewModel($result); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @return array|ViewModel |
98
|
|
|
*/ |
99
|
|
|
public function detailAction() |
100
|
|
|
{ |
101
|
|
|
$translator = $this->translator; |
102
|
|
|
$repo = $this->repo; |
103
|
|
|
$id = $this->params('id'); |
104
|
|
|
|
105
|
|
|
if(is_null($id)){ |
106
|
|
|
$this->getResponse()->setStatusCode(Response::STATUS_CODE_404); |
|
|
|
|
107
|
|
|
return [ |
108
|
|
|
'message' => $translator->translate('Can not access profile page without id'), |
109
|
|
|
'exception' => new \InvalidArgumentException('Null Organization Profile Id') |
110
|
|
|
]; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
$organization = $repo->find($id); |
114
|
|
|
if(!$organization instanceof Organization){ |
115
|
|
|
throw new NotFoundException($id); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
if( |
119
|
|
|
Organization::PROFILE_DISABLED == $organization->getProfileSetting() |
120
|
|
|
|| is_null($organization->getProfileSetting()) |
121
|
|
|
){ |
122
|
|
|
throw new UnauthorizedAccessException(/*@translate*/ 'This Organization Profile is disabled'); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
$result = $this->pagination([ |
|
|
|
|
126
|
|
|
'params' => [ |
127
|
|
|
'Organization_Jobs',[ |
128
|
|
|
'organization_id' => $organization->getId() |
129
|
|
|
] |
130
|
|
|
], |
131
|
|
|
'paginator' => ['as' => 'jobs','Organizations/ListJob'], |
132
|
|
|
]); |
133
|
|
|
|
134
|
|
|
if( |
135
|
|
|
Organization::PROFILE_ACTIVE_JOBS == $organization->getProfileSetting() |
136
|
|
|
){ |
137
|
|
|
/* @var \Zend\Paginator\Paginator $paginator */ |
138
|
|
|
$paginator = $result['jobs']; |
139
|
|
|
$count = $paginator->getTotalItemCount(); |
140
|
|
|
if(0===$count){ |
141
|
|
|
throw new UnauthorizedAccessException(/*@translate*/ 'This Organization Profile is disabled'); |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
$result['organization'] = $organization; |
145
|
|
|
$result['organizationImageCache'] = $this->imageFileCacheManager; |
146
|
|
|
|
147
|
|
|
return new ViewModel($result); |
148
|
|
|
} |
149
|
|
|
} |
150
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.