Skip to content

Commit

Permalink
add a very basic model for sharing (inviting people to the chat and
Browse files Browse the repository at this point in the history
emailing) a chat.
  • Loading branch information
mfairchild365 committed Apr 25, 2012
1 parent 7fc7708 commit 29c98aa
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/UNL/VisitorChat/Conversation/Routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public static function getGetRoutes()

public static function getPostRoutes()
{
return array('/^conversation\/(?P<id>[\d]+)\/edit$/i' => 'Edit');
return array('/^conversation\/(?P<id>[\d]+)\/edit$/i' => 'Edit',
'/^conversation\/(?P<id>[\d]+)\/share$/i' => 'Share');
}

public static function getDeleteRoutes()
Expand Down
53 changes: 53 additions & 0 deletions src/UNL/VisitorChat/Conversation/Share.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
namespace UNL\VisitorChat\Conversation;

class Share extends \UNL\VisitorChat\Conversation\Record
{
function __construct($options = array())
{
//Needs to be atleast a user to login.
\UNL\VisitorChat\Controller::requireClientLogin();

if (isset($options['id']) && $object = \UNL\VisitorChat\Conversation\Record::getByID($options['id'])) {
$this->synchronizeWithArray($object->toArray());
} else {
if (!$conversation = \UNL\VisitorChat\Conversation\Record::getCurrentUser()->getConversation()) {
throw new \Exception("No conversation was found", 400);
}
$this->synchronizeWithArray($conversation->toArray());
}
}

function canShare($userID)
{
//Anyone currently involved in a chat can edit it.
if (in_array($userID, $this->getInvolvedUsers())) {
return true;
}

return false;
}

function handlePost($post = array())
{
if (!$this->canShare($_SESSION['id'])) {
throw new \Exception("you do not have permission to share this conversation.", 401);
}

if (!isset($post['method']) || !in_array($post['method'], array('invite'))) {
throw new \Exception('A valid method was not given.', 400);
}

if (!isset($post['to'])) {
throw new \Exception('No one was specified to share this conversation with.', 400);
}

switch ($post['to']) {
case 'invite':
//Start a new invitation here.
break;
}

\Epoch\Controller::redirect(\UNL\VisitorChat\Controller::$URLService->generateSiteURL("success", true));
}
}
32 changes: 32 additions & 0 deletions www/templates/default/UNL/VisitorChat/Conversation/Share.tpl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<h2>Share this conversation</h2>
<form name="share action="<?php UNL\VisitorChat\Controller::$URLService->generateSiteURL('conversation/' . $context->id . '/share', true)?>" method="POST">
<fieldset>
<legend>Select sharing method</legend>
<ul>
<li><input type='radio' name='method' value='invite' checked='checked' />Invite to conversation</li>
</ul>
</fieldset>

<fieldset>
<legend>Select who you want to share with</legend>
<fieldset>
<legend>Your sites</legend>
<?php
//Display a list of your sites first.
$list = \UNL\VisitorChat\Controller::$registryService->getSitesForUser(\UNL\VisitorChat\User\Record::getCurrentUser()->uid);
echo \Epoch\Controller::$templater->render($list, 'UNL/Visitorchat/Conversation/ShareList.tpl.php');
?>
</fieldset>

<fieldset>
<legend>All sites</legend>
<?php
//Display a list of all sites next.
$list = \UNL\VisitorChat\Controller::$registryService->getAllSites();
echo \Epoch\Controller::$templater->render($list, 'UNL/Visitorchat/Conversation/ShareList.tpl.php');
?>
</fieldset>
</fieldset>

<input type="submit" value="Submit"/>
</form>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<ul>
<?php
foreach ($context as $site) {
$class = "offline";
if ($site->getAvailableCount()) {
$class = "online";
}
?>
<li class=<?php echo $class?>>
<input type='radio' name='to' value='<?php echo $site->getURL();?>' /><?php echo $site->getTitle();?>
<ul>
<?php
foreach ($site->getMembers() as $member) {
if (!$account = $member->getAccount()) {
continue;
}

//Do not display yourself.
if ($account->id == \UNL\VisitorChat\User\Record::getCurrentUser()->id) {
continue;
}

$class = "offline";
if ($account->status == "AVAILABLE") {
$class = "online";
}

echo "<li class='" . $class . "'><input type='radio' name='to' value='" . $account->uid . "' />" . $account->name . "</li>";
}
?>
</ul>
</li>
<?php
}?>
</ul>

0 comments on commit 29c98aa

Please sign in to comment.