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

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

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


Revision 1.20 - (show annotations) (download) (as text)
Tue Nov 3 21:47:11 2009 UTC (3 weeks, 1 day ago) by boombatower
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-7--1
Changes since 1.19: +2 -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.test.inc,v 1.19 2009/10/23 22:32:12 boombatower Exp $
3 /**
4 * @file
5 * Provide test functions.
6 *
7 * Copyright 2008-2009 by Jimmy Berry ("boombatower", http://drupal.org/user/214218)
8 */
9
10 /**
11 * Get the test with the specified ID.
12 *
13 * @param integer $test_id Test ID.
14 * @return array Test data.
15 */
16 function pift_test_get($test_id) {
17 return db_fetch_array(db_query('SELECT t.*, f.fid, f.filename, f.filepath, f.filesize,
18 IF(u.nid IS NULL, cu.nid, u.nid) AS nid, cu.cid
19 FROM {pift_test} t
20 LEFT JOIN {files} f
21 ON (t.type = %d AND t.id = f.fid)
22 LEFT JOIN {upload} u
23 ON f.fid = u.fid
24 LEFT JOIN {comment_upload} cu
25 ON f.fid = cu.fid
26 WHERE t.test_id = %d', PIFT_TYPE_FILE, $test_id));
27 }
28
29 /**
30 * Get the files and test data for the specified comment ID.
31 *
32 * @param integer $cid Comment ID.
33 * @return array List of files and test data.
34 */
35 function pift_test_get_files_comment($cid) {
36 $result = db_query('SELECT f.fid, f.filename, f.filepath, f.filesize, cu.nid, cu.cid, t.*
37 FROM {files} f
38 INNER JOIN {comment_upload} cu
39 ON f.fid = cu.fid
40 LEFT JOIN {pift_test} t
41 ON (t.type = %d AND f.fid = t.id)
42 WHERE cu.cid = %d
43 ORDER BY cu.weight, f.fid', PIFT_TYPE_FILE, $cid);
44 $files = array();
45 while ($file = db_fetch_array($result)) {
46 $files[] = $file;
47 }
48 return $files;
49 }
50
51 /**
52 * Get the files and test data on comments for the specified node ID.
53 *
54 * @param integer $nid Node ID.
55 * @return array List of files and test data.
56 */
57 function pift_test_get_files_comment_all($nid) {
58 $result = db_query('SELECT f.fid, f.filename, f.filepath, f.filesize, cu.nid, cu.cid, t.*
59 FROM {files} f
60 INNER JOIN {comment_upload} cu
61 ON f.fid = cu.fid
62 LEFT JOIN {pift_test} t
63 ON (t.type = %d AND f.fid = t.id)
64 WHERE cu.nid = %d
65 ORDER BY cu.weight, f.fid', PIFT_TYPE_FILE, $nid);
66 $files = array();
67 while ($file = db_fetch_array($result)) {
68 $files[] = $file;
69 }
70 return $files;
71 }
72
73
74 /**
75 * Get the files and test data for the specified node ID.
76 *
77 * @param integer $nid Node ID.
78 * @return array List of files and test data.
79 */
80 function pift_test_get_files_node($nid) {
81 $result = db_query('SELECT f.fid, f.filename, f.filepath, f.filesize, u.nid, t.*
82 FROM {files} f
83 INNER JOIN {upload} u
84 ON f.fid = u.fid
85 LEFT JOIN {pift_test} t
86 ON (t.type = %d AND f.fid = t.id)
87 WHERE u.nid = %d
88 ORDER BY u.weight, f.fid', PIFT_TYPE_FILE, $nid);
89 $files = array();
90 while ($file = db_fetch_array($result)) {
91 $files[] = $file;
92 }
93 return $files;
94 }
95
96
97 /**
98 * Get the files and test data for the specified node ID and its comments.
99 *
100 * @param integer $nid Node ID.
101 * @return array List of files and test data.
102 */
103 function pift_test_get_files_node_all($nid) {
104 return array_merge(pift_test_get_files_node($nid), pift_test_get_files_comment_all($nid));
105 }
106
107 /**
108 * Check the criteria for the specified issue.
109 *
110 * @param object $node Node object.
111 * @return boolean Passed criteria.
112 */
113 function pift_test_check_criteria_issue($node) {
114 if (!pift_project_enabled($node->project_issue['pid'])) {
115 return FALSE;
116 }
117
118 $release = node_load($node->project_issue['rid']);
119 list($api_version, $api_tid) = pift_core_api($release);
120 if (!in_array($api_version, array_filter(variable_get('pift_core', array())))) {
121 return FALSE;
122 }
123
124 if (!in_array($node->project_issue['sid'], variable_get('pift_status', array()))) {
125 return FALSE;
126 }
127
128 return TRUE;
129 }
130
131 /**
132 * Check the criteria for the specified file.
133 *
134 * @param array $file File to check.
135 * @return boolean Passed criteria.
136 */
137 function pift_test_check_criteria_file(array $file) {
138 if (!preg_match(PIFT_REGEX, $file['filename'])) {
139 return FALSE;
140 }
141 return TRUE;
142 }
143
144 /**
145 * Add files to test tables.
146 *
147 * @param array $files Files to add.
148 */
149 function pift_test_add_files(array $files) {
150 foreach ($files as $file) {
151 $file = (array) $file;
152 if (pift_test_check_criteria_file($file)) {
153 pift_test_add(PIFT_TYPE_FILE, $file['fid']);
154 }
155 }
156 }
157
158 /**
159 * Add a test to the test tables.
160 *
161 * @param integer $type The type of test to add, PIFT_TYPE_*.
162 * @param integer $id Related test detail record ID, either rid, or fid.
163 */
164 function pift_test_add($type, $id) {
165 db_query('INSERT INTO {pift_test} (type, id, status)
166 VALUES (%d, %d, %d)', $type, $id, PIFT_STATUS_QUEUE);
167 }
168
169 function pift_test_sent($test_id, $type, $id) {
170 db_query('UPDATE {pift_test}
171 SET test_id = %d,
172 status = %d
173 WHERE type = %d
174 AND id = %d', $test_id, PIFT_STATUS_SENT, $type, $id);
175 }
176
177 /**
178 * Add a test back to the queue.
179 *
180 * @param integer $test_id Test ID.
181 */
182 function pift_test_requeue($test_id) {
183 db_query('UPDATE {pift_test}
184 SET status = %d
185 WHERE test_id = %d', PIFT_STATUS_QUEUE, $test_id);
186 }
187
188 /**
189 * Clean up data since master records are removed before PIFT has a chance to
190 * remove its related data.
191 */
192 function pift_test_delete_files() {
193 db_query('DELETE FROM {pift_test}
194 WHERE type = %d
195 AND id NOT IN (
196 SELECT fid
197 FROM {files}
198 )', PIFT_TYPE_FILE);
199 }
200
201 /**
202 * Add previously submitted files once the node meets the criteria.
203 *
204 * @param integer $nid Node ID.
205 */
206 function pift_test_add_previous_files($nid) {
207 $files = pift_test_get_files_node_all($nid);
208 foreach ($files as $file) {
209 $file = (array) $file;
210 if ($file['test_id'] === NULL && pift_test_check_criteria_file($file)) {
211 pift_test_add(PIFT_TYPE_FILE, $file['fid']);
212 }
213 }
214 }

  ViewVC Help
Powered by ViewVC 1.1.2