本文整理汇总了PHP中CTask::updateDependencies方法的典型用法代码示例。如果您正苦于以下问题:PHP CTask::updateDependencies方法的具体用法?PHP CTask::updateDependencies怎么用?PHP CTask::updateDependencies使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CTask
的用法示例。
在下文中一共展示了CTask::updateDependencies方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: importTasks
//.........这里部分代码省略.........
$q = new DBQuery();
$q->addTable('tasks');
$q->addQuery('task_id');
$q->addWhere('task_project =' . $from_project_id);
$sql = $q->prepare();
$q->clear();
$tasks = array_flip(db_loadColumn($sql));
//Pristine Start and End Dates of Source and Destination Projects
$origStartDate = new CDate($origProject->project_start_date);
$origEndDate = new CDate($origProject->project_end_date);
$destStartDate = new CDate($this->project_start_date);
$destEndDate = new CDate($this->project_end_date);
$dateOffset = $destStartDate->dateDiff($origStartDate);
//Check that we have enough information to scale properly
//(i.e. no information is missing or "zero")
if (empty($origProject->project_start_date) || empty($origProject->project_end_date) || empty($this->project_start_date) || empty($this->project_end_date) || $origProject->project_start_date == '0000-00-00 00:00:00' || $origProject->project_end_date == '0000-00-00 00:00:00' || $this->project_start_date == '0000-00-00 00:00:00' || $this->project_end_date == '0000-00-00 00:00:00') {
$scale_project = false;
}
if ($scale_project) {
//get ratio for scaling, protect from division by 0
$ratio = (abs($destEndDate->dateDiff($destStartDate)) + 1) / (abs($origEndDate->dateDiff($origStartDate)) + 1);
}
// Old dependencies array from imported tasks
$deps = array();
// New dependencies array for new copies of imported tasks
$newDeps = array();
// Old2New task ID array
$taskXref = array();
// New task ID to old parent array
$nid2op = array();
// Copy each task into this project and get their deps
foreach ($tasks as $orig => $void) {
$objTask = new CTask();
$objTask->load($orig);
// Grab the old parent id
$oldParent = (int) $objTask->task_parent;
$deps[$orig] = $objTask->getDependencies();
$destTask = $objTask->copy($this->project_id, 0);
$nid2op[$destTask->task_id] = $oldParent;
$tasks[$orig] = $destTask;
$taskXref[$orig] = (int) $destTask->task_id;
}
// Build new dependencies array
foreach ($deps as $odkey => $od) {
$ndt = '';
$ndkey = $taskXref[$odkey];
$odep = explode(',', $od);
foreach ($odep as $odt) {
$ndt = $ndt . $taskXref[$odt] . ',';
}
$ndt = rtrim($ndt, ',');
$newDeps[$ndkey] = $ndt;
}
$q->addTable('tasks');
$q->addQuery('task_id');
$q->addWhere('task_project =' . $this->project_id);
$tasks = $q->loadColumn();
// Update dates based on new project's start date.
$origDate = new CDate($origProject->project_start_date);
$origStartHour = new CDate($this->project_start_date);
$destDate = new CDate($this->project_start_date);
foreach ($tasks as $task_id) {
$newTask = new CTask();
$newTask->load($task_id);
if (in_array($task_id, $taskXref)) {
$task_date_vars = array('task_start_date', 'task_end_date');
//Adjust task dates based on calculated offsets
foreach ($task_date_vars as $my_date) {
if (!empty($newTask->{$my_date}) && $newTask->{$my_date} != '0000-00-00 00:00:00') {
$origDate->setDate($newTask->{$my_date});
$origStartHour->setDate($newTask->{$my_date});
$origStartHour->setTime(intval(dPgetConfig('cal_day_start')));
$destDate->setDate($newTask->{$my_date});
$destDate->addDays($dateOffset);
if ($scale_project) {
$offsetAdd = round($origDate->dateDiff($origStartDate) * $ratio) - $origDate->dateDiff($origStartDate);
$destDate->addDays($offsetAdd);
$hours_in = $origStartHour->calcDuration($origDate);
$offsetAddHours = round($hours_in * $ratio) - $hours_in;
if ($offsetAddHours % dPgetConfig('daily_working_hours')) {
$destDate->addDuration($offsetAddHours);
}
}
$destDate = $destDate->next_working_day();
$newTask->{$my_date} = $destDate->format(FMT_DATETIME_MYSQL);
}
}
//Adjust durration to scale
if ($scale_project) {
$newTask->task_duration = round($newTask->task_duration * $ratio, 2);
}
$newTask->task_parent = $taskXref[$nid2op[$newTask->task_id]];
$newTask->store();
$newTask->updateDependencies($newDeps[$task_id]);
}
// end check if imported task
$newTask->store();
}
// end Fix record integrity
}
示例2: executePost
//.........这里部分代码省略.........
} elseif ($tmp[0] != '') {
$hperc_assign_ar[$tmp[0]] = 100;
}
}
// let's check if there are some assigned departments to task
$task->task_departments = implode(',', $this->getParam('dept_ids', self::TYPE_ARRAY));
// convert dates to SQL format first
if ($task->task_start_date) {
$date = new w2p_Utilities_Date($task->task_start_date);
$task->task_start_date = $date->format(FMT_DATETIME_MYSQL);
}
$end_date = null;
if ($task->task_end_date) {
if (strpos($task->task_end_date, '2400') !== false) {
$task->task_end_date = str_replace('2400', '2359', $task->task_end_date);
}
$end_date = new w2p_Utilities_Date($task->task_end_date);
$task->task_end_date = $end_date->format(FMT_DATETIME_MYSQL);
}
$error_array = $task->store($AppUI);
// Return all the validation messages
if ($error_array !== true) {
$error_message = '';
foreach ($error_array as $error) {
$error_message .= $error . '. ';
}
throw new Frapi_Error('SAVE_ERROR', $error_message);
}
$task_parent = $this->getParam('task_parent') ? $this->getParam('task_parent', SELF::TYPE_INT) : 0;
$old_task_parent = $this->getParam('old_task_parent') ? $this->getParam('old_task_parent', SELF::TYPE_INT) : 0;
if ($task_parent != $old_task_parent) {
$oldTask = new CTask();
$oldTask->load($old_task_parent);
$oldTask->updateDynamics(false);
}
// How to handle custom fields? Do we support it in api?
// Now add any task reminders
// If there wasn't a task, but there is one now, and
// that task date is set, we need to set a reminder.
if (empty($task_end_date) || !empty($end_date) && $task_end_date->dateDiff($end_date)) {
$task->addReminder();
}
if (isset($hassign)) {
$task->updateAssigned($hassign, $hperc_assign_ar);
}
if (isset($hdependencies)) {
// && !empty($hdependencies)) {
// there are dependencies set!
// backup initial start and end dates
$tsd = new w2p_Utilities_Date($task->task_start_date);
$ted = new w2p_Utilities_Date($task->task_end_date);
// updating the table recording the
// dependency relations with this task
$task->updateDependencies($hdependencies, $task_parent);
// we will reset the task's start date based upon dependencies
// and shift the end date appropriately
if ($adjustStartDate && !is_null($hdependencies)) {
// load already stored task data for this task
$tempTask = new CTask();
$tempTask->load($task->task_id);
// shift new start date to the last dependency end date
$nsd = new w2p_Utilities_Date($tempTask->get_deps_max_end_date($tempTask));
// prefer Wed 8:00 over Tue 16:00 as start date
$nsd = $nsd->next_working_day();
// prepare the creation of the end date
$ned = new w2p_Utilities_Date();
$ned->copy($nsd);
if (empty($task->task_start_date)) {
// appropriately calculated end date via start+duration
$ned->addDuration($task->task_duration, $task->task_duration_type);
} else {
// calc task time span start - end
$d = $tsd->calcDuration($ted);
// Re-add (keep) task time span for end date.
// This is independent from $obj->task_duration.
// The value returned by Date::Duration() is always in hours ('1')
$ned->addDuration($d, '1');
}
// prefer tue 16:00 over wed 8:00 as an end date
$ned = $ned->prev_working_day();
$task->task_start_date = $nsd->format(FMT_DATETIME_MYSQL);
$task->task_end_date = $ned->format(FMT_DATETIME_MYSQL);
$q = new w2p_Database_Query();
$q->addTable('tasks', 't');
$q->addUpdate('task_start_date', $task->task_start_date);
$q->addUpdate('task_end_date', $task->task_end_date);
$q->addWhere('task_id = ' . (int) $task->task_id);
$q->addWhere('task_dynamic <> 1');
$q->exec();
$q->clear();
}
$task->pushDependencies($task->task_id, $task->task_end_date);
}
//$task = (array)$task;
$task->load($task_id);
unset($task->_query, $task->_error, $task->_tbl_prefix, $task->_tbl, $task->_tbl_key, $task->_tbl_module);
$this->data['task'] = $task;
$this->data['success'] = true;
return $this->toArray();
}
示例3:
if ($result) {
$AppUI->setMsg('Task deleted');
$AppUI->redirect('m=projects&a=view&project_id=' . $obj->task_project);
} else {
$AppUI->setMsg($obj->getError(), UI_MSG_ERROR);
$AppUI->redirect('m=tasks&a=view&task_id=' . $task_id);
}
}
$result = $obj->store();
if ($result) {
if (isset($hassign)) {
$obj->updateAssigned($hassign, $hperc_assign_ar);
}
// This call has to be here to make sure that old dependencies are
// cleared on save, even if there's no new dependencies
$obj->updateDependencies($hdependencies, $obj->task_id);
if (isset($hdependencies) && '' != $hdependencies) {
// there are dependencies set!
$nsd = new w2p_Utilities_Date($obj->get_deps_max_end_date($obj));
if (isset($start_date)) {
$shift = $nsd->compare($start_date, $nsd);
if ($shift < 1) {
//$obj->task_start_date = $nsd->format(FMT_DATETIME_MYSQL);
$osd = new w2p_Utilities_Date($obj->task_start_date);
$ned = new w2p_Utilities_Date($obj->task_end_date);
$dur = -$ned->calcDuration($osd);
$ned->copy($nsd);
$ned->addDuration($dur, 1);
$new_start_date = $nsd->format(FMT_DATETIME_MYSQL);
$obj->task_start_date = $AppUI->formatTZAwareTime($new_start_date, '%Y-%m-%d %T');
$new_end_date = $ned->format(FMT_DATETIME_MYSQL);
示例4: CustomFields
if ($msg = $obj->store()) {
$AppUI->setMsg($msg, UI_MSG_ERROR);
$AppUI->redirect();
// Store failed don't continue?
} else {
$custom_fields = new CustomFields($m, 'addedit', $obj->task_id, "edit");
$custom_fields->bind($_POST);
$sql = $custom_fields->store($obj->task_id);
// Store Custom Fields
$AppUI->setMsg($task_id ? 'Task updated' : 'Task added', UI_MSG_OK);
}
if (isset($hassign)) {
$obj->updateAssigned($hassign, $hperc_assign_ar);
}
if (isset($hdependencies)) {
$obj->updateDependencies($hdependencies);
}
// If there is a set of post_save functions, then we process them
if (isset($post_save)) {
foreach ($post_save as $post_save_function) {
$post_save_function();
}
}
if ($notify) {
if ($msg = $obj->notify($comment)) {
$AppUI->setMsg($msg, UI_MSG_ERROR);
}
}
$AppUI->redirect();
}
}
示例5: importTasks
/** Import tasks from another project
*
* @param int Project ID of the tasks come from.
* @return bool
**/
function importTasks($from_project_id)
{
// Load the original
$origProject = new CProject();
$origProject->load($from_project_id);
$q = new DBQuery();
$q->addTable('tasks');
$q->addQuery('task_id');
$q->addWhere('task_project =' . $from_project_id);
$sql = $q->prepare();
$q->clear();
$tasks = array_flip(db_loadColumn($sql));
$origDate = new CDate($origProject->project_start_date);
$destDate = new CDate($this->project_start_date);
$dateOffset = $destDate->dateDiff($origDate);
// Old dependencies array from imported tasks
$deps = array();
// New dependencies array for new copies of imported tasks
$newDeps = array();
// Old2New task ID array
$taskXref = array();
// New task ID to old parent array
$nid2op = array();
// Copy each task into this project and get their deps
foreach ($tasks as $orig => $void) {
$objTask = new CTask();
$objTask->load($orig);
// Grab the old parent id
$oldParent = (int) $objTask->task_parent;
$deps[$orig] = $objTask->getDependencies();
$destTask = $objTask->copy($this->project_id, 0);
$nid2op[$destTask->task_id] = $oldParent;
$tasks[$orig] = $destTask;
$taskXref[$orig] = (int) $destTask->task_id;
}
// Build new dependencies array
foreach ($deps as $odkey => $od) {
$ndt = '';
$ndkey = $taskXref[$odkey];
$odep = explode(',', $od);
foreach ($odep as $odt) {
$ndt = $ndt . $taskXref[$odt] . ',';
}
$ndt = rtrim($ndt, ',');
$newDeps[$ndkey] = $ndt;
}
$q->addTable('tasks');
$q->addQuery('task_id');
$q->addWhere('task_project =' . $this->project_id);
$tasks = $q->loadColumn();
// Update dates based on new project's start date.
foreach ($tasks as $task_id) {
$newTask = new CTask();
$newTask->load($task_id);
if (in_array($task_id, $taskXref)) {
// Fix task start date from project start date offset
$origDate->setDate($newTask->task_start_date);
$destDate->setDate($newTask->task_start_date);
$destDate->addDays($dateOffset);
$destDate = $destDate->next_working_day();
$newTask->task_start_date = $destDate->format(FMT_DATETIME_MYSQL);
// Fix task end date from start date + work duration
//$newTask->calc_task_end_date();
if (!empty($newTask->task_end_date) && $newTask->task_end_date != '0000-00-00 00:00:00') {
$origDate->setDate($newTask->task_end_date);
$destDate->setDate($newTask->task_end_date);
$destDate->addDays($dateOffset);
$destDate = $destDate->next_working_day();
$newTask->task_end_date = $destDate->format(FMT_DATETIME_MYSQL);
}
$newTask->task_parent = $taskXref[$nid2op[$newTask->task_id]];
$newTask->store();
$newTask->updateDependencies($newDeps[$task_id]);
}
// end check if imported task
$newTask->store();
}
// end Fix record integrity
}