<?php
define('AJAX_LOCKING_LOCKED', 'locked');
define('AJAX_LOCKING_UNLOCKED', 'unlocked');
define('AJAX_LOCKING_OWNED', 'owned');
define('AJAX_LOCKING_TIMEOUT', 'timeout');
define('AJAX_LOCKING_PREFIX', 'ajaxlock');
/**
* This class implements a base class for AJAX_Locking drivers.
*/
class AJAX_Locking_Driver
{
var $timeout = 3600;
/**
* Constructor
*
* @return AJAX_Locking_Driver
*/
function AJAX_Locking_Driver($timeout = 3600)
{
if ($timeout) $this->timeout = $timeout;
}
/**
* Locks an object
*
* @param mixed $user id of the user who wants to lock
* @param string $type type/classname of the object
* @param mixed $id id of the object
* @return boolean true if the lock was successfull or the user is the owner
* false otherwise
*/
function lock($user, $type, $id)
{
return true;
}
/**
* Unlocks an object
*
* @param mixed $user id of the user who wants to unlock
* @param string $type type/classname of the object
* @param mixed $id id of the object
* @return boolean true if the unlock was successfull, false otherwise
*/
function unlock($user, $type, $id)
{
return true;
}
/**
* Returns the status of the object (lock or unlocked)
*
* @param mixed $user id of the user who wants to know the object's status
* @param string $type type/classname of the object
* @param mixed $id id of the object
* @return string the status and the owner of the object
*/
function status($user, $type, $id)
{
return AJAX_LOCKING_UNLOCKED . "~";
}
/**
* Returns the list of all active locks for administration purpose
*
* @return array of locks (owner, type, id), false if not implemented
*/
function getLocks()
{
return false;
}
/**
* Administrately delete a lock
*
* @param string $type
* @param mixed $id
*
* @return true if the lock is deleted successfully, false otherwise
*/
function deleteLock($type, $id)
{
return false;
}
function _getKey($type, $id)
{
return AJAX_LOCKING_PREFIX . '.' . $type . '.' . $id;
}
function _getValue($user, $type, $id)
{
return implode('~', array($user, $type, $id, time()));
}
function _parseValue($value)
{
return explode('~', $value);
}
}
?>