function taskstyle_pd($task)
{
    $now = new w2p_Utilities_Date();
    $start_date = intval($task['task_start_date']) ? new w2p_Utilities_Date($task['task_start_date']) : null;
    $end_date = intval($task['task_end_date']) ? new w2p_Utilities_Date($task['task_end_date']) : null;
    if ($start_date && !$end_date) {
        $end_date = $start_date;
        $end_date->addSeconds($task['task_duration'] * $task['task_duration_type'] * SEC_HOUR);
    } else {
        if (!$start_date) {
            return '';
        }
    }
    $style = 'class=';
    if ($task['task_percent_complete'] == 0) {
        $style .= $now->before($start_date) ? '"task_future"' : '"task_notstarted"';
    } else {
        if ($task['task_percent_complete'] == 100) {
            $t = new CTask();
            $t->load($task['task_id']);
            $actual_end_date = new w2p_Utilities_Date(get_actual_end_date_pd($t->task_id, $t));
            $style .= $actual_end_date->after($end_date) ? '"task_late"' : '"task_done"';
        } else {
            $style .= $now->after($end_date) ? '"task_overdue"' : '"task_started"';
        }
    }
    return $style;
}
 $q->addOrder('project_id, task_start_date');
 $q->addWhere('project_original_parent = ' . (int) $original_project_id);
 //$tasks = $q->loadList();
 $task = new CTask();
 $task->setAllowedSQL($AppUI->user_id, $q);
 $proTasks = $q->loadHashList('task_id');
 $orrarr[] = array('task_id' => 0, 'order_up' => 0, 'order' => '');
 $end_max = '0000-00-00 00:00:00';
 $start_min = date('Y-m-d H:i:s');
 //pull the tasks into an array
 foreach ($proTasks as $rec) {
     if ($rec['task_start_date'] == '0000-00-00 00:00:00') {
         $rec['task_start_date'] = date('Y-m-d H:i:s');
     }
     $tsd = new w2p_Utilities_Date($rec['task_start_date']);
     if ($tsd->before(new w2p_Utilities_Date($start_min))) {
         $start_min = $rec['task_start_date'];
     }
     // calculate or set blank task_end_date if unset
     if ($rec['task_end_date'] == '0000-00-00 00:00:00') {
         if ($rec['task_duration']) {
             $rec['task_end_date'] = db_unix2dateTime(db_dateTime2unix($rec['task_start_date']) + SECONDS_PER_DAY * convert2days($rec['task_duration'], $rec['task_duration_type']));
         } else {
             $rec['task_end_date'] = '';
         }
     }
     $ted = new w2p_Utilities_Date($rec['task_end_date']);
     if ($ted->after(new w2p_Utilities_Date($end_max))) {
         $end_max = $rec['task_end_date'];
     }
     $projects[$rec['task_project']]['tasks'][] = $rec;
 public function remove(CAppUI $AppUI, w2p_Utilities_Date $date)
 {
     $perms = $AppUI->acl();
     $removed = false;
     if ($this->holiday_id && $perms->checkModuleItem('holiday', 'edit', $this->holiday_id)) {
         $holiday_start_date = new w2p_Utilities_Date($this->holiday_start_date);
         $holiday_end_date = new w2p_Utilities_Date($this->holiday_end_date);
         if ($holiday_start_date->equals($date->duplicate())) {
             if ($holiday_end_date->equals($date->duplicate())) {
                 $removed = $this->delete($AppUI);
             } else {
                 $holiday_start_date = new w2p_Utilities_Date($this->holiday_start_date);
                 $this->holiday_start_date = $holiday_start_date->getNextDay()->getDate();
                 $removed = $this->store($AppUI);
             }
         } elseif ($holiday_end_date->equals($date->duplicate())) {
             $holiday_end_date = new w2p_Utilities_Date($this->holiday_end_date);
             $this->holiday_end_date = $holiday_end_date->getPrevDay()->getDate();
             $removed = $this->store($AppUI);
         } elseif ($holiday_start_date->before($date->duplicate()) && $holiday_end_date->after($date->duplicate())) {
             $holiday_end_date = $this->holiday_end_date;
             $this->holiday_end_date = $date->getPrevDay()->getDate();
             $removed = $this->store($AppUI);
             $this->holiday_id = 0;
             // create new record
             $this->holiday_start_date = $date->getNextDay()->getDate();
             $this->holiday_end_date = $holiday_end_date;
             $removed = $this->store($AppUI);
         }
     }
     return $removed;
 }
Beispiel #4
0
/**
 * Sub-function to collect tasks within a period
 *
 * @param Date the starting date of the period
 * @param Date the ending date of the period
 * @param array by-ref an array of links to append new items to
 * @param int the length to truncate entries by
 * @param int the company id to filter by
 * @author Andrew Eddie <*****@*****.**>
 */
function getTaskLinks($startPeriod, $endPeriod, &$links, $strMaxLen, $company_id = 0, $minical = false)
{
    global $a, $AppUI, $w2Pconfig;
    $tasks = CTask::getTasksForPeriod($startPeriod, $endPeriod, $company_id, 0);
    $df = $AppUI->getPref('SHDATEFORMAT');
    $tf = $AppUI->getPref('TIMEFORMAT');
    //subtract one second so we don't have to compare the start dates for exact matches with the startPeriod which is 00:00 of a given day.
    $startPeriod->subtractSeconds(1);
    $link = array();
    $sid = 3600 * 24;
    // assemble the links for the tasks
    foreach ($tasks as $row) {
        // the link
        $link['task'] = true;
        if (!$minical) {
            $link['href'] = '?m=tasks&a=view&task_id=' . $row['task_id'];
            // the link text
            if (mb_strlen($row['task_name']) > $strMaxLen) {
                $row['short_name'] = mb_substr($row['task_name'], 0, $strMaxLen) . '...';
            } else {
                $row['short_name'] = $row['task_name'];
            }
            $link['text'] = '<span style="color:' . bestColor($row['color']) . ';background-color:#' . $row['color'] . '">' . $row['short_name'] . ($row['task_milestone'] ? '&nbsp;' . w2PshowImage('icons/milestone.gif') : '') . '</span>';
        }
        // determine which day(s) to display the task
        $start = new w2p_Utilities_Date($AppUI->formatTZAwareTime($row['task_start_date'], '%Y-%m-%d %T'));
        $end = $row['task_end_date'] ? new w2p_Utilities_Date($AppUI->formatTZAwareTime($row['task_end_date'], '%Y-%m-%d %T')) : null;
        // First we test if the Tasks Starts and Ends are on the same day, if so we don't need to go any further.
        if ($start->after($startPeriod) && ($end && $end->after($startPeriod) && $end->before($endPeriod) && !$start->dateDiff($end))) {
            if ($minical) {
                $temp = array('task' => true);
            } else {
                $temp = $link;
                if ($a != 'day_view') {
                    $temp['text'] = w2PtoolTip($row['task_name'], getTaskTooltip($row['task_id'], true, true, $tasks), true) . w2PshowImage('block-start-16.png') . $start->format($tf) . ' ' . $temp['text'] . ' ' . $end->format($tf) . w2PshowImage('block-end-16.png') . w2PendTip();
                    $temp['text'] .= '<a href="?m=tasks&amp;a=view&amp;task_id=' . $row['task_id'] . '&amp;tab=1&amp;date=' . $AppUI->formatTZAwareTime($row['task_end_date'], '%Y%m%d') . '">' . w2PtoolTip('Add Log', 'create a new log record against this task') . w2PshowImage('edit_add.png') . w2PendTip() . '</a>';
                }
            }
            $links[$end->format(FMT_TIMESTAMP_DATE)][] = $temp;
        } else {
            // If they aren't, we will now need to see if the Tasks Start date is between the requested period
            if ($start->after($startPeriod) && $start->before($endPeriod)) {
                if ($minical) {
                    $temp = array('task' => true);
                } else {
                    $temp = $link;
                    if ($a != 'day_view') {
                        $temp['text'] = w2PtoolTip($row['task_name'], getTaskTooltip($row['task_id'], true, false, $tasks), true) . w2PshowImage('block-start-16.png') . $start->format($tf) . ' ' . $temp['text'] . w2PendTip();
                        $temp['text'] .= '<a href="?m=tasks&amp;a=view&amp;task_id=' . $row['task_id'] . '&amp;tab=1&amp;date=' . $AppUI->formatTZAwareTime($row['task_start_date'], '%Y%m%d') . '">' . w2PtoolTip('Add Log', 'create a new log record against this task') . w2PshowImage('edit_add.png') . w2PendTip() . '</a>';
                    }
                }
                $links[$start->format(FMT_TIMESTAMP_DATE)][] = $temp;
            }
            // And now the Tasks End date is checked if it is between the requested period too.
            if ($end && $end->after($startPeriod) && $end->before($endPeriod) && $start->before($end)) {
                if ($minical) {
                    $temp = array('task' => true);
                } else {
                    $temp = $link;
                    if ($a != 'day_view') {
                        $temp['text'] = w2PtoolTip($row['task_name'], getTaskTooltip($row['task_id'], false, true, $tasks), true) . ' ' . $temp['text'] . ' ' . $end->format($tf) . w2PshowImage('block-end-16.png') . w2PendTip();
                        $temp['text'] .= '<a href="?m=tasks&amp;a=view&amp;task_id=' . $row['task_id'] . '&amp;tab=1&amp;date=' . $AppUI->formatTZAwareTime($row['task_end_date'], '%Y%m%d') . '">' . w2PtoolTip('Add Log', 'create a new log record against this task') . w2PshowImage('edit_add.png') . w2PendTip() . '</a>';
                    }
                }
                $links[$end->format(FMT_TIMESTAMP_DATE)][] = $temp;
            }
        }
    }
}
Beispiel #5
0
 /**
  * Tests before when the dates are equal
  */
 public function testBeforeIsSame()
 {
     $date1 = new w2p_Utilities_Date('2010-11-04 11:00:00');
     $date2 = new w2p_Utilities_Date('2010-11-04 11:00:00');
     $this->assertFalse($date1->before($date2));
 }