/[drupal]/contributions/modules/project_issue_file_test/pift.pages.inc
ViewVC logotype

Contents of /contributions/modules/project_issue_file_test/pift.pages.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.26 - (show annotations) (download) (as text)
Tue Nov 3 21:47:11 2009 UTC (3 weeks, 3 days ago) by boombatower
Branch: MAIN
Branch point for: DRUPAL-7--1
Changes since 1.25: +3 -2 lines
File MIME type: text/x-php
Add array_filter() everywhere pifr_core is used to ensure only enabled versions are used.
1 <?php
2 // $Id: pift.pages.inc,v 1.25 2009/10/23 21:18:58 boombatower Exp $
3 /**
4 * @file
5 * Provide general pages and UI functions.
6 *
7 * Copyright 2008-2009 by Jimmy Berry ("boombatower", http://drupal.org/user/214218)
8 */
9
10 /**
11 * Add additional description to attachment form.
12 */
13 function pift_pages_description_add(&$form, $form_state, $form_id) {
14 global $user;
15
16 // Add description on uploads if it is set.
17 if (PIFT_DESCRIPTION) {
18 // Detect project issue node ID.
19 $nid = NULL;
20 if ($form_id == 'comment_form' && isset($form['original_issue'])) {
21 $node = node_load($form['nid']['#value']);
22 $nid = $node->project_issue['pid'];
23 }
24 elseif ($form_id == 'project_issue_node_form') {
25 $nid = $form['project_info']['pid']['#value'];
26 }
27
28 if (isset($form['attachments']['wrapper']['new']['upload']) && $nid && pift_project_enabled($nid)) {
29 $description = filter_xss_admin(PIFT_DESCRIPTION);
30 $form['attachments']['wrapper']['new']['upload']['#description'] .= $description;
31 }
32 }
33 }
34
35 /**
36 * Add testing setting.
37 */
38 function pift_pages_project_issue_settings(&$form, $form_state) {
39 $form['issue']['#weight'] = -10;
40 $form['issue']['#email'] = -8;
41 $form['testing'] = array(
42 '#type' => 'fieldset',
43 '#title' => t('Testing'),
44 '#collapsible' => TRUE,
45 '#weight' => -9,
46 '#access' => user_access('pift enable project testing'),
47 );
48 $versions = array_filter(variable_get('pift_core', array()));
49 $form['testing']['pift_enable'] = array(
50 '#type' => 'checkbox',
51 '#title' => t('Enable automated testing'),
52 '#description' => t('Enable automated testing of @versions compatible branches and patches.',
53 array('@versions' => implode('.x, ', $versions) . '.x')),
54 '#default_value' => pift_project_enabled($form['nid']['#value']),
55 );
56 $form['#submit'][] = 'pift_pages_project_issue_settings_submit';
57 }
58
59 /**
60 * Store project testing preferences.
61 */
62 function pift_pages_project_issue_settings_submit($form, &$form_state) {
63 $enabled = pift_project_enabled($form_state['values']['nid']);
64 if ($form_state['values']['pift_enable'] && !$enabled) {
65 db_query('INSERT INTO {pift_project}
66 VALUES (%d)', $form_state['values']['nid']);
67 }
68 else if (!$form_state['values']['pift_enable'] && $enabled) {
69 db_query('DELETE FROM {pift_project}
70 WHERE pid = %d', $form_state['values']['nid']);
71 }
72 }
73
74 /**
75 * Confirm re-test.
76 *
77 * @param integer Test ID to re-test.
78 */
79 function pift_pages_retest_confirm_form(&$form_state, $test_id) {
80 $test = pift_test_get($test_id);
81
82 if ($test) {
83 $form = array();
84 $form['test'] = array(
85 '#type' => 'value',
86 '#value' => array(
87 'test_id' => $test_id,
88 'fid' => $test['fid'],
89 'nid' => ($test['fid'] ? $test['nid'] : $test['rid']),
90 'cid' => ($test['cid'] ? $test['cid'] : 0),
91 'status' => $test['status'],
92 'title' => ($test['fid'] ? $test['filename'] : project_release_get_version((object) $test))
93 ),
94 );
95 $form['#redirect'] = 'node/' . $form['test']['#value']['nid'];
96
97 return confirm_form(
98 $form,
99 t('Are you sure you want to request that %title be re-tested?', array('%title' => $form['test']['#value']['title'])),
100 $form['#redirect'],
101 t('Once requested the test will be re-queued and results will be updated once the re-test has finished.'),
102 t('Re-test'),
103 t('Cancel')
104 );
105 }
106 else {
107 drupal_set_message(t('Invalid test.'), 'error');
108 }
109 }
110
111 /**
112 * Re-queue test if it still meets are criteria.
113 */
114 function pift_pages_retest_confirm_form_submit($form, &$form_state) {
115 $test = $form_state['values']['test'];
116
117 if ($test['status'] > PIFT_STATUS_SENT) {
118 project_issue_add_auto_followup(array(
119 'nid' => $test['nid'],
120 'sid' => PIFT_FOLLOWUP_RETEST,
121 'comment' => theme('pift_auto_followup', 'retest', $test['nid'], $test['cid']),
122 ));
123
124 db_query('UPDATE {pift_test}
125 SET status = %d
126 WHERE test_id = %d', PIFT_STATUS_QUEUE, $test['test_id']);
127
128 if (db_affected_rows()) {
129 drupal_set_message(t('%title has been submitted for re-testing. Please be patient while you wait for results.',
130 array('%title' => $test['title'])));
131 }
132 else {
133 drupal_set_message(t('Invalid test.'), 'error');
134 }
135 }
136 else {
137 drupal_set_message(t('%title is not currently eligible for re-testing.',
138 array('%title' => $test['title'])), 'error');
139 }
140 }
141
142 /**
143 * Theme attachments into a table with test results.
144 *
145 * @param array $files List of file attachments.
146 * @return string HTML output.
147 */
148 function theme_pift_attachments(array $files) {
149 $header = array(t('Attachment'), t('Size'), t('Status'), t('Test result'), t('Operations'));
150 $rows = array();
151 foreach ($files as $file) {
152 $row = array();
153
154 $row[] = l($file['filename'], file_create_url($file['filepath']));
155 $row[] = format_size($file['filesize']);
156
157 if ($file['test_id'] !== NULL) {
158 list($row[], $class) = pift_attachment_process($file['status'], (bool) $file['message']);
159 $row[] = $file['message'] ? check_plain($file['message']) : '<em>' . t('None') . '</em>';
160 }
161 else {
162 $row[] = '<em>' . t('Ignored') . '</em>';
163 $row[] = '<em>' . t('None') . '</em>';
164 $class = '';
165 }
166
167 // Add valid operations.
168 $operations = array();
169 if ($file['status'] > PIFT_STATUS_QUEUE || $file['message']) {
170 $operations[] = l(t('View details'), PIFT_SERVER . 'pifr/test/' . $file['test_id']);
171 }
172 if ($file['status'] > PIFT_STATUS_SENT) {
173 $operations[] = l(t('Re-test'), 'pift/retest/' . $file['test_id']);
174 }
175 $row[] = ($operations ? implode(' | ', $operations) : '<em>' . t('None') . '</em>');
176
177 $rows[] = array('class' => $class, 'data' => $row);
178 }
179 return theme('table', $header, $rows);
180 }
181
182 /**
183 * Process the specified attachment information and return the valid status
184 * message and and row CSS class.
185 *
186 * @param integer $status Test status, PIFT_STATUS_*.
187 * @param boolean $has_message Attachment has a message.
188 * @return array Cell value and CSS class.
189 */
190 function pift_attachment_process($status, $has_message) {
191 $class = '';
192 if ($status == PIFT_STATUS_QUEUE && $has_message) {
193 $cell = t('Queued for re-testing');
194 $class = 'pift-retest';
195 }
196 else if ($status == PIFT_STATUS_QUEUE) {
197 $cell = t('Queued for testing');
198 }
199 elseif ($status == PIFT_STATUS_SENT) {
200 $cell = t('Test request sent');
201 }
202 elseif ($status > PIFT_STATUS_SENT) {
203 $cell = t('Idle');
204 $class = $status == PIFT_STATUS_PASS ? 'pift-pass' : 'pift-fail';
205 }
206 return array($cell, $class);
207 }

  ViewVC Help
Powered by ViewVC 1.1.2