Exemple #1
0
 function processLenderInvite($invitee, $lender_invite_visit)
 {
     global $database;
     $lender_invite = array();
     if ($lender_invite_visit['lender_invite_id']) {
         $lender_invite = $database->getLenderInviteById($lender_invite_visit['lender_invite_id']);
         if (!$lender_invite) {
             return false;
         }
     }
     for ($retry = 0; $retry < 3; $retry++) {
         $database->startDbTxn();
         $amount = 25;
         if ($lender_invite) {
             $res1 = $database->updateLenderInvite($lender_invite['id'], $invitee['userid']);
         } else {
             $lender_invite = $database->addLenderInvite(array('lender_id' => $lender_invite_visit['lender_id'], 'email' => $invitee['Email'], 'invitee_id' => $invitee['userid'], 'hash' => null));
             $res1 = $lender_invite !== false;
         }
         $res2 = $database->setLenderInviteTransaction($lender_invite['lender_id'], $amount, 'Lender invite credit', LENDER_INVITE_INVITER);
         $res3 = $database->setLenderInviteTransaction($invitee['userid'], $amount, 'Lender invitee credit', LENDER_INVITE_INVITEE);
         if ($res1 && $res2 && $res3) {
             $database->commitTxn();
             $lender = $database->getLenderDetails($lender_invite['lender_id']);
             if ($lender['invite_notify']) {
                 $this->sendLenderInviteCredit($lender_invite);
             }
             Mixpanel::track('Invite accepted', array('username' => $invitee['username'], 'email' => $lender_invite['email'], 'lender_id' => $lender_invite['lender_id']));
             $mixpanel = MixpanelClient::getInstance(MIXPANEL_TOKEN);
             $mixpanel->identify($lender_invite['lender_id']);
             $share_type = $lender_invite_visit['share_type'];
             $share_types = array(1 => 'email', 2 => 'twitter', 3 => 'facebook');
             $mixpanel->track('Recruited new lender', array('share_type' => array_get($share_types, $share_type, 'website'), 'lender_id' => $lender_invite['lender_id'], 'invitee_id' => $lender_invite['invitee_id']));
             $mixpanel->people->set($lender_invite['lender_id'], array('Recruited new lender' => date('Y-m-d H:i:s')), '0');
             $mixpanel->people->increment($lender_invite['lender_id'], 'Recruited new lender counter', 1, '0');
             return $lender_invite;
         } else {
             $database->rollbackTxn();
         }
     }
     return false;
 }
Exemple #2
0
 /**
  * Returns a singleton instance of Mixpanel
  * @param $token
  * @param array $options
  * @return MixpanelClient
  */
 public static function getInstance($token, $options = array())
 {
     if (!isset(self::$_instance)) {
         self::$_instance = new MixpanelClient($token, $options);
     }
     return self::$_instance;
 }
<?php

set_include_path(get_include_path() . PATH_SEPARATOR . dirname(dirname(__FILE__)));
include "library/session.php";
global $database, $session, $db;
$mixpanel = MixpanelClient::getInstance(MIXPANEL_TOKEN);
$q = "SELECT COUNT(*) FROM lenders l JOIN users u ON l.userid=u.userid\n      WHERE u.emailVerified = 1\n        AND last_login > ?\n        AND l.Active=1";
$lenderCount = $db->getOne($q, array(strtotime('2014-03-19')));
$limit = 200;
$offset = 0;
while ($offset < $lenderCount) {
    $q = "SELECT * FROM lenders l JOIN users u ON l.userid=u.userid\n          WHERE u.emailVerified=1\n            AND last_login > ?\n            AND l.Active=1\n          LIMIT {$offset}, {$limit}";
    $lenders = $db->getAll($q, array(strtotime('2014-03-19')));
    echo $offset . "\n";
    foreach ($lenders as $lender) {
        $mixpanel->people->set($lender['userid'], ['$first_name' => $lender['FirstName'], '$last_name' => $lender['LastName'], '$username' => $lender['username'], '$email' => $lender['Email'], '$created' => date('D, d M Y H:i:s Z', $lender['regdate']), '$last_login' => date('D, d M Y H:i:s Z', $lender['last_login']), 'userlevel' => $session->userlevel_to_string($lender['userlevel']), 'user_id' => $lender['userid']], '0', true);
    }
    $mixpanel->flush();
    $offset += $limit;
}