/** * Gets all information about a task (and caches information if wanted) * @param integer $task_id * @param bool $cache_enabled * @access public static * @return mixed an array with all taskdetails or false on failure * @version 1.0 */ public static function GetTaskDetails($task_id, $cache_enabled = false) { global $db, $fs; static $cache = array(); if (isset($cache[$task_id]) && $cache_enabled) { return $cache[$task_id]; } //for some reason, task_id is not here // run away inmediately.. if (!is_numeric($task_id)) { return false; } $get_details = $db->Query('SELECT t.*, p.*, c.category_name, c.category_owner, c.lft, c.rgt, c.project_id as cproj, o.os_name, r.resolution_name, tt.tasktype_name, vr.version_name AS reported_version_name, vd.version_name AS due_in_version_name, uo.real_name AS opened_by_name, ue.real_name AS last_edited_by_name, uc.real_name AS closed_by_name, lst.status_name AS status_name FROM {tasks} t LEFT JOIN {projects} p ON t.project_id = p.project_id LEFT JOIN {list_category} c ON t.product_category = c.category_id LEFT JOIN {list_os} o ON t.operating_system = o.os_id LEFT JOIN {list_resolution} r ON t.resolution_reason = r.resolution_id LEFT JOIN {list_tasktype} tt ON t.task_type = tt.tasktype_id LEFT JOIN {list_version} vr ON t.product_version = vr.version_id LEFT JOIN {list_version} vd ON t.closedby_version = vd.version_id LEFT JOIN {list_status} lst ON t.item_status = lst.status_id LEFT JOIN {users} uo ON t.opened_by = uo.user_id LEFT JOIN {users} ue ON t.last_edited_by = ue.user_id LEFT JOIN {users} uc ON t.closed_by = uc.user_id WHERE t.task_id = ?', array($task_id)); if (!$db->CountRows($get_details)) { return false; } if ($get_details = $db->FetchRow($get_details)) { $get_details += array('severity_name' => $get_details['task_severity'] == 0 ? '' : $fs->severities[$get_details['task_severity']]); $get_details += array('priority_name' => $get_details['task_priority'] == 0 ? '' : $fs->priorities[$get_details['task_priority']]); } $get_details['tags'] = Flyspray::getTags($task_id); $get_details['assigned_to'] = $get_details['assigned_to_name'] = array(); if ($assignees = Flyspray::GetAssignees($task_id, true)) { $get_details['assigned_to'] = $assignees[0]; $get_details['assigned_to_name'] = $assignees[1]; } $cache[$task_id] = $get_details; return $get_details; }
public function can_change_private($task) { return !$task['is_closed'] && ($this->perms('manage_project', $task['project_id']) || in_array($this->id, Flyspray::GetAssignees($task['task_id']))); }
/** * Adds a reminder to a task * @param integer $task_id * @param string $message * @param integer $how_often send a reminder every ~ seconds * @param integer $start_time time when the reminder starts * @param $user_id the user who is reminded. by default (null) all users assigned to the task are reminded. * @access public * @return bool * @version 1.0 */ public static function add_reminder($task_id, $message, $how_often, $start_time, $user_id = null) { global $user, $db; $task = Flyspray::GetTaskDetails($task_id); if (!$user->perms('manage_project', $task['project_id'])) { return false; } if (is_null($user_id)) { // Get all users assigned to a task $user_id = Flyspray::GetAssignees($task_id); } else { $user_id = array(Flyspray::ValidUserId($user_id)); if (!reset($user_id)) { return false; } } foreach ($user_id as $id) { $sql = $db->Replace('{reminders}', array('task_id' => $task_id, 'to_user_id' => $id, 'from_user_id' => $user->id, 'start_time' => $start_time, 'how_often' => $how_often, 'reminder_message' => $message), array('task_id', 'to_user_id', 'how_often', 'reminder_message')); if (!$sql) { // query has failed :( return false; } } // 2 = no record has found and was INSERT'ed correclty if (isset($sql) && $sql == 2) { Flyspray::logEvent($task_id, 17, $task_id); } return true; }
/** * Gets all information about a task (and caches information if wanted) * @param integer $task_id * @param bool $cache_enabled * @access public static * @return mixed an array with all taskdetails or false on failure */ function GetTaskDetails($task_id, $cache_enabled = false, $prefix = null) { global $db, $fs, $proj; static $cache = array(); $task_id = intval($task_id); if (isset($cache[$task_id . (string) $prefix]) && $cache_enabled) { return $cache[$task_id . (string) $prefix]; } if (!is_null($prefix) && $prefix != 'FS' && trim($prefix) != 'bug') { $where = 't.prefix_id = ? AND project_prefix = ?'; $params = array($task_id, trim($prefix)); } else { $where = 't.task_id = ?'; $params = array($task_id); } $task = $db->x->getRow('SELECT t.*, p.project_prefix, p.project_title, r.item_name AS resolution_name, uo.real_name AS opened_by_name, ue.real_name AS last_edited_by_name, uc.real_name AS closed_by_name FROM {tasks} t LEFT JOIN {list_items} r ON t.resolution_reason = r.list_item_id LEFT JOIN {users} uo ON t.opened_by = uo.user_id LEFT JOIN {users} ue ON t.last_edited_by = ue.user_id LEFT JOIN {users} uc ON t.closed_by = uc.user_id LEFT JOIN {projects} p ON t.project_id = p.project_id WHERE ' . $where, null, $params); if (!$task) { return false; } // Now add custom fields $sql = $db->x->getAll('SELECT field_value, field_name, f.field_id, li.item_name, lc.category_name, user_name FROM {field_values} fv LEFT JOIN {fields} f ON f.field_id = fv.field_id LEFT JOIN {list_items} li ON (f.list_id = li.list_id AND field_value = li.list_item_id) LEFT JOIN {list_category} lc ON (f.list_id = lc.list_id AND field_value = lc.category_id) LEFT JOIN {users} u ON (field_type = ? AND field_value = u.user_id) WHERE task_id = ?', null, array(FIELD_USER, $task['task_id'])); foreach ($sql as $row) { $task['field' . $row['field_id']] = $row['field_value']; $task['field' . $row['field_id'] . '_name'] = $row['user_name'] ? $row['user_name'] : ($row['item_name'] ? $row['item_name'] : $row['category_name']); } $task['assigned_to'] = $task['assigned_to_name'] = $task['assigned_to_uname'] = array(); if ($assignees = Flyspray::GetAssignees($task_id, true)) { $task['assigned_to'] = $assignees[0]; $task['assigned_to_name'] = $assignees[1]; $task['assigned_to_uname'] = $assignees[2]; } $cache[$task_id . (string) $prefix] = $task; return $task; }