Commit 70ad0b2e authored by Matthieu Le Corre's avatar Matthieu Le Corre

PHP cs:fix run

Signed-off-by: Matthieu Le Corre's avatarMatthieu Le Corre <matthieu.lecorre@univ-nantes.fr>
parent 15ac52f0
node_modules
.vscode/
vendor
\ No newline at end of file
vendor
.php_cs.cache
{"php":"7.3.14-1~deb10u1","version":"2.16.3:v2.16.3#83baf823a33a1cbd5416c8626935cf3f843c10b0","indent":"\t","lineEnding":"\n","rules":{"encoding":true,"full_opening_tag":true,"blank_line_after_namespace":true,"braces":{"position_after_anonymous_constructs":"same","position_after_control_structures":"same","position_after_functions_and_oop_constructs":"same"},"class_definition":true,"constant_case":true,"elseif":true,"function_declaration":{"closure_function_spacing":"one"},"indentation_type":true,"line_ending":true,"lowercase_keywords":true,"no_break_comment":true,"no_closing_tag":true,"no_spaces_after_function_name":true,"no_spaces_inside_parenthesis":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":true,"single_import_per_statement":true,"single_line_after_imports":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"visibility_required":{"elements":["property","method","const"]},"align_multiline_comment":true,"array_indentation":true,"array_syntax":{"syntax":"short"},"blank_line_after_opening_tag":true,"no_unused_imports":true},"hashes":{"lib\/Migration\/Version000001Date20200416.php":1953890070,"lib\/AppInfo\/Application.php":174795872,"lib\/Collaboration\/CollaborationEngine.php":2351675227,"lib\/Collaboration\/SimpleFileCollaborationEngine.php":2415317954,"lib\/Collaboration\/ICollaborationEngine.php":2942581184,"lib\/Controller\/FileController.php":2479672228,"lib\/Controller\/CollaborationController.php":2467698673,"lib\/Db\/UserMapper.php":3118327894,"lib\/Db\/StepMapper.php":2228899967,"lib\/Db\/Step.php":730276846,"lib\/Db\/User.php":924648166,"appinfo\/app.php":2708770990,"appinfo\/routes.php":3100920729}}
\ No newline at end of file
......@@ -19,4 +19,4 @@
*
*/
$app = new \OCA\whiteboard\AppInfo\Application() ;
\ No newline at end of file
$app = new \OCA\whiteboard\AppInfo\Application() ;
......@@ -19,22 +19,20 @@
*
*/
return [
'routes' => [
[ 'name' => 'file#save', 'url' => '/file/save', 'verb' => 'POST' ],
[ 'name' => 'file#load', 'url' => '/file/load', 'verb' => 'GET' ],
return [
'routes' => [
[ 'name' => 'file#save', 'url' => '/file/save', 'verb' => 'POST' ],
[ 'name' => 'file#load', 'url' => '/file/load', 'verb' => 'GET' ],
[ 'name'=> 'collaboration#startSession', 'url' => '/collaboration/startsession','verb' => 'POST'],
[ 'name'=> 'collaboration#startSession', 'url' => '/collaboration/startsession','verb' => 'POST'],
[ 'name'=> 'collaboration#addStep', 'url' => '/collaboration/addstep','verb' => 'POST'],
[ 'name'=> 'collaboration#getSteps', 'url' => '/collaboration/getsteps','verb' => 'GET'],
[ 'name'=> 'collaboration#addStep', 'url' => '/collaboration/addstep','verb' => 'POST'],
[ 'name'=> 'collaboration#getSteps', 'url' => '/collaboration/getsteps','verb' => 'GET'],
[ 'name'=> 'collaboration#addUser', 'url' => '/collaboration/adduser','verb' => 'POST'],
[ 'name'=> 'collaboration#removeUser', 'url' => '/collaboration/removeuser','verb' => 'POST'],
[ 'name'=> 'collaboration#getUserList', 'url' => '/collaboration/getuserlist','verb' => 'GET'],
[ 'name'=> 'collaboration#addUser', 'url' => '/collaboration/adduser','verb' => 'POST'],
[ 'name'=> 'collaboration#removeUser', 'url' => '/collaboration/removeuser','verb' => 'POST'],
[ 'name'=> 'collaboration#getUserList', 'url' => '/collaboration/getuserlist','verb' => 'GET'],
[ 'name'=> 'collaboration#pushStep', 'url'=> '/collaboration/pushstep', 'verb' => 'GET']
]
];
[ 'name'=> 'collaboration#pushStep', 'url'=> '/collaboration/pushstep', 'verb' => 'GET']
]
];
......@@ -19,34 +19,27 @@
*
*/
namespace OCA\whiteboard\Appinfo ;
use OCP\AppFramework\App;
class Application extends App {
public function __construct(array $urlParams = []) {
parent::__construct('whiteboard', $urlParams);
$container = $this->getContainer();
$server = $container->getServer();
$eventDispatcher = $server->getEventDispatcher();
$this->addPrivateListeners($eventDispatcher) ;
}
protected function addPrivateListeners ($eventDispatcher) {
$eventDispatcher->addListener('OCA\Files::loadAdditionalScripts',
function() {
\OCP\Util::addscript('whiteboard', 'main');
\OCP\Util::addStyle('whiteboard','style') ;
\OCP\Util::addStyle('whiteboard','literallycanvas') ;
});
}
}
\ No newline at end of file
namespace OCA\whiteboard\Appinfo ;
use OCP\AppFramework\App;
class Application extends App {
public function __construct(array $urlParams = []) {
parent::__construct('whiteboard', $urlParams);
$container = $this->getContainer() ;
$server = $container->getServer() ;
$eventDispatcher = $server->getEventDispatcher() ;
$this->addPrivateListeners($eventDispatcher) ;
}
protected function addPrivateListeners($eventDispatcher) {
$eventDispatcher->addListener('OCA\Files::loadAdditionalScripts',
function () {
\OCP\Util::addscript('whiteboard', 'main');
\OCP\Util::addStyle('whiteboard','style') ;
\OCP\Util::addStyle('whiteboard','literallycanvas') ;
});
}
}
......@@ -21,7 +21,6 @@
namespace OCA\whiteboard\Collaboration ;
use OCP\ICache ;
use OCP\ICacheFactory;
use OCA\whiteboard\Db\Step ;
......@@ -31,137 +30,126 @@ use OCA\whiteboard\Db\User ;
use OCA\whiteboard\Db\UserMapper ;
class CollaborationEngine {
private $StepMapper ;
private $UserMapper ;
// private $cache ;
public function __construct(ICacheFactory $cacheFactory, StepMapper $StepMapper, UserMapper $UserMapper) {
$this->StepMapper = $StepMapper ;
$this->UserMapper = $UserMapper ;
$this->AppName = "whiteboard";
//$this->cache = $cacheFactory->createDistributed('WhiteboardSession::'.$this->file);
}
//DONE
public function startSession(int $fileId) {
// nothing to setup with DB engine
}
//DONE
public function addUser(int $fileId, string $user) {
$usr = $this->UserMapper->find($user,$this->AppName,$fileId) ;
if (! $usr) {
$Nuser = new User() ;
$Nuser->setAppId($this->AppName) ;
$Nuser->setUserId($user) ;
$Nuser->setLastSeen(time()) ;
$Nuser->setFileId($fileId) ;
return $this->UserMapper->insert($Nuser);
} else {
$this->updateLastSeen($user,$fileId) ;
return "already there" ;
} ;
}
//DONE
public function removeUser(int $fileId, string $user) {
$usr = $this->UserMapper->find($user,$this->AppName,$fileId) ;
$cnt = count($this->UserMapper->findAll($this->AppName,$fileId)) ;
if ($usr) {
$this->UserMapper->delete($usr) ;
}
$cnt = count($this->UserMapper->findAll($this->AppName,$fileId)) ;
if ( $cnt == 0 ) {
$this->StepMapper->removeAll($fileId) ;
}
return "user removed" ;
}
// DONE
public function addStep(int $fileId,string $user, string $type, string $datas) {
$this->updateLastSeen($user,$fileId) ;
$Nstep = new Step() ;
$Nstep->setAppId($this->AppName) ;
$Nstep->setUserId($user) ;
$Nstep->setStepId(time()) ;
$Nstep->setFileId($fileId) ;
$Nstep->setStepForwarded($user) ;
$Nstep->setStepType($type) ;
$Nstep->setStepData($datas) ;
return $this->StepMapper->insert($Nstep);
}
// DONE
public function getSteps($fileId) {
$result =$this->StepMapper->findAll($this->AppName,$fileId) ;
return $result ;
}
// DONE
public function getUserList($fileId) {
$users = $this->UserMapper->findAll($this->AppName,$fileId) ;
foreach ($users as $user) {
if ($user->getLastSeen() + 60 < time()) {
$this->UserMapper->delete($user) ;
}
}
return $users ;
}
// DONE
public function waitForNewSteps(int $fileId, string $user){
$timeout = 20 ;
$elapsedTime = 0;
while (empty($steps) && $elapsedTime < $timeout) {
$steps = $this->StepMapper->findLasts($this->AppName,$fileId,$user) ;
$elapsedTime++ ;
if (empty($steps)) {
sleep(1) ;
}
} ;
$this->updateLastSeen($user,$fileId) ;
foreach ($steps as $step) {
$forwarded = explode(',',$step->getStepForwarded()) ;
$forwarded[] = $user ;
$result = implode(',',$forwarded) ;
$step->setStepForwarded($result) ;
$this->StepMapper->update($step) ;
} ;
return $steps ;
}
// PRIVATE
private function updateLastSeen(string $userId, int $fileId) {
$usr = $this->UserMapper->find($userId,$this->AppName,$fileId) ;
$usr->setLastSeen(time()) ;
$this->UserMapper->update($usr) ;
}
}
\ No newline at end of file
private $StepMapper ;
private $UserMapper ;
// private $cache ;
public function __construct(ICacheFactory $cacheFactory, StepMapper $StepMapper, UserMapper $UserMapper) {
$this->StepMapper = $StepMapper ;
$this->UserMapper = $UserMapper ;
$this->AppName = "whiteboard";
// $this->cache = $cacheFactory->createDistributed('WhiteboardSession::'.$this->file);
}
//DONE
public function startSession(int $fileId) {
// nothing to setup with DB engine
}
//DONE
public function addUser(int $fileId, string $user) {
$usr = $this->UserMapper->find($user,$this->AppName,$fileId) ;
if (! $usr) {
$Nuser = new User() ;
$Nuser->setAppId($this->AppName) ;
$Nuser->setUserId($user) ;
$Nuser->setLastSeen(time()) ;
$Nuser->setFileId($fileId) ;
return $this->UserMapper->insert($Nuser);
} else {
$this->updateLastSeen($user,$fileId) ;
return "already there" ;
} ;
}
//DONE
public function removeUser(int $fileId, string $user) {
$usr = $this->UserMapper->find($user,$this->AppName,$fileId) ;
$cnt = count($this->UserMapper->findAll($this->AppName,$fileId)) ;
if ($usr) {
$this->UserMapper->delete($usr) ;
}
$cnt = count($this->UserMapper->findAll($this->AppName,$fileId)) ;
if ($cnt == 0) {
$this->StepMapper->removeAll($fileId) ;
}
return "user removed" ;
}
// DONE
public function addStep(int $fileId,string $user, string $type, string $datas) {
$this->updateLastSeen($user,$fileId) ;
$Nstep = new Step() ;
$Nstep->setAppId($this->AppName) ;
$Nstep->setUserId($user) ;
$Nstep->setStepId(time()) ;
$Nstep->setFileId($fileId) ;
$Nstep->setStepForwarded($user) ;
$Nstep->setStepType($type) ;
$Nstep->setStepData($datas) ;
return $this->StepMapper->insert($Nstep);
}
// DONE
public function getSteps($fileId) {
$result =$this->StepMapper->findAll($this->AppName,$fileId) ;
return $result ;
}
// DONE
public function getUserList($fileId) {
$users = $this->UserMapper->findAll($this->AppName,$fileId) ;
foreach ($users as $user) {
if ($user->getLastSeen() + 60 < time()) {
$this->UserMapper->delete($user) ;
}
}
return $users ;
}
// DONE
public function waitForNewSteps(int $fileId, string $user) {
$timeout = 20 ;
$elapsedTime = 0;
while (empty($steps) && $elapsedTime < $timeout) {
$steps = $this->StepMapper->findLasts($this->AppName,$fileId,$user) ;
$elapsedTime++ ;
if (empty($steps)) {
sleep(1) ;
}
} ;
$this->updateLastSeen($user,$fileId) ;
foreach ($steps as $step) {
$forwarded = explode(',',$step->getStepForwarded()) ;
$forwarded[] = $user ;
$result = implode(',',$forwarded) ;
$step->setStepForwarded($result) ;
$this->StepMapper->update($step) ;
} ;
return $steps ;
}
// PRIVATE
private function updateLastSeen(string $userId, int $fileId) {
$usr = $this->UserMapper->find($userId,$this->AppName,$fileId) ;
$usr->setLastSeen(time()) ;
$this->UserMapper->update($usr) ;
}
}
......@@ -22,85 +22,83 @@
namespace OCA\whiteboard\Controller ;
use OCP\AppFramework\Controller ;
use OCP\IRequest;;
use OCP\User ;
use OCP\ICache ;
use OCP\IRequest;
;
use OCP\ICacheFactory;
use OCA\whiteboard\Collaboration\CollaborationEngine ;
class CollaborationController extends Controller {
/**
* @NoAdminRequired
*
**/
public function __construct($AppName,IRequest $request,ICacheFactory $cacheFactory, CollaborationEngine $engine) {
parent::__construct($AppName, $request);
//$this->id = $request->getParam("id") ;
$this->engine = $engine ;
/**
* @NoAdminRequired
*
**/
public function __construct($AppName,IRequest $request,ICacheFactory $cacheFactory, CollaborationEngine $engine) {
parent::__construct($AppName, $request);
}
//$this->id = $request->getParam("id") ;
$this->engine = $engine ;
}
/**
* @NoAdminRequired
*
**/
public function startSession($id) {
return $this->engine->startSession($id) ;
}
/**
* @NoAdminRequired
*
**/
public function startSession($id) {
return $this->engine->startSession($id) ;
}
/**
* @NoAdminRequired
*
**/
public function addUser($id,$user) {
return $this->engine->addUser($id,$user) ;
}
/**
* @NoAdminRequired
*
**/
public function addUser($id,$user) {
return $this->engine->addUser($id,$user) ;
}
/**
* @NoAdminRequired
*
**/
public function removeUser($id,$user) {
return $this->engine->removeUser($id,$user) ;
}
/**
* @NoAdminRequired
*
**/
public function removeUser($id,$user) {
return $this->engine->removeUser($id,$user) ;
}
/**
* @NoAdminRequired
*
**/
public function getUserList($id) {
return $this->engine->getUserList($id) ;
}
/**
* @NoAdminRequired
*
**/
public function getUserList($id) {
return $this->engine->getUserList($id) ;
}
/**
* @NoAdminRequired
*
* @param int $id
* @param string $user
* @param string $type
* @param string $step
*
**/
public function addStep(int $id,string $user,string $type, string $step) {
return $this->engine->addStep($id,$user,$type,$step) ;
}
/**
* @NoAdminRequired
*
* @param int $id
* @param string $user
* @param string $type
* @param string $step
*
**/
public function addStep(int $id,string $user,string $type, string $step) {
return $this->engine->addStep($id,$user,$type,$step) ;
}
/**
* @NoAdminRequired
*
**/
public function getSteps($id) {
return $this->engine->getSteps($id) ;
}
/**
* @NoAdminRequired
*
**/
public function getSteps($id) {
return $this->engine->getSteps($id) ;
}
/**
* @NoAdminRequired
*
**/
public function pushStep(int $id,string $user) {
return $this->engine->waitForNewSteps($id,$user) ;
}
}
\ No newline at end of file
/**
* @NoAdminRequired
*
**/
public function pushStep(int $id,string $user) {
return $this->engine->waitForNewSteps($id,$user) ;
}
}
......@@ -27,32 +27,30 @@ use OCP\Files\File;
use OCP\Files\Folder;
class FileController extends Controller {
public function __construct($AppName, IRequest $request, Folder $userFolder) {
parent::__construct($AppName, $request);
//$this->request = $request ;
$this->userFolder = $userFolder;
}
/**
* @NoAdminRequired
*/
public function save($path,$content) {
/** @var File $file */
$file = $this->userFolder->get($path);
$file->putContent($content);
}
/**
* @NoAdminRequired
*/
public function load($path) {
/** @var File $file */
$file = $this->userFolder->get($path);
return $file->getContent();
}
public function __construct($AppName, IRequest $request, Folder $userFolder) {
parent::__construct($AppName, $request);
//$this->request = $request ;
$this->userFolder = $userFolder;
}
/**
* @NoAdminRequired
*/
public function save($path,$content) {
/** @var File $file */
$file = $this->userFolder->get($path);
$file->putContent($content);
}
/**
* @NoAdminRequired
*/
public function load($path) {
/** @var File $file */
$file = $this->userFolder->get($path);
return $file->getContent();
}
}
......@@ -26,37 +26,35 @@ use JsonSerializable;
use OCP\AppFramework\Db\Entity;
class Step extends Entity implements JsonSerializable {
protected $appId;
protected $userId;
protected $stepId;
protected $stepType;
protected $stepForwarded;
protected $stepData;
protected $fileId ;
public function __construct() {
$this->addType("id",integer) ;
$this->addType("appId",string) ;
$this->addType("userId",string) ;
$this->addType("fileId",integer) ;
$this->addType("stepId",integer) ;
$this->addType("stepType",string) ;
$this->addType("stepData",string) ;
$this->addType("stepForwarded",string) ;
}
public function jsonSerialize() {
return [
'id' => $this->id,
'appId' => $this->appId,
'userId' => $this->userId,
'fileId' => $this->fileId,
'stepData' => $this->stepData,
'stepId'=> $this->stepId,
'stepType' => $this->stepType,
'stepForwarded' => $this->stepForwarded
];
}
protected $appId;