-
-
Save fayqLs/78a8a653ceecf6714967b5da9c49cc3f to your computer and use it in GitHub Desktop.
CLASSE SERVICE VALIDAÇÃO PARA BLOQUEAR EDIÇÃO (BLOCK)
This file contains hidden or 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
<?php | |
# EXEMPLO: LockRegisterService::checkLocked($object,'ClienteList'); | |
class LockRegisterService | |
{ | |
public static function checkLocked($object, $listClass = NULL) | |
{ | |
$userid = TSession::getValue('userid'); | |
$lock_time = 5; # 5 MINUTOS | |
if (!empty($object->usuario_lock_id) AND $object->usuario_lock_id != $userid AND date('Y-m-d H:i:s', strtotime($object->data_lock)) > date('Y-m-d H:i:s', strtotime("-{$lock_time} minutes"))) | |
{ | |
if (isset($listClass) AND !empty($listClass)) | |
{ | |
TApplication::loadPage($listClass, 'onShow'); | |
} | |
throw new Exception('O registro encontra-se bloqueado para o usuário:<br/><b>'.$object->usuario_lock->nome.'</b>.'); | |
} | |
else | |
{ | |
self::clearLock($userid); | |
$object->usuario_lock_id = $userid; | |
$object->data_lock = date('Y-m-d H:i:s'); | |
$object->store(); | |
} | |
} | |
private static function clearLock($pessoa_fisica_id) | |
{ | |
$criteria = new TCriteria; | |
$criteria->add(new TFilter('usuario_lock_id', '=', $pessoa_fisica_id)); | |
$repository = new TRepository('Cliente'); | |
$repository->update(['usuario_lock_id'=>NULL, 'data_lock'=>NULL], $criteria); | |
} | |
# AGRADECIMENTO: ALISSON ROCHA |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment