Ejemplo n.º 1
0
 public function acceptInvitationEvent($runData)
 {
     $pl = $runData->getParameterList();
     $invitationId = $pl->getParameterValue("invitation_id");
     $userId = $runData->getUserId();
     $user = $runData->getUser();
     $invitation = DB_MemberInvitationPeer::instance()->selectByPrimaryKey($invitationId);
     $site = DB_SitePeer::instance()->selectByPrimaryKey($invitation->getSiteId());
     if ($invitation == null || $invitation->getUserId() != $userId || $site == null) {
         throw new ProcessException(_("Invitation can not be found."), "no_invitation");
     }
     if ($site->getPrivate()) {
         $settings = $site->getSettings();
         $maxMembers = $settings->getMaxPrivateMembers();
         $c = new Criteria();
         $c->add("site_id", $site->getSiteId());
         $cmem = DB_MemberPeer::instance()->selectCount($c);
         if ($cmem >= $maxMembers) {
             throw new ProcessException(sprintf(_('Sorry, at the moment max %d member limit apply for private Wikis. The Site would have to be upgraded to allow more members.'), $maxMembers));
         }
     }
     // all ok... ;-)
     $db = Database::connection();
     $db->begin();
     // create membership
     $member = new DB_Member();
     $member->setUserId($userId);
     $member->setSiteId($invitation->getSiteId());
     $member->setDateJoined(new ODate());
     $member->save();
     $ml = new DB_MembershipLink();
     $ml->setUserId($userId);
     $ml->setSiteId($invitation->getSiteId());
     $ml->setDate(new ODate());
     $ml->setType('INTERNAL_INVITATION');
     $ml->setByUserId($invitation->getByUserId());
     $ml->save();
     // remove application (if any)
     $c = new Criteria();
     $c->add("site_id", $site->getSiteId());
     $c->add("user_id", $userId);
     DB_MemberApplicationPeer::instance()->delete($c);
     DB_MemberInvitationPeer::instance()->deleteByPrimaryKey($invitationId);
     $runData->ajaxResponseAdd("message", _('Now you are a member of the site') . ' <a href="http://' . htmlspecialchars($site->getDomain()) . '">' . htmlspecialchars($site->getName()) . '</a>');
     AdminNotificationMaker::instance()->memberInvitationAccepted($site, $user);
     $db->commit();
 }
Ejemplo n.º 2
0
 public function acceptApplicationEvent($runData)
 {
     $pl = $runData->getParameterList();
     $userId = $pl->getParameterValue("user_id");
     $site = $runData->getTemp("site");
     $siteId = $site->getSiteId();
     $user = DB_OzoneUserPeer::instance()->selectByPrimaryKey($userId);
     if ($user == null) {
         throw new ProcessException("Error");
     }
     $type = $pl->getParameterValue("type");
     $text = $pl->getParameterValue("text");
     if ($type !== 'accept' && $type !== 'decline') {
         throw new ProcessException("Invalid action", "invalid_action");
     }
     $c = new Criteria();
     $c->add("user_id", $userId);
     $c->add("site_id", $siteId);
     $db = Database::connection();
     $db->begin();
     $application = DB_MemberApplicationPeer::instance()->selectOne($c);
     if ($application == null) {
         throw new ProcessException(_("This application does not exist (anymore)."), "no_application");
     }
     if ($type == "accept") {
         // add to members
         $mem = new DB_Member();
         $mem->setUserId($userId);
         $mem->setSiteId($siteId);
         $mem->setDateJoined(new ODate());
         $mem->save();
         $ml = new DB_MembershipLink();
         $ml->setUserId($userId);
         $ml->setSiteId($site->getSiteId());
         $ml->setDate(new ODate());
         $ml->setType('APPLICATION_ACCEPTED');
         $ml->setByUserId($runData->getUser()->getUserId());
         $ml->save();
         NotificationMaker::instance()->membershipApplicationAccepted($site, $user);
     } else {
         NotificationMaker::instance()->membershipApplicationDeclined($site, $user);
     }
     $application->setReply($text);
     if ($type == "accept") {
         $application->setStatus("accepted");
     } else {
         $application->setStatus("declined");
     }
     $application->save();
     $db->commit();
 }
Ejemplo n.º 3
0
 public function acceptEmailInvitationEvent($runData)
 {
     $pl = $runData->getParameterList();
     $user = $runData->getUser();
     $hash = $pl->getParameterValue("hash");
     // get the invitation entry (if any)
     $c = new Criteria();
     $c->add("hash", $hash);
     $c->add("accepted", false);
     $inv = DB_EmailInvitationPeer::instance()->selectOne($c);
     $runData->contextAdd("user", $user);
     if (!$inv) {
         throw new ProcessException(_("Sorry, no invitation can be found."));
     }
     $site = DB_SitePeer::instance()->selectByPrimaryKey($inv->getSiteId());
     // check if not a member already
     $c = new Criteria();
     $c->add("user_id", $user->getUserId());
     $c->add("site_id", $site->getSiteId());
     $mem = DB_MemberPeer::instance()->selectOne($c);
     if ($mem) {
         throw new ProcessException(_("It seems you already are a member of this site! Congratulations anyway ;-)"));
     }
     // check if not > max _members
     if ($site->getPrivate()) {
         $settings = $site->getSettings();
         $maxMembers = $settings->getMaxPrivateMembers();
         $c = new Criteria();
         $c->add("site_id", $site->getSiteId());
         $cmem = DB_MemberPeer::instance()->selectCount($c);
         if ($cmem >= $maxMembers) {
             throw new ProcessException(sprintf(_('Sorry, at the moment max %d member limit apply for private Wikis. The Site would have to be upgraded to allow more members.'), $maxMembers));
         }
     }
     // all should be fine at this point - add to members
     $db = Database::connection();
     $db->begin();
     $mem = new DB_Member();
     $mem->setDateJoined(new ODate());
     $mem->setSiteId($site->getSiteId());
     $mem->setUserId($user->getUserId());
     $mem->save();
     $ml = new DB_MembershipLink();
     $ml->setUserId($user->getUserId());
     $ml->setSiteId($site->getSiteId());
     $ml->setDate(new ODate());
     $ml->setType('EMAIL_INVITATION');
     $ml->setByUserId($inv->getUserId());
     $ml->save();
     // add to contacts?
     $sender = DB_OzoneUserPeer::instance()->selectByPrimaryKey($inv->getUserId());
     if ($inv->getToContacts() && $sender->getUserId() != $user->getUserId()) {
         try {
             // check if contact already exists
             $c = new Criteria();
             $c->add("user_id", $user->getUserId());
             $c->add("target_user_id", $sender->getUserId());
             $con0 = DB_ContactPeer::instance()->selectOne($c);
             if (!$con0) {
                 $con = new DB_Contact();
                 $con->setUserId($user->getUserId());
                 $con->setTargetUserId($sender->getUserId());
                 $con->save();
             }
         } catch (Exception $e) {
         }
         try {
             // check if contact already exists
             $c = new Criteria();
             $c->add("user_id", $sender->getUserId());
             $c->add("target_user_id", $user->getUserId());
             $con0 = DB_ContactPeer::instance()->selectOne($c);
             if (!$con0) {
                 $con = new DB_Contact();
                 $con->setUserId($sender->getUserId());
                 $con->setTargetUserId($user->getUserId());
                 $con->save();
             }
         } catch (Exception $e) {
         }
     }
     // set accepted
     $inv->setAccepted(true);
     $inv->save();
     // create a notification
     AdminNotificationMaker::instance()->acceptedEmailInvitation($inv, $user);
     $db->commit();
     $runData->contextAdd("site", $site);
 }