File: HudsonJobWidget.class.php

package info (click to toggle)
fusionforge 5.3.2%2B20141104-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 60,472 kB
  • sloc: php: 271,846; sql: 36,817; python: 14,575; perl: 6,406; sh: 5,980; xml: 4,294; pascal: 1,411; makefile: 911; cpp: 52; awk: 27
file content (126 lines) | stat: -rw-r--r-- 4,014 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
/**
 * Copyright (c) Xerox Corporation, Codendi Team, 2001-2009. All rights reserved
 *
 * This file is a part of Fusionforge.
 *
 * Fusionforge is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * Fusionforge is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Fusionforge. If not, see <http://www.gnu.org/licenses/>.
 */

require_once 'HudsonWidget.class.php';
require_once 'common/widget/Widget.class.php';
require_once 'PluginHudsonJobDao.class.php';

abstract class HudsonJobWidget extends HudsonWidget {

	var $widget_id;
	var $group_id;
	var $job;
	var $job_url;
	var $job_id;

	function isUnique() {
		return false;
	}

	function create(&$request) {
		$content_id = false;
		$vId = new Valid_Uint('job_id');
		$vId->setErrorMessage(_("Cannot add empty job id"));
		$vId->required();
		if ($request->valid($vId)) {
			$job_id = $request->get('job_id');
			$sql = 'INSERT INTO plugin_hudson_widget (widget_name, owner_id, owner_type, job_id) VALUES ($1,$2,$3,$4)';
			$res = db_query_params($sql,array($this->id,$this->owner_id,$this->owner_type,$job_id));
			$content_id = db_insertid($res,'plugin_hudson_widget','id');
		}
		return $content_id;
	}

	function destroy($id) {
		$sql = 'DELETE FROM plugin_hudson_widget WHERE id = $1 AND owner_id = $2 AND owner_type = $3';
		db_query_params($sql,array($id,$this->owner_id,$this->owner_type));
	}

	function getInstallPreferences() {
		$prefs  = '';
		$prefs .= '<strong>'._("Monitored job:").'</strong><br />';
		$jobs = $this->getAvailableJobs();
		$selected_jobs_id = $this->getSelectedJobsId();

		foreach ($jobs as $job_id => $job) {
			if (in_array($job_id, $selected_jobs_id)) {
				$options = ' disabled="disabled"';
				$comment = ' <em>('._('Already used') .')</em>';
			} else {
				$options = '';
				$comment = '';
			}
			$prefs .= '<input type="radio" name="job_id" value="'.$job_id.'"'.$options.'/> '.$job->getName().$comment;
			$prefs .= '<br />';
		}
		return $prefs;
	}

	function hasPreferences() {
		return true;
	}

	function getPreferences() {
		$prefs  = '';
		$prefs .= '<strong>'._("Monitored job:").'</strong><br />';
		$jobs = $this->getAvailableJobs();
		$selected_jobs_id = $this->getSelectedJobsId();

		foreach ($jobs as $job_id => $job) {
			if (in_array($job_id, $selected_jobs_id)) {
				$options = ' disabled="disabled"';
				$comment = ' <em>('._('Already used') .')</em>';
			} else {
				$options = '';
				$comment = '';
			}
			if ($job_id == $this->job_id) {
				$options = ' checked="checked"';
				$comment = ' <em>('._('Current used') .')</em>';
			}
			$prefs .= '<input type="radio" name="' . $this->id . '" value="'.$job_id.'"' . $options . '> '.$job->getName().$comment.'<br />';
		}
		return $prefs;
	}

	function updatePreferences(&$request) {
		$request->valid(new Valid_String('cancel'));
		if (!$request->exist('cancel')) {
			$job_id = $request->get($this->id);
			$sql = "UPDATE plugin_hudson_widget SET job_id=$1 WHERE owner_id = $2 AND owner_type = $3 AND id = $4";
			$res = db_query_params($sql,array($job_id,$this->owner_id,$this->owner_type,(int)$request->get('content_id')));
		}
		return true;
	}

	/**
	 * Returns the jobs selected for this widget
	 */
	function getSelectedJobsId() {
		$sql = "SELECT job_id FROM plugin_hudson_widget WHERE widget_name=$1 AND owner_id=$2 AND owner_type=$3";
		$res = db_query_params($sql,array($this->widget_id,$this->owner_id,$this->owner_type));

		$selected_jobs_id = array();
		while ($data = db_fetch_array($res)) {
			$selected_jobs_id[] = $data['job_id'];
		}
		return $selected_jobs_id;
	}
}