source: trunk/server/www/app/controllers/validators_controller.php @ 283

Last change on this file since 283 was 283, checked in by sander, 11 years ago

View detailed validator output

File size: 2.9 KB
Line 
1<?php
2/**
3 * Officeshots.org - Test your office documents in different applications
4 * Copyright (C) 2009 Stichting Lone Wolves
5 * Written by Sander Marechal <s.marechal@jejik.com>
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU Affero General Public License for more details.
16 *
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21/**
22 * The Validators controller
23 */
24class ValidatorsController extends AppController
25{
26        /** @var array The helpers that will be available on the view */
27        public $helpers = array('Html', 'ValidatorModel');
28       
29        /** @var array The components this controller uses */
30        public $components = array('AuthCert');
31
32        /**
33         * Set the auth permissions for this controller
34         * @return void
35         */
36        public function beforeFilter()
37        {
38                parent::beforeFilter();
39                if (Configure::read('Auth.allowAnonymous')) {
40                        $this->AuthCert->allow('view');
41                }
42        }
43
44        /**
45         * Get the result by it's ID and check access control.
46         *
47         * Calling methods should ensure that Job.Request is contained in the model query.
48         *
49         * @param string $id The result ID
50         * @param return array An array containing the result.
51         */
52        private function _getValidator($id)
53        {
54                if (!$id) {
55                        $this->Session->setFlash(__('Invalid Result.', true));
56                        $this->redirect(array('controller' => 'requests', 'action'=>'add'));
57                }
58
59                $this->Validator->contain(array(
60                        'Request',
61                        'Request.Gallery',
62                        'Result',
63                        'Result.Job',
64                        'Result.Job.Application',
65                        'Result.Job.Platform',
66                        'Result.Job.Request',
67                        'Result.Job.Request.Gallery',
68                ));
69               
70                $validator = $this->Validator->read(null, $id);
71                if (isset($validator['Result']['Job']['Request'])) {
72                        $validator['Request'] = $validator['Result']['Job']['Request'];
73                }
74
75                if ($validator['Request']['user_id'] == $this->AuthCert->user('id')) {
76                        return $validator;
77                }
78
79                if (!empty($validator['Request']['Gallery'])) {
80                        return $validator;
81                }
82
83                $this->Session->setFlash(__('Invalid validator.', true));
84                $this->redirect(array('controller' => 'requests', 'action'=>'add'));
85        }
86       
87        /**
88         * You can't index results. Redirect to requests.
89         * @return void
90         */
91        public function index()
92        {
93                $this->redirect(array('controller' => 'requests', 'action' => 'index'));
94        }
95
96        /**
97         * View a single Validator result
98         *
99         * @param string $id The Validator ID
100         * @return void
101         */
102        public function view($id = null)
103        {
104                $validator = $this->_getValidator($id);
105                $this->set(array(
106                        'validator' => $validator,
107                ));
108        }
109}
110
111?>
Note: See TracBrowser for help on using the repository browser.