function getMilestone() { if ($this->getMilestoneId() > 0 && !$this->milestone) { $this->milestone = ProjectMilestones::findById($this->getMilestoneId()); } return $this->milestone; }
/** * * @author Ignacio Vazquez - elpepe.uy@gmail.com * @param ProjectTask $object */ function addObject($object) { if ($this->hasObject($object)) { return; } if (!$object->isTemplate() && $object->canBeTemplate()) { // the object isn't a template but can be, create a template copy $copy = $object->copy(); $copy->setColumnValue('is_template', true); if ($copy instanceof ProjectTask) { // don't copy milestone and parent task $copy->setMilestoneId(0); $copy->setParentId(0); } $copy->save(); //Also copy members.. // $memberIds = json_decode(array_var($_POST, 'members')); // $controller = new ObjectController() ; // $controller->add_to_members($copy, $memberIds); // copy subtasks if ($copy instanceof ProjectTask) { ProjectTasks::copySubTasks($object, $copy, true); } else { if ($copy instanceof ProjectMilestone) { ProjectMilestones::copyTasks($object, $copy, true); } } // copy custom properties $copy->copyCustomPropertiesFrom($object); // copy linked objects $linked_objects = $object->getAllLinkedObjects(); if (is_array($linked_objects)) { foreach ($linked_objects as $lo) { $copy->linkObject($lo); } } // copy reminders $reminders = ObjectReminders::getByObject($object); foreach ($reminders as $reminder) { $copy_reminder = new ObjectReminder(); $copy_reminder->setContext($reminder->getContext()); $copy_reminder->setDate(EMPTY_DATETIME); $copy_reminder->setMinutesBefore($reminder->getMinutesBefore()); $copy_reminder->setObject($copy); $copy_reminder->setType($reminder->getType()); // $copy_reminder->setContactId($reminder->getContactId()); //TODO Feng 2 - No anda $copy_reminder->save(); } $template = $copy; } else { // the object is already a template or can't be one, use it as it is $template = $object; } $to = new TemplateObject(); $to->setObject($template); $to->setTemplate($this); $to->save(); return $template->getObjectId(); }
/** * Return all projects that this user is part of * * @access public * @param User $user * @param * @return array */ function getProjectsByUser(User $user, $additional_conditions = null, $additional_sort = null) { trace(__FILE__, "getProjectsByUser(user, {$additional_conditions}, {$additional_sort})"); $projects_table = Projects::instance()->getTableName(true); trace(__FILE__, "getProjectsByUser():1"); $project_users_table = ProjectUsers::instance()->getTableName(true); trace(__FILE__, "getProjectsByUser():2"); $project_milestones_table = ProjectMilestones::instance()->getTableName(true); trace(__FILE__, "getProjectsByUser():3"); $empty_datetime = DB::escape(EMPTY_DATETIME); $projects = array(); if (trim($additional_sort) == 'milestone') { $sql = "SELECT distinct {$projects_table}.* FROM {$projects_table}"; $sql .= " left outer join {$project_milestones_table} on {$project_milestones_table}.`project_id` = {$projects_table}.`id`"; $sql .= " inner join {$project_users_table} on {$projects_table}.`id` = {$project_users_table}.`project_id`"; $sql .= " where {$project_users_table}.`user_id` = " . DB::escape($user->getId()) . " and ({$project_milestones_table}.`completed_on` = {$empty_datetime} or isnull({$project_milestones_table}.`completed_on`))"; } else { $sql = "SELECT {$projects_table}.* FROM {$projects_table}, {$project_users_table} WHERE ({$projects_table}.`id` = {$project_users_table}.`project_id` AND {$project_users_table}.`user_id` = " . DB::escape($user->getId()) . ')'; } if (trim($additional_conditions) != '') { $sql .= " AND ({$additional_conditions})"; } // if if (trim($additional_sort) == 'priority') { $sql .= " ORDER BY isnull({$projects_table}.`priority`), {$projects_table}.`priority`, {$projects_table}.`name`"; } elseif (trim($additional_sort) == 'milestone') { $sql .= " ORDER BY isnull({$project_milestones_table}.`due_date`), {$project_milestones_table}.`due_date`, {$projects_table}.`name` "; } else { $sql .= " ORDER BY {$projects_table}.`name`"; } trace(__FILE__, "getProjectsByUser(): sql={$sql}"); $rows = DB::executeAll($sql); trace(__FILE__, "getProjectsByUser(): sql={$sql} ok"); if (is_array($rows)) { foreach ($rows as $row) { $projects[] = Projects::instance()->loadFromRow($row); } // foreach } // if return count($projects) ? $projects : null; }
/** * Return array of milestones that are assigned to specific user or his company * * @param User $user * @return array */ function getUsersMilestones(User $user) { $conditions = DB::prepareString('`project_id` = ? AND ((`assigned_to_user_id` = ? AND `assigned_to_company_id` = ?) OR (`assigned_to_user_id` = ? AND `assigned_to_company_id` = ?) OR (`assigned_to_user_id` = ? AND `assigned_to_company_id` = ?)) AND `completed_on` = ?', array($this->getId(), $user->getId(), $user->getCompanyId(), 0, $user->getCompanyId(), 0, 0, EMPTY_DATETIME)); if (!$user->isMemberOfOwnerCompany()) { $conditions .= DB::prepareString(' AND `is_private` = ?', array(0)); } // if return ProjectMilestones::findAll(array('conditions' => $conditions, 'order' => '`due_date`')); }
/** * Return manager instance * * @access protected * @param void * @return ProjectMilestones */ function manager() { if(!($this->manager instanceof ProjectMilestones)) $this->manager = ProjectMilestones::instance(); return $this->manager; } // manager
static function getMilestonesInfo($mid) { if (self::$info_cache == null) { self::$info_cache = array(); // completed $rows = DB::executeAll("select count(object_id) as row_count, milestone_id from " . TABLE_PREFIX . "project_tasks use index (completed_on) where completed_on > '0000-00-00' group by milestone_id;"); if (is_array($rows)) { foreach ($rows as $row) { if (array_var($row, 'milestone_id') > 0) { if (!isset(self::$info_cache[$row['milestone_id']])) { self::$info_cache[$row['milestone_id']] = array(); } self::$info_cache[$row['milestone_id']]['tc'] = array_var($row, 'row_count'); } } } // all milestone tasks $rows = DB::executeAll("select count(object_id) as row_count, milestone_id from " . TABLE_PREFIX . "project_tasks use index (milestone_id) group by milestone_id;"); if (is_array($rows)) { foreach ($rows as $row) { if (array_var($row, 'milestone_id') > 0) { if (!isset(self::$info_cache[$row['milestone_id']])) { self::$info_cache[$row['milestone_id']] = array(); } self::$info_cache[$row['milestone_id']]['tnum'] = array_var($row, 'row_count'); } } } } return array_var(self::$info_cache, $mid); }
$timeformat = 'g:i A'; } echo stylesheet_tag('event/day.css'); $today = DateTimeValueLib::now(); $today->add('h', logged_user()->getTimezone()); $currentday = $today->format("j"); $currentmonth = $today->format("n"); $currentyear = $today->format("Y"); $drawHourLine = $day == $currentday && $month == $currentmonth && $year == $currentyear; $dtv = DateTimeValueLib::make(0, 0, 0, $month, $day, $year); $result = ProjectEvents::getDayProjectEvents($dtv, $tags, active_project(), $user_filter, $status_filter); if (!$result) { $result = array(); } $alldayevents = array(); $milestones = ProjectMilestones::getRangeMilestonesByUser($dtv, $dtv, $user_filter != -1 ? $user : null, $tags, active_project()); $tasks = ProjectTasks::getRangeTasksByUser($dtv, $dtv, $user_filter != -1 ? $user : null, $tags, active_project()); $birthdays = Contacts::instance()->getRangeContactsByBirthday($dtv, $dtv); foreach ($result as $key => $event) { if ($event->getTypeId() > 1) { $alldayevents[] = $event; unset($result[$key]); } } if ($milestones) { $alldayevents = array_merge($alldayevents, $milestones); } if ($tasks) { $tmp_tasks = array(); $dtv_end = new DateTimeValue($dtv->getTimestamp() + 60 * 60 * 24); foreach ($tasks as $task) {
function new_list_tasks() { //load config options into cache for better performance load_user_config_options_by_category_name('task panel'); // get query parameters, save user preferences if necessary $status = array_var($_GET, 'status', null); if (is_null($status) || $status == '') { $status = user_config_option('task panel status', 2); } else { if (user_config_option('task panel status') != $status) { set_user_config_option('task panel status', $status, logged_user()->getId()); } } $previous_filter = user_config_option('task panel filter', 'no_filter'); $filter = array_var($_GET, 'filter'); if (is_null($filter) || $filter == '') { $filter = $previous_filter; } else { if ($previous_filter != $filter) { set_user_config_option('task panel filter', $filter, logged_user()->getId()); } } if ($filter != 'no_filter') { $filter_value = array_var($_GET, 'fval'); if (is_null($filter_value) || $filter_value == '') { $filter_value = user_config_option('task panel filter value', null, logged_user()->getId()); set_user_config_option('task panel filter value', $filter_value, logged_user()->getId()); $filter = $previous_filter; set_user_config_option('task panel filter', $filter, logged_user()->getId()); } else { if (user_config_option('task panel filter value') != $filter_value) { set_user_config_option('task panel filter value', $filter_value, logged_user()->getId()); } } } $isJson = array_var($_GET, 'isJson', false); if ($isJson) { ajx_current("empty"); } $template_condition = "`is_template` = 0 "; //Get the task query conditions $task_filter_condition = ""; switch ($filter) { case 'assigned_to': $assigned_to = $filter_value; if ($assigned_to > 0) { $task_filter_condition = " AND (`assigned_to_contact_id` = " . $assigned_to . ") "; } else { if ($assigned_to == -1) { $task_filter_condition = " AND `assigned_to_contact_id` = 0"; } } break; case 'assigned_by': if ($filter_value != 0) { $task_filter_condition = " AND `assigned_by_id` = " . $filter_value . " "; } break; case 'created_by': if ($filter_value != 0) { $task_filter_condition = " AND `created_by_id` = " . $filter_value . " "; } break; case 'completed_by': if ($filter_value != 0) { $task_filter_condition = " AND `completed_by_id` = " . $filter_value . " "; } break; case 'milestone': $task_filter_condition = " AND `milestone_id` = " . $filter_value . " "; break; case 'priority': $task_filter_condition = " AND `priority` = " . $filter_value . " "; break; case 'subtype': if ($filter_value != 0) { $task_filter_condition = " AND `object_subtype` = " . $filter_value . " "; } break; case 'no_filter': $task_filter_condition = ""; break; default: flash_error(lang('task filter criteria not recognised', $filter)); } $task_status_condition = ""; $now = DateTimeValueLib::now()->format('Y-m-j 00:00:00'); switch ($status) { case 0: // Incomplete tasks $task_status_condition = " AND `completed_on` = " . DB::escape(EMPTY_DATETIME); break; case 1: // Complete tasks $task_status_condition = " AND `completed_on` > " . DB::escape(EMPTY_DATETIME); break; case 10: // Active tasks $task_status_condition = " AND `completed_on` = " . DB::escape(EMPTY_DATETIME) . " AND `start_date` <= '{$now}'"; break; case 11: // Overdue tasks $task_status_condition = " AND `completed_on` = " . DB::escape(EMPTY_DATETIME) . " AND `due_date` < '{$now}'"; break; case 12: // Today tasks $task_status_condition = " AND `completed_on` = " . DB::escape(EMPTY_DATETIME) . " AND `due_date` = '{$now}'"; break; case 13: // Today + Overdue tasks $task_status_condition = " AND `completed_on` = " . DB::escape(EMPTY_DATETIME) . " AND `due_date` <= '{$now}'"; break; case 14: // Today + Overdue tasks $task_status_condition = " AND `completed_on` = " . DB::escape(EMPTY_DATETIME) . " AND `due_date` <= '{$now}'"; break; case 20: // Actives task by current user $task_status_condition = " AND `completed_on` = " . DB::escape(EMPTY_DATETIME) . " AND `start_date` <= '{$now}' AND `assigned_to_contact_id` = " . logged_user()->getId(); break; case 21: // Subscribed tasks by current user $res20 = DB::execute("SELECT object_id FROM " . TABLE_PREFIX . "object_subscriptions WHERE `contact_id` = " . logged_user()->getId()); $subs_rows = $res20->fetchAll($res20); foreach ($subs_rows as $row) { $subs[] = $row['object_id']; } unset($res20, $subs_rows, $row); $task_status_condition = " AND `completed_on` = " . DB::escape(EMPTY_DATETIME) . " AND `id` IN(" . implode(',', $subs) . ")"; break; case 2: // All tasks break; default: throw new Exception('Task status "' . $status . '" not recognised'); } $conditions = "AND {$template_condition} {$task_filter_condition} {$task_status_condition}"; //Now get the tasks //$tasks = ProjectTasks::getContentObjects(active_context(), ObjectTypes::findById(ProjectTasks::instance()->getObjectTypeId()), null, null, $conditions,null)->objects; $tasks = ProjectTasks::instance()->listing(array("extra_conditions" => $conditions, "start" => 0, "limit" => 501, "count_results" => false))->objects; $pendingstr = $status == 0 ? " AND `completed_on` = " . DB::escape(EMPTY_DATETIME) . " " : ""; $milestone_conditions = " AND `is_template` = false " . $pendingstr; //Find all internal milestones for these tasks //$internalMilestones = ProjectMilestones::getContentObjects(active_context(), ObjectTypes::findById(ProjectMilestones::instance()->getObjectTypeId()), null, null, $milestone_conditions,null)->objects; $internalMilestones = ProjectMilestones::instance()->listing(array("extra_conditions" => $milestone_conditions))->objects; //Find all external milestones for these tasks, external milestones are the ones that belong to a parent member and have tasks in the current member $milestone_ids = array(); if ($tasks) { foreach ($tasks as $task) { if ($task->getMilestoneId() != 0) { $milestone_ids[$task->getMilestoneId()] = $task->getMilestoneId(); } } } $int_milestone_ids = array(); foreach ($internalMilestones as $milestone) { $int_milestone_ids[] = $milestone->getId(); } $milestone_ids = array_diff($milestone_ids, $int_milestone_ids); if (count($milestone_ids) == 0) { $milestone_ids[] = 0; } $ext_milestone_conditions = " `is_template` = false " . $pendingstr . ' AND `object_id` IN (' . implode(',', $milestone_ids) . ')'; $externalMilestones = ProjectMilestones::findAll(array('conditions' => $ext_milestone_conditions)); // Get Users Info $users = allowed_users_in_context(ProjectTasks::instance()->getObjectTypeId(), active_context(), ACCESS_LEVEL_READ); $allUsers = Contacts::getAllUsers(); $user_ids = array(-1); foreach ($users as $user) { $user_ids[] = $user->getId(); } // only companies with users $companies = Contacts::findAll(array("conditions" => "e.is_company = 1", "join" => array("table" => Contacts::instance()->getTableName(), "jt_field" => "object_id", "j_sub_q" => "SELECT xx.object_id FROM " . Contacts::instance()->getTableName(true) . " xx WHERE \n\t\t\t\t\txx.is_company=0 AND xx.company_id = e.object_id AND xx.object_id IN (" . implode(",", $user_ids) . ") LIMIT 1"))); tpl_assign('tasks', $tasks); if (config_option('use tasks dependencies')) { $dependency_count = array(); foreach ($tasks as $task) { $previous = 0; $ptasks = ProjectTaskDependencies::getDependenciesForTask($task->getId()); foreach ($ptasks as $pdep) { $ptask = ProjectTasks::findById($pdep->getPreviousTaskId()); if ($ptask instanceof ProjectTask && !$ptask->isCompleted()) { $previous++; } } $dependants = ProjectTaskDependencies::getDependantsForTask($task->getId()); $dep_csv = ""; foreach ($dependants as $dep) { $dep_csv .= ($dep_csv == "" ? "" : ",") . $dep->getTaskId(); } $dependency_count[] = array('id' => $task->getId(), 'count' => $previous, 'dependants' => $dep_csv); } tpl_assign('dependency_count', $dependency_count); } if (!$isJson) { $all_templates = COTemplates::findAll(array('conditions' => '`trashed_by_id` = 0 AND `archived_by_id` = 0')); tpl_assign('all_templates', $all_templates); if (user_config_option('task_display_limit') > 0 && count($tasks) > user_config_option('task_display_limit')) { tpl_assign('displayTooManyTasks', true); array_pop($tasks); } tpl_assign('object_subtypes', array()); tpl_assign('internalMilestones', $internalMilestones); tpl_assign('externalMilestones', $externalMilestones); tpl_assign('users', $users); tpl_assign('allUsers', $allUsers); tpl_assign('companies', $companies); $userPref = array(); $userPref = array('filterValue' => isset($filter_value) ? $filter_value : '', 'filter' => $filter, 'status' => $status, 'showWorkspaces' => user_config_option('tasksShowWorkspaces', 1), 'showTime' => user_config_option('tasksShowTime'), 'showDates' => user_config_option('tasksShowDates'), 'showTags' => user_config_option('tasksShowTags', 0), 'showEmptyMilestones' => user_config_option('tasksShowEmptyMilestones', 1), 'showTimeEstimates' => user_config_option('tasksShowTimeEstimates', 1), 'groupBy' => user_config_option('tasksGroupBy', 'milestone'), 'orderBy' => user_config_option('tasksOrderBy', 'priority'), 'defaultNotifyValue' => user_config_option('can notify from quick add')); hook::fire('tasks_user_preferences', null, $userPref); tpl_assign('userPreferences', $userPref); ajx_set_no_toolbar(true); } }
static function getOverdueAndUpcomingObjects($limit = null) { $conditions_tasks = " AND is_template = 0 AND `e`.`completed_by_id` = 0 AND `e`.`due_date` > 0"; $conditions_milestones = " AND is_template = 0 AND `e`.`completed_by_id` = 0 AND `e`.`due_date` > 0"; if (!SystemPermissions::userHasSystemPermission(logged_user(), 'can_see_assigned_to_other_tasks')) { $conditions_tasks .= " AND assigned_to_contact_id = ".logged_user()->getId(); } $tasks_result = self::instance()->listing(array( "limit" => $limit, "extra_conditions" => $conditions_tasks, "order"=> array('due_date', 'priority'), "order_dir" => "ASC" )); $tasks = $tasks_result->objects; $milestones_result = ProjectMilestones::instance()->listing(array( "limit" => $limit, "extra_conditions" => $conditions_milestones, "order" => array('due_date'), "order_dir" => "ASC" )); $milestones = $milestones_result->objects; $ordered = array(); foreach ($tasks as $task) { /* @var $task ProjectTask */ if (!$task->isCompleted() && $task->getDueDate() instanceof DateTimeValue ) { if (!isset($ordered[$task->getDueDate()->getTimestamp()])){ $ordered[$task->getDueDate()->getTimestamp()] = array(); } $ordered[$task->getDueDate()->getTimestamp()][] = $task; } } foreach ($milestones as $milestone) { if (!isset($ordered[$milestone->getDueDate()->getTimestamp()])) { $ordered[$milestone->getDueDate()->getTimestamp()] = array(); } $ordered[$milestone->getDueDate()->getTimestamp()][] = $milestone; } ksort($ordered, SORT_NUMERIC); $ordered_flat = array(); foreach ($ordered as $k => $values) { foreach ($values as $v) $ordered_flat[] = $v; } return $ordered_flat; }
function new_list_tasks() { //load config options into cache for better performance load_user_config_options_by_category_name('task panel'); $isJson = array_var($_GET, 'isJson', false); if ($isJson) { ajx_current("empty"); } $request_conditions = $this->get_tasks_request_conditions(); $conditions = $request_conditions['conditions']; $filter_value = $request_conditions['filterValue']; $filter = $request_conditions['filter']; $status = $request_conditions['status']; $tasks = array(); $pendingstr = $status == 0 ? " AND `e`.`completed_on` = " . DB::escape(EMPTY_DATETIME) . " " : ""; $milestone_conditions = " AND `is_template` = false " . $pendingstr; //Find all internal milestones for these tasks $internalMilestones = ProjectMilestones::instance()->listing(array("extra_conditions" => $milestone_conditions))->objects; //Find all external milestones for these tasks, external milestones are the ones that belong to a parent member and have tasks in the current member $milestone_ids = array(); $task_ids = array(); if ($tasks) { foreach ($tasks as $task) { $task_ids[] = $task['id']; if ($task['milestone_id'] != 0) { $milestone_ids[$task['milestone_id']] = $task['milestone_id']; } } // generate request cache ObjectMembers::instance()->getCachedObjectMembers(0, $task_ids); ProjectTasks::instance()->findByRelatedCached(0, $task_ids); } $cp_values = array(); if (count($task_ids) > 0) { $cp_rows = DB::executeAll("SELECT * FROM " . TABLE_PREFIX . "custom_property_values WHERE object_id IN (" . implode(',', $task_ids) . ")"); if (is_array($cp_rows)) { foreach ($cp_rows as $row) { if (!isset($cp_values[$row['object_id']])) { $cp_values[$row['object_id']] = array(); } if (!isset($cp_values[$row['object_id']][$row['custom_property_id']])) { $cp_values[$row['object_id']][$row['custom_property_id']] = array(); } $cp_values[$row['object_id']][$row['custom_property_id']][] = $row['value']; } } } tpl_assign('cp_values', $cp_values); $int_milestone_ids = array(); foreach ($internalMilestones as $milestone) { $int_milestone_ids[] = $milestone->getId(); } $milestone_ids = array_diff($milestone_ids, $int_milestone_ids); if (count($milestone_ids) == 0) { $milestone_ids[] = 0; } $ext_milestone_conditions = " `is_template` = false " . $pendingstr . ' AND `object_id` IN (' . implode(',', $milestone_ids) . ')'; $externalMilestones = ProjectMilestones::findAll(array('conditions' => $ext_milestone_conditions)); // Get Users Info if (logged_user()->isGuest()) { $users = array(logged_user()); } else { $users = allowed_users_in_context(ProjectTasks::instance()->getObjectTypeId(), active_context(), ACCESS_LEVEL_READ, '', true); } $allUsers = Contacts::getAllUsers(null, true); $user_ids = array(-1); foreach ($allUsers as $user) { $user_ids[] = $user->getId(); } // only companies with users $companies = Contacts::findAll(array("conditions" => "e.is_company = 1", "join" => array("table" => Contacts::instance()->getTableName(), "jt_field" => "object_id", "j_sub_q" => "SELECT xx.object_id FROM " . Contacts::instance()->getTableName(true) . " xx WHERE \r\n\t\t\t\t\txx.is_company=0 AND xx.company_id = e.object_id AND xx.object_id IN (" . implode(",", $user_ids) . ") LIMIT 1"))); tpl_assign('tasks', $tasks); if (!$isJson) { $all_templates = COTemplates::findAll(array('conditions' => '`trashed_by_id` = 0 AND `archived_by_id` = 0')); tpl_assign('all_templates', $all_templates); if (user_config_option('task_display_limit') > 0 && count($tasks) > user_config_option('task_display_limit')) { tpl_assign('displayTooManyTasks', true); array_pop($tasks); } tpl_assign('object_subtypes', array()); tpl_assign('internalMilestones', $internalMilestones); tpl_assign('externalMilestones', $externalMilestones); tpl_assign('users', $users); tpl_assign('allUsers', $allUsers); tpl_assign('companies', $companies); if (strtotime(user_config_option('tasksDateStart'))) { //this return null if date is 0000-00-00 00:00:00 $dateStart = new DateTime('@' . strtotime(user_config_option('tasksDateStart'))); $dateStart = $dateStart->format(user_config_option('date_format')); } else { $dateStart = ''; } if (strtotime(user_config_option('tasksDateEnd'))) { //this return null if date is 0000-00-00 00:00:00 $dateEnd = new DateTime('@' . strtotime(user_config_option('tasksDateEnd'))); $dateEnd = $dateEnd->format(user_config_option('date_format')); } else { $dateEnd = ''; } $userPref = array(); $showDimensionCols = array_map('intval', explode(',', user_config_option('tasksShowDimensionCols'))); $userPref = array('filterValue' => isset($filter_value) ? $filter_value : '', 'filter' => $filter, 'dateStart' => $dateStart, 'dateEnd' => $dateEnd, 'status' => $status, 'showTime' => user_config_option('tasksShowTime'), 'showDates' => user_config_option('tasksShowDates'), 'showStartDates' => user_config_option('tasksShowStartDates'), 'showEndDates' => user_config_option('tasksShowEndDates'), 'showBy' => user_config_option('tasksShowAssignedBy'), 'showClassification' => user_config_option('tasksShowClassification'), 'showSubtasksStructure' => user_config_option('tasksShowSubtasksStructure'), 'showTags' => user_config_option('tasksShowTags', 0), 'showEmptyMilestones' => user_config_option('tasksShowEmptyMilestones', 1), 'showTimeEstimates' => user_config_option('tasksShowTimeEstimates', 1), 'showTimePending' => user_config_option('tasksShowTimePending', 1), 'showTimeWorked' => user_config_option('tasksShowTimeWorked', 1), 'showPercentCompletedBar' => user_config_option('tasksShowPercentCompletedBar', 1), 'showQuickEdit' => user_config_option('tasksShowQuickEdit', 1), 'showQuickComplete' => user_config_option('tasksShowQuickComplete', 1), 'showQuickComment' => user_config_option('tasksShowQuickComment', 1), 'showQuickAddSubTasks' => user_config_option('tasksShowQuickAddSubTasks', 1), 'showDimensionCols' => $showDimensionCols, 'groupBy' => user_config_option('tasksGroupBy'), 'orderBy' => user_config_option('tasksOrderBy'), 'previousPendingTasks' => user_config_option('tasksPreviousPendingTasks', 1), 'defaultNotifyValue' => user_config_option('can notify from quick add')); hook::fire('tasks_user_preferences', null, $userPref); tpl_assign('userPreferences', $userPref); tpl_assign('userPermissions', array('can_add' => ProjectTask::canAdd(logged_user(), active_context()) ? 1 : 0)); ajx_set_no_toolbar(true); } }
private function get_ext_values($field, $manager = null) { $values = array(array('id' => '', 'name' => '-- ' . lang('select') . ' --')); if ($field == 'contact_id' || $field == 'created_by_id' || $field == 'updated_by_id' || $field == 'assigned_to_contact_id' || $field == 'completed_by_id' || $field == 'approved_by_id') { $users = Contacts::getAllUsers(); foreach ($users as $user) { $values[] = array('id' => $user->getId(), 'name' => $user->getObjectName()); } } else { if ($field == 'milestone_id') { $milestones = ProjectMilestones::getActiveMilestonesByUser(logged_user()); foreach ($milestones as $milestone) { $values[] = array('id' => $milestone->getId(), 'name' => $milestone->getObjectName()); } /*} else if($field == 'object_subtype'){ $object_types = ProjectCoTypes::findAll(array('conditions' => (!is_null($manager) ? "`object_manager`='$manager'" : ""))); foreach($object_types as $object_type){ $values[] = array('id' => $object_type->getId(), 'name' => $object_type->getName()); }*/ } } return $values; }
/** * Returns the milestones included in the present workspace and all of its parents. This is because tasks from a particular workspace * can only be assigned to milestones from that workspace and from any of its parents. */ function get_assignable_milestones() { ajx_current("empty"); $ms = ProjectMilestones::findAll(); if ($ms === null) $ms = array(); $ms_info = array(); foreach ($ms as $milestone) { $ms_info[] = $milestone->getArrayInfo(); } ajx_extra_data(array('milestones' => $ms_info)); }
function instantiate() { $id = get_id(); $template = COTemplates::findById($id); if (!$template instanceof COTemplate) { flash_error(lang("template dnx")); ajx_current("empty"); return; } $parameters = TemplateParameters::getParametersByTemplate($id); $parameterValues = array_var($_POST, 'parameterValues'); if (count($parameters) > 0 && !isset($parameterValues)) { ajx_current("back"); return; } $objects = $template->getObjects(); foreach ($objects as $object) { if (!$object instanceof ProjectDataObject) { continue; } // copy object $copy = $object->copy(); if ($copy->columnExists('is_template')) { $copy->setColumnValue('is_template', false); } if ($copy instanceof ProjectTask) { // don't copy parent task and milestone $copy->setMilestoneId(0); $copy->setParentId(0); } $copy->save(); $wsId = array_var($_POST, 'project_id', active_or_personal_project()->getId()); // if specified, set workspace $workspace = Projects::findById($wsId); if (!$workspace instanceof Project) { $workspace = active_or_personal_project(); } $copy->addToWorkspace($workspace); // add object tags and specified tags $tags = implode(',', $object->getTagNames()); $copy->setTagsFromCSV($tags . "," . array_var($_POST, 'tags')); // copy linked objects $copy->copyLinkedObjectsFrom($object); // copy subtasks if applicable if ($copy instanceof ProjectTask) { ProjectTasks::copySubTasks($object, $copy, false); $manager = new ProjectTask(); } else { if ($copy instanceof ProjectMilestone) { ProjectMilestones::copyTasks($object, $copy, false); $manager = new ProjectMilestone(); } } // copy custom properties $copy->copyCustomPropertiesFrom($object); // set property values as defined in template $objProp = TemplateObjectProperties::getPropertiesByTemplateObject($id, $object->getId()); foreach ($objProp as $property) { $propName = $property->getProperty(); $value = $property->getValue(); if ($manager->getColumnType($propName) == DATA_TYPE_STRING) { if (is_array($parameterValues)) { foreach ($parameterValues as $param => $val) { $value = str_replace('{' . $param . '}', $val, $value); } } } else { if ($manager->getColumnType($propName) == DATA_TYPE_DATE || $manager->getColumnType($propName) == DATA_TYPE_DATETIME) { $operator = '+'; if (strpos($value, '+') === false) { $operator = '-'; } $opPos = strpos($value, $operator); if ($opPos !== false) { $dateParam = substr($value, 1, strpos($value, '}') - 1); $dateUnit = substr($value, strlen($value) - 1); // d, w or m (for days, weeks or months) if ($dateUnit == 'm') { $dateUnit = 'M'; // make month unit uppercase to call DateTimeValue::add with correct parameter } $dateNum = (int) substr($value, strpos($value, $operator), strlen($value) - 2); $date = $parameterValues[$dateParam]; $date = DateTimeValueLib::dateFromFormatAndString(user_config_option('date_format'), $date); $value = $date->add($dateUnit, $dateNum); } } else { if ($manager->getColumnType($propName) == DATA_TYPE_INTEGER) { if (is_array($parameterValues)) { foreach ($parameterValues as $param => $val) { $value = str_replace('{' . $param . '}', $val, $value); } } } } } if ($value != '') { $copy->setColumnValue($propName, $value); $copy->save(); } } //copy assigned to company if applicable if ($copy->getAssignedToUserId() != 0) { $copy->setAssignedToCompanyId($copy->getAssignedTo()->getCompanyId()); $copy->save(); } // copy reminders $reminders = ObjectReminders::getByObject($object); foreach ($reminders as $reminder) { $copy_reminder = new ObjectReminder(); $copy_reminder->setContext($reminder->getContext()); $reminder_date = $copy->getColumnValue($reminder->getContext()); if ($reminder_date instanceof DateTimeValue) { $reminder_date = new DateTimeValue($reminder_date->getTimestamp()); $reminder_date->add('m', -$reminder->getMinutesBefore()); } $copy_reminder->setDate($reminder_date); $copy_reminder->setMinutesBefore($reminder->getMinutesBefore()); $copy_reminder->setObject($copy); $copy_reminder->setType($reminder->getType()); $copy_reminder->setUserId($reminder->getUserId()); $copy_reminder->save(); } } if (is_array($parameters) && count($parameters) > 0) { ajx_current("back"); } else { ajx_current("reload"); } }
/** * Call back function for milestone link * * @param mixed $matches * @return */ function replace_milestone_link_callback($matches) { if (count($matches) < 2) { return null; } // if if (!logged_user()->isMemberOfOwnerCompany()) { $object = ProjectMilestones::findOne(array('conditions' => array('`id` = ? AND `project_id` = ? AND `is_private` = 0 ', $matches[1], active_project()->getId()))); } else { $object = ProjectMilestones::findOne(array('conditions' => array('`id` = ? AND `project_id` = ?', $matches[1], active_project()->getId()))); } // if if (!$object instanceof ProjectMilestone) { return '<del>' . lang('invalid reference') . '</del>'; } else { return '<a href="' . $object->getViewUrl() . '">' . $object->getName() . '</a>'; } // if }
function getExternalColumnValue($field, $id, $manager = null){ $value = ''; if($field == 'user_id' || $field == 'contact_id' || $field == 'created_by_id' || $field == 'updated_by_id' || $field == 'assigned_to_contact_id' || $field == 'completed_by_id'|| $field == 'approved_by_id'){ $contact = Contacts::findById($id); if($contact instanceof Contact) $value = $contact->getObjectName(); } else if($field == 'milestone_id'){ $milestone = ProjectMilestones::findById($id); if($milestone instanceof ProjectMilestone) $value = $milestone->getObjectName(); } else if($field == 'company_id'){ $company = Contacts::findById($id); if($company instanceof Contact && $company->getIsCompany()) $value = $company->getObjectName(); } else if ($manager instanceof ContentDataObjects) { $value = $manager->getExternalColumnValue($field, $id); } return $value; }
/** * Show calendar for specific project * * @param void * @return null */ function project_ical() { $this->setLayout('ical'); $user = $this->loginUserByToken(); if (!$user instanceof User) { header('HTTP/1.0 404 Not Found'); die; } // if $project = Projects::findById(array_var($_GET, 'project')); if (!$project instanceof Project) { header('HTTP/1.0 404 Not Found'); die; } // if if (!$user->isProjectUser($project)) { header('HTTP/1.0 404 Not Found'); die; } // if $this->renderCalendar($user, lang('project calendar', $project->getName()), ProjectMilestones::getActiveMilestonesByUserAndProject($user, $project)); }
/** * This function will return paginated result. Result is an array where first element is * array of returned object and second populated pagination object that can be used for * obtaining and rendering pagination data using various helpers. * * Items and pagination array vars are indexed with 0 for items and 1 for pagination * because you can't use associative indexing with list() construct * * @access public * @param array $arguments Query argumens (@see find()) Limit and offset are ignored! * @param integer $items_per_page Number of items per page * @param integer $current_page Current page number * @return array */ function paginate($arguments = null, $items_per_page = 10, $current_page = 1) { if (isset($this) && instance_of($this, 'ProjectMilestones')) { return parent::paginate($arguments, $items_per_page, $current_page); } else { return ProjectMilestones::instance()->paginate($arguments, $items_per_page, $current_page); //$instance =& ProjectMilestones::instance(); //return $instance->paginate($arguments, $items_per_page, $current_page); } // if }
/** * Return manager instance * * @access protected * @param void * @return ProjectMilestones */ function manager() { if (!$this->manager instanceof ProjectMilestones) { $this->manager = ProjectMilestones::instance(); } return $this->manager; }
private function get_ext_values($field, $manager = null) { $values = array(array('id' => '', 'name' => '-- ' . lang('select') . ' --')); if ($field == 'company_id' || $field == 'assigned_to_company_id') { $companies = Companies::getVisibleCompanies(logged_user()); foreach ($companies as $company) { $values[] = array('id' => $company->getId(), 'name' => $company->getName()); } } else { if ($field == 'user_id' || $field == 'created_by_id' || $field == 'updated_by_id' || $field == 'assigned_to_user_id' || $field == 'completed_by_id') { $users = Users::getVisibleUsers(logged_user()); foreach ($users as $user) { $values[] = array('id' => $user->getId(), 'name' => $user->getDisplayName()); } } else { if ($field == 'milestone_id') { $milestones = ProjectMilestones::getActiveMilestonesByUser(logged_user()); foreach ($milestones as $milestone) { $values[] = array('id' => $milestone->getId(), 'name' => $milestone->getName()); } } else { if ($field == 'workspace') { $workspaces = logged_user()->getWorkspaces(false, 0); foreach ($workspaces as $ws) { $values[] = array('id' => $ws->getId(), 'name' => $ws->getName()); } } else { if ($field == 'tag') { $tags = Tags::getTagNames(); foreach ($tags as $tag) { $values[] = array('id' => $tag['name'], 'name' => $tag['name']); } } else { if ($field == 'object_subtype') { $object_types = ProjectCoTypes::findAll(array('conditions' => !is_null($manager) ? "`object_manager`='{$manager}'" : "")); foreach ($object_types as $object_type) { $values[] = array('id' => $object_type->getId(), 'name' => $object_type->getName()); } } } } } } } return $values; }
function new_list_tasks() { //load config options into cache for better performance load_user_config_options_by_category_name('task panel'); // get query parameters, save user preferences if necessary $status = array_var($_GET, 'status', null); if (is_null($status) || $status == '') { $status = user_config_option('task panel status', 2); } else { if (user_config_option('task panel status') != $status) { set_user_config_option('task panel status', $status, logged_user()->getId()); } } $previous_filter = user_config_option('task panel filter', 'assigned_to'); $filter = array_var($_GET, 'filter'); if (is_null($filter) || $filter == '') { $filter = user_config_option('task panel filter', 'assigned_to'); } else { if (user_config_option('task panel filter') != $filter) { set_user_config_option('task panel filter', $filter, logged_user()->getId()); } } if ($filter != 'no_filter') { $filter_value = array_var($_GET, 'fval'); if (is_null($filter_value) || $filter_value == '') { $filter_value = user_config_option('task panel filter value', logged_user()->getCompanyId() . ':' . logged_user()->getId()); set_user_config_option('task panel filter value', $filter_value, logged_user()->getId()); $filter = $previous_filter; set_user_config_option('task panel filter', $filter, logged_user()->getId()); } else { if (user_config_option('task panel filter value') != $filter_value) { set_user_config_option('task panel filter value', $filter_value, logged_user()->getId()); } } } $isJson = array_var($_GET, 'isJson', false); if ($isJson) { ajx_current("empty"); } $project = active_project(); $tag = active_tag(); $template_condition = "`is_template` = 0 "; //Get the task query conditions $task_filter_condition = ""; switch ($filter) { case 'assigned_to': $assigned_to = explode(':', $filter_value); $assigned_to_user = array_var($assigned_to, 1, 0); $assigned_to_company = array_var($assigned_to, 0, 0); if ($assigned_to_user > 0) { $task_filter_condition = " AND (`assigned_to_user_id` = " . $assigned_to_user . " OR (`assigned_to_company_id` = " . $assigned_to_company . " AND `assigned_to_user_id` = 0)) "; } else { if ($assigned_to_company > 0) { $task_filter_condition = " AND `assigned_to_company_id` = " . $assigned_to_company . " AND `assigned_to_user_id` = 0"; } else { if ($assigned_to_company == -1 && $assigned_to_user == -1) { $task_filter_condition = " AND `assigned_to_company_id` = 0 AND `assigned_to_user_id` = 0 "; } } } break; case 'assigned_by': if ($filter_value != 0) { $task_filter_condition = " AND `assigned_by_id` = " . $filter_value . " "; } break; case 'created_by': if ($filter_value != 0) { $task_filter_condition = " AND `created_by_id` = " . $filter_value . " "; } break; case 'completed_by': if ($filter_value != 0) { $task_filter_condition = " AND `completed_by_id` = " . $filter_value . " "; } break; case 'milestone': $task_filter_condition = " AND `milestone_id` = " . $filter_value . " "; break; case 'priority': $task_filter_condition = " AND `priority` = " . $filter_value . " "; break; case 'subtype': if ($filter_value != 0) { $task_filter_condition = " AND `object_subtype` = " . $filter_value . " "; } break; case 'no_filter': $task_filter_condition = ""; break; default: flash_error(lang('task filter criteria not recognised', $filter)); } if ($project instanceof Project) { $pids = $project->getAllSubWorkspacesQuery(true); $projectstr = " AND " . ProjectTasks::getWorkspaceString($pids); } else { $pids = ""; $projectstr = ""; } $permissions = " AND " . permissions_sql_for_listings(ProjectTasks::instance(), ACCESS_LEVEL_READ, logged_user()); $task_status_condition = ""; switch ($status) { case 0: // Incomplete tasks $task_status_condition = " AND `completed_on` = " . DB::escape(EMPTY_DATETIME); break; case 1: // Complete tasks $task_status_condition = " AND `completed_on` > " . DB::escape(EMPTY_DATETIME); break; case 10: // Active tasks $now = date('Y-m-j 00:00:00'); $task_status_condition = " AND `completed_on` = " . DB::escape(EMPTY_DATETIME) . " AND `start_date` <= '{$now}'"; break; case 11: // Overdue tasks $now = date('Y-m-j 00:00:00'); $task_status_condition = " AND `completed_on` = " . DB::escape(EMPTY_DATETIME) . " AND `due_date` < '{$now}'"; break; case 12: // Today tasks $now = date('Y-m-j 00:00:00'); $task_status_condition = " AND `completed_on` = " . DB::escape(EMPTY_DATETIME) . " AND `due_date` = '{$now}'"; break; case 13: // Today + Overdue tasks $now = date('Y-m-j 00:00:00'); $task_status_condition = " AND `completed_on` = " . DB::escape(EMPTY_DATETIME) . " AND `due_date` <= '{$now}'"; break; case 14: // Today + Overdue tasks $now = date('Y-m-j 00:00:00'); $task_status_condition = " AND `completed_on` = " . DB::escape(EMPTY_DATETIME) . " AND `due_date` <= '{$now}'"; break; case 20: // Actives task by current user $now = date('Y-m-j 00:00:00'); $task_status_condition = " AND `completed_on` = " . DB::escape(EMPTY_DATETIME) . " AND `start_date` <= '{$now}' AND `assigned_to_user_id` = " . logged_user()->getId(); break; case 21: // Subscribed tasks by current user $res20 = DB::execute("SELECT object_id FROM " . TABLE_PREFIX . "object_subscriptions WHERE `object_manager` LIKE 'ProjectTasks' AND `user_id` = " . logged_user()->getId()); $subs_rows = $res20->fetchAll($res20); foreach ($subs_rows as $row) { $subs[] = $row['object_id']; } unset($res20, $subs_rows, $row); $now = date('Y-m-j 00:00:00'); $task_status_condition = " AND `completed_on` = " . DB::escape(EMPTY_DATETIME) . " AND `id` IN(" . implode(',', $subs) . ")"; break; case 2: // All tasks break; default: throw new Exception('Task status "' . $status . '" not recognised'); } if (!$tag) { $tagstr = ""; } else { $tagstr = " AND (select count(*) from " . TABLE_PREFIX . "tags where " . TABLE_PREFIX . "project_tasks.id = " . TABLE_PREFIX . "tags.rel_object_id and " . TABLE_PREFIX . "tags.tag = " . DB::escape($tag) . " and " . TABLE_PREFIX . "tags.rel_object_manager ='ProjectTasks' ) > 0 "; } $conditions = $template_condition . $task_filter_condition . $task_status_condition . $permissions . $tagstr . $projectstr . " AND `trashed_by_id` = 0 AND `archived_by_id` = 0"; //Now get the tasks $tasks = ProjectTasks::findAll(array('conditions' => $conditions, 'order' => 'created_on DESC', 'limit' => user_config_option('task_display_limit') > 0 ? user_config_option('task_display_limit') + 1 : null)); ProjectTasks::populateData($tasks); //Find all internal milestones for these tasks $internalMilestones = ProjectMilestones::getProjectMilestones(active_or_personal_project(), null, 'DESC', "", null, null, null, $status == 0, false); ProjectMilestones::populateData($internalMilestones); //Find all external milestones for these tasks $milestone_ids = array(); if ($tasks) { foreach ($tasks as $task) { if ($task->getMilestoneId() != 0) { $milestone_ids[$task->getMilestoneId()] = $task->getMilestoneId(); } } } $milestone_ids_condition = ''; if (count($milestone_ids) > 0) { $milestone_ids_condition = ' OR id in (' . implode(',', $milestone_ids) . ')'; } if ($status == 0) { $pendingstr = " AND `completed_on` = " . DB::escape(EMPTY_DATETIME) . " "; } else { $pendingstr = ""; } if (!$tag) { $tagstr = ""; } else { $tagstr = " AND (select count(*) from " . TABLE_PREFIX . "tags where " . TABLE_PREFIX . "project_milestones.id = " . TABLE_PREFIX . "tags.rel_object_id and " . TABLE_PREFIX . "tags.tag = " . DB::escape($tag) . " and " . TABLE_PREFIX . "tags.rel_object_manager ='ProjectMilestones' ) > 0 "; } $projectstr = " AND (" . ProjectMilestones::getWorkspaceString($pids) . $milestone_ids_condition . ")"; $archivedstr = " AND `archived_by_id` = 0 "; $milestone_conditions = " `is_template` = false " . $archivedstr . $projectstr . $pendingstr; $externalMilestonesTemp = ProjectMilestones::findAll(array('conditions' => $milestone_conditions)); $externalMilestones = array(); if ($externalMilestonesTemp) { foreach ($externalMilestonesTemp as $em) { $found = false; if ($internalMilestones) { foreach ($internalMilestones as $im) { if ($im->getId() == $em->getId()) { $found = true; break; } } } if (!$found) { $externalMilestones[] = $em; } } } ProjectMilestones::populateData($externalMilestones); //Get Users Info if (logged_user()->isMemberOfOwnerCompany()) { $users = Users::getAll(); $allUsers = array(); } else { $users = logged_user()->getAssignableUsers(); $allUsers = Users::getAll(); } //Get Companies Info if (logged_user()->isMemberOfOwnerCompany()) { $companies = Companies::getCompaniesWithUsers(); } else { $companies = logged_user()->getAssignableCompanies(); } if (!$isJson) { if (active_project() instanceof Project) { $task_templates = WorkspaceTemplates::getTemplatesByWorkspace(active_project()->getId()); } else { $task_templates = array(); } tpl_assign('project_templates', $task_templates); tpl_assign('all_templates', COTemplates::findAll()); if (user_config_option('task_display_limit') > 0 && count($tasks) > user_config_option('task_display_limit')) { tpl_assign('displayTooManyTasks', true); array_pop($tasks); } tpl_assign('tasks', $tasks); tpl_assign('object_subtypes', ProjectCoTypes::getObjectTypesByManager('ProjectTasks')); tpl_assign('internalMilestones', $internalMilestones); tpl_assign('externalMilestones', $externalMilestones); tpl_assign('users', $users); tpl_assign('allUsers', $allUsers); tpl_assign('companies', $companies); tpl_assign('userPreferences', array('filterValue' => isset($filter_value) ? $filter_value : '', 'filter' => $filter, 'status' => $status, 'showWorkspaces' => user_config_option('tasksShowWorkspaces', 1), 'showTime' => user_config_option('tasksShowTime', 0), 'showDates' => user_config_option('tasksShowDates', 0), 'showTags' => user_config_option('tasksShowTags', 0), 'showEmptyMilestones' => user_config_option('tasksShowEmptyMilestones', 0), 'groupBy' => user_config_option('tasksGroupBy', 'milestone'), 'orderBy' => user_config_option('tasksOrderBy', 'priority'), 'defaultNotifyValue' => user_config_option('can notify from quick add'))); ajx_set_no_toolbar(true); } }
// beginning of the week, monday $endday = $startday + 7; // end of week $today = DateTimeValueLib::now(); $today->add('h', logged_user()->getTimezone()); $currentday = $today->format("j"); $currentmonth = $today->format("n"); $currentyear = $today->format("Y"); $drawHourLine = false; $lastday = date("t", mktime(0, 0, 0, $month, 1, $year)); // # of days in the month $date_start = new DateTimeValue(mktime(0, 0, 0, $month, $startday, $year)); $date_end = new DateTimeValue(mktime(0, 0, 0, $month, $endday, $year)); // $date_start->add('h', logged_user()->getTimezone()); // $date_end->add('h', logged_user()->getTimezone()); $milestones = ProjectMilestones::getRangeMilestones($date_start, $date_end); if ($task_filter != "hide") { $tasks = ProjectTasks::getRangeTasksByUser($date_start, $date_end, $user_filter != -1 ? $user : null, $task_filter); } // FIXME $birthdays = array(); //Contacts::instance()->getRangeContactsByBirthday($date_start, $date_end); $tmp_tasks = array(); foreach ($tasks as $task) { $tmp_tasks = array_merge($tmp_tasks, replicateRepetitiveTaskForCalendar($task, $date_start, $date_end)); } $dates = array(); //datetimevalue for each day of week $results = array(); $allday_events_count = array(); $alldayevents = array();
function change_due_date() { $milestone = ProjectMilestones::findById(get_id()); if (!$milestone->canEdit(logged_user())) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } $year = array_var($_GET, 'year', $milestone->getDueDate()->getYear()); $month = array_var($_GET, 'month', $milestone->getDueDate()->getMonth()); $day = array_var($_GET, 'day', $milestone->getDueDate()->getDay()); try { DB::beginWork(); $milestone->setDueDate(new DateTimeValue(mktime(0, 0, 0, $month, $day, $year))); $milestone->save(); DB::commit(); } catch (Exception $e) { DB::rollback(); flash_error(lang('error change due date milestone')); } // try ajx_current("empty"); }
function getExternalColumnValue($field, $id, $manager = null, $object = null) { $value = ''; if ($field == 'user_id' || $field == 'contact_id' || $field == 'created_by_id' || $field == 'updated_by_id' || $field == 'assigned_to_contact_id' || $field == 'assigned_by_id' || $field == 'completed_by_id' || $field == 'approved_by_id') { $contact = Contacts::findById($id); if ($contact instanceof Contact) { $value = $contact->getObjectName(); } } else { if ($field == 'milestone_id') { $milestone = ProjectMilestones::findById($id); if ($milestone instanceof ProjectMilestone) { $value = $milestone->getObjectName(); } } else { if ($field == 'company_id') { $company = Contacts::findById($id); if ($company instanceof Contact && $company->getIsCompany()) { $value = $company->getObjectName(); } } else { if ($field == 'rel_object_id') { $value = $id; } else { if ($manager instanceof ContentDataObjects) { $value = $manager->getExternalColumnValue($field, $id); } } } } } Hook::fire('custom_reports_get_external_column_value', array('field' => $field, 'external_id' => $id, 'manager' => $manager, 'object' => $object), $value); return $value; }
/** * Return milestone * * @access public * @param void * @return array */ function getMilestone() { if (is_null($this->milestone)) { $this->milestone = ProjectMilestones::findById($this->getMilestoneId()); } // if return $this->milestone; }
echo stylesheet_tag('event/day.css'); //today in gmt 0 $today = DateTimeValueLib::now(); //user today // $today->add('h', logged_user()->getTimezone()); $currentday = $today->format("j"); $currentmonth = $today->format("n"); $currentyear = $today->format("Y"); $drawHourLine = $day == $currentday && $month == $currentmonth && $year == $currentyear; $dtv = DateTimeValueLib::make(0, 0, 0, $month, $day, $year); $result = ProjectEvents::getDayProjectEvents($dtv, active_context(), $user_filter, $status_filter); if (!$result) { $result = array(); } $alldayevents = array(); $milestones = ProjectMilestones::getRangeMilestones($dtv, $dtv); if ($task_filter != "hide") { $tasks = ProjectTasks::getRangeTasksByUser($dtv, $dtv, $user_filter != -1 ? $user : null, $task_filter); } if (user_config_option('show_birthdays_in_calendar')) { $birthdays = Contacts::instance()->getRangeContactsByBirthday($dtv, $dtv, active_context_members(false)); } else { $birthdays = array(); } foreach ($result as $key => $event) { if ($event->getTypeId() > 1) { $alldayevents[] = $event; unset($result[$key]); } } if ($milestones) {
/** * Renders select milestone box * * @param string $name * @param Project $project * @param integer $selected ID of selected milestone * @param array $attributes Array of additional attributes * @return string * @throws InvalidInstanceError */ function select_milestone($name, $context = null, $selected = null, $attributes = null) { if(is_array($attributes)) { if(!isset($attributes['class'])) $attributes['class'] = 'select_milestone'; } else { $attributes = array('class' => 'select_milestone'); } $options = array(option_tag(lang('none'), 0)); $milestones = ProjectMilestones::getActiveMilestonesByUser(logged_user(), $context); if(is_array($milestones)) { foreach($milestones as $milestone) { $option_attributes = $milestone->getId() == $selected ? array('selected' => 'selected') : null; $options[] = option_tag($milestone->getObjectName(), $milestone->getId(), $option_attributes); } } return select_box($name, $options, $attributes); } // select_milestone
/** * Open specific milestone * * @access public * @param void * @return null */ function open() { $milestone = ProjectMilestones::findById(get_id()); if (!$milestone instanceof ProjectMilestone) { flash_error(lang('milestone dnx')); $this->redirectTo('milestone'); } // if if (!$milestone->canChangeStatus(logged_user())) { flash_error(lang('no access permissions')); $this->redirectToReferer(get_url('milestone')); } // if try { $milestone->setCompletedOn(null); $milestone->setCompletedById(0); DB::beginWork(); $milestone->save(); ApplicationLogs::createLog($milestone, active_project(), ApplicationLogs::ACTION_OPEN); DB::commit(); flash_success(lang('success open milestone', $milestone->getName())); } catch (Exception $e) { DB::rollback(); flash_error(lang('error open milestone')); } // try $this->redirectToReferer($milestone->getViewUrl()); }
function instantiate() { $selected_members = array(); $id = get_id(); $template = COTemplates::findById($id); if (!$template instanceof COTemplate) { flash_error(lang("template dnx")); ajx_current("empty"); return; } $parameters = TemplateParameters::getParametersByTemplate($id); $parameterValues = array_var($_POST, 'parameterValues'); if (count($parameters) > 0 && !isset($parameterValues)) { ajx_current("back"); return; } if (array_var($_POST, 'members')) { $selected_members = json_decode(array_var($_POST, 'members')); } else { $context = active_context(); foreach ($context as $selection) { if ($selection instanceof Member) { $selected_members[] = $selection->getId(); } } } $objects = $template->getObjects(); $controller = new ObjectController(); if (count($selected_members > 0)) { $selected_members_instances = Members::findAll(array('conditions' => 'id IN (' . implode($selected_members) . ')')); } else { $selected_members_instances = array(); } DB::beginWork(); $active_context = active_context(); foreach ($objects as $object) { if (!$object instanceof ContentDataObject) { continue; } // copy object $copy = $object->copy(); if ($copy->columnExists('is_template')) { $copy->setColumnValue('is_template', false); } if ($copy instanceof ProjectTask) { // don't copy parent task and milestone $copy->setMilestoneId(0); $copy->setParentId(0); } $copy->save(); /* if (!can_write(logged_user(), $selected_members_instances, $copy->getObjectTypeId()) ) { flash_error(lang('no context permissions to add', $copy instanceof ProjectTask ? lang("tasks") : ($copy instanceof ProjectMilestone ? lang('milestones') : ''))); DB::rollback(); ajx_current("empty"); return; }*/ // Copy members from origial object, if it doesn't have then use active context members /* $template_object_members = $object->getMemberIds(); if (count($template_object_members) == 0) { $object_member_ids = active_context_members(false); if (count($object_member_ids) > 0) { $template_object_members = Members::findAll(array("id" => true, "conditions" => "id IN (".implode(",", $object_member_ids).")")); } }*/ /* Set instantiated object members: * foreach dimension: * if no member is active then the instantiated object is put in the same members as the original for current dimension * if a member is selected in current dimension then the instantiated object will be put in that member */ $template_object_members = $object->getMembers(); $object_members = array(); foreach ($active_context as $selection) { if ($selection instanceof Member) { // member selected $object_members[] = $selection->getId(); } else { if ($selection instanceof Dimension) { // no member selected foreach ($template_object_members as $tom) { if ($tom->getDimensionId() == $selection->getId()) { $object_members[] = $tom->getId(); } } } } } $controller->add_to_members($copy, $object_members); // copy linked objects $copy->copyLinkedObjectsFrom($object); // copy subtasks if applicable if ($copy instanceof ProjectTask) { ProjectTasks::copySubTasks($object, $copy, false); foreach ($copy->getOpenSubTasks(false) as $m_task) { $controller->add_to_members($m_task, $object_members); } $manager = $copy->manager(); } else { if ($copy instanceof ProjectMilestone) { ProjectMilestones::copyTasks($object, $copy, false); foreach ($copy->getTasks(false) as $m_task) { $controller->add_to_members($m_task, $object_members); } $manager = $copy->manager(); } } // copy custom properties $copy->copyCustomPropertiesFrom($object); // set property values as defined in template $objProp = TemplateObjectProperties::getPropertiesByTemplateObject($id, $object->getId()); foreach ($objProp as $property) { $propName = $property->getProperty(); $value = $property->getValue(); if ($manager->getColumnType($propName) == DATA_TYPE_STRING || $manager->getColumnType($propName) == DATA_TYPE_INTEGER) { if (is_array($parameterValues)) { foreach ($parameterValues as $param => $val) { if (strpos($value, '{' . $param . '}') !== FALSE) { $value = str_replace('{' . $param . '}', $val, $value); } } } } else { if ($manager->getColumnType($propName) == DATA_TYPE_DATE || $manager->getColumnType($propName) == DATA_TYPE_DATETIME) { $operator = '+'; if (strpos($value, '+') === false) { $operator = '-'; } $opPos = strpos($value, $operator); if ($opPos !== false) { // Is parametric $dateParam = substr($value, 1, strpos($value, '}') - 1); $date = $parameterValues[$dateParam]; $dateUnit = substr($value, strlen($value) - 1); // d, w or m (for days, weeks or months) if ($dateUnit == 'm') { $dateUnit = 'M'; // make month unit uppercase to call DateTimeValue::add with correct parameter } $dateNum = (int) substr($value, strpos($value, $operator), strlen($value) - 2); $date = DateTimeValueLib::dateFromFormatAndString(user_config_option('date_format'), $date); $date = new DateTimeValue($date->getTimestamp() - logged_user()->getTimezone() * 3600); // set date to GMT 0 $value = $date->add($dateUnit, $dateNum); } else { $value = DateTimeValueLib::dateFromFormatAndString(user_config_option('date_format'), $value); } } } if ($value != '') { if (!$copy->setColumnValue($propName, $value)) { $copy->object->setColumnValue($propName, $value); } $copy->save(); } } // subscribe assigned to if ($copy instanceof ProjectTask) { foreach ($copy->getOpenSubTasks(false) as $m_task) { if ($m_task->getAssignedTo() instanceof Contact) { $m_task->subscribeUser($copy->getAssignedTo()); } } if ($copy->getAssignedTo() instanceof Contact) { $copy->subscribeUser($copy->getAssignedTo()); } } else { if ($copy instanceof ProjectMilestone) { foreach ($copy->getTasks(false) as $m_task) { if ($m_task->getAssignedTo() instanceof Contact) { $m_task->subscribeUser($copy->getAssignedTo()); } } } } // copy reminders $reminders = ObjectReminders::getByObject($object); foreach ($reminders as $reminder) { $copy_reminder = new ObjectReminder(); $copy_reminder->setContext($reminder->getContext()); $reminder_date = $copy->getColumnValue($reminder->getContext()); if ($reminder_date instanceof DateTimeValue) { $reminder_date = new DateTimeValue($reminder_date->getTimestamp()); $reminder_date->add('m', -$reminder->getMinutesBefore()); } $copy_reminder->setDate($reminder_date); $copy_reminder->setMinutesBefore($reminder->getMinutesBefore()); $copy_reminder->setObject($copy); $copy_reminder->setType($reminder->getType()); $copy_reminder->setUserId($reminder->getUserId()); $copy_reminder->save(); } } DB::commit(); if (is_array($parameters) && count($parameters) > 0) { ajx_current("back"); } else { if (!$choose_ctx) { ajx_current("back"); } else { ajx_current("reload"); } } }
/** * Return today milestones that this user have access to * * @access public * @param void * @return array */ function getTodayMilestones() { if (is_null($this->today_milestones)) { $this->today_milestones = ProjectMilestones::getTodayMilestonesByUser($this); } // if return $this->today_milestones; } // getTodayMilestones
/** * Return all late milestones * * @param void * @return array */ function getLateMilestones() { return ProjectMilestones::getLateMilestonesByCompany($this); }