public function younified() { $dry_run = $this->args[0] ? TRUE : FALSE; App::import('Model', 'ProductCredit'); $product_credit = new ProductCredit(); App::import('Model', 'Presenter'); $presenter = new Presenter(); include_once '../Vendor/twilio/sdk/Services/Twilio.php'; // set your AccountSid and AuthToken from www.twilio.com/user/account $AccountSid = "AC651e0c523991847b5fe3f33486cc36ec"; $AuthToken = "a81ee6848d844828d6cad82a42f2e5ac"; $client = new Services_Twilio($AccountSid, $AuthToken); $now = new DateTime(); $date = $now->format('Y-m-d'); $presenters = $this->Presenter->getDynamicData(FALSE, 'younified', $date); if (empty($presenters)) { $this->out('No Younified attendees found.'); return; } $attendees = []; foreach ($presenters as $presenter_dc) { $result = $presenter->find('first', array('conditions' => array('Presenter.id' => $presenter_dc['entity_id']), 'contain' => array('User' => array('Phone')))); $attendees[] = $result; if ($dry_run) { $this->out($result['User']['first_name'] . " " . $result['User']['last_name'] . " " . $result['User']['Phone']['phone']); } } if ($dry_run) { return; } $this->out("Preparing to send Y-Cash..."); foreach ($attendees as $attendee) { $sql = "Insert into product_credits\r\n\t\t\t\t\t\t(market_id, user_id, presenter_id, product_credit_type_id, product_credit_entry_type_id, product_credit_status_type_id, entry_user, created, reference_id, amount)\r\n\t\t\t\t\t\t\tselect presenters.market_id, users.id, presenters.id, '1', '2', '2', 'younified', NOW(), 'Younified Retreat - Gift', '10'\r\n\t\t\t\t\t\t\t\tfrom presenters\r\n\t\t\t\t\t\t\t\t\tjoin users on users.id = user_id\r\n\t\t\t\t\t\t\t\twhere presenters.presenter_sequence_id = {$attendee['Presenter']['presenter_sequence_id']}"; $product_credit->query($sql); $phone_number = $attendee['User']['Phone']['phone']; if (!empty($phone_number)) { try { $message = $client->account->messages->create(array("From" => "385-399-1960", "To" => $phone_number, "Body" => "You've got Y-cash!")); } catch (Exception $e) { } } $this->out("Y-Cash for " . $attendee['User']['first_name']); } $this->out("Y-Cash for everyone!"); }
public function websiteLinkDetails($presenterId, $usePresenterNumber = false) { if ($usePresenterNumber) { $conditions = array("Presenter.presenter_sequence_id" => $presenterId); } else { $conditions = array("Presenter.id" => $presenterId); } $presenter = $this->find('first', array("contain" => array("PresenterSite", "User" => array("Email", "Phone", "UserFacebookSocial", "UserOauth2" => array('order' => 'UserOauth2.primary DESC', 'limit' => 1)), 'Sponsor' => array("User")), 'conditions' => $conditions)); App::uses("CustomizeProvider", "Lib"); $img_array = CustomizeProvider::getProviderImages($presenter['User']['UserOauth2'][0]['provider'], $presenter['User']['UserOauth2'][0]['imageUrl'], $presenter['User']['facebook_id']); // check if current sponsor is active and compress if not $sponsor_id = $this->findActiveSponsor($presenter['Presenter']['id']); if ($presenter['Sponsor']['id'] != $sponsor_id) { $spon = new Presenter(); $sponsor = $spon->find('first', array("conditions" => array('Presenter.id' => $sponsor_id), "fields" => array("id", "user_id", "presenter_sequence_id"), "contain" => array("User" => array("fields" => array("first_name", "last_name", "id"), "Email" => array("fields" => array("email", "id"))), "PresenterSite" => array("fields" => array("site_url", "id"))))); $presenter['Sponsor'] = $sponsor['Presenter']; $presenter['Sponsor']['User'] = $sponsor['User']; $presenter['Sponsor']['PresenterSite'] = $sponsor['PresenterSite']; } if (!empty($presenter['User']['UserFacebookSocial'])) { $facebookUrl = $presenter['User']['UserFacebookSocial']['social_id']; } if (empty($facebookUrl)) { $facebookUrl = $presenter['User']['facebook_id']; } $facebookUrl = "https://www.facebook.com/" . $facebookUrl; $details = array("id" => $presenter['Presenter']['id'], "presenterNumber" => $presenter['Presenter']['presenter_sequence_id'], "name" => $presenter['User']['first_name'] . " " . $presenter['User']['last_name'], "siteurl" => $presenter['PresenterSite']['site_url'], "analytics_code" => $presenter['PresenterSite']['analytics_code'], "email" => $presenter['User']['Email']['email'], "phone" => $presenter['User']['Phone']['phone'], "sponsor" => $presenter['Sponsor']['User']['first_name'] . " " . $presenter['Sponsor']['User']['last_name'], "facebookurl" => $facebookUrl, "userid" => $presenter['Presenter']['user_id']); $details = array_merge($details, $img_array); return $details; }
/** * Roll up suspended presenters trees to * next 1-3 month inactive or active sponsor * * @param Presenter $Model * @param array $thread * @return array|bool */ public function rollupPresenters(Presenter $Model, $thread = null) { try { /** * Threads */ if (!isset($thread)) { $mod = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; } else { $mod = (int) $thread; } $this->setupDates(); $log_output = Configure::read('log_output'); /** * Get 3-6 Month Suspended Presenters */ $presenters = Hash::extract($Model->find('all', ['fields' => ['Presenter.*', '(select count(*) from presenters p2 where p2.original_sponsor_id IS NULL AND p2.sponsor_id = Presenter.id) as count_child'], 'conditions' => ['Presenter.presenter_status_id' => PresenterStatus::SUSPENDED, 'AND' => ['Presenter.terminated_date >=' => $this->six_month, 'Presenter.terminated_date <=' => $this->three_month], 'MOD(Presenter.id, 10)' => $mod], 'order' => 'Presenter.id DESC', 'group' => ['Presenter.id HAVING count_child > 0']]), '{n}.Presenter'); if ($log_output == true) { print 'Found ' . count($presenters) . " presenters for dates 6mo: {$this->six_month} 3mo: {$this->three_month}"; } /** * Get Presenters with sponsor in 3-6 Month Suspended Presenters */ foreach ($presenters as $presenter) { /** * Get Up line active */ $up_active = $this->findActiveSponsor($Model, $presenter['id']); $log_message = "Presenter.id " . $presenter['id'] . " with terminated_date: " . $presenter['terminated_date'] . "\n"; if ($log_output == true) { print $log_message; } else { $this->results['log'] .= $log_message; } /** * Get all presenters with sponsor */ $sponsor_presenters = Hash::extract($Model->find('all', ['conditions' => ['Presenter.sponsor_id' => $presenter['id'], 'Presenter.original_sponsor_id IS NULL', 'Presenter.presenter_status_id >=' => PresenterStatus::COMPLETE], 'order' => 'Presenter.id DESC']), '{n}.Presenter'); /** * Get Down line active presenter to move up if inactive */ foreach ($sponsor_presenters as $sponsor_presenter) { /** * Set new sponsor_id to $up_active */ $Model->clear(); $Model->id = $sponsor_presenter['id']; if (!$Model->save(['original_sponsor_id' => $sponsor_presenter['sponsor_id'], 'sponsor_id' => $up_active])) { $this->results['success'] = false; return $this->results; } else { $this->results['success'] = true; $log_message = " Rolled up sponsor_id for presenter_id: " . $Model->id . " from: " . $sponsor_presenter['sponsor_id'] . " to: " . $up_active . "\n"; if ($log_output == true) { print $log_message; } else { $this->results['log'] .= $log_message; } } } } $this->results['success'] = true; } catch (Exception $e) { $this->results['success'] = false; $this->results['log'] = $e->getMessage(); } return $this->results; }
function info() { $this->requirePresenterLoggedIn(); $sponsor_id = $this->Presenter->findActiveSponsor($this->presenterId); $presenter = $this->Presenter->find("first", array("conditions" => array("Presenter.id" => $this->presenterId), "fields" => array("id", "presenter_sequence_id", "sponsor_id"), "contain" => array("User" => array("fields" => array("first_name", "last_name")), "Sponsor" => array("fields" => array("id", "presenter_sequence_id"), "User" => array("fields" => array("first_name", "last_name", "largeimage"), "Email" => array("fields" => array("email"))), "PresenterSite" => array("fields" => array("site_url"))), "PresenterSite" => array("fields" => array("site_url", "head_shot", "bio"))))); // replace sponsor information with current active sponsor (with compression) if ($presenter['Sponsor']['id'] != $sponsor_id) { $spon = new Presenter(); $sponsor = $spon->find('first', array("conditions" => array('Presenter.id' => $sponsor_id), "fields" => array("id", "user_id", "presenter_sequence_id"), "contain" => array("User" => array("fields" => array("first_name", "last_name", "id"), "Email" => array("fields" => array("email", "id"))), "PresenterSite" => array("fields" => array("site_url", "id"))))); $presenter['Sponsor'] = $sponsor['Presenter']; $presenter['Sponsor']['User'] = $sponsor['User']; $presenter['Sponsor']['PresenterSite'] = $sponsor['PresenterSite']; } if (!$presenter) { $this->sendError("404", "We were not able to locate the presenter"); } $presenter["UplineElite"] = $this->Presenter->getUplineElite($this->presenterId); $this->sendSuccess($presenter); }