3 * Copyright (c) Xerox Corporation, Codendi Team, 2001-2009. All rights reserved
5 * This file is a part of Fusionforge.
7 * Fusionforge is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * Fusionforge 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 General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Fusionforge. If not, see <http://www.gnu.org/licenses/>.
21 require_once 'HudsonJobWidget.class.php';
22 require_once 'common/include/HTTPRequest.class.php';
23 require_once 'PluginHudsonJobDao.class.php';
24 require_once 'HudsonJob.class.php';
26 class hudson_Widget_JobLastBuilds extends HudsonJobWidget {
28 function hudson_Widget_JobLastBuilds($owner_type, $owner_id) {
29 $request =& HTTPRequest::instance();
30 if ($owner_type == WidgetLayoutManager::OWNER_TYPE_USER) {
31 $this->widget_id = 'plugin_hudson_my_joblastbuilds';
32 $this->group_id = $owner_id;
34 $this->widget_id = 'plugin_hudson_project_joblastbuilds';
35 $this->group_id = $request->get('group_id');
37 $this->Widget($this->widget_id);
38 $this->setOwner($owner_id, $owner_type);
44 $title .= sprintf(_('%s Last Builds'), $this->job->getName());
46 $title .= _('Last Builds');
51 function getDescription() {
52 return _("Show the last builds for this job (last one, last successfull, last failed) and the weather report. The trend is represented by a weather report (sun, thunder, etc.) meaning that the trend is good or not.");
55 function loadContent($id) {
56 $sql = "SELECT * FROM plugin_hudson_widget WHERE widget_name=$1 AND owner_id=$2 AND owner_type=$3 AND id=$4";
57 $res = db_query_params($sql,array($this->widget_id,$this->owner_id,$this->owner_type,$id));
58 if ($res && db_numrows($res)) {
59 $data = db_fetch_array($res);
60 $this->job_id = $data['job_id'];
61 $this->content_id = $id;
62 $jobs = $this->getAvailableJobs();
63 if (array_key_exists($this->job_id, $jobs)) {
64 $used_job = $jobs[$this->job_id];
65 $this->job_url = $used_job->getUrl();
66 $this->job = $used_job;
73 function getContent() {
75 if ($this->job != null) {
77 $html .= '<table class="fullwidth">';
81 if ($job->hasBuilds()) {
82 $html .= ' <li>'._("Last Build:").' <a href="/plugins/hudson/?action=view_build&group_id='.$this->group_id.'&job_id='.$this->job_id.'&build_id='.$job->getLastBuildNumber().'"># '.$job->getLastBuildNumber().'</a></li>';
83 $html .= ' <li>'._("Last Success")._(": ").'<a href="/plugins/hudson/?action=view_build&group_id='.$this->group_id.'&job_id='.$this->job_id.'&build_id='.$job->getLastSuccessfulBuildNumber().'"># '.$job->getLastSuccessfulBuildNumber().'</a></li>';
84 $html .= ' <li>'._("Last Failure")._(": ").'<a href="/plugins/hudson/?action=view_build&group_id='.$this->group_id.'&job_id='.$this->job_id.'&build_id='.$job->getLastFailedBuildNumber().'"># '.$job->getLastFailedBuildNumber().'</a></li>';
86 $html .= ' <li>'. _("No build found for this job.") . '</li>';
90 $html .= ' <td class="widget_lastbuilds_weather">';
91 $html .= _("Weather Report:").'<img src="'.$job->getWeatherReportIcon().'" class="widget_lastbuilds_weather_img" />';
96 $html .= _("Job not found.");