3 * Copyright (c) Xerox Corporation, Codendi Team, 2001-2009. All rights reserved
4 * Copyright 2014, 2015 Franck Villaume - TrivialDev
6 * This file is a part of Fusionforge.
8 * Fusionforge is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * Fusionforge is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with Fusionforge. If not, see <http://www.gnu.org/licenses/>.
22 require_once 'HudsonJobWidget.class.php';
23 require_once 'common/include/HTTPRequest.class.php';
24 require_once 'PluginHudsonJobDao.class.php';
25 require_once 'HudsonJob.class.php';
27 class hudson_Widget_JobLastBuilds extends HudsonJobWidget {
31 function __construct($owner_type, $owner_id) {
32 $request =& HTTPRequest::instance();
33 if ($owner_type == WidgetLayoutManager::OWNER_TYPE_USER) {
34 $this->widget_id = 'plugin_hudson_my_joblastbuilds';
35 $this->group_id = $owner_id;
37 $this->widget_id = 'plugin_hudson_project_joblastbuilds';
38 $this->group_id = $request->get('group_id');
40 parent::__construct($this->widget_id);
41 $this->setOwner($owner_id, $owner_type);
42 if ($this->widget_id == 'plugin_hudson_project_joblastbuilds' && forge_check_perm('hudson', $this->group_id, 'read')) {
43 $this->content['title'] = '';
45 $this->content['title'] .= sprintf(_('%s Last Builds'), $this->job->getName());
47 $this->content['title'] .= _('Last Builds');
50 $this->content['title'] = '';
52 $this->content['title'] .= sprintf(_('%s Last Builds'), $this->job->getName());
54 $this->content['title'] .= _('Last Builds');
60 return $this->content['title'];
63 function getDescription() {
64 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.");
67 function loadContent($id) {
68 $sql = "SELECT * FROM plugin_hudson_widget WHERE widget_name=$1 AND owner_id=$2 AND owner_type=$3 AND id=$4";
69 $res = db_query_params($sql,array($this->widget_id,$this->owner_id,$this->owner_type,$id));
70 if ($res && db_numrows($res)) {
71 $data = db_fetch_array($res);
72 $this->job_id = $data['job_id'];
73 $this->content_id = $id;
74 $jobs = $this->getAvailableJobs();
75 if (array_key_exists($this->job_id, $jobs)) {
76 $used_job = $jobs[$this->job_id];
77 $this->job_url = $used_job->getUrl();
78 $this->job = $used_job;
85 function getContent() {
88 if ($this->job != null) {
90 $html .= $HTML->listTableTop();
94 if ($job->hasBuilds()) {
95 $html .= ' <li>'._("Last Build")._(": ").util_make_link('/plugins/hudson/?action=view_build&group_id='.$this->group_id.'&job_id='.$this->job_id.'&build_id='.$job->getLastBuildNumber(), '# '.$job->getLastBuildNumber()).'</li>';
96 $html .= ' <li>'._("Last Success")._(": ").util_make_link('/plugins/hudson/?action=view_build&group_id='.$this->group_id.'&job_id='.$this->job_id.'&build_id='.$job->getLastSuccessfulBuildNumber(), '# '.$job->getLastSuccessfulBuildNumber()).'</li>';
97 $html .= ' <li>'._("Last Failure")._(": ").util_make_link('/plugins/hudson/?action=view_build&group_id='.$this->group_id.'&job_id='.$this->job_id.'&build_id='.$job->getLastFailedBuildNumber(), '# '.$job->getLastFailedBuildNumber()).'</li>';
99 $html .= ' <li>'. $HTML->information(_('No build found for this job.')) . '</li>';
103 $html .= ' <td class="widget_lastbuilds_weather">';
104 $html .= _('Weather Report')._(':').'<img src="'.$job->getWeatherReportIcon().'" class="widget_lastbuilds_weather_img" />';
107 $html .= $HTML->listTableBottom();
109 $html .= $HTML->information(_('Job not found.'));
114 function isAvailable() {
115 return isset($this->content['title']);