?? projecttask.class
字號:
$project_task_id=$this->getID(); $perm =& $this->ProjectGroup->Group->getPermission( session_get_user() ); if (!$perm || !is_object($perm) || !$perm->isPMAdmin()) { $this->setPermissionDeniedError(); return false; } }*/ /** * getOtherTasks - Return a result set of tasks in this subproject that do not equal * the current task_id. * * @returns Database result set. */ function getOtherTasks () { // // May not yet have an ID, if we are creating a NEW task // if ($this->getID()) { $addstr=" AND project_task_id <> '". $this->getID() ."' "; } $sql="SELECT project_task_id,summary FROM project_task WHERE group_project_id='". $this->ProjectGroup->getID() ."' $addstr ORDER BY project_task_id DESC"; return db_query($sql); } /** * getHistory - returns a result set of audit trail for this ProjectTask. * * @return database result set. */ function getHistory() { $sql="SELECT * FROM project_history_user_vw WHERE project_task_id='". $this->getID() ."' ORDER BY mod_date DESC"; return db_query($sql); } /** * getMessages - get the list of messages attached to this ProjectTask. * * @return database result set. */ function getMessages() { $sql="select * FROM project_message_user_vw WHERE project_task_id='". $this->getID() ."' ORDER BY postdate DESC"; return db_query($sql); } /** * addMessage - Handle the addition of a followup message to this task. * * @param string The message. * @returns boolean success. */ function addMessage($message) { $sql="INSERT INTO project_messages (project_task_id,body,posted_by,postdate) VALUES ('". $this->getID() ."','". htmlspecialchars($message) ."','".user_getid()."','". time() ."')"; $res=db_query($sql); if (!$res || db_affected_rows($res) < 1) { $this->setError('AddMessage():: '.db_error()); return false; } else { return true; } } /** * addHistory - Handle the insertion of history for these parameters. * * @param string The field name. * @param string The old value. * @returns boolean success. */ function addHistory ($field_name,$old_value) { $sql="insert into project_history(project_task_id,field_name,old_value,mod_by,mod_date) VALUES ('". $this->getID() ."','$field_name','$old_value','".user_getid()."','".time()."')"; $result=db_query($sql); if (!$result) { $this->setError('ERROR IN AUDIT TRAIL - '.db_error()); return false; } else { return true; } } /** * checkCircular - recursive function calls itself to look at all tasks you are dependent on. * * @param int The project_task_id you are dependent on. * @param int The project_task_id you are checking circular dependencies for. * @returns boolean success. */ function checkCircular($depend_on_id, $original_id) { global $Language; if ($depend_on_id == $original_id) { $this->setError($Language->getText('pm_projecttask','circular_dependency')); return false; } $res=db_query("SELECT is_dependent_on_task_id AS id FROM project_dependencies WHERE project_task_id='$depend_on_id'"); $rows=db_numrows($res); for ($i=0; $i<$rows; $i++) { if (!$this->checkCircular(db_result($res,$i,'id'), $original_id)) { return false; } } return true; } /** * setDependentOn - takes an array of project_task_id's and builds dependencies. * * @param array The array of project_task_id's. * @returns boolean success. */ function setDependentOn(&$arr) {//// IMPORTANT - MUST VERIFY NO CIRCULAR DEPENDENCY!! // //get existing dependencies to diff against $arr2 =& $this->getDependentOn(); $this->dependon =& $arr2; if (count($arr) || count($arr2)) { $add_arr = array_diff ($arr, $arr2); $del_arr = array_diff ($arr2, $arr); for ($i=0; $i<count($del_arr); $i++) { db_query("DELETE FROM project_dependencies WHERE project_task_id='".$this->getID()."' AND is_dependent_on_task_id='". $del_arr[$i] ."'"); if (db_error()) { $this->setError('setDependentOn()-1:: '.db_error()); return false; } } for ($i=0; $i<count($add_arr); $i++) { // // Check task for circular dependencies // if (!$this->checkCircular($add_arr[$i],$this->getID())) { return false; } db_query("INSERT INTO project_dependencies (project_task_id,is_dependent_on_task_id) VALUES ('".$this->getID()."','". $add_arr[$i] ."')"); if (db_error()) { $this->setError('setDependentOn()-2:: '.db_error()); return false; } } return true; } else { return true; } } /** * getDependentOn - get an array of project_task_id's that you are dependent on. * * @return array The array of project_task_id's. */ function &getDependentOn() { if (!$this->getID()) { return array(); } if (!$this->dependon) { $this->dependon =& util_result_column_to_array(db_query("SELECT is_dependent_on_task_id FROM project_dependencies WHERE project_task_id='".$this->getID()."'")); } return $this->dependon; } /** * setAssignedTo - takes an array of user_id's and builds assignments. * * @param array The array of user_id's. * @returns boolean success. */ function setAssignedTo(&$arr) { $arr2 =& $this->getAssignedTo(); $this->assignedto =& $arr2; //If no one is assigned, then assign it to "100" - NOBODY if (count($arr) < 1 || ((count($arr)==1) && ($arr[0]==''))) { $arr=array('100'); } if (count($arr) || count($arr2)) { $add_arr = array_diff ($arr, $arr2); $del_arr = array_diff ($arr2, $arr); for ($i=0; $i<count($del_arr); $i++) { db_query("DELETE FROM project_assigned_to WHERE project_task_id='".$this->getID()."' AND assigned_to_id='". $del_arr[$i] ."'"); if (db_error()) { $this->setError('setAssignedTo()-1:: '.db_error()); return false; } } for ($i=0; $i<count($add_arr); $i++) { db_query("INSERT INTO project_assigned_to (project_task_id,assigned_to_id) VALUES ('".$this->getID()."','". $add_arr[$i] ."')"); if (db_error()) { $this->setError('setAssignedTo()-2:: '.db_error()); return false; } } return true; } else { return true; } } /** * getAssignedTo - get an array of user_id's that you are assigned to. * * @return array The array of user_id's. */ function &getAssignedTo() { if (!$this->getID()) { return array(); } if (!$this->assignedto) { $this->assignedto =& util_result_column_to_array(db_query("SELECT assigned_to_id FROM project_assigned_to WHERE project_task_id='".$this->getID()."'")); } return $this->assignedto; } /** * update - update this 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 status_id 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 update($summary,$details,$priority,$hours,$start_date,$end_date, $status_id,$category_id,$percent_complete,&$assigned_arr,&$depend_arr) { $v = new Validator(); $v->check($summary, "summary"); $v->check($priority, "priority"); $v->check($hours, "hours"); $v->check($start_date, "start date"); $v->check($end_date, "end date"); $v->check($status_id, "status"); $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(); if ($details) { if (!$this->addMessage($details)) { db_rollback(); return false; } } if ($this->getStatusID() != $status_id) { $this->addHistory ('status_id',$this->getStatusID()); } if ($this->getCategoryID() != $category_id) { $this->addHistory ('category_id',$this->getCategoryID()); } if ($this->getPriority() != $priority) { $this->addHistory ('priority',$this->getPriority()); } if ($this->getSummary() != htmlspecialchars(stripslashes($summary))) { $this->addHistory ('summary',addslashes($this->getSummary())); } if ($this->getPercentComplete() != $percent_complete) { $this->addHistory ('percent_complete',$this->getPercentComplete()); } if ($this->getHours() != $hours) { $this->addHistory ('hours',$this->getHours()); } if ($this->getStartDate() != $start_date) { $this->addHistory ('start_date',$this->getStartDate()); } if ($this->getEndDate() != $end_date) { $this->addHistory ('end_date',$this->getEndDate()); } if (!$this->setDependentOn($depend_arr)) { db_rollback(); return false; } elseif (!$this->setAssignedTo($assigned_arr)) { db_rollback(); return false; } else { $sql="UPDATE project_task SET summary='".htmlspecialchars($summary)."', priority='$priority', hours='$hours', start_date='$start_date', end_date='$end_date', status_id='$status_id', percent_complete='$percent_complete', category_id='$category_id' WHERE group_project_id='".$this->ProjectGroup->getID()."' AND project_task_id='".$this->getID()."'"; $res=db_query($sql); if (!$res || db_affected_rows($res) < 1) { $this->setError('Error On Update: '.db_error()); db_rollback(); return false; } else { if (!$this->fetchData($this->getID())) { return false; } else { $this->sendNotice(); db_commit(); return true; } } } } /** * sendNotice - contains the logic for sending email/jabber updates. * * @return boolean success. */ function sendNotice($first=false) { $ids =& $this->getAssignedTo(); // // See if there is anyone to send messages to // if (count($ids) < 1 && !$this->ProjectGroup->getSendAllPostsTo()) { return true; } $body = "Task #". $this->getID() ." has been updated. ". "\n\nProject: ". $this->ProjectGroup->Group->getPublicName() . "\nSubproject: ". $this->ProjectGroup->getName() . "\nSummary: ".util_unconvert_htmlspecialchars( $this->getSummary() ). "\nComplete: ". $this->getPercentComplete() ."%". "\nStatus: ". $this->getStatusName() . "\n\nDescription: ". util_unconvert_htmlspecialchars( $this->getDetails() ); /* Now get the followups to this task */ $result2=$this->getMessages(); $rows=db_numrows($result2); if ($result2 && $rows > 0) { $body .= "\n\nFollow-Ups:"; for ($i=0; $i<$rows;$i++) { $body .= "\n\n-------------------------------------------------------"; $body .= "\nDate: ". date($GLOBALS['sys_datefmt'],db_result($result2,$i,'postdate')); $body .= "\nBy: ".db_result($result2,$i,'user_name'); $body .= "\n\nComment:\n".util_unconvert_htmlspecialchars(db_result($result2,$i,'body')); } } $body .= "\n\n-------------------------------------------------------". "\nFor more info, visit:". "\n\nhttp://$GLOBALS[sys_default_domain]/pm/task.php?func=detailtask&project_task_id=". $this->getID() ."&group_id=". $this->ProjectGroup->Group->getID() ."&group_project_id=". $this->ProjectGroup->getID(); $subject="[Task #". $this->getID() .'] '. util_unconvert_htmlspecialchars( $this->getSummary() ); util_handle_message(array_unique($ids),$subject,$body,$this->ProjectGroup->getSendAllPostsTo()); return true; }}?>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -