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 $dao = CodendiDataAccess::instance();
42 $job_dao = new PluginHudsonJobDao($dao);
43 $dar = $job_dao->searchByGroupID($group_id);
45 while ($dar->valid()) {
46 $row = $dar->current();
48 $job = new Hudsonjob($row['job_url']);
49 $jobs[$row['job_id']] = $job;
50 } catch (exception $e) {
51 // Do not add unvalid jobs
58 protected function getJobsByUser($user_id) {
59 $job_dao = new PluginHudsonJobDao(CodendiDataAccess::instance());
60 $dar = $job_dao->searchByUserID($user_id);
62 while ($dar->valid()) {
63 $row = $dar->current();
65 $job = new Hudsonjob($row['job_url']);
66 $jobs[$row['job_id']] = $job;
67 } catch (exception $e) {
68 // Do not add unvalid jobs