3 * Copyright (C) 2015 Vitaliy Pylypiv <vitaliy.pylypiv@gmail.com>
5 * This file is 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
9 * by the Free Software Foundation; either version 2 of the License,
10 * or (at your option) any later version.
12 * FusionForge is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 require_once $gfcommon.'include/FFError.class.php';
23 require_once $gfplugins.'taskboard/common/TaskBoard.class.php';
25 class TaskBoardRelease extends FFError {
27 * The Taskboard object.
29 * @var object $Taskboard.
31 var $Taskboard; //taskboard object
35 * Array of release data.
37 * @var array $data_array.
42 * release title (name of related extra field element)
46 private $_title = NULL;
52 function TaskBoardRelease($Taskboard, $arr = false) {
54 if (!$Taskboard || !is_object($Taskboard)) {
55 $this->setError('No Valid Taskboard Object');
58 if ($Taskboard->isError()) {
59 $this->setError('TaskBoardRelease: '.$Taskboard->getErrorMessage());
63 $this->Taskboard = $Taskboard;
64 if (!$arr || !is_array($arr)) {
65 if (!$this->fetchData($arr)) {
69 $this->data_array =& $arr;
70 if ($this->data_array['taskboard_id'] != $this->Taskboard->getID()) {
71 $this->setError('taskboard_id in db result does not match TaskBoard Object');
72 $this->data_array = null;
79 * create - create taskboard release
83 function create($element_id, $start_date, $end_date, $goals, $page_url) {
84 $res = db_query_params (
85 'INSERT INTO plugin_taskboard_releases(taskboard_id, element_id, start_date, end_date, goals, page_url)
86 VALUES($1, $2, $3, $4, $5, $6)',
88 $this->Taskboard->getID(),
105 * update - update taskboard release
109 function update($element_id, $start_date, $end_date, $goals, $page_url) {
110 $res = db_query_params(
111 'UPDATE plugin_taskboard_releases SET element_id=$1, start_date=$2, end_date=$3, goals=$4, page_url=$5 WHERE taskboard_release_id=$6',
124 db_free_result($res);
130 $res = db_query_params(
131 'DELETE FROM plugin_taskboard_releases_snapshots WHERE taskboard_release_id=$1',
132 array($this->getID())
139 $res = db_query_params(
140 'DELETE FROM plugin_taskboard_releases WHERE taskboard_release_id=$1',
141 array($this->getID())
151 * fetchData - re-fetch the data for this TaskBoardColumn from the database.
153 * @param int The taskboard column ID.
154 * @return boolean success.
156 function fetchData($id) {
157 $res = db_query_params('SELECT * FROM plugin_taskboard_releases WHERE taskboard_release_id=$1', array ($id));
158 if (!$res || db_numrows($res) < 1) {
159 $this->setError('TaskBoard: Invalid TaskBoardReleaseID');
162 $this->data_array = db_fetch_array($res);
163 db_free_result($res);
168 * getID - get this TaskBoardReleaseID.
170 * @return int The taskboard_release_id
173 return $this->data_array['taskboard_release_id'];
177 * getTaskboardID - get related TaskBoard ID.
179 * @return int The taskboard_id
181 function getTaskBoardID() {
182 return $this->data_array['taskboard_id'];
186 * getElementID - get related element ID.
188 * @return int The element_id
190 function getElementID() {
191 return $this->data_array['element_id'];
195 * getTitle - get release title
199 function getTitle() {
200 if( !$this->_title ) {
201 // retrieve element name
202 $releases = $this->Taskboard->getReleaseValues();
203 foreach($releases as $release_name => $release_id) {
204 if($release_id == $this->getElementID()) {
205 $this->_title = $release_name;
210 return $this->_title;
214 * getStartDate - get release start date as unixtime
218 function getStartDate() {
219 return $this->data_array['start_date'];
223 * getEndDate - get release end date as unixtime
227 function getEndDate() {
228 return $this->data_array['end_date'];
232 * getGoals - get release goals
236 function getGoals() {
237 return $this->data_array['goals'];
241 * getPageUrl - get release page URL
245 function getPageUrl() {
246 return $this->data_array['page_url'];
250 * Save current taskboard snapshot. So, we can have a history of release implementation,
251 * that could be used for different indicators calculation.
253 * @param int Snapshot unix date time
254 * @return boolean success.
256 function saveSnapshot($snapshot_datetime) {