예제 #1
0
 /**
  * Uses GET data
  */
 public function processRemoveMember()
 {
     $wikiplace = $this->checkWikiPlace($this->name);
     if (is_null($wikiplace)) {
         return;
     }
     // else, the wikiplace exists and the User executing this instance is the wikiplace owner, continue
     $this->action = self::ACTION_LIST_MEMBERS;
     // always
     if (!($user = User::newFromName($this->user)) instanceof User || $user->getId() == 0) {
         $this->msgKey = 'noname';
         // invalid username
         $this->msgType = 'error';
     } elseif (!($member = WpMember::GetFromWikiPlaceAndUser($wikiplace, $user)) instanceof WpMember) {
         $this->msgKey = 'wp-not-member';
         $this->msgType = 'error';
     } elseif (!$member->delete()) {
         $this->msgKey = 'internalerror';
         // sql error ?
         $this->msgType = 'error';
     } else {
         // everything is fine :)
         $user->invalidateCache();
         // necessary to update menus and link of the user
         $this->logActionMember('remove', $wikiplace->getTitle(), $user);
         $this->msgKey = 'wp-remove-member-success';
         $this->msgType = 'success';
     }
     // always
     $this->display();
     return;
 }
예제 #2
0
 /**
  * 
  * @param int|WpWikiplace $wikiplace An instance of WpWikiplace, or the wikiplace id (int)
  * @param int|User $user An instance of User, or the user id (int)
  * @return boolean Returns false if user is not memeber of the wikiplace
  */
 public static function IsMember($wikiplace, $user)
 {
     return WpMember::GetFromWikiPlaceAndUser($wikiplace, $user) instanceof WpMember;
 }
 private function changeWikiplaceOwner($wikiplace_name = null, $user_name = null, $confirm = false)
 {
     $output = $this->getOutput();
     $output->addWikiText("=== Change Wikiplace Owner ===");
     $this->prettyOutput($output, array('wikiplace' => $wikiplace_name, 'user' => $user_name));
     $output->addWikiText("----");
     if (empty($wikiplace_name)) {
         $output->addWikiText("=== Specify a wikiplace name. ===");
         return;
     }
     $wikiplace = WpWikiplace::newFromName($wikiplace_name);
     if (is_null($wikiplace)) {
         $output->addWikiText("== ERROR! No Wikiplace with that name was found. ==");
         return;
     }
     $output->addWikiText("=== Wikiplace ===");
     $this->prettyOutput($output, array('id' => $wikiplace->getId(), 'name' => $wikiplace->getName(), 'report_expires' => $wikiplace->getDateExpires(), 'report_updated' => $wikiplace->getReportUpdated()));
     $owner = User::newFromId($wikiplace->getOwnerUserId());
     if (!$owner->loadFromId()) {
         $output->addWikiText("== WARNING! Owner is not an existing user! ==");
     } else {
         $output->addWikiText("==== Current owner ====");
         $this->prettyOutput($output, array('id' => $owner->getId(), 'name' => $owner->getName(), 'email' => $owner->getEmail(), 'email confirmed' => $owner->isEmailConfirmed() ? 'yes' : 'no', 'timestamp of account creation' => $owner->getRegistration()));
     }
     $output->addWikiText("----");
     if (empty($user_name)) {
         $output->addWikiText("=== Specify a user name. ===");
         return;
     }
     $user = User::newFromName($user_name);
     if (!$user || $user->getId() == 0) {
         $output->addWikiText("== ERROR! The user doesn't exist ! ==");
         return;
     }
     $output->addWikiText("=== New Owner ===");
     $this->prettyOutput($output, array('id' => $user->getId(), 'name' => $user->getName(), 'email' => $user->getEmail(), 'email confirmed' => $user->isEmailConfirmed() ? 'yes' : 'no', 'timestamp of account creation' => $user->getRegistration()));
     if (!$user->isEmailConfirmed()) {
         $output->addWikiText("== WARNING! Email is not confirmed! ==");
     }
     $last_subscription = WpSubscription::newByUserId($user->getId());
     if (is_null($last_subscription)) {
         $output->addWikiText("== ERROR! The user doesn't have any subscription! ==");
         return;
     }
     $output->addWikiText("==== Last subscription ====");
     $this->prettyOutput($output, array('id' => $last_subscription->getId(), 'starts' => $last_subscription->getStart(), 'ends' => $last_subscription->getEnd(), 'active' => $last_subscription->isActive() ? "yes" : "no", 'transaction status' => $last_subscription->getTmrStatus()));
     if (!$last_subscription->isActive()) {
         $output->addWikiText("== WARNING! The subscription is not active! ==");
     }
     $plan = $last_subscription->getPlan();
     if (is_null($plan)) {
         $output->addWikiText("== ERROR! The subscribed plan doesn't exist! ==");
         return;
     }
     $output->addWikiText("==== Plan ====");
     $price = $plan->getPrice();
     $this->prettyOutput($output, array('id' => $plan->getId(), 'name' => $plan->getName(), 'period' => $plan->getPeriod() . ' month(s)', 'by invitation only' => $plan->isInvitationRequired() ? 'yes' : 'no', 'price' => $price['amount'] . ' ' . $price['currency']));
     $output->addWikiText("==== Membership ====");
     $member = WpMember::GetFromWikiPlaceAndUser($wikiplace, $user);
     if ($member instanceof WpMember) {
         $output->addWikiText("Target user, {$user->getName()}, is a member of {$wikiplace->getName()}.");
         $output->addWikiText("Membership will be removed for ownership change.");
     } else {
         $output->addWikiText("{$user->getName()} is <b>NOT</b> a member of {$wikiplace->getName()}.");
     }
     $output->addWikiText("----");
     if ($confirm !== true) {
         $output->addWikiText("=== To confirm ===");
         $output->addHTML($this->getLink(self::ACTION_CHANGE_WIKIPLACE_OWNER, array('wikiplace' => $wikiplace_name, 'user' => $user_name), true));
     } else {
         if ($member instanceof WpMember) {
             $member->delete();
         }
         $wikiplace->setOwnerUserId($user->getId());
         $output->addWikiText("== Done ! ==");
     }
 }