/** * 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; }
protected function execute() { $select = new Gpf_SqlBuilder_SelectBuilder(); $select->select->addAll(Pap_Db_Table_RecurringCommissions::getInstance()); $select->from->add(Pap_Db_Table_RecurringCommissions::getName()); foreach ($select->getAllRowsIterator() as $row) { $recurringCommission = new Pap_Features_RecurringCommissions_RecurringCommission(); $recurringCommission->fillFromRecord($row); $recurringCommission->setPersistent(true); if ($this->isDone($recurringCommission->getId())) { continue; } $recurrencePreset = $recurringCommission->getRecurrencePreset(); $lastCommissionDate = $recurringCommission->getLastCommissionDate(); if ($lastCommissionDate == null) { $lastCommissionDate = $recurringCommission->getTransaction()->getDateInserted(); } $nextTimestamp = $recurrencePreset->getNextDate(Gpf_Common_DateUtils::mysqlDateTime2Timestamp($lastCommissionDate)); if ($nextTimestamp == null || $nextTimestamp > time()) { continue; } $recurringCommission->setLastCommissionDate(Gpf_Common_DateUtils::getDateTime($nextTimestamp)); if ($recurringCommission->getStatus() == Pap_Common_Constants::STATUS_APPROVED) { try { $recurringCommission->createCommissions(); } catch (Gpf_Exception $e) { Gpf_Log::critical('Recurring commissions - error create commissions: ' . $e->getMessage()); $this->setDone(); } } $recurringCommission->save(); $this->setDone(); } }
public function scheduleTasks($inclusion_type, $inclusion_tasks) { $select = new Gpf_SqlBuilder_SelectBuilder(); $select->select->addAll(Gpf_Db_Table_PlannedTasks::getInstance()); $select->from->add(Gpf_Db_Table_PlannedTasks::getName()); $condition = new Gpf_SqlBuilder_CompoundWhereCondition(); $condition->add(Gpf_Db_Table_PlannedTasks::LASTPLANDATE, '<', Gpf_Common_DateUtils::now(), 'OR'); $condition->add(Gpf_Db_Table_PlannedTasks::LASTPLANDATE, 'is', 'NULL', 'OR', false); $select->where->addCondition($condition); if ($inclusion_type == Gpf_Tasks_Runner::INCLUDE_TASKS) { $select->where->add(Gpf_Db_Table_PlannedTasks::CLASSNAME, 'IN', $inclusion_tasks); } else { if ($inclusion_type == Gpf_Tasks_Runner::EXCLUDE_TASKS) { $select->where->add(Gpf_Db_Table_PlannedTasks::CLASSNAME, 'NOT IN', $inclusion_tasks); } } foreach ($select->getAllRows() as $plannedTaskRow) { $plannedTask = new Gpf_Db_PlannedTask(); $plannedTask->fillFromRecord($plannedTaskRow); if ($plannedTask->getLastPlanDate() == null) { $plannedTask->setLastPlanDate(Gpf_Common_DateUtils::now()); } $task = new Gpf_Db_Task(); $task->setClassName($plannedTask->getClassName()); $task->setParams($plannedTask->getParams()); $task->setAccountId($plannedTask->getAccountId()); $task->save(); $preset = new Gpf_Recurrence_Preset(); $preset->setId($plannedTask->getRecurrencePresetId()); $preset->load(); $nextDate = $preset->getNextDate(Gpf_Common_DateUtils::mysqlDateTime2Timestamp($plannedTask->getLastPlanDate())); if ($nextDate != null && $nextDate > 0) { $plannedTask->setLastPlanDate(Gpf_Common_DateUtils::getDateTime($nextDate)); $plannedTask->update(); } } }