Esempio n. 1
0
 public function getChapter() : Chapter
 {
     if (!$this->_chapter) {
         $this->_chapter = Chapter::find($this->_pdo, $this->chapter_id);
     }
     return $this->_chapter;
 }
 public function main()
 {
     $org_id = Utility::cleanInt($_POST["org_id"], 1);
     $uni_id = Utility::cleanInt($_POST["uni_id"], 1);
     $email = Utility::cleanString($_POST["university_email"]);
     $name_first = Utility::cleanString($_POST["name_first"]);
     $name_last = Utility::cleanString($_POST["name_last"]);
     $password = Utility::cleanString($_POST["password"]);
     $pledge_class = Utility::cleanString($_POST["pledge_class"]);
     $year = Utility::getDateTimeFromYear(Utility::cleanString($_POST["year"]));
     if (!$org_id) {
         $this->setError(self::$E_ORG_INVALID);
         return;
     }
     if (!$uni_id) {
         $this->setError(self::$E_UNI_INVALID);
         return;
     }
     $_org = GreekOrganization::find($this->_pdo, $org_id);
     $_uni = University::find($this->_pdo, $uni_id);
     if (is_null($_org)) {
         $this->setError(self::$E_ORG_INVALID);
         return;
     }
     if (is_null($_uni)) {
         $this->setError(self::$E_UNI_INVALID);
         return;
     }
     if (Chapter::findByOrgAndUni($this->_pdo, $_org, $_uni)) {
         $this->setError(self::$E_CHAPTER_EXISTS);
         return;
     }
     if ($name_first == "") {
         $this->setError(self::$E_NAME_F_INVALID);
         return;
     }
     if ($name_last == "") {
         $this->setError(self::$E_NAME_L_INVALID);
         return;
     }
     if (!Utility::isValidEmail($email)) {
         $this->setError(self::$E_EMAIL_INVALID);
         return;
     }
     if (User::findByEmail($this->_pdo, $email)) {
         $this->setError(self::$E_USER_EXISTS);
         return;
     }
     if ($pledge_class == "") {
         $this->setError(self::$E_PLEDGE_CLASS_INVALID);
         return;
     }
     if (!Utility::cleanInt($_POST["year"], date("Y") - 6)) {
         $this->setError(self::$E_YEAR_INVALID);
         return;
     }
     if ($year === false) {
         $this->setError(self::$E_YEAR_INVALID);
         return;
     }
     if (!Utility::isValidPassword($password)) {
         $this->setError(self::$E_PASSWORD_INVALID);
         return;
     }
     $_chapter = new Chapter($this->_pdo);
     $_chapter->create($_org, $_uni);
     $_pc = new PledgeClass($this->_pdo);
     $_pc->create($_chapter, $pledge_class);
     $_user = new User($this->_pdo);
     $_user->create($_chapter, $_pc, $name_first, $name_last, $email, $password, $year, true);
     $worker = new EmailWorker($this->_pdo);
     //TODO: Send email to user about what's next
     $worker->queueSignUpNotificationEmail($_chapter);
 }
Esempio n. 3
0
 public function sendSignUpNotificationEmail(Chapter $_chapter)
 {
     $this->send(self::$T_SIGN_UP_NOTIFICATION, Config::getDevUser($this->_pdo), ["CHAPTER_ID" => $_chapter->getId(), "NAME" => $_chapter->getGreekOrganization()->getName(), "LETTERS" => $_chapter->getGreekOrganization()->getLetters(), "UNIVERSITY" => $_chapter->getUniversity()->getName()]);
 }
Esempio n. 4
0
     }
     $chapter = \FMA\Organization\Chapter::find($_pdo, $cid);
     if (is_null($chapter)) {
         return ["err" => true, "msg" => "No chapter by that id."];
     }
     if ($chapter->getGreekOrganizationId() != $org->getId()) {
         return ["err" => true, "msg" => "Organization has no chapter by that id."];
     }
     return \FMA\User\User::findAllForChapterAsArray($_pdo, $chapter);
 });
 $router->map("GET", "/organization/[i:id]/chapter/[i:cid]/user/[i:uid]/", function ($id, $cid, $uid) use($_pdo) {
     $org = \FMA\Organization\GreekOrganization::find($_pdo, $id);
     if (is_null($org)) {
         return ["err" => true, "msg" => "No organization by that id."];
     }
     $chapter = \FMA\Organization\Chapter::find($_pdo, $cid);
     if (is_null($chapter)) {
         return ["err" => true, "msg" => "No chapter by that id."];
     }
     if ($chapter->getGreekOrganizationId() != $org->getId()) {
         return ["err" => true, "msg" => "Organization has no chapter by that id."];
     }
     $user = \FMA\User\User::find($_pdo, $uid);
     if (is_null($user)) {
         return ["err" => true, "msg" => "No user by that id."];
     }
     if ($user->getChapterId() != $chapter->getId()) {
         return ["err" => true, "msg" => "Chapter has no user by that id."];
     }
     return $user->toArray();
 });
Esempio n. 5
0
 /**
  * @param BasePDO $_pdo
  * @param Chapter $_c
  * @return User[]
  */
 public static function findAllActiveAssociatesForChapter(BasePDO $_pdo, Chapter $_c) : array
 {
     $query = "SELECT * FROM `user` WHERE chapter_id = :c AND is_active = 1 AND is_brother = 0";
     return $_pdo->fetchAssoc($query, ["c" => $_c->getId()], function ($row) use($_pdo, $_c) {
         $tmp = new self($_pdo, $row);
         $tmp->_chapter = $_c;
         return $tmp;
     });
 }
Esempio n. 6
0
 /**
  * @param BasePDO $_pdo
  * @param Chapter $_chapter
  * @return self[]
  */
 public static function findAllForChapter(BasePDO $_pdo, Chapter $_chapter) : array
 {
     $query = "SELECT e.* FROM `event` e LEFT JOIN `user` u ON u.id = e.creator_id WHERE u.chapter_id = :cid";
     return $_pdo->fetchAll($query, ["cid" => $_chapter->getId()], function ($row) use($_pdo, $_chapter) {
         $row = new self($_pdo, $row);
         $row->_group = $_chapter;
         return $row;
     });
 }
Esempio n. 7
0
 private function sendSignUpNotificationEmail(\int $chapter_id)
 {
     $_chapter = Chapter::find($this->_pdo, $chapter_id);
     $this->_mailer->sendSignUpNotificationEmail($_chapter);
 }
Esempio n. 8
0
 /**
  * @param BasePDO $_pdo
  * @param Chapter $_chapter
  * @return Swag[]
  */
 public static function findAllForChapter(BasePDO $_pdo, Chapter $_chapter) : array
 {
     $query = "SELECT s.* FROM chapter c\n\t\t\t\t\t\tRIGHT JOIN `user` u ON u.chapter_id = c.id\n\t\t\t\t\t\tRIGHT JOIN swag s ON s.creator_id = u.id\n\t\t\t\t\t  WHERE c.id = :cid";
     return $_pdo->fetchAssoc($query, ["cid" => $_chapter->getId()], function (array $row) use($_pdo) {
         return new self($_pdo, $row);
     });
 }