3 * Copyright (c) Xerox Corporation, Codendi Team, 2001-2009. All rights reserved
5 * This file is a part of Codendi.
7 * Codendi 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 * Codendi 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 Codendi. If not, see <http://www.gnu.org/licenses/>.
20 require_once('common/widget/Widget.class.php');
21 require_once('PluginHudsonJobDao.class.php');
22 require_once('common/widget/WidgetLayoutManager.class.php');
24 abstract class HudsonWidget extends Widget {
26 function getCategory() {
30 protected function getAvailableJobs() {
32 if ($this->owner_type == WidgetLayoutManager::OWNER_TYPE_USER) {
33 $jobs = $this->getJobsByUser($user = UserManager::instance()->getCurrentUser()->getId());
35 $jobs = $this->getJobsByGroup($this->group_id);
40 protected function getJobsByGroup($group_id) {
41 $job_dao = new PluginHudsonJobDao(CodendiDataAccess::instance());
42 $dar = $job_dao->searchByGroupID($group_id);
44 while ($dar->valid()) {
45 $row = $dar->current();
47 $job = new Hudsonjob($row['job_url']);
48 $jobs[$row['job_id']] = $job;
49 } catch (exception $e) {
50 // Do not add unvalid jobs
57 protected function getJobsByUser($user_id) {
58 $job_dao = new PluginHudsonJobDao(CodendiDataAccess::instance());
59 $dar = $job_dao->searchByUserID($user_id);
61 while ($dar->valid()) {
62 $row = $dar->current();
64 $job = new Hudsonjob($row['job_url']);
65 $jobs[$row['job_id']] = $job;
66 } catch (exception $e) {
67 // Do not add unvalid jobs