private function previousIntroductions() { $output = ''; $introductionsQ = $this->db->prepare('SELECT i.id, i.introducer_id, introducer.name as introducer_name, i.introducee1_id, in1.name as introducee1_name, i.introducee2_id, in2.name as introducee2_name, i.time, i.link_password FROM introduction i LEFT JOIN person introducer ON introducer.id = i.introducer_id LEFT JOIN person in1 ON in1.id = i.introducee1_id LEFT JOIN person in2 ON in2.id = i.introducee2_id WHERE (i.introducer_id = :id OR i.introducee1_id = :id OR i.introducee2_id = :id) ORDER BY time DESC'); $introductionsQ->execute(array(':id' => $this->userId)); $introductions = $introductionsQ->fetchAll(PDO::FETCH_ASSOC); if (!empty($introductions)) { $you = (string) Content::c()->home->you; $youCapital = (string) Content::c()->home->you_capital; $story = (string) Content::c()->home->story; $output .= '<div id="previousIntroductions"><h2>' . Content::c()->home->history . '</h2>'; foreach ($introductions as $introd) { $url = APP_URL . '/' . Content::l() . '/A' . $introd['link_password'] . BaseConvert::base10ToBase62($introd['id']); if ($this->userId == $introd['introducer_id']) { $output .= '<p><a href="' . $url . '">' . str_replace('INTRODUCEE1_NAME', '<strong>' . $introd['introducee1_name'] . '</strong>', str_replace('INTRODUCEE2_NAME', '<strong>' . $introd['introducee2_name'] . '</strong>', str_replace('INTRODUCER_NAME', $youCapital, $story))) . '</a></p>'; } elseif ($this->userId == $introd['introducee1_id']) { $output .= '<p><a href="' . $url . '">' . str_replace('INTRODUCEE1_NAME', $you, str_replace('INTRODUCEE2_NAME', '<strong>' . $introd['introducee2_name'] . '</strong>', str_replace('INTRODUCER_NAME', '<strong>' . $introd['introducer_name'] . '</strong>', $story))) . '</a></p>'; } else { $output .= '<p><a href="' . $url . '">' . str_replace('INTRODUCEE1_NAME', $you, str_replace('INTRODUCEE2_NAME', '<strong>' . $introd['introducee1_name'] . '</strong>', str_replace('INTRODUCER_NAME', '<strong>' . $introd['introducer_name'] . '</strong>', $story))) . '</a></p>'; } $output .= $this->formatTime(strtotime($introd['time'])); } $output .= '</div>'; } return $output; }
public function __construct($introductionId, $introducee, $other) { $this->introductionId = $introductionId; $this->introducee = $introducee; $this->other = $other; $this->userId = SessionManager::getInstance()->getUserId(); $this->db = Database::getInstance(); // Get the introducee details $userDetailsQ = $this->db->prepare('SELECT p.name, f.id as facebook_id, f.access_token as facebook_access_token, l.id as linkedin_id, l.access_token as linkedin_access_token, t.id as twitter_id, t.access_token as twitter_access_token FROM person p LEFT JOIN facebook f ON p.id = f.person_id LEFT JOIN linkedin l ON p.id = l.person_id LEFT JOIN twitter t ON p.id = t.person_id WHERE p.id = :id'); $userDetailsQ->execute(array(':id' => $this->userId)); $this->userDetails = $userDetailsQ->fetch(PDO::FETCH_ASSOC); $this->userName = $this->userDetails['name']; // Get the personalised link for the introducee $linkQ = $this->db->prepare('SELECT id, link_password FROM link WHERE introduction_id = :introduction_id AND person_id = :person_id'); $linkQ->execute(array(':introduction_id' => $this->introductionId, ':person_id' => $this->introducee->getId())); $link = $linkQ->fetch(PDO::FETCH_ASSOC); $this->introductionUrl = APP_URL . '/B' . $link['link_password'] . BaseConvert::base10ToBase62($link['id']); }
public function __construct() { session_start(); // Connect to the database $this->db = Database::getInstance(); // Get the website user $userId = SessionManager::getInstance()->getUserId(); if (empty($userId)) { Debug::l('No user logged in'); header('Location: ' . APP_URL . '/' . Content::l() . '/'); exit; } // Get the introduction that hasn't been sent yet $this->introductionQ = $this->db->prepare('SELECT id, introducee1_id, introducee2_id, introducee1_notified, introducee2_notified, link_password FROM introduction WHERE introducer_id = :id AND (introducee1_notified IS NULL OR introducee2_notified IS NULL) ORDER BY time DESC LIMIT 1'); $this->introductionQ->execute(array(':id' => $userId)); $this->introduction = $this->introductionQ->fetch(PDO::FETCH_ASSOC); if (empty($this->introduction)) { Debug::l('No unsent introductions found'); header('Location: ' . APP_URL . '/' . Content::l() . '/'); exit; } $introducee1 = new Person(array()); $introducee1->getDataFromId($this->introduction['introducee1_id']); $introducee2 = new Person(array()); $introducee2->getDataFromId($this->introduction['introducee2_id']); // Notify introducee 1 if (empty($this->introduction['introducee1_notified'])) { $notifyManager = new NotifyManager($this->introduction['id'], $introducee1, $introducee2); $updateQ = $this->db->prepare('UPDATE introduction SET introducee1_notified = :method WHERE id = :id'); $this->notifyPerson($notifyManager, $introducee1, $updateQ); } // Notify introducee 2 if (empty($this->introduction['introducee2_notified'])) { $notifyManager = new NotifyManager($this->introduction['id'], $introducee2, $introducee1); $updateQ = $this->db->prepare('UPDATE introduction SET introducee2_notified = :method WHERE id = :id'); $this->notifyPerson($notifyManager, $introducee2, $updateQ); } $base62 = BaseConvert::base10ToBase62($this->introduction['id']); // Redirect to introduction page header('Location: ' . APP_URL . '/' . Content::l() . '/A' . $this->introduction['link_password'] . $base62); }