/** * Helper function that adds a member to parents if necessary * * @param org_openpsa_projects_task_dba $object The object for which we search the parent */ function add_resource_to_parent(&$object) { $parent = $object->get_parent(); if (!$parent) { return; } if (is_a($parent, 'org_openpsa_projects_project')) { org_openpsa_contacts_role_dba::add($parent->guid, $this->person, $this->orgOpenpsaObtype); return; } $mc = self::new_collector('task', $parent->id); $mc->add_constraint('orgOpenpsaObtype', '=', $this->orgOpenpsaObtype); $mc->add_constraint('person', '=', $this->person); $mc->execute(); if ($mc->count() > 0) { //Resource is already present, aborting return; } $new_resource = new org_openpsa_projects_task_resource_dba(); $new_resource->person = $this->person; $new_resource->orgOpenpsaObtype = $this->orgOpenpsaObtype; $new_resource->task = $parent->id; $new_resource->create(); }
public function _on_created() { //Remove the resource if necessary if ($this->type == org_openpsa_projects_task_status_dba::DECLINED && $this->targetPerson) { $qb = org_openpsa_projects_task_resource_dba::new_query_builder(); $qb->add_constraint('task', '=', $this->task); $qb->add_constraint('person', '=', $this->targetPerson); $qb->add_constraint('orgOpenpsaObtype', '=', ORG_OPENPSA_OBTYPE_PROJECTRESOURCE); if ($qb->count() > 0) { $results = $qb->execute(); foreach ($results as $result) { debug_add("removing user #{$this->targetPerson} from resources"); $result->delete(); } } } $this->_update_task(); }
/** * Calls find_task_prospects and saves the results as prospects * * @param org_openpsa_projects_task_dba &$task object to search prospect resources for * @return boolean indicating success/failure */ function save_task_prospects(&$task) { midcom::get('auth')->request_sudo('org.openpsa.projects'); $task->set_parameter('org.openpsa.projects.projectbroker', 'local_search', 'SEARCH_IN_PROGRESS'); $task->get_members(); $prospects = $this->find_task_prospects($task); if (!is_array($prospects)) { return false; } foreach ($prospects as $person) { if (isset($task->resources[$person->id]) && $task->resources[$person->id]) { continue; } $prospect = new org_openpsa_projects_task_resource_dba(); $prospect->person = $person->id; $prospect->task = $task->id; $prospect->orgOpenpsaObtype = ORG_OPENPSA_OBTYPE_PROJECTPROSPECT; if (!$prospect->create()) { // TODO: Error reporting } } $task->set_parameter('org.openpsa.projects.projectbroker', 'local_search', 'SEARCH_COMPLETE'); midcom::get('auth')->drop_sudo(); return true; }
/** * This function is called from the DM2 schema */ static function get_task_resources() { $resource_array = array(); $view_data =& midcom_core_context::get()->get_custom_key('request_data'); if (!array_key_exists('task', $view_data)) { return $resource_array; } $mc = org_openpsa_projects_task_resource_dba::new_collector('task', $view_data['task']->id); $mc->add_constraint('orgOpenpsaObtype', '=', ORG_OPENPSA_OBTYPE_PROJECTRESOURCE); $resources = $mc->get_values('person'); foreach ($resources as $resource) { try { $person = org_openpsa_contacts_person_dba::get_cached($resource); $resource_array[$person->id] = $person->rname; } catch (midcom_error $e) { } } return $resource_array; }
/** * Support for contacts person merge */ function org_openpsa_contacts_duplicates_merge_person(&$person1, &$person2, $mode) { switch ($mode) { case 'all': break; /* In theory we could have future things (like resource/manager ships), but now we don't support that mode, we just exit */ /* In theory we could have future things (like resource/manager ships), but now we don't support that mode, we just exit */ case 'future': return true; break; default: // Mode not implemented debug_add("mode {$mode} not implemented", MIDCOM_LOG_ERROR); return false; break; } // Transfer links from classes we drive // ** resources ** $qb_member = org_openpsa_projects_task_resource_dba::new_query_builder(); $qb_member->add_constraint('person', '=', $person2->id); $members = $qb_member->execute(); if ($members === false) { // Some error with QB debug_add('QB Error', MIDCOM_LOG_ERROR); return false; } // Transfer memberships foreach ($members as $member) { // TODO: figure out duplicate memberships and delete unneeded ones $member->person = $person1->id; debug_add("Transferred task resource #{$member->id} to person #{$person1->id} (from #{$member->person})", MIDCOM_LOG_INFO); if (!$member->update()) { debug_add("Failed to update task resource #{$member->id}, errstr: " . midcom_connection::get_error_string(), MIDCOM_LOG_ERROR); return false; } } // ** task statuses ** $qb_receipt = org_openpsa_projects_task_status_dba::new_query_builder(); $qb_receipt->add_constraint('targetPerson', '=', $person2->id); $receipts = $qb_receipt->execute(); if ($receipts === false) { // Some error with QB debug_add('QB Error / status', MIDCOM_LOG_ERROR); return false; } foreach ($receipts as $receipt) { debug_add("Transferred task_status #{$receipt->id} to person #{$person1->id} (from #{$receipt->person})", MIDCOM_LOG_INFO); $receipt->targetPerson = $person1->id; if (!$receipt->update()) { // Error updating debug_add("Failed to update status #{$receipt->id}, errstr: " . midcom_connection::get_error_string(), MIDCOM_LOG_ERROR); return false; } } // ** hour reports ** $qb_log = org_openpsa_projects_hour_report_dba::new_query_builder(); $qb_log->add_constraint('person', '=', $person2->id); $logs = $qb_log->execute(); if ($logs === false) { // Some error with QB debug_add('QB Error / hours', MIDCOM_LOG_ERROR); return false; } foreach ($logs as $log) { debug_add("Transferred hour_report #{$log->id} to person #{$person1->id} (from #{$log->person})", MIDCOM_LOG_INFO); $log->person = $person1->id; if (!$log->update()) { // Error updating debug_add("Failed to update hour_report #{$log->id}, errstr: " . midcom_connection::get_error_string(), MIDCOM_LOG_ERROR); return false; } } // ** Task managers ** $qb_task = org_openpsa_projects_task_dba::new_query_builder(); $qb_task->add_constraint('manager', '=', $person2->id); $tasks = $qb_task->execute(); if ($tasks === false) { // Some error with QB debug_add('QB Error / tasks', MIDCOM_LOG_ERROR); return false; } foreach ($tasks as $task) { debug_add("Transferred task #{$task->id} to person #{$person1->id} (from #{$task->person})", MIDCOM_LOG_INFO); $task->manager = $person1->id; if (!$task->update()) { // Error updating debug_add("Failed to update task #{$task->id}, errstr: " . midcom_connection::get_error_string(), MIDCOM_LOG_ERROR); return false; } } // Transfer metadata dependencies from classes that we drive $classes = array('org_openpsa_projects_task_resource_dba', 'org_openpsa_projects_task_status_dba', 'org_openpsa_projects_task_dba', 'org_openpsa_projects_hour_report_dba'); $metadata_fields = array('creator' => 'guid', 'revisor' => 'guid'); foreach ($classes as $class) { $ret = org_openpsa_contacts_duplicates_merge::person_metadata_dependencies_helper($class, $person1, $person2, $metadata_fields); if (!$ret) { // Failure updating metadata debug_add("Failed to update metadata dependencies in class {$class}, errsrtr: " . midcom_connection::get_error_string(), MIDCOM_LOG_ERROR); return false; } } // All done return true; }
/** * @param mixed $handler_id The ID of the handler. * @param Array $args The argument list. * @param Array &$data The local request data. */ public function _handler_list_prospects($handler_id, array $args, array &$data) { $this->_task = new org_openpsa_projects_task_dba($args[0]); $this->_task->require_do('midgard:create'); $qb = org_openpsa_projects_task_resource_dba::new_query_builder(); $qb->add_constraint('task', '=', $this->_task->id); $qb->begin_group('OR'); $qb->add_constraint('orgOpenpsaObtype', '=', ORG_OPENPSA_OBTYPE_PROJECTPROSPECT); $qb->add_constraint('orgOpenpsaObtype', '=', ORG_OPENPSA_OBTYPE_PROJECTRESOURCE); $qb->end_group('OR'); $qb->add_order('orgOpenpsaObtype'); $data['prospects'] = $qb->execute(); midcom::get()->skip_page_style = true; midcom::get('cache')->content->content_type("text/xml; charset=UTF-8"); midcom::get()->header("Content-type: text/xml; charset=UTF-8"); }
public function _handler_list_user($handler_id, array $args, array &$data) { midcom::get('auth')->require_valid_user(); $this->_request_data['view'] = 'grid'; $this->_request_data['view_identifier'] = 'my_tasks'; $siteconfig = org_openpsa_core_siteconfig::get_instance(); $this->_request_data['contacts_url'] = $siteconfig->get_node_full_url('org.openpsa.contacts'); //get possible priorities from schema $this->_get_priorities(); $this->_provider = new org_openpsa_widgets_grid_provider($this, 'local'); $resource_statuses = array(org_openpsa_projects_task_status_dba::PROPOSED, org_openpsa_projects_task_status_dba::ACCEPTED, org_openpsa_projects_task_status_dba::STARTED, org_openpsa_projects_task_status_dba::REOPENED, org_openpsa_projects_task_status_dba::COMPLETED); $task_statuses = array(org_openpsa_projects_task_status_dba::PROPOSED, org_openpsa_projects_task_status_dba::DECLINED, org_openpsa_projects_task_status_dba::COMPLETED, org_openpsa_projects_task_status_dba::ONHOLD); $mc = org_openpsa_projects_task_resource_dba::new_collector('person', midcom_connection::get_user()); $mc->add_constraint('orgOpenpsaObtype', '=', ORG_OPENPSA_OBTYPE_PROJECTRESOURCE); $mc->add_constraint('task.orgOpenpsaObtype', '=', ORG_OPENPSA_OBTYPE_TASK); $mc->add_constraint('task.status', 'IN', $resource_statuses); $resource_tasks = $mc->get_values('task'); $this->_qb = org_openpsa_projects_task_dba::new_query_builder(); $this->_qb->add_constraint('orgOpenpsaObtype', '=', ORG_OPENPSA_OBTYPE_TASK); $this->_qb->begin_group('OR'); if (!empty($resource_tasks)) { //Get active tasks where user is a resource $this->_qb->add_constraint('id', 'IN', $resource_tasks); } //Get relevant tasks where user is manager $this->_qb->begin_group('AND'); $this->_qb->add_constraint('manager', '=', midcom_connection::get_user()); $this->_qb->add_constraint('status', 'IN', $task_statuses); $this->_qb->end_group(); $this->_qb->end_group(); org_openpsa_widgets_grid::add_head_elements(); }