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

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

Generate and display jobs and results for test suites

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                $this->AuthCert->allow('view');
40        }
41
42        /**
43         * Get the result by it's ID and check access control.
44         *
45         * Calling methods should ensure that Job.Request is contained in the model query.
46         *
47         * @param string $id The result ID
48         * @param return array An array containing the result.
49         */
50        private function _getValidator($id)
51        {
52                if (!$id) {
53                        $this->Session->setFlash(__('Invalid Result.', true));
54                        $this->redirect(array('controller' => 'requests', 'action'=>'add'));
55                }
56
57                $this->Validator->contain(array(
58                        'Request',
59                        'Result',
60                        'Result.Job',
61                        'Result.Job.Application',
62                        'Result.Job.Platform',
63                        'Result.Job.Request',
64                ));
65               
66                $validator = $this->Validator->read(null, $id);
67                if (isset($validator['Result']['Job']['Request'])) {
68                        $validator['Request'] = $validator['Result']['Job']['Request'];
69                }
70
71                if ($this->Validator->Request->checkAccess($this->AuthCert->user('id'), 'read', $validator['Request']['id'])) {
72                        return $validator;
73                }
74
75                $this->Session->setFlash(__('Invalid validator.', true));
76                $this->redirect(array('controller' => 'requests', 'action'=>'add'));
77        }
78       
79        /**
80         * You can't index results. Redirect to requests.
81         * @return void
82         */
83        public function index()
84        {
85                $this->redirect(array('controller' => 'requests', 'action' => 'index'));
86        }
87
88        /**
89         * View a single Validator result
90         *
91         * @param string $id The Validator ID
92         * @return void
93         */
94        public function view($id = null)
95        {
96                $validator = $this->_getValidator($id);
97
98                // Strip HTML skeleton
99                if (preg_match('#^<html>.*<body>(.*)</body>#si', $validator['Validator']['response'], $match)) {
100                        $validator['Validator']['response'] = $match[1];
101                }
102
103                $this->set(array(
104                        'validator' => $validator,
105                ));
106        }
107}
108
109?>
Note: See TracBrowser for help on using the repository browser.