public function calculate($user) { $c = new Criteria(); $c->add('user_id', $user->getUserId()); $c->addOr('target_user_id', $user->getUserId()); $count = DB_ContactPeer::instance()->selectCount($c); return $count; }
public function build($runData) { $user = $runData->getUser(); // get all contacts $c = new Criteria(); $c->add("contact.target_user_id", $user->getUserId()); $c->addJoin("user_id", "ozone_user.user_id"); $c->addOrderAscending("ozone_user.nick_name"); $contacts = DB_ContactPeer::instance()->select($c); $runData->contextAdd("contacts", $contacts); }
public function build($runData) { $user = $runData->getUser(); // get all contacts $c = new Criteria(); $c->add("contact.user_id", $user->getUserId()); $c->addJoin("target_user_id", "ozone_user.user_id"); $c->addOrderAscending("ozone_user.nick_name"); $contacts = DB_ContactPeer::instance()->select($c); // avatar uri foreach ($contacts as &$co) { $userId = $co->getTargetUserId(); $co->setTemp("avatarUri", '/common--images/avatars/' . floor($userId / 1000) . '/' . $userId . '/a16.png'); } $runData->contextAdd("contacts", $contacts); }
public function build($runData) { $user = $runData->getUser(); // get all contacts $c = new Criteria(); $c->add("contact.user_id", $user->getUserId()); $c->addJoin("target_user_id", "ozone_user.user_id"); $c->addOrderAscending("ozone_user.nick_name"); $contacts = DB_ContactPeer::instance()->select($c); if (true || count($contacts) > 0) { // get the list who contacts you back to display emails. // by query $q = "SELECT user_id FROM contact WHERE target_user_id='" . $user->getUserId() . "'"; $db = Database::connection(); $res = $db->query($q); $back = $res->fetchAll(); if ($back) { foreach ($back as &$b) { $b = $b['user_id']; } foreach ($contacts as &$contact) { if (in_array($contact->getTargetUserId(), $back)) { $contact->setTemp("showEmail", true); } } } if (!$back) { $back = null; } $runData->contextAdd("back", $back); $runData->contextAdd("countBack", count($back)); } $runData->contextAdd("contacts", $contacts); $maxContacts = 10; $runData->contextAdd("maxContacts", $maxContacts); }
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); }
/** * Check if $user can send a private message to $toUser. */ public function hasPmPermission($user, $toUser) { if ($user && ($user->getSuperAdmin() || $user->getSuperModerator())) { return true; } // first check if if $user has pm enabled $us = DB_UserSettingsPeer::instance()->selectByPrimaryKey($toUser->getUserId()); $p = $us->getReceivePm(); //echo "ad"; if ($this->isUserSuperior($user, $toUser)) { return true; } // accept from none (unless from moderators/admins of common sites) if ($p == 'n') { throw new WDPermissionException(_("This user does wish to receive private messages.")); } if ($p == 'mf') { if ($this->shareSites($user, $toUser)) { // so they share common sites. check for blocks! if ($this->userBlocksUser($toUser, $user)) { throw new WDPermissionException(_("You are blocked by this user.")); } return true; } // if friends - return true (todo) $c = new Criteria(); $c->add("user_id", $user->getUserId()); $c->add("target_user_id", $toUser->getUserId()); $con = DB_ContactPeer::instance()->selectOne($c); if ($con) { return true; } throw new WDPermissionException(_("This user wishes to receive messages only from selected users.")); } if ($p == 'f') { //echo "fff"; // check if a friend $c = new Criteria(); $c->add("user_id", $toUser->getUserId()); $c->add("target_user_id", $user->getUserId()); $con = DB_ContactPeer::instance()->selectOne($c); if ($con) { return true; } throw new WDPermissionException(_("This user wishes to receive messages only from selected users.")); } if ($p == 'a') { // check if not blocked if ($this->userBlocksUser($toUser, $user)) { throw new WDPermissionException(_("You are blocked by this user.")); } } // in any other case check return true; }