?? projecttask.class
字號:
<?php/** * GForge Project Management Facility * * Copyright 2002 GForge, LLC * http://gforge.org/ * * @version $Id: ProjectTask.class,v 1.15 2003/02/12 17:23:47 bigdisk Exp $ * * This file is part of GForge. * * GForge is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * GForge is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GForge; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US *//* Project/Task Manager By Tim Perdue, Sourceforge, 11/99 Heavy rewrite by Tim Perdue April 2000 Total rewrite in OO and GForge coding guidelines 12/2002 by Tim Perdue*/require_once('common/include/Error.class');require_once('common/pm/Validator.class');class ProjectTask extends Error { /** * Associative array of data from db. * * @var array $data_array. */ var $data_array; /** * The ProjectGroup object. * * @var object $ProjectGroup. */ var $ProjectGroup; var $dependon; var $assignedto; var $relatedartifacts; /** * Constructor. * * @param object The ProjectGroup object to which this ProjectTask is associated. * @param int The project_task_id. * @param array The associative array of data. * @return boolean success. */ function ProjectTask(&$ProjectGroup, $project_task_id=false, $arr=false) { $this->Error(); if (!$ProjectGroup || !is_object($ProjectGroup)) { $this->setError('ProjectTask:: No Valid ProjectGroup Object'); return false; } if ($ProjectGroup->isError()) { $this->setError('ProjectTask:: '.$ProjectGroup->getErrorMessage()); return false; } $this->ProjectGroup =& $ProjectGroup; if ($project_task_id) { if (!$arr || !is_array($arr)) { if (!$this->fetchData($project_task_id)) { return false; } } else { $this->data_array =& $arr; // // Verify this message truly belongs to this ProjectGroup // if ($this->data_array['group_project_id'] != $this->ProjectGroup->getID()) { $this->setError('Group_project_id in db result does not match ProjectGroup Object'); return false; } } } return true; } /** * create - create a new ProjectTask in the database. * * @param string The summary of this task. * @param string The detailed description of this task. * @param int The Priority of this task. * @param int The Hours estimated to complete this task. * @param int The (unix) start date of this task. * @param int The (unix) end date of this task. * @param int The category_id of this task. * @param int The percentage of completion in integer format of this task. * @param array An array of user_id's that are assigned this task. * @param array An array of project_task_id's that this task depends on. * @return boolean success. */ function create($summary,$details,$priority,$hours,$start_date,$end_date, $category_id,$percent_complete,&$assigned_arr,&$depend_arr) { $v = new Validator(); $v->check($summary, "summary"); $v->check($details, "details"); $v->check($priority, "priority"); $v->check($hours, "hours"); $v->check($start_date, "start date"); $v->check($end_date, "end date"); $v->check($category_id, "category"); if (!$v->isClean()) { $this->setError($v->formErrorMsg("Must include ")); return false; } $perm =& $this->ProjectGroup->Group->getPermission( session_get_user() ); if (!$perm || !is_object($perm) || !$perm->isPMAdmin()) { $this->setPermissionDeniedError(); return false; } db_begin(); $res=db_query("SELECT nextval('project_task_pk_seq') AS id"); if (!$project_task_id=db_result($res,0,'id')) { $this->setError('Could Not Get Next ID'); db_rollback(); return false; } else { $this->data_array['project_task_id']=$project_task_id; if (!$this->setDependentOn($depend_arr)) { db_rollback(); return false; } elseif (!$this->setAssignedTo($assigned_arr)) { db_rollback(); return false; } else { $sql="INSERT INTO project_task (project_task_id,group_project_id,created_by,summary, details,start_date,end_date,status_id,category_id,priority,percent_complete,hours) VALUES ('$project_task_id','". $this->ProjectGroup->getID() ."', '".user_getid()."', '". htmlspecialchars($summary) ."', '". htmlspecialchars($details) ."','$start_date','$end_date','1','$category_id','$priority','$percent_complete','$hours')"; $result=db_query($sql); if (!$result || db_affected_rows($result) < 1) { $this->setError('ProjectTask::create() Posting Failed '.db_error()); db_rollback(); return false; } else { if (!$this->fetchData($project_task_id)) { db_rollback(); return false; } else { $this->sendNotice(1); db_commit(); return true; } } } } } /** * fetchData - re-fetch the data for this ProjectTask from the database. * * @param int The project_task_id. * @return boolean success. */ function fetchData($project_task_id) { $res=db_query("SELECT * FROM project_task_vw WHERE project_task_id='$project_task_id' AND group_project_id='". $this->ProjectGroup->getID() ."'"); if (!$res || db_numrows($res) < 1) { $this->setError('ProjectTask::fetchData() Invalid MessageID'.db_error()); return false; } $this->data_array =& db_fetch_array($res); db_free_result($res); return true; } /** * getProjectGroup - get the ProjectGroup object this ProjectTask is associated with. * * @return Object The ProjectGroup object. */ function &getProjectGroup() { return $this->ProjectGroup; } /** * getID - get this project_task_id. * * @return int The project_task_id. */ function getID() { return $this->data_array['project_task_id']; } /** * getSubmittedRealName - get the real name of the person who created this task. * * @return string The real name person who created this task. */ function getSubmittedRealName() { return $this->data_array['realname']; } /** * getSubmittedUnixName - get the unix name of the person who created this task. * * @return string The unix name of the person who created this task. */ function getSubmittedUnixName() { return $this->data_array['user_name']; } /** * getSummary - get the subject/summary of this task. * * @return string The summary. */ function getSummary() { return $this->data_array['summary']; } /** * getDetails - get the body/details of this task. * * @return string The body/details. */ function getDetails() { return $this->data_array['details']; } /** * getPercentComplete - an integer between 0 and 100. * * @return int The percentage of completion of this task. */ function getPercentComplete() { return $this->data_array['percent_complete']; } /** * getPriority - the priority, between 1 and 9 of this task. * * @return int The priority. */ function getPriority() { return $this->data_array['priority']; } /** * getHours - the hours this task is expected to take. * * @return int The hours. */ function getHours() { return $this->data_array['hours']; } /** * getStartDate - the unix time that this task will start. * * @return int The unix start time of this task. */ function getStartDate() { return $this->data_array['start_date']; } /** * getEndDate - the unix time that this task will end. * * @return int The unix end time of this task. */ function getEndDate() { return $this->data_array['end_date']; } /** * getStatusID - the integer of the status of this task. * * @return int the status_id. */ function getStatusID() { return $this->data_array['status_id']; } /** * getStatusName - the string of the status of this task. * * @return string the status_name. */ function getStatusName() { return $this->data_array['status_name']; } /** * getCategoryID - the category_id of this task. * * @return int the category_id. */ function getCategoryID() { return $this->data_array['category_id']; } /** * getCategoryName - the category_name of this task. * * @return int the category_name. */ function getCategoryName() { return $this->data_array['category_name']; } /** * getRelatedArtifacts - Return a result set of artifacts which are related to this task. * * @returns Database result set. */ function getRelatedArtifacts() { if (!$this->relatedartifacts) { $this->relatedartifacts= db_query("SELECT agl.group_id,agl.name,agl.group_artifact_id,a.artifact_id,a.open_date,a.summary FROM artifact_group_list agl, artifact a WHERE a.group_artifact_id=agl.group_artifact_id AND EXISTS (SELECT artifact_id FROM project_task_artifact WHERE artifact_id=a.artifact_id AND project_task_id='". $this->getID() ."')"); } return $this->relatedartifacts; } /** * addRelatedArtifacts - take an array of artifact_id's and build relationships. * * @param array An array of artifact_id's to be attached to this task. * @return boolean success. */ function addRelatedArtifacts($art_array) { $perm =& $this->ProjectGroup->Group->getPermission( session_get_user() ); if (!$perm || !is_object($perm) || !$perm->isPMAdmin()) { $this->setPermissionDeniedError(); return false; }//// SHOULD REALLY INSTANTIATE THIS ARTIFACT OBJECT TO ENSURE PROPER SECURITY - FUTURE//// new ArtifactFromID($id)// for ($i=0; $i<count($art_array); $i++) { if ($art_array[$i] < 1) { continue; } $res=db_query("INSERT INTO project_task_artifact (project_task_id,artifact_id) VALUES ('".$this->getID()."','".$art_array[$i]."')"); if (!$res) { $this->setError('Error inserting artifact relationship: '.db_error()); return false; } } return true; } /** * removeRelatedArtifacts - take an array of artifact_id's and delete relationships. * * @param array An array of artifact_id's to be removed from this task. * @return boolean success. */ function removeRelatedArtifacts($art_array) { $perm =& $this->ProjectGroup->Group->getPermission( session_get_user() ); if (!$perm || !is_object($perm) || !$perm->isPMAdmin()) { $this->setPermissionDeniedError(); return false; } for ($i=0; $i<count($art_array); $i++) { $res=db_query("DELETE FROM project_task_artifact WHERE project_task_id='".$this->getID()."' AND artifact_id='".$art_array[$i]."'"); if (!$res) { $this->setError('Error deleting artifact relationship: '.db_error()); return false; } } return true; }/* function delete() {
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -