Skip to content

Commit

Permalink
Added 5 minute wait
Browse files Browse the repository at this point in the history
  • Loading branch information
SeanVella committed Feb 4, 2017
1 parent c7dca61 commit 1d2747c
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 32 deletions.
50 changes: 37 additions & 13 deletions assets/js/multi_user.js
@@ -1,28 +1,52 @@
jQuery(document).ready(function($) {

//get User info
function saveUser(id, entry, ajaxURL){
$.ajax({
method: 'GET',
url: ajaxURL,
data: {
id: id,
entry: parseInt(entry)
}
})
}

//get info
id = parseInt($('#session li').eq(0).find('a').attr('href').match(/\/([^\/]+)\/?$/)[1]);
name = $('#session li').eq(0).find('a').text();
// name = $('#session li').eq(0).find('a').text();
entry = document.URL.match(/\/([^\/]+)\/?$/)[1];
ajaxURL = Symphony.Context.get('symphony') + '/extension/multi_user_edit/multi_user/';


//send User info
console.log('test');

var ajaxURL = Symphony.Context.get('symphony') + '/extension/multi_user_edit/multi_user/';

//Check if the entry is being used by another author
$.ajax({
method: 'GET',
url: ajaxURL,
data: {
id: id,
name: name,
entry: parseInt(entry)
},
success: function(response){
response = $(response);
if(response.hasClass('locked')){
//if locked, get difference in minutes
$diff = response.find('#diff').text();
if($diff > 5){
//Gain access to the article as author is taking too long.
console.log('Exceeded 5 minutes; Updated log.')
saveUser(id, entry, ajaxURL);
}
else{
console.log(response.find('.show').text());
console.log((5 - $diff).toFixed(2) + ' minute/s to go.');
}
}
else{
//Save User info
saveUser(id, entry, ajaxURL);
}
}
}).done(function(response){ // after the request has been loaded...
$('#results').html(response); // put the response in the div
}).done(function(response){
//code..
});



});
43 changes: 38 additions & 5 deletions content/content.multi_user.php
@@ -1,10 +1,13 @@
<?php

require_once(TOOLKIT . '/class.administrationpage.php');
require_once(TOOLKIT . '/class.administrationpage.php');

Class contentExtensionMulti_User_EditMulti_User extends AdministrationPage {
Class contentExtensionMulti_User_EditMulti_User extends AdministrationPage {

public function __viewIndex() {
public function __viewIndex() {

//Lock entry to user
if(isset($_GET['id']) && isset($_GET['entry'])){

$userId = MySQL::cleanValue($_GET['id']);
$entryId = MySQL::cleanValue($_GET['entry']);
Expand All @@ -18,14 +21,44 @@ public function __viewIndex() {
$update['user_id'] = intval($userId);
$update['session_start'] = date($dateTime);


if(Symphony::Database()->update($update, 'sym_multi_user', "`entry_id` = ".$entryId)){
echo('Success');
}
else{
echo('error');
}
die;
}

//Check if entry is being used
if(isset($_GET['entry']) && !isset($_GET['id'])){

$entryId = MySQL::cleanValue($_GET['entry']);

$query = "SELECT session_start, user_id
FROM sym_multi_user
WHERE `entry_id` = '".$entryId."'
LIMIT 1";

$userId = Symphony::Database()->fetchVar('user_id',0,$query);

if( $userId == 0){
echo('<div class="unlocked">Unlocked</div>');
}
else{
$time = new DateTime(Symphony::Database()->fetchVar('session_start',0,$query));

$now = new DateTime();

//Check for how long the article is locked
$diff = $now->diff($time);

$diffString = $diff->format('%i.%S');


echo('<div class="locked">User ID <div class="user">'.$userId.'</div> has this article locked for <div id="diff">'.$diffString.'</div> (minutes.seconds).<div class="show">Please wait for other editors to finish editing this article.</div></div>');
}
die;
}
}

}
20 changes: 6 additions & 14 deletions extension.driver.php
Expand Up @@ -48,8 +48,6 @@ public function enable(){

public function preRender($context) {

// var_dump($context);die;

$entry_id = $context['entry']->get('id');

//Check if the entry id is already created in the table.
Expand All @@ -58,12 +56,10 @@ public function preRender($context) {
FROM tbl_multi_user as multi
WHERE multi.entry_id = '". $entry_id ."'";



$count = Symphony::Database()->fetchVar('count',0,$query);

if ($count == 0){
//Add the user and entry id to the database. Adding 0 as a temporary value for author.
//Add the entry id to the database. Adding 0 as a temporary value for author.
$query = "INSERT INTO tbl_multi_user (user_id, entry_id)
VALUES ('0', $entry_id)";

Expand All @@ -86,16 +82,12 @@ public function preRender($context) {
public function postEdit($context) {
$entry_id = $context['entry']->get('id');

//Delete all the entries related to this entry.

$query = "DELETE FROM tbl_multi_user
WHERE multi.entry_id = '". $entry_id ."'";

if(Symphony::Database()->query($query) == TRUE){
return true;
}
//Release lock.
$update = array();
$update['user_id'] = intval('0');
$update['session_start'] = date('0');

return false;
Symphony::Database()->update($update, 'sym_multi_user', "`entry_id` = ".$entry_id);

}
}

0 comments on commit 1d2747c

Please sign in to comment.