|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* YAWIK |
|
4
|
|
|
* |
|
5
|
|
|
* @filesource |
|
6
|
|
|
* @license MIT |
|
7
|
|
|
* @copyright 2013 - 2016 Cross Solution <http://cross-solution.de> |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace Jobs\Factory\Controller; |
|
11
|
|
|
|
|
12
|
|
|
use Interop\Container\ContainerInterface; |
|
13
|
|
|
use Jobs\Controller\ApiJobListByOrganizationController; |
|
14
|
|
|
use Jobs\Entity\StatusInterface; |
|
15
|
|
|
|
|
16
|
|
|
use Zend\ServiceManager\Factory\FactoryInterface; |
|
17
|
|
|
use Zend\InputFilter\InputFilter; |
|
18
|
|
|
|
|
19
|
|
|
class ApiJobListByOrganizationControllerFactory implements FactoryInterface |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* Create an object |
|
23
|
|
|
* |
|
24
|
|
|
* @param ContainerInterface $container |
|
25
|
|
|
* @param string $requestedName |
|
26
|
|
|
* @param null|array $options |
|
27
|
|
|
* |
|
28
|
|
|
* @return object |
|
29
|
|
|
*/ |
|
30
|
1 |
|
public function __invoke(ContainerInterface $container, $requestedName, array $options = null) |
|
31
|
|
|
{ |
|
32
|
|
|
/** @var \Jobs\Repository\Job $jobRepository */ |
|
33
|
1 |
|
$jobRepository = $container->get('repositories')->get('Jobs/Job'); |
|
34
|
|
|
|
|
35
|
|
|
/** @var \Jobs\Model\ApiJobDehydrator $apiJobDehydrator */ |
|
36
|
1 |
|
$apiJobDehydrator = $container->get('Jobs\Model\ApiJobDehydrator'); |
|
37
|
|
|
|
|
38
|
1 |
|
$filterStatus = function ($value) { |
|
39
|
|
|
static $validValues = [ |
|
40
|
|
|
StatusInterface::ACTIVE, |
|
41
|
|
|
StatusInterface::CREATED, |
|
42
|
|
|
StatusInterface::PUBLISH, |
|
43
|
|
|
StatusInterface::EXPIRED, |
|
44
|
|
|
StatusInterface::REJECTED, |
|
45
|
|
|
StatusInterface::INACTIVE |
|
46
|
|
|
]; |
|
47
|
|
|
|
|
48
|
|
|
if ('all' == $value) { |
|
49
|
|
|
return true; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
return in_array($value, $validValues) ? $value : StatusInterface::ACTIVE; |
|
53
|
1 |
|
}; |
|
54
|
|
|
|
|
55
|
|
|
$inputFilter = new InputFilter(); |
|
56
|
|
|
$inputFilter->add( |
|
57
|
|
|
[ |
|
58
|
|
|
'name' => 'callback', |
|
59
|
|
|
'filters' => [ |
|
60
|
|
|
['name' => 'StringTrim'], |
|
61
|
|
|
['name' => 'Alpha'], |
|
62
|
|
|
], |
|
63
|
|
|
] |
|
64
|
|
|
); |
|
65
|
|
|
$inputFilter->add( |
|
66
|
|
|
[ |
|
67
|
|
|
'name' => 'status', |
|
68
|
|
|
'filters' => [ |
|
69
|
|
|
[ |
|
70
|
|
|
'name' => 'Callback', |
|
71
|
|
|
'options' => [ |
|
72
|
|
|
'callback' => $filterStatus |
|
73
|
|
|
], |
|
74
|
|
|
], |
|
75
|
|
|
], |
|
76
|
|
|
] |
|
77
|
|
|
); |
|
78
|
|
|
|
|
79
|
|
|
$controller = new ApiJobListByOrganizationController($jobRepository, $apiJobDehydrator, $inputFilter); |
|
80
|
|
|
|
|
81
|
|
|
return $controller; |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|