/** * Returns query parts for filtering users ( by default: suspended, not approved, not verified ). * Result array includes strings: join, where, order * * @param array $tables * @param array $fields * @param array $options * @return array */ public function getQueryFilter(array $tables, array $fields, $options = array()) { if (empty($tables[BASE_CLASS_QueryBuilderEvent::TABLE_USER]) || empty($fields[BASE_CLASS_QueryBuilderEvent::FIELD_USER_ID])) { throw new InvalidArgumentException("User table name or key field were not provided."); } $tableAlias = $tables[BASE_CLASS_QueryBuilderEvent::TABLE_USER]; $keyField = $fields[BASE_CLASS_QueryBuilderEvent::FIELD_USER_ID]; $event = new BASE_CLASS_QueryBuilderEvent(self::EVENT_QUERY_FILTER, array_merge(array("tables" => $tables, "fields" => $fields), $options)); $userTable = "base_user_table_alias"; $event->addJoin("INNER JOIN `" . $this->getTableName() . "` {$userTable} ON {$userTable}.`id` = `{$tableAlias}`.`{$keyField}`"); $suspendTable = "base_user_suspend_table_alias"; $event->addJoin("LEFT JOIN `" . BOL_UserSuspendDao::getInstance()->getTableName() . "` {$suspendTable} ON {$suspendTable}.`userId` = `{$userTable}`.`id`"); $event->addWhere("`{$suspendTable}`.`id` IS NULL"); if (OW::getConfig()->getValue('base', 'mandatory_user_approve')) { $approveTable = "base_user_approve_table_alias"; $event->addJoin("LEFT JOIN `" . BOL_UserApproveDao::getInstance()->getTableName() . "` {$approveTable} ON {$approveTable}.`userId` = `{$userTable}`.`id`"); $event->addWhere("`{$approveTable}`.`id` IS NULL"); } if (OW::getConfig()->getValue('base', 'confirm_email')) { $event->addWhere("`{$userTable}`.`emailVerify` = 1"); } OW::getEventManager()->trigger($event); return array("join" => $event->getJoin(), "where" => $event->getWhere(), "order" => $event->getOrder()); }
public function getUserQueryFilter($tableAlias, $keyField, $params = array()) { $event = new BASE_CLASS_QueryBuilderEvent("base.query.user_filter", $params); $userTable = "base_user_table_alias"; $event->addJoin("INNER JOIN `" . $this->getTableName() . "` {$userTable} ON {$userTable}.`id` = `{$tableAlias}`.`{$keyField}`"); $suspendTable = "base_user_suspend_table_alias"; $event->addJoin("LEFT JOIN `" . BOL_UserSuspendDao::getInstance()->getTableName() . "` {$suspendTable} ON {$suspendTable}.`userId` = `{$userTable}`.`id`"); $event->addWhere("`{$suspendTable}`.`id` IS NULL"); if (OW::getConfig()->getValue('base', 'mandatory_user_approve')) { $approveTable = "base_user_approve_table_alias"; $event->addJoin("LEFT JOIN `" . BOL_UserApproveDao::getInstance()->getTableName() . "` {$approveTable} ON {$approveTable}.`userId` = `{$userTable}`.`id`"); $event->addWhere("`{$approveTable}`.`id` IS NULL"); } if (OW::getConfig()->getValue('base', 'confirm_email')) { $event->addWhere("`{$userTable}`.`emailVerify` = 1"); } OW::getEventManager()->trigger($event); return array("join" => $event->getJoin(), "where" => $event->getWhere(), "order" => $event->getOrder()); }
function questionSearchSql(BASE_CLASS_QueryBuilderEvent $e) { $params = $e->getParams(); $question = !empty($params['question']) ? $params['question'] : null; $questionValue = !empty($params['value']) ? $params['value'] : null; if (!empty($question) && $question->name == 'googlemap_location') { if (empty($questionValue) || empty($questionValue['json'])) { $e->addWhere(" 1 "); return; } $element = new GOOGLELOCATION_CLASS_Location('location'); $element->setValue($params['value']); $value = $element->getListValue(); $json = !empty($value['json']) ? json_decode($value['json'], true) : array(); $countryCode = ""; if (!empty($json['address_components'])) { foreach ($json['address_components'] as $component) { if (!empty($component['types']) && is_array($component['types']) && in_array('country', $component['types'])) { $countryCode = !empty($component['short_name']) ? $component['short_name'] : ""; } } } if (!empty($value['distance']) && (double) $value['distance'] > 0) { $coord = GOOGLELOCATION_BOL_LocationService::getInstance()->getNewCoordinates($value['southWestLat'], $value['southWestLng'], 225, (double) $value['distance']); $value['southWestLat'] = $coord['lat']; $value['southWestLng'] = $coord['lng']; $coord = GOOGLELOCATION_BOL_LocationService::getInstance()->getNewCoordinates($value['northEastLat'], $value['northEastLng'], 45, (double) $value['distance']); $value['northEastLat'] = $coord['lat']; $value['northEastLng'] = $coord['lng']; } $sql = GOOGLELOCATION_BOL_LocationService::getInstance()->getSearchInnerJoinSql('user', $value['southWestLat'], $value['southWestLng'], $value['northEastLat'], $value['northEastLng'], $countryCode); $e->addJoin($sql); } }