/** * @param $pattern * @param $searchProperties * @param $options * @return array|false */ public function search($pattern, $searchProperties, $options) { $ids = array(); $results = array(); $query = 'SELECT DISTINCT `contactid` FROM `' . self::PROPERTY_TABLE . '` WHERE ('; $params = array(); foreach ($searchProperties as $property) { $params[] = $property; $params[] = '%' . $pattern . '%'; $query .= '(`name` = ? AND `value` LIKE ?) OR '; } $query = substr($query, 0, strlen($query) - 4); $query .= ')'; $stmt = \OCP\DB::prepare($query); $result = $stmt->execute($params); if (\OCP\DB::isError($result)) { \OCP\Util::writeLog('contacts', __METHOD__ . 'DB error: ' . \OC_DB::getErrorMessage($result), \OCP\Util::ERROR); return false; } while ($row = $result->fetchRow()) { $ids[] = $row['contactid']; } if (count($ids) > 0) { $query = 'SELECT `' . self::CONTACT_TABLE . '`.`addressbookid`, `' . self::PROPERTY_TABLE . '`.`contactid`, `' . self::PROPERTY_TABLE . '`.`name`, `' . self::PROPERTY_TABLE . '`.`value` FROM `' . self::PROPERTY_TABLE . '`,`' . self::CONTACT_TABLE . '` WHERE `' . self::CONTACT_TABLE . '`.`addressbookid` = \'' . $this->addressBook->getId() . '\' AND `' . self::PROPERTY_TABLE . '`.`contactid` = `' . self::CONTACT_TABLE . '`.`id` AND `' . self::PROPERTY_TABLE . '`.`contactid` IN (' . join(',', array_fill(0, count($ids), '?')) . ')'; \OCP\Util::writeLog('contacts', __METHOD__ . 'DB query: ' . $query, \OCP\Util::DEBUG); $stmt = \OCP\DB::prepare($query); $result = $stmt->execute($ids); } while ($row = $result->fetchRow()) { $this->getProperty($results, $row); } return $results; }
/** * @param $pattern * @param $searchProperties * @param $options * @return array|false */ public function search($pattern, $searchProperties, $options) { $ids = array(); $results = array(); $query = 'SELECT DISTINCT `contactid` FROM `' . self::PROPERTY_TABLE . '` WHERE ('; $params = array(); foreach ($searchProperties as $property) { $params[] = $property; $params[] = '%' . $pattern . '%'; $query .= '(`name` = ? AND `value` LIKE ?) OR '; } $query = substr($query, 0, strlen($query) - 4); $query .= ')'; $stmt = \OCP\DB::prepare($query); $result = $stmt->execute($params); if (\OCP\DB::isError($result)) { \OCP\Util::writeLog('contacts', __METHOD__ . 'DB error: ' . \OC_DB::getErrorMessage($result), \OCP\Util::ERROR); return false; } while ($row = $result->fetchRow()) { $ids[] = $row['contactid']; } if (count($ids) > 0) { foreach ($ids as $id) { $contact = $this->addressBook->getChild($id); $j = JSONSerializer::serializeContact($contact); $j['data']['id'] = $id; if (isset($contact->PHOTO)) { $url = \OCP\Util::linkToRoute('contacts_contact_photo', array('backend' => $contact->getBackend()->name, 'addressBookId' => $this->addressBook->getId(), 'contactId' => $contact->getId())); $url = \OC_Helper::makeURLAbsolute($url); $j['data']['PHOTO'] = "VALUE=uri:{$url}"; } $results[] = $this->convertToSearchResult($j); } } return $results; }