public function execute($par) { $this->setHeaders(); // sets robotPolicy = "noindex,nofollow" + set page title $user = $this->getUser(); $output = $this->getOutput(); $request = $this->getRequest(); // Check rights and block if necessary if (!$this->userCanExecute($user)) { // If anon, redirect to login if ($user->isAnon()) { $output->redirect($this->getTitleFor('UserLogin')->getLocalURL(array('returnto' => $this->getFullTitle())), '401'); return; } // Else display an error page. $this->displayRestrictionError(); return; } if (isset($par) && $par != '') { $explosion = explode(':', $par); if (count($explosion) == 1) { $this->action = $explosion[0]; $this->category_id = $this->getRequest()->getText('category', null); } else { if (count($explosion) == 2) { $this->action = $explosion[0]; $this->category_id = $explosion[1]; } } } else { $this->action = $this->getRequest()->getText('action', null); $this->category_id = $this->getRequest()->getText('category', null); } if ($user->isAllowed(WP_ADMIN_RIGHT)) { $this->userIsAdmin = true; $this->userInvitationsCategories = WpInvitationCategory::factoryAllAvailable(true); // with admin categories } else { $this->userIsAdmin = false; $this->userActiveSubscription = WpSubscription::newActiveByUserId($user->getId()); $this->userInvitationsCategories = WpInvitationCategory::factoryAllAvailable(false); // without admin categories $this->setUsageThisMonth(); $this->setUsageLeftThisMonth(); } $this->msgType = $request->getText('msgtype', null); $msgKey = $request->getText('msgkey', null); if ($msgKey != null) { $msg = wfMessage($msgKey); if ($msg->exists()) { $this->msg = $msg; } } $this->display(); }
/** * * @param WpInvitationCategory $invitationCategory * @param User $fromUser * * @param string $code * @param string $toEmail * @param int $counter * @return WpInvitation */ public static function create($invitationCategory, $fromUser, $code, $toEmail = null, $counter = 1) { $invitationCategoryId = $invitationCategory->getId(); $code = strtolower($code); $dbw = wfGetDB(DB_MASTER); $created = WpSubscription::now(); $dbw->begin(); $fromUserId = $fromUser->getId(); // With PostgreSQL, a value is returned, but null returned for MySQL because of autoincrement system $id = $dbw->nextSequenceValue('wp_invitation_wpi_id_seq'); $success = $dbw->insert('wp_invitation', array('wpi_id' => $id, 'wpi_code' => $code, 'wpi_to_email' => $toEmail, 'wpi_from_user_id' => $fromUserId, 'wpi_date_created' => $created, 'wpi_counter' => $counter, 'wpi_wpic_id' => $invitationCategoryId)); // Setting id from auto incremented id in DB $id = $dbw->insertId(); $dbw->commit(); if (!$success) { return null; } return new self($id, $code, $toEmail, $fromUserId, $created, null, $counter, $invitationCategoryId); }