/** * Query all installed components for objects related to given object * * If optional $defaults (org_openpsa_relatedto_dba object) is given * it's used to fill default values for link objects returned. * * NOTE: Only returns new suspected relations, confirmed/notrelated links are filtered out * * returns array with the target object and prefilled link object * * The see org.openpsa.projects for an example of how the component interface method * org_openpsa_relatedto_find_suspects() should work. */ public static function find_links_object($object, $defaults = false) { $ret = array(); //Copied on purpose TODO: when upgrading to PHP5 make sure this is passed as copy $manifests = midcom::get('componentloader')->manifests; //Check all installed components foreach ($manifests as $component => $manifest) { if ($component == 'midcom') { //Skip midcom core continue; } $component_ret = org_openpsa_relatedto_suspect::find_links_object_component($object, $component, $defaults); foreach ($component_ret as $linkdata) { $ret[] = $linkdata; } unset($component_ret, $linkdata); } //TODO: Filter out duplicates (not likely but theoretically possible) return $ret; }
/** * Queries org.openpsa.sales for suspected task links and saves them */ function get_suspected_sales_links() { debug_add('called'); //Safety if (!$this->_suspects_classes_present()) { debug_add('required classes not present, aborting', MIDCOM_LOG_WARN); return; } // Do no seek if we already have confirmed links $mc = new org_openpsa_relatedto_collector($this->guid, array('org_openpsa_salesproject_dba', 'org_openpsa_salesproject_deliverable_dba')); $mc->add_constraint('status', '=', org_openpsa_relatedto_dba::CONFIRMED); $links = $mc->get_related_guids(); if (!empty($links)) { $cnt = count($links); debug_add("Found {$cnt} confirmed links already, skipping seek"); return; } $link_def = $this->_suspect_defaults(); $sales_suspect_links = org_openpsa_relatedto_suspect::find_links_object_component($this, 'org.openpsa.sales', $link_def); foreach ($sales_suspect_links as $linkdata) { debug_add("processing sales link {$linkdata['other_obj']->guid}, (class: " . get_class($linkdata['other_obj']) . ")"); $stat = $linkdata['link']->create(); if ($stat) { debug_add("saved link to {$linkdata['other_obj']->guid} (link id #{$linkdata['link']->id})", MIDCOM_LOG_INFO); } else { debug_add("could not save link to {$linkdata['other_obj']->guid}, errstr" . midcom_connection::get_error_string(), MIDCOM_LOG_WARN); } } debug_add('done'); return; }
/** * Used by org_openpsa_relatedto_find_suspects to in case the given object is a person */ private function _org_openpsa_relatedto_find_suspects_person(&$object, &$defaults, &$links_array) { //List all projects and tasks given person is involved with $qb = org_openpsa_projects_task_resource_dba::new_query_builder(); $qb->add_constraint('person', '=', $object->id); $qb->add_constraint('task.status', '<', org_openpsa_projects_task_status_dba::COMPLETED); $qb->add_constraint('task.status', '<>', org_openpsa_projects_task_status_dba::DECLINED); $qbret = @$qb->execute(); if (!is_array($qbret)) { debug_add('QB returned with error, aborting, errstr: ' . midcom_connection::get_error_string(), MIDCOM_LOG_ERROR); return; } $seen_tasks = array(); foreach ($qbret as $resource) { debug_add("processing resource #{$resource->id}"); if (isset($seen_tasks[$resource->task])) { //Only process one task once (someone might be both resource and contact for example) continue; } $seen_tasks[$resource->task] = true; $to_array = array('other_obj' => false, 'link' => false); $task = new org_openpsa_projects_task_dba($resource->task); $link = new org_openpsa_relatedto_dba(); org_openpsa_relatedto_suspect::defaults_helper($link, $defaults, $this->_component, $task); $to_array['other_obj'] = $task; $to_array['link'] = $link; $links_array[] = $to_array; } return; }
/** * Used by org_openpsa_relatedto_find_suspects to in case the given object is a person */ private function _org_openpsa_relatedto_find_suspects_person(&$object, &$defaults, &$links_array) { $seen_sp = array(); $mc = org_openpsa_contacts_role_dba::new_collector('role', ORG_OPENPSA_OBTYPE_SALESPROJECT_MEMBER); $mc->add_constraint('person', '=', array_keys($object->id)); $guids = $mc->get_values('objectGuid'); if (!empty($guids)) { $qb = org_openpsa_sales_salesproject_dba::new_query_builder(); $qb->add_constraint('status', '=', org_openpsa_sales_salesproject_dba::STATUS_ACTIVE); $qb->add_constraint('guid', 'IN', $guids); $qbret = @$qb->execute(); if (is_array($qbret)) { foreach ($qbret as $salesproject) { if (isset($seen_sp[$salesproject->id])) { //Only process one salesproject once (someone might be both resource and contact for example) continue; } $seen_sp[$salesproject->id] = true; $to_array = array('other_obj' => false, 'link' => false); $link = new org_openpsa_relatedto_dba(); org_openpsa_relatedto_suspect::defaults_helper($link, $defaults, $this->_component, $salesproject); $to_array['other_obj'] = $salesproject; $to_array['link'] = $link; $links_array[] = $to_array; } } } $qb2 = org_openpsa_sales_salesproject_dba::new_query_builder(); $qb2->add_constraint('owner', '=', $object->id); $qb2->add_constraint('status', '=', org_openpsa_sales_salesproject_dba::STATUS_ACTIVE); $qb2ret = @$qb2->execute(); if (is_array($qb2ret)) { foreach ($qb2ret as $sp) { if (isset($seen_sp[$sp->id])) { //Only process one task once (someone might be both resource and contact for example) continue; } $seen_sp[$sp->id] = true; $to_array = array('other_obj' => false, 'link' => false); $link = new org_openpsa_relatedto_dba(); org_openpsa_relatedto_suspect::defaults_helper($link, $defaults, $this->_component, $sp); $to_array['other_obj'] = $sp; $to_array['link'] = $link; $links_array[] = $to_array; } } }