public function getNumberOfRecordsFromSameIP($ip, $transType, $periodInSeconds, $parentTransId, $visitDateTime, $campaignId = null, $orderId = null) { $select = new Gpf_SqlBuilder_SelectBuilder(); $select->select->add("count(transid)", "count"); $select->from->add(Pap_Db_Table_Transactions::getName()); $select->where->add(Pap_Db_Table_Transactions::IP, "=", $ip); $select->where->add(Pap_Db_Table_Transactions::R_TYPE, "=", $transType); $select->where->add(Pap_Db_Table_Transactions::TIER, "=", "1"); if (!is_null($campaignId)) { $select->where->add(Pap_Db_Table_Transactions::CAMPAIGN_ID, "=", $campaignId); } if (!is_null($orderId)) { $select->where->add(Pap_Db_Table_Transactions::ORDER_ID, "=", $orderId); } $dateFrom = new Gpf_DateTime($visitDateTime); $dateFrom->addSecond(-1*$periodInSeconds); $select->where->add(Pap_Db_Table_Transactions::DATE_INSERTED, ">", $dateFrom->toDateTime()); if($parentTransId != null && $parentTransId != '') { $select->where->add(Pap_Db_Table_Transactions::PARRENT_TRANSACTION_ID, "<>", $parentTransId); } $recordSet = new Gpf_Data_RecordSet(); $recordSet->load($select); foreach($recordSet as $record) { return $record->get("count"); } return 0; }
public function recognize(Pap_Contexts_Action $context) { if ($context->isVisitorAffiliateRecognized()) { return; } if(Gpf_Settings::get(Pap_Settings::TRACK_BY_IP_SETTING_NAME) != Gpf::YES) { return; } $ip = $context->getIp(); $context->debug('Trying to get visitor affiliate from IP address '. $ip); $visitorAffiliate = $this->visitorAffiliateCache->getLatestVisitorAffiliateFromIp($ip, $context->getAccountId()); if ($visitorAffiliate == null) { $context->debug("No visitor affiliate from IP '$ip'"); return; } try { $periodInSeconds = $this->getValidityInSeconds(); } catch (Gpf_Exception $e) { $context->debug($e->getMessage()); return; } $dateFrom = new Gpf_DateTime($context->getVisitDateTime()); $dateFrom->addSecond(-1*$periodInSeconds); $dateVisit = new Gpf_DateTime($visitorAffiliate->getDateVisit()); if ($dateFrom->compare($dateVisit) > 0) { $context->debug(" No click from IP '$ip' found within ip validity period"); return null; } if (!$context->isTrackingMethodSet()) { $context->setTrackingMethod(Pap_Common_Transaction::TRACKING_METHOD_IP_ADDRESS); } $context->debug('Visitor affiliate recognized from IP, id: '.$visitorAffiliate->getId(). ', accountId: '. $visitorAffiliate->getAccountId()); $context->setVisitorAffiliate($visitorAffiliate); }
public function getNumberOfUsersFromSameIP($ip, $periodInSeconds) { $select = new Gpf_SqlBuilder_SelectBuilder(); $select->select->add("count(au.authid)", "count"); $select->from->add(Pap_Db_Table_Users::getName(), 'pu'); $select->from->addInnerJoin(Gpf_Db_Table_Users::getName(), 'qu', 'pu.' . Pap_Db_Table_Users::ACCOUNTUSERID . '=qu.' . Gpf_Db_Table_Users::ID); $select->from->addInnerJoin(Gpf_Db_Table_AuthUsers::getName(), 'au', 'au.' . Gpf_Db_Table_AuthUsers::ID . '=qu.' . Gpf_Db_Table_Users::AUTHID . ' and qu.' . Gpf_Db_Table_Users::ROLEID . "='" . Pap_Application::DEFAULT_ROLE_AFFILIATE . "'"); $select->where->add('au.' . Gpf_Db_Table_AuthUsers::IP, "=", $ip); $dateFrom = new Gpf_DateTime(); $dateFrom->addSecond(-1 * $periodInSeconds); $select->where->add(Pap_Db_Table_Users::DATEINSERTED, ">", $dateFrom->toDateTime()); $recordSet = new Gpf_Data_RecordSet(); $recordSet->load($select); foreach ($recordSet as $record) { return $record->get("count"); } return 0; }
/** * returns latest undeclined click from the given IP address * * @param string $ip * @param int $periodInSeconds * @return unknown */ public function getLatestClickFromIP($ip, $periodInSeconds) { $select = new Gpf_SqlBuilder_SelectBuilder(); $select->select->add(Pap_Db_Table_RawClicks::USERID, "userid"); $select->select->add(Pap_Db_Table_RawClicks::CHANNEL, "channel"); $select->from->add(Pap_Db_Table_RawClicks::getName()); $select->where->add(Pap_Db_Table_RawClicks::IP, "=", $ip); $select->where->add(Pap_Db_Table_RawClicks::RTYPE, "<>", Pap_Db_ClickImpression::STATUS_DECLINED); $dateFrom = new Gpf_DateTime(); $dateFrom->addSecond(-1*$periodInSeconds); $select->where->add(Pap_Db_Table_RawClicks::DATETIME, ">", $dateFrom->toDateTime()); $select->orderBy->add(Pap_Db_Table_RawClicks::DATETIME, false); $select->limit->set(0, 1); $recordSet = new Gpf_Data_RecordSet(); $recordSet->load($select); foreach($recordSet as $record) { return array('userid' => $record->get("userid"), 'channel' => $record->get("channel")); } return null; }
public function setSleepTime($sleepSeconds) { $time = new Gpf_DateTime(); $time->addSecond($sleepSeconds); $this->setSleepUntil($time); }