/** * Returns the contract status associated with the given customer ID. * Possible return values are 'active', 'in_grace_period' and 'expired'. * * @access public * @param integer $customer_id The customer ID * @return string The contract status */ function getContractStatus($customer_id) { // active contracts have an expiration date in the future $expiration = strtotime($this->data[$customer_id]['expiration_date']); $now = Date_API::getCurrentUnixTimestampGMT(); if ($expiration > $now) { return 'active'; } elseif ($expiration > $now + DAY * $this->getExpirationOffset()) { return 'in_grace_period'; } else { return 'expired'; } }
/** * Retrieves the next assignee in the given project's round robin queue. * * @access public * @param integer $prj_id The project ID * @return integer The assignee's user ID */ function getNextAssignee($prj_id) { // get the full list of users for the given project list($blackout_start, $blackout_end, $users) = Round_Robin::getUsersByProject($prj_id); if (count($users) == 0) { return 0; } else { $user_ids = array_keys($users); $next_usr_id = 0; foreach ($users as $usr_id => $details) { if ($details['is_next']) { $next_usr_id = $usr_id; break; } } // if no user is currently set as the 'next' assignee, // then just get the first one in the list if (empty($next_usr_id)) { $next_usr_id = $user_ids[0]; } // counter to keep the number of times we found an invalid user $ignored_users = 0; // check the blackout hours do { $user = new Date(Date_API::getCurrentUnixTimestampGMT()); $user->convertTZById($users[$next_usr_id]['timezone']); list($today, $tomorrow) = Round_Robin::getBlackoutDates(&$user, $blackout_start, $blackout_end); $first = new Date($today . ' ' . $blackout_start); $first->setTZById($users[$next_usr_id]['timezone']); $second = new Date($tomorrow . ' ' . $blackout_end); $second->setTZById($users[$next_usr_id]['timezone']); if (Date::compare($first, $user) == -1 && Date::compare($user, $second) == -1) { $ignored_users++; $current_index = array_search($next_usr_id, $user_ids); // if we reached the end of the list of users and none of them // was a valid one, then just select the first one // however, we want to complete at least one full iteration over the list of users // that is, if we didn't start checking the users in the beginning of the list, // then do another run over the users just in case if ($ignored_users >= count($user_ids) && $current_index == count($user_ids) - 1) { $assignee = $user_ids[0]; break; } // if we reached the end of the list, and we still didn't find an user, // then go back to the beginning of the list one last time if ($current_index == count($user_ids) - 1) { $current_index = 0; $next_usr_id = $user_ids[++$current_index]; $found = 0; continue; } $next_usr_id = $user_ids[++$current_index]; $found = 0; } else { $assignee = $next_usr_id; $found = 1; } } while (!$found); // mark the next user in the list as the 'next' assignment $assignee_index = array_search($assignee, $user_ids); if ($assignee_index == count($user_ids) - 1) { $next_assignee = $user_ids[0]; } else { $next_assignee = $user_ids[++$assignee_index]; } Round_Robin::markNextAssignee($prj_id, $next_assignee); return $assignee; } }
/** * Method used to get all open issues and group them by user. * * @access public * @param integer $prj_id The project ID * @param integer $cutoff_days The number of days to use as a cutoff period * @return array The list of issues */ function getOpenIssuesByUser($prj_id, $cutoff_days) { $prj_id = Misc::escapeInteger($prj_id); $cutoff_days = Misc::escapeInteger($cutoff_days); $ts = Date_API::getCurrentUnixTimestampGMT(); $cutoff_ts = $ts - $cutoff_days * DAY; $stmt = "SELECT\n usr_full_name,\n iss_id,\n iss_summary,\n sta_title,\n iss_sta_id,\n iss_created_date,\n iss_updated_date,\n iss_last_response_date,\n sta_color\n FROM\n (\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue,\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_user,\n " . ETEL_USER_TABLE . "\n )\n LEFT JOIN\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "status\n ON\n iss_sta_id=sta_id\n WHERE\n sta_is_closed=0 AND\n iss_prj_id={$prj_id} AND\n iss_id=isu_iss_id AND\n isu_usr_id=usr_id AND\n UNIX_TIMESTAMP(iss_created_date) < {$cutoff_ts}\n ORDER BY\n usr_full_name"; $res = $GLOBALS["db_api"]->dbh->getAll($stmt, DB_FETCHMODE_ASSOC); if (PEAR::isError($res)) { Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); return ""; } else { Time_Tracking::getTimeSpentByIssues($res); $issues = array(); for ($i = 0; $i < count($res); $i++) { if (empty($res[$i]['iss_updated_date'])) { $res[$i]['iss_updated_date'] = $res[$i]['iss_created_date']; } if (empty($res[$i]['iss_last_response_date'])) { $res[$i]['iss_last_response_date'] = $res[$i]['iss_created_date']; } $issues[$res[$i]['usr_full_name']][$res[$i]['iss_id']] = array('iss_summary' => $res[$i]['iss_summary'], 'sta_title' => $res[$i]['sta_title'], 'iss_created_date' => Date_API::getFormattedDate($res[$i]['iss_created_date']), 'time_spent' => Misc::getFormattedTime($res[$i]['time_spent']), 'status_color' => $res[$i]['sta_color'], 'last_update' => Date_API::getFormattedDateDiff($ts, Date_API::getUnixTimestamp($res[$i]['iss_updated_date'], Date_API::getDefaultTimezone())), 'last_email_response' => Date_API::getFormattedDateDiff($ts, Date_API::getUnixTimestamp($res[$i]['iss_last_response_date'], Date_API::getDefaultTimezone()))); } return $issues; } }
/** * Returns the status of a quarantine. * * @param integer $issue_id The issue ID * @return integer Indicates what the current state of quarantine is. */ function getQuarantineInfo($issue_id) { $stmt = "SELECT\n iqu_status,\n iqu_expiration\n FROM\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_quarantine\n WHERE\n iqu_iss_id = " . Misc::escapeInteger($issue_id) . " AND\n (iqu_expiration > '" . Date_API::getCurrentDateGMT() . "' OR\n iqu_expiration IS NULL)"; $res = $GLOBALS["db_api"]->dbh->getRow($stmt, DB_FETCHMODE_ASSOC); if (PEAR::isError($res)) { Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); return array(); } else { if (!empty($res["iqu_expiration"])) { $expiration_ts = Date_API::getUnixTimestamp($res['iqu_expiration'], Date_API::getDefaultTimezone()); $res["time_till_expiration"] = Date_API::getFormattedDateDiff($expiration_ts, Date_API::getCurrentUnixTimestampGMT()); } return $res; } }