-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a very basic model for sharing (inviting people to the chat and
emailing) a chat.
- Loading branch information
1 parent
7fc7708
commit 29c98aa
Showing
4 changed files
with
122 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
32
www/templates/default/UNL/VisitorChat/Conversation/Share.tpl.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
35 changes: 35 additions & 0 deletions
35
www/templates/default/UNL/VisitorChat/Conversation/ShareList.tpl.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |