Exemplo n.º 1
0
    /**
     * Load Location of last 20 IP addresses of logins of selected affiliate
     *
     * @service online_user read
     * @return Gpf_Data_RecordSet
     */
    public function getAffiliateLogins(Gpf_Rpc_Params $params) {
        $sql = new Gpf_SqlBuilder_SelectBuilder();

        $sql->select->add('l.'.Gpf_Db_Table_LoginsHistory::IP);
        $sql->select->add('MAX(l.'.Gpf_Db_Table_LoginsHistory::LOGIN . ')', 'login');

        $sql->from->add(Gpf_Db_Table_LoginsHistory::getName(), 'l');
        $sql->from->addInnerJoin(Gpf_Db_Table_Users::getName(), 'u', 'l.accountuserid=u.accountuserid');
        $sql->from->addInnerJoin(Gpf_Db_Table_AuthUsers::getName(), 'au', 'u.authid=au.authid');

        $sql->where->add(Gpf_Db_Table_AuthUsers::USERNAME, '=', $params->get('username'));
        $sql->where->add('l.'.Gpf_Db_Table_LoginsHistory::IP, '<>', '127.0.0.1');

        $sql->orderBy->add(Gpf_Db_Table_LoginsHistory::LOGIN, false);

        $sql->groupBy->add('l.'.Gpf_Db_Table_LoginsHistory::IP);

        $sql->limit->set(0, 20);

        $recordset = $sql->getAllRows();

        $recordset->addColumn('countryCode', '');
        $recordset->addColumn('countryName', '');
        $recordset->addColumn('city', '');
        $recordset->addColumn('latitude', '');
        $recordset->addColumn('longitude', '');
        $recordset->addColumn('postalCode', '');
        $recordset->addColumn('region', '');

        foreach ($recordset as $record) {
            $location = new GeoIp_Location();
            $location->setIpString($record->get('ip'));
            $location->load();

            $record->set('countryCode', $location->getCountryCode());
            $record->set('countryName', $location->getCountryName());
            $record->set('city', $location->getCity());
            $record->set('latitude', $location->getLatitude());
            $record->set('longitude', $location->getLongitude());
            $record->set('postalCode', $location->getPostalCode());
            $record->set('region', $location->getRegion());

            $record->set('login', Gpf_Common_DateUtils::getHumanRelativeTime(Gpf_Common_DateUtils::getClientTime(
            Gpf_Common_DateUtils::mysqlDateTime2Timestamp($record->get('login')))));
        }

        return $recordset;
    }
Exemplo n.º 2
0
    /**
     * Load Location information for Ip address specified in Id
     *
     * @anonym
     * @service geoip read
     * @param $fields
     */
    public function load(Gpf_Rpc_Params $params) {
        $data = new Gpf_Rpc_Data($params);

        $location = new GeoIp_Location();
        $location->setIpString($data->getId());
        $location->load();

        $data->setValue('ip', $location->getIpString());
        $data->setValue('countryCode', $location->getCountryCode());
        $data->setValue('countryName', $location->getCountryName());
        $data->setValue('city', $location->getCity());
        $data->setValue('areaCode', $location->getAreaCode());
        $data->setValue('dmaCode', $location->getDmaCode());
        $data->setValue('latitude', $location->getLatitude());
        $data->setValue('longitude', $location->getLongitude());
        $data->setValue('postalCode', $location->getPostalCode());
        $data->setValue('region', $location->getRegion());

        return $data;
    }