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 'HudsonBuild.class.php';
26 class hudson_Widget_JobLastArtifacts extends HudsonJobWidget {
31 function hudson_Widget_JobLastArtifacts($owner_type, $owner_id) {
32 $request =& HTTPRequest::instance();
33 if ($owner_type == WidgetLayoutManager::OWNER_TYPE_USER) {
34 $this->widget_id = 'plugin_hudson_my_joblastartifacts';
35 $this->group_id = $owner_id;
37 $this->widget_id = 'plugin_hudson_project_joblastartifacts';
38 $this->group_id = $request->get('group_id');
40 $this->Widget($this->widget_id);
41 $this->setOwner($owner_id, $owner_type);
47 $title .= sprintf(_('%s Last Artifacts'), $this->job->getName());
49 $title .= _('Last Artifacts');
54 function getDescription() {
55 return _("Show the last successfully published artifacts of one job. To display something, your job needs to publish artifacts.");
58 function loadContent($id) {
59 $sql = "SELECT * FROM plugin_hudson_widget WHERE widget_name=$1 AND owner_id=$2 AND owner_type=$3 AND id=$4";
60 $res = db_query_params($sql,array($this->widget_id,$this->owner_id,$this->owner_type,$id));
61 if ($res && db_numrows($res)) {
62 $data = db_fetch_array($res);
63 $this->job_id = $data['job_id'];
64 $this->content_id = $id;
65 $jobs = $this->getAvailableJobs();
66 if (array_key_exists($this->job_id, $jobs)) {
67 $used_job = $jobs[$this->job_id];
68 $this->job_url = $used_job->getUrl();
69 $this->job = $used_job;
70 $this->last_build_url = $this->job_url.'/lastBuild/';
72 $this->build = new HudsonBuild($this->last_build_url);
73 } catch (Exception $e) {
83 function getContent() {
85 if ($this->job != null && $this->build != null) {
86 $build = $this->build;
88 $dom = $build->getDom();
89 foreach ($dom->artifact as $artifact) {
90 $html .= ' <li><a href="'.$build->getUrl().'/artifact/'.$artifact->relativePath.'">'.$artifact->displayPath.'</a></li>';
94 if ($this->job != null) {
95 $html .= _("No build found for this job.");
97 $html .= _("Job not found.");