/** * Import selected todoes to today. * * @access public * @return void */ public function import2Today($todoID = 0) { $todoIDList = $_POST ? $this->post->todoIDList : array($todoID); $date = !empty($_POST['date']) ? $_POST['date'] : date::today(); $this->dao->update(TABLE_TODO)->set('date')->eq($date)->where('id')->in($todoIDList)->exec(); $this->locate($this->session->todoList); }
/** * Compute the begin date and end date of a period. * * @param string $period all|today|yesterday|twodaysago|latest2days|thisweek|lastweek|thismonth|lastmonth * @access public * @return array */ public function computeBeginAndEnd($period) { $this->app->loadClass('date'); $today = date::today(); $tomorrow = date::tomorrow(); $yesterday = date::yesterday(); $twoDaysAgo = date::twoDaysAgo(); $period = strtolower($period); if ($period == 'all') { return array('begin' => '1970-1-1', 'end' => '2109-1-1'); } if ($period == 'today') { return array('begin' => $today, 'end' => $tomorrow); } if ($period == 'yesterday') { return array('begin' => $yesterday, 'end' => $today); } if ($period == 'twodaysago') { return array('begin' => $twoDaysAgo, 'end' => $yesterday); } if ($period == 'latest3days') { return array('begin' => $twoDaysAgo, 'end' => $tomorrow); } /* If the period is by week, add the end time to the end date. */ if ($period == 'thisweek' or $period == 'lastweek') { $func = "get{$period}"; extract(date::$func()); return array('begin' => $begin, 'end' => $end . ' 23:59:59'); } if ($period == 'thismonth') { return date::getThisMonth(); } if ($period == 'lastmonth') { return date::getLastMonth(); } }
/** * Import selected todoes to today. * * @access public * @return void */ public function import2Today($todoID = 0) { $todoIDList = $_POST ? $this->post->todoIDList : array($todoID); $date = !empty($_POST['date']) ? $_POST['date'] : date::today(); $this->dao->update(TABLE_TODO)->set('date')->eq($date)->where('id')->in($todoIDList)->exec(); if (dao::isError()) { $this->send(array('result' => 'fail', 'message' => dao::getError())); } $this->send(array('result' => 'success', 'locate' => $this->session->todoList)); }
/** * Get todo list of a user. * * @param date $date * @param string $account * @param string $status all|today|thisweek|lastweek|before, or a date. * @param int $limit * @access public * @return void */ public function getList($date = 'today', $account = '', $status = 'all', $limit = 0, $pager = null, $orderBy = "date, status, begin") { $this->app->loadClass('date'); $todos = array(); $date = strtolower($date); if ($date == 'today') { $begin = date::today(); $end = $begin; } elseif ($date == 'yesterday') { $begin = date::yesterday(); $end = $begin; } elseif ($date == 'thisweek') { extract(date::getThisWeek()); } elseif ($date == 'lastweek') { extract(date::getLastWeek()); } elseif ($date == 'thismonth') { extract(date::getThisMonth()); } elseif ($date == 'lastmonth') { extract(date::getLastMonth()); } elseif ($date == 'thisseason') { extract(date::getThisSeason()); } elseif ($date == 'thisyear') { extract(date::getThisYear()); } elseif ($date == 'future') { $begin = '2030-01-01'; $end = $begin; } elseif ($date == 'all') { $begin = '1970-01-01'; $end = '2109-01-01'; } elseif ($date == 'before') { $begin = '1970-01-01'; $end = date::yesterday(); } else { $begin = $end = $date; } if ($account == '') { $account = $this->app->user->account; } $stmt = $this->dao->select('*')->from(TABLE_TODO)->where('account')->eq($account)->andWhere("date >= '{$begin}'")->andWhere("date <= '{$end}'")->beginIF($status != 'all' and $status != 'undone')->andWhere('status')->in($status)->fi()->beginIF($status == 'undone')->andWhere('status')->ne('done')->fi()->orderBy($orderBy)->beginIF($limit > 0)->limit($limit)->fi()->page($pager)->query(); /* Set session. */ $sql = explode('WHERE', $this->dao->get()); $sql = explode('ORDER', $sql[1]); $this->session->set('todoReportCondition', $sql[0]); while ($todo = $stmt->fetch()) { if ($todo->type == 'task') { $todo->name = $this->dao->findById($todo->idvalue)->from(TABLE_TASK)->fetch('name'); } if ($todo->type == 'bug') { $todo->name = $this->dao->findById($todo->idvalue)->from(TABLE_BUG)->fetch('title'); } $todo->begin = date::formatTime($todo->begin); $todo->end = date::formatTime($todo->end); /* If is private, change the title to private. */ if ($todo->private and $this->app->user->account != $todo->account) { $todo->name = $this->lang->todo->thisIsPrivate; } $todos[] = $todo; } return $todos; }
/** Replace dynamic account and date. * * @param string $query * @access public * @return string */ public function replaceDynamic($query) { $this->app->loadClass('date'); $lastWeek = date::getLastWeek(); $thisWeek = date::getThisWeek(); $lastMonth = date::getLastMonth(); $thisMonth = date::getThisMonth(); $yesterday = date::yesterday(); $today = date::today(); if (strpos($query, '$') !== false) { $query = str_replace('$@me', $this->app->user->account, $query); $query = str_replace("'\$lastMonth'", "'" . $lastMonth['begin'] . "' and '" . $lastMonth['end'] . "'", $query); $query = str_replace("'\$thisMonth'", "'" . $thisMonth['begin'] . "' and '" . $thisMonth['end'] . "'", $query); $query = str_replace("'\$lastWeek'", "'" . $lastWeek['begin'] . "' and '" . $lastWeek['end'] . "'", $query); $query = str_replace("'\$thisWeek'", "'" . $thisWeek['begin'] . "' and '" . $thisWeek['end'] . "'", $query); $query = str_replace("'\$yesterday'", "'" . $yesterday . "' and '" . $yesterday . "'", $query); $query = str_replace("'\$today'", "'" . $today . "' and '" . $today . "'", $query); } return $query; }
private static function _build_datebox_sql($today, $today_arr, $then, $then_arr, $mark) { $t =& $GLOBALS["t"]; $fields = explode(",", $GLOBALS["current_view"]["ENABLE_CALENDAR"]); if (count($fields) == 1) { self::$today = $today; self::$then = $then; $sql = "(" . $fields[0] . " between " . $today . " and " . $then . ")"; } else { if (count($fields) == 2) { $sql = "((" . $fields[1] . " between " . $today . " and " . $then . ") or (" . $fields[0] . " between " . $today . " and " . $then . "))"; } else { // 0-start,1-end,2-recurrence,3-until,4-allday,5-repeatinterval,6-repeatexclusions,7-repeatstart,8-repeatend $start = $fields[0]; $end = $fields[1]; $rec = $fields[2]; $until = $fields[3]; $rstart = $fields[7]; $rend = $fields[8]; $wtoday = $today_arr["wday"]; $wthen = $then_arr["wday"]; $mtoday = $today_arr["mday"]; $mthen = $then_arr["mday"]; $ytoday = $today_arr["yday"]; $ythen = $then_arr["yday"]; $sql = "(({$end} between {$today} and {$then}) or ({$then} between {$start} and {$end})"; $sql .= " or ({$start} < {$then} and ({$until}=0 or {$until} > {$today}) and "; $sql .= "({$rec}='days'"; if ($mark == "day") { $sql .= " or ({$rec}='weeks' and (({$rend} between {$wtoday} and {$wthen}) or ({$rend}>={$rstart} and {$wthen} between {$rstart} and {$rend}) or ({$rend}<{$rstart} and {$wthen} not between {$rend}+1 and {$rstart}-1)) )"; } else { $sql .= " or {$rec}='weeks'"; } if ($mark == "day" or $mark == "week") { $sql .= " or ({$rec}='months' and (({$rend} between {$mtoday} and {$mthen}) or ({$rend}>={$rstart} and {$mthen} between {$rstart} and {$rend}) or ({$rend}<{$rstart} and {$mthen} not between {$rend}+1 and {$rstart}-1)) )"; } else { $sql .= " or {$rec}='months'"; } if ($mark == "day" or $mark == "week" or $mark == "month" or $mark == "gantt") { $sql .= " or ({$rec}='years' and (({$rend} between {$ytoday} and {$ythen}) or ({$rend}>={$rstart} and {$ythen} between {$rstart} and {$rend}) or ({$rend}<{$rstart} and {$ythen} not between {$rend}+1 and {$rstart}-1)) )"; } else { $sql .= " or {$rec}='years'"; } $sql .= ")))"; } } $t["sqlwhere"][] = $sql; $t["sqlwhere_default"][] = $sql; }
/** * Get todo list of a user. * * @param string $mode all|self|assignedToOther|assignedToMe * @param string $account * @param date $date all|today|thisweek|lastweek|before, or a date. * @param string $status * @param string $orderBy * @param object $pager * @access public * @return void */ public function getList($mode = 'self', $account = '', $date = 'all', $status = 'all', $orderBy = "date, status, begin", $pager = null) { if ($account == '') { $account = $this->app->user->account; } $mode = strtolower($mode); $this->app->loadClass('date'); $todos = array(); if (!is_array($date)) { $date = strtolower($date); } if (is_array($date)) { $begin = strtolower($date['begin']); $end = strtolower($date['end']); } elseif ($date == 'today') { $begin = date::today(); $end = $begin; } elseif ($date == 'yesterday') { $begin = date::yesterday(); $end = $begin; } elseif ($date == 'thisweek') { extract(date::getThisWeek()); } elseif ($date == 'lastweek') { extract(date::getLastWeek()); } elseif ($date == 'thismonth') { extract(date::getThisMonth()); } elseif ($date == 'lastmonth') { extract(date::getLastMonth()); } elseif ($date == 'thisseason') { extract(date::getThisSeason()); } elseif ($date == 'thisyear') { extract(date::getThisYear()); } elseif ($date == 'future') { $begin = '0000-00-00'; $end = '1970-01-01'; } elseif ($date == 'all') { $begin = '1970-01-01'; $end = '2109-01-01'; } elseif ($date == 'before') { $begin = '1970-01-01'; $end = date::yesterday(); } else { $begin = $end = $date; } $stmt = $this->dao->select('*')->from(TABLE_TODO)->where('1=1')->beginIF($mode == 'self')->andWhere()->markLeft()->where('account')->eq($account)->orWhere('assignedTo')->eq($account)->markRight()->fi()->beginIF($mode == 'assignedtoother')->andWhere('account')->eq($account)->andWhere('assignedTo')->ne($account)->andWhere('assignedTo')->ne('')->fi()->beginIF($mode == 'assignedtome')->andWhere('account')->ne($account)->andWhere('assignedTo')->eq($account)->fi()->andWhere("date >= '{$begin}'")->andWhere("date <= '{$end}'")->beginIF($status != 'all' and $status != 'undone' and $status != 'unclosed')->andWhere('status')->in($status)->fi()->beginIF($status == 'undone')->andWhere('status')->notin('done,closed')->fi()->beginIF($status == 'unclosed')->andWhere('status')->ne('closed')->fi()->orderBy($orderBy)->page($pager)->query(); /* Set session. */ $sql = explode('WHERE', $this->dao->get()); $sql = explode('ORDER', $sql[1]); $this->session->set('todoReportCondition', $sql[0]); while ($todo = $stmt->fetch()) { if ($todo->type == 'task') { $todo->name = $this->dao->findById($todo->idvalue)->from(TABLE_TASK)->fetch('name'); } if ($todo->type == 'customer') { $todo->name = $this->dao->findById($todo->idvalue)->from(TABLE_CUSTOMER)->fetch('name'); } if ($todo->type == 'order') { $order = $this->dao->select('c.name, o.createdDate')->from(TABLE_ORDER)->alias('o')->leftJoin(TABLE_CUSTOMER)->alias('c')->on('o.customer=c.id')->where('o.id')->eq($todo->idvalue)->fetch(); $todo->name = $order->name . '|' . date('Y-m-d', strtotime($order->createdDate)); } $todo->begin = date::formatTime($todo->begin); $todo->end = date::formatTime($todo->end); /* If is private, change the title to private. */ if ($todo->private and $this->app->user->account != $todo->account) { $todo->name = $this->lang->todo->thisIsPrivate; } $todos[] = $todo; } return $todos; }