private function _add_customer_constraint($guid, midcom_core_query $qb) { try { $this->_request_data['customer'] = new org_openpsa_contacts_group_dba($guid); $qb->add_constraint('customer', '=', $this->_request_data['customer']->id); } catch (midcom_error $e) { $this->_request_data['customer'] = new org_openpsa_contacts_person_dba($guid); $qb->add_constraint('customerContact', '=', $this->_request_data['customer']->id); } return $qb; }
/** * Modify a query instance for searching by username, with differences between * mgd1 and mgd2 abstracted away * * @param midcom_core_query &$query The QB or MC instance to work on * @param string $operator The operator for the username constraint * @param string $value The value for the username constraint */ public static function add_username_constraint(midcom_core_query &$query, $operator, $value) { if (method_exists('midgard_user', 'login')) { $mc = new midgard_collector('midgard_user', 'authtype', $GLOBALS['midcom_config']['auth_type']); $mc->set_key_property('person'); $mc->add_constraint('login', $operator, $value); $mc->execute(); $user_results = $mc->list_keys(); if (count($user_results) < 1) { // make sure we don't return any results if no midgard_user entry was found $query->add_constraint('id', '=', 0); } else { $query->add_constraint('guid', 'IN', array_keys($user_results)); } } else { $query->add_constraint('username', $operator, $value); } }
private function _apply_constraints(midcom_core_query &$qb, array $fields) { if (sizeof($this->_query) > 1) { //if we have more than one token in the query, we try to match the entire string as well $qb->begin_group('OR'); foreach ($fields as $field) { if (empty($field)) { continue; } $qb->add_constraint($field, 'LIKE', str_replace('__TERM__', $this->_query_string_processed, $this->_wildcard_template)); } } $qb->begin_group('AND'); foreach ($this->_query as $term) { $qb->begin_group('OR'); foreach ($fields as $field) { if (empty($field)) { continue; } $qb->add_constraint($field, 'LIKE', str_replace('__TERM__', $term, $this->_wildcard_template)); } $qb->end_group(); } $qb->end_group(); if (sizeof($this->_query) > 1) { $qb->end_group(); } }