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 | * A helper to assist in outputting Jobs |
---|
23 | */ |
---|
24 | class JobModelHelper extends AppHelper |
---|
25 | { |
---|
26 | /** @var array Add the Time helper */ |
---|
27 | public $helpers = array('Html'); |
---|
28 | |
---|
29 | /** |
---|
30 | * Return the description of a Job |
---|
31 | */ |
---|
32 | public function getDescription($job, $request_state) |
---|
33 | { |
---|
34 | if (!isset($job['Job'])) { |
---|
35 | $job = array('Job' => $job); |
---|
36 | } |
---|
37 | |
---|
38 | if (!empty($job['Job']['Result'])) { |
---|
39 | return $this->output($job['Job']['Result']['Format']['name']); |
---|
40 | } |
---|
41 | |
---|
42 | if ($request_state & (Request::STATE_UPLOADING | Request::STATE_PREPROCESSOR_QUEUED | Request::STATE_QUEUED)) { |
---|
43 | if ($job['Job']['locked'] == '0000-00-00 00:00:00') { |
---|
44 | return $this->output(__('Queued')); |
---|
45 | } |
---|
46 | |
---|
47 | if (empty($job['Job']['Result'])) { |
---|
48 | return $this->output(__('Processing')); |
---|
49 | } |
---|
50 | } |
---|
51 | |
---|
52 | return $this->output(__('Failed', true)); |
---|
53 | } |
---|
54 | |
---|
55 | /** |
---|
56 | * Return the icon of a Job |
---|
57 | */ |
---|
58 | public function getIcon($job, $request_state) |
---|
59 | { |
---|
60 | if (!isset($job['Job'])) { |
---|
61 | $job = array('Job' => $job); |
---|
62 | } |
---|
63 | |
---|
64 | if (!empty($job['Job']['Result'])) { |
---|
65 | if ($job['Job']['Result']['state'] == Result::STATE_SCAN_FOUND) { |
---|
66 | $icon = 'virus.png'; |
---|
67 | } else { |
---|
68 | $icon = $job['Job']['Result']['Mimetype']['icon']; |
---|
69 | } |
---|
70 | |
---|
71 | return $this->output($this->Html->image('icons/' . $icon, array( |
---|
72 | 'alt' => $job['Job']['Result']['Format']['name'], |
---|
73 | 'url' => array('controller'=> 'results', 'action'=>'view', $job['Job']['Result']['id']) |
---|
74 | ))); |
---|
75 | } |
---|
76 | |
---|
77 | if ($request_state & (Request::STATE_UPLOADING | Request::STATE_PREPROCESSOR_QUEUED | Request::STATE_QUEUED)) { |
---|
78 | if ($job['Job']['locked'] == '0000-00-00 00:00:00') { |
---|
79 | return $this->output($this->Html->image('icons/queued.png', array('alt' => __('Queued', true)))); |
---|
80 | } |
---|
81 | |
---|
82 | if (empty($job['Job']['Result'])) { |
---|
83 | return $this->output($this->Html->image('icons/busy.png', array('alt' => __('Processing', true)))); |
---|
84 | } |
---|
85 | } |
---|
86 | |
---|
87 | return $this->output($this->Html->image('icons/error.png', array('alt' => __('Failed', true)))); |
---|
88 | } |
---|
89 | } |
---|
90 | |
---|
91 | ?> |
---|