Пример #1
0
function usearch_set_question_sql(BASE_CLASS_QueryBuilderEvent $event)
{
    $params = $event->getParams();
    if (empty($params['question']) || !$params['question'] instanceof BOL_Question || empty($params['value']) || !in_array($params['question']->name, array('sex', 'match_sex'))) {
        return;
    }
    $value = is_array($params['value']) ? array_sum($params['value']) : (int) $params['value'];
    $prefix = !empty($params['prefix']) ? $params['prefix'] : 'q' . rand(100, 10000);
    $questionName = $params['question']->name == 'sex' ? 'match_sex' : 'sex';
    $innerJoin = " INNER JOIN `" . BOL_QuestionDataDao::getInstance()->getTableName() . "` `" . $prefix . "`\n        ON ( `user`.`id` = `" . $prefix . "`.`userId` AND `" . $prefix . "`.`questionName` = '" . OW::getDbo()->escapeString($questionName) . "' AND `" . $prefix . "`.`intValue` & " . OW::getDbo()->escapeString($value) . " ) ";
    $event->addJoin($innerJoin);
}
 public function photoGetPhotoList(BASE_CLASS_QueryBuilderEvent $event)
 {
     if (!OW::getUser()->isAuthenticated()) {
         return;
     }
     $params = $event->getParams();
     $aliases = $params['tables'];
     $currentId = OW::getUser()->getId();
     $sex = BOL_QuestionService::getInstance()->getQuestionData(array($currentId), array('sex'));
     $join = ' INNER JOIN `' . BOL_QuestionDataDao::getInstance()->getTableName() . '` AS `bqdt` ON(`' . $aliases['content'] . '`.`userId` = `bqdt`.`userId`
         AND `bqdt`.`questionName` = \'sex\' 
         AND (`bqdt`.`intValue` != ' . $sex[$currentId]['sex'] . ' OR `' . $aliases['content'] . '`.`userId` = ' . $currentId . ' )) ';
     $params = array('sex' => $sex[$currentId]['sex'], 'currentId' => $currentId);
     $event->addJoin($join);
 }
Пример #3
0
 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());
 }
Пример #4
0
 /**
  * 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());
 }
Пример #5
0
 public function photoGetPhotoList(BASE_CLASS_QueryBuilderEvent $event)
 {
     $params = $event->getParams();
     $aliases = $params['aliases'];
     if (empty($params['listType']) || !in_array($params['listType'], array('latest', 'featured', 'toprated', 'most_discussed', 'searchByDesc', 'searchByHashtag', 'searchByUsername'))) {
         return;
     }
     if (!OW::getUser()->isAuthenticated() || !(bool) OW::getConfig()->getValue('skadate', 'photo_filter_setting_matching') || OW::getUser()->isAuthorized('photo') || OW::getUser()->isAuthorized('base')) {
         return;
     }
     $userId = OW::getUser()->getId();
     $matchValue = BOL_QuestionService::getInstance()->getQuestionData(array($userId), array('sex', 'match_sex'));
     if (empty($matchValue[$userId]['match_sex'])) {
         return;
     }
     $join = 'INNER JOIN `' . BOL_UserDao::getInstance()->getTableName() . '` AS `sk_u` ON(`' . $aliases['album'] . '`.`userId` = `sk_u`.`id`)
         INNER JOIN `' . BOL_QuestionDataDao::getInstance()->getTableName() . '` AS `sk_qd` ON (`sk_qd`.`userId` = `sk_u`.`id` AND `sk_qd`.`questionName` = :sk_sexQuestionName AND `sk_qd`.`intValue` & :sk_matchSexValue)
         INNER JOIN `' . BOL_QuestionDataDao::getInstance()->getTableName() . '` AS `sk_qd1` ON (`sk_qd1`.`userId` = `sk_u`.`id` AND `sk_qd1`.`questionName` = :sk_matchSexQuestionName AND `sk_qd1`.`intValue` & :sk_sexValue)';
     $params = array('sk_sexQuestionName' => 'sex', 'sk_matchSexQuestionName' => 'match_sex', 'sk_sexValue' => $matchValue[$userId]['sex'], 'sk_matchSexValue' => $matchValue[$userId]['match_sex']);
     $event->addJoin($join);
     $event->addBatchQueryParams($params);
 }
Пример #6
0
 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);
     }
 }