/** * * @param mixed $handler_id The ID of the handler. * @param array &$data The local request data. */ public function _show_list($handler_id, array &$data) { if ($handler_id == 'mycontacts_xml') { $schemadb_person = midcom_helper_datamanager2_schema::load_database($this->_config->get('schemadb_person')); $datamanager = new midcom_helper_datamanager2_datamanager($schemadb_person); $xml = '<contacts></contacts>'; $simplexml = simplexml_load_string($xml); foreach ($data['mycontacts'] as $person) { $contact = $simplexml->addChild('contact'); $contact->addAttribute('guid', $person->guid); $datamanager->autoset_storage($person); $person_data = $datamanager->get_content_xml(); foreach ($person_data as $key => $value) { $contact->addChild($key, $value); } $mc = midcom_db_member::new_collector('uid', $person->id); $memberships = $mc->get_values('gid'); $qb = org_openpsa_contacts_group_dba::new_query_builder(); $qb->add_constraint('gid', 'IN', $memberships); $qb->add_constraint('orgOpenpsaObtype', '>', org_openpsa_contacts_list_dba::MYCONTACTS); $organisations = $qb->execute(); foreach ($organisations as $organisation) { $contact->addChild('company', str_replace('&', '&', ${$organisation}->get_label())); } } echo $simplexml->asXml(); } else { midcom_show_style("show-mycontacts-header"); foreach ($data['mycontacts'] as $person) { $data['person'] = $person; midcom_show_style("show-mycontacts-item"); } midcom_show_style("show-mycontacts-footer"); } }
/** * Prepares the component's indexer client */ public function _on_reindex($topic, $config, &$indexer) { $qb_organisations = org_openpsa_contacts_group_dba::new_query_builder(); $qb_organisations->add_constraint('orgOpenpsaObtype', '<>', org_openpsa_contacts_group_dba::MYCONTACTS); $organisation_schema = midcom_helper_datamanager2_schema::load_database($config->get('schemadb_group')); $qb_persons = org_openpsa_contacts_person_dba::new_query_builder(); $person_schema = midcom_helper_datamanager2_schema::load_database($config->get('schemadb_person')); $indexer = new org_openpsa_contacts_midcom_indexer($topic, $indexer); $indexer->add_query('organisations', $qb_organisations, $organisation_schema); $indexer->add_query('persons', $qb_persons, $person_schema); return $indexer; }
private function _import_subscribers_organization($subscriber) { $organization = null; if (array_key_exists('official', $subscriber['organization']) && $subscriber['organization']['official']) { // Perform a simple check for existing organization. More complicated duplicate checking is best left to the o.o.contacts duplicate checker $qb = org_openpsa_contacts_group_dba::new_query_builder(); if (array_key_exists('company_id', $this->_schemadbs['organization']['default']->fields) && array_key_exists('company_id', $subscriber['organization']) && $subscriber['organization']['company_id']) { // Imported data has a company id, we use that instead of name $qb->add_constraint($this->_schemadbs['organization']['default']->fields['company_id']['storage']['location'], '=', $subscriber['organization']['company_id']); } else { // Seek by official name $qb->add_constraint('official', '=', $subscriber['organization']['official']); if (array_key_exists('city', $this->_schemadbs['organization']['default']->fields) && array_key_exists('city', $subscriber['organization']) && $subscriber['organization']['city']) { // Imported data has a city, we use also that for matching $qb->add_constraint($this->_schemadbs['organization']['default']->fields['city']['storage']['location'], '=', $subscriber['organization']['city']); } } $organizations = $qb->execute_unchecked(); if (count($organizations) > 0) { // Match found, use it // Use first match $organization = array_shift($organizations); } } if (!$organization) { // We didn't have person matching the email in DB. Create a new one. $organization = new org_openpsa_contacts_group_dba(); if (!$organization->create()) { $this->_request_data['new_objects']['organization'] =& $organization; debug_add("Failed to create organization, reason " . midcom_connection::get_error_string()); return null; } } if (!$this->_datamanager_process('organization', $subscriber, $organization)) { return null; } return $organization; }
/** * * @param mixed $handler_id The ID of the handler. * @param array &$data The local request data. */ public function _show_action($handler_id, array &$data) { switch ($this->_view) { case "area_group_members": // This is most likely a dynamic_load $qb = new org_openpsa_qbpager('midcom_db_member', 'group_members'); $qb->add_constraint('gid', '=', $this->_request_data['group']->id); $qb->results_per_page = 10; $results = $qb->execute(); $this->_request_data['members_qb'] =& $qb; if (count($results) > 0) { midcom_show_style("show-group-persons-header"); foreach ($results as $member) { $this->_request_data['member'] = $member; if ($member->extra == "") { $member->extra = $this->_l10n->get('<title>'); } $this->_request_data['member_title'] = $member->extra; $this->_request_data['person'] = new org_openpsa_contacts_person_dba($member->uid); midcom_show_style("show-group-persons-item"); } midcom_show_style("show-group-persons-footer"); } break; case "area_group_subgroups": $qb = org_openpsa_contacts_group_dba::new_query_builder(); $qb->add_constraint('owner', '=', $this->_request_data['group']->id); $results = $qb->execute(); if (count($results) > 0) { midcom_show_style("show-group-subgroups-header"); foreach ($results as $subgroup) { $this->_request_data['subgroup'] = $subgroup; midcom_show_style("show-group-subgroups-item"); } midcom_show_style("show-group-subgroups-footer"); } break; } }
/** * Does a QB query for groups, returns false or number of matched entries * * Displays style element 'search-groups-empty' only if $displayEmpty is * set to true. */ private function _search_qb_groups() { if (!$this->_query_string) { return false; } // Search using only the fields defined in config $org_fields = explode(',', $this->_config->get('organization_search_fields')); if (!is_array($org_fields) || count($org_fields) == 0) { throw new midcom_error('Invalid organization search configuration'); } $qb_org = org_openpsa_contacts_group_dba::new_query_builder(); $qb_org->add_constraint('orgOpenpsaObtype', '<>', org_openpsa_contacts_group_dba::MYCONTACTS); $this->_apply_constraints($qb_org, $org_fields); $this->_groups = $qb_org->execute(); }
/** * Find duplicates for given org_openpsa_contacts_group_dba object * @param org_openpsa_contacts_group_dba $group org_openpsa_contacts_group_dba object (does not need id) * @return array array of possible duplicates */ function find_duplicates_group($group, $threshold = 1) { $this->p_map = array(); //Make sure this is clean before starting $ret = array(); $qb = org_openpsa_contacts_group_dba::new_query_builder(); if ($group->id) { $qb->add_constraint('id', '<>', $group->id); } $qb->begin_group('OR'); //Shared official if ($group->official) { $qb->add_constraint('official', 'LIKE', $group->official); } //Shared street if ($group->street) { $qb->add_constraint('street', 'LIKE', $group->street); } //Shared phone if ($group->phone) { $qb->add_constraint('phone', 'LIKE', $group->phone); } //Shared homepage if ($group->homepage) { $qb->add_constraint('homepage', 'LIKE', $group->homepage); } //Shared city if ($group->city) { $qb->add_constraint('city', 'LIKE', $group->city); } $qb->end_group(); $check_groups = $qb->execute(); if (!is_array($check_groups)) { return false; } foreach ($check_groups as $check_group) { $p_array = $this->p_duplicate_group($group, $check_group); $this->p_map[$check_group->guid] = $p_array; if ($p_array['p'] >= $threshold) { $ret[] = $check_group; } } return $ret; }