Completed
Push — develop ( 6abf52...f3539b )
by
unknown
27:56 queued 14:17
created

TemplateController::getOrganizationLogo()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 9
rs 9.2
cc 4
eloc 5
nc 2
nop 1
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @filesource
6
 * @copyright (c) 2013-2015 Cross Solution (http://cross-solution.de)
7
 * @author [email protected]
8
 * @license   MIT
9
 */
10
11
namespace Jobs\Controller;
12
13
use Jobs\Repository;
14
use Zend\Mvc\Controller\AbstractActionController;
15
use Zend\View\Model\ViewModel;
16
use Zend\View\Model\JsonModel;
17
use Zend\Stdlib\AbstractOptions;
18
19
/**
20
 * Handles rendering the job in formular and in preview mode
21
 *
22
 * Class TemplateController
23
 * @package Jobs\Controller
24
 */
25
class TemplateController extends AbstractActionController
26
{
27
28
    /**
29
     * @var Repository\Job $jobRepository
30
     */
31
    private $jobRepository;
32
33
    /**
34
     * @var AbstractOptions
35
     */
36
    protected $config;
37
38
    public function __construct(Repository\Job $jobRepository, AbstractOptions $config)
39
    {
40
        $this->jobRepository = $jobRepository;
41
        $this->config = $config;
42
    }
43
44
    /**
45
     * Handles the job opening template in preview mode
46
     *
47
     * @return ViewModel
48
     * @throws \RuntimeException
49
     */
50
    public function viewAction()
51
    {
52
        $id = $this->params()->fromQuery('id');
53
        $job = $this->jobRepository->find($id);
54
        $services             = $this->getServiceLocator();
55
        $mvcEvent             = $this->getEvent();
56
        $applicationViewModel = $mvcEvent->getViewModel();
57
58
        $isAdmin=$this->auth()->isAdmin();
0 ignored issues
show
Documentation Bug introduced by
The method auth does not exist on object<Jobs\Controller\TemplateController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
Unused Code introduced by
$isAdmin is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
59
60
        $model = $services->get('Jobs/viewModelTemplateFilter')->__invoke($job);
61
62
        # @todo make this working for anonymous users
0 ignored issues
show
Unused Code Comprehensibility introduced by
53% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
63
//        if ($job->status != 'active' && !$job->getPermissions()->isChangeGranted($this->auth()->getUser()) && ! $isAdmin) {
64
//            $this->response->setStatusCode(404);
65
//            $model->setVariable('message','job is not available');
66
//        } else {
67
            $applicationViewModel->setTemplate('iframe/iFrameInjection');
68
//        }
69
        return $model;
70
    }
71
72
    /**
73
     * Handles the job opening template in formular mode.
74
     *
75
     * All template forms are sending the ID of a job posting and an identifier of the sending
76
     * form.
77
     *
78
     * @return ViewModel
79
     */
80
    protected function editTemplateAction()
81
    {
82
        $id = $this->params('id');
83
        $formIdentifier=$this->params()->fromQuery('form');
84
        $job = $this->jobRepository->find($id);
85
86
        /** @var \Zend\Http\Request $request */
87
        $request              = $this->getRequest();
88
        $isAjax               = $request->isXmlHttpRequest();
89
        $services             = $this->getServiceLocator();
90
        $viewHelperManager    = $services->get('ViewHelperManager');
91
        $mvcEvent             = $this->getEvent();
92
        $applicationViewModel = $mvcEvent->getViewModel();
93
        $forms                = $services->get('FormElementManager');
94
95
        /** @var \Jobs\Form\JobDescriptionTemplate $formTemplate */
96
        $formTemplate         = $forms->get(
97
            'Jobs/Description/Template',
98
            array(
99
            'mode' => $job->id ? 'edit' : 'new'
100
            )
101
        );
102
103
        $formTemplate->setParam('id', $job->id);
104
        $formTemplate->setParam('applyId', $job->applyId);
105
106
        $formTemplate->setEntity($job);
107
108
        if (isset($formIdentifier) && $request->isPost()) {
109
            // at this point the form get instantiated and immediately accumulated
110
111
            $instanceForm = $formTemplate->get($formIdentifier);
112
            if (!isset($instanceForm)) {
113
                throw new \RuntimeException('No form found for "' . $formIdentifier . '"');
114
            }
115
116
            // the id is part of the postData, but it never should be altered
117
            $postData = $request->getPost();
118
119
            unset($postData['id']);
120
            unset($postData['applyId']);
121
122
            $instanceForm->setData($postData);
123
            if ($instanceForm->isValid()) {
124
//                if (0 === strpos($formIdentifier,"templateLabel")) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
61% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
125
//                    $organization=$job->organization;
126
//                    $organization->template->labelRequirements = $postData['description-label-requirements'];
127
//                    $this->getServiceLocator()->get('repositories')->persist($organization);
128
//                }else{
129
                    $this->getServiceLocator()->get('repositories')->persist($job);
130
//                }
131
132
            }
133
        }
134
135
        $model = $services->get('Jobs/ViewModelTemplateFilter')->__invoke($formTemplate);
136
137
        if (!$isAjax) {
138
            $basePath   = $viewHelperManager->get('basepath');
139
            $headScript = $viewHelperManager->get('headscript');
140
            $headScript->appendFile($basePath->__invoke('/Core/js/core.forms.js'));
141
        } else {
142
            return new JsonModel(array('valid' => true));
143
        }
144
        $applicationViewModel->setTemplate('iframe/iFrameInjection');
145
        return $model;
146
    }
147
}
148