Beispiel #1
0
 public static function instance()
 {
     if (self::$instance == null) {
         self::$instance = new NotificationMaker();
     }
     return self::$instance;
 }
Beispiel #2
0
 public function sendEvent($runData)
 {
     $pl = $runData->getParameterList();
     $source = $pl->getParameterValue("source");
     $subject = $pl->getParameterValue("subject");
     if ($subject == null || $subject === '') {
         $subject = "(No subject)";
     }
     $db = Database::connection();
     $db->begin();
     $toUserId = $pl->getParameterValue("to_user_id");
     // TODO: validation. also check if user exists
     $toUser = DB_OzoneUserPeer::instance()->selectByPrimaryKey($toUserId);
     if ($toUser == null) {
         $message = _("The recipient does not exist.");
         throw new ProcessException($message, "no_recipient");
     }
     // check if allowed
     $fromUser = $runData->getUser();
     WDPermissionManager::instance()->hasPmPermission($fromUser, $toUser);
     // compile content
     $wt = new WikiTransformation();
     $wt->setMode('pm');
     $body = $wt->processSource($source);
     $message = new DB_PrivateMessage();
     $message->setDate(new ODate());
     $message->setFromUserId($runData->getUserId());
     $message->setToUserId($toUserId);
     $message->setSubject($subject);
     $message->setBody($body);
     $message->setFlag(0);
     // 0 for inbox
     $message->save();
     NotificationMaker::instance()->privateMessageNotification($message);
     //also make a copy for "sent" folder
     $message->setNew(true);
     $message->setMessageId(null);
     $message->setFlag(1);
     //1 for sent
     $message->save();
     $db->commit();
 }
 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();
 }