psr2 Squiz.WhiteSpace.ScopeClosingBrace.Indent

This commit is contained in:
Frédéric FRANCE
2019-02-03 14:29:45 +01:00
parent 2e5382f40d
commit 80a12fcd1c
104 changed files with 2035 additions and 2058 deletions

View File

@@ -48,8 +48,8 @@ class Projects extends DolibarrApi
*/
function __construct()
{
global $db, $conf;
$this->db = $db;
global $db, $conf;
$this->db = $db;
$this->project = new Project($this->db);
$this->task = new Task($this->db);
}
@@ -61,26 +61,26 @@ class Projects extends DolibarrApi
*
* @param int $id ID of project
* @return array|mixed data without useless information
*
*
* @throws RestException
*/
function get($id)
{
if(! DolibarrApiAccess::$user->rights->projet->lire) {
throw new RestException(401);
}
if(! DolibarrApiAccess::$user->rights->projet->lire) {
throw new RestException(401);
}
$result = $this->project->fetch($id);
if( ! $result ) {
throw new RestException(404, 'Project not found');
}
if( ! DolibarrApi::_checkAccessToResource('project',$this->project->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
if( ! DolibarrApi::_checkAccessToResource('project',$this->project->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
$this->project->fetchObjectLinked();
return $this->_cleanObjectDatas($this->project);
return $this->_cleanObjectDatas($this->project);
}
@@ -133,7 +133,7 @@ class Projects extends DolibarrApi
{
throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
}
$regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
$regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
$sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
}
@@ -171,7 +171,7 @@ class Projects extends DolibarrApi
if( ! count($obj_ret)) {
throw new RestException(404, 'No project found');
}
return $obj_ret;
return $obj_ret;
}
/**
@@ -182,9 +182,9 @@ class Projects extends DolibarrApi
*/
function post($request_data = null)
{
if(! DolibarrApiAccess::$user->rights->projet->creer) {
throw new RestException(401, "Insuffisant rights");
}
if(! DolibarrApiAccess::$user->rights->projet->creer) {
throw new RestException(401, "Insuffisant rights");
}
// Check mandatory fields
$result = $this->_validate($request_data);
@@ -217,34 +217,32 @@ class Projects extends DolibarrApi
*/
function getLines($id, $includetimespent = 0)
{
if(! DolibarrApiAccess::$user->rights->projet->lire) {
throw new RestException(401);
}
if (! DolibarrApiAccess::$user->rights->projet->lire) {
throw new RestException(401);
}
$result = $this->project->fetch($id);
if( ! $result ) {
throw new RestException(404, 'Project not found');
}
$result = $this->project->fetch($id);
if ( ! $result ) {
throw new RestException(404, 'Project not found');
}
if( ! DolibarrApi::_checkAccessToResource('project',$this->project->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
$this->project->getLinesArray(DolibarrApiAccess::$user);
$result = array();
foreach ($this->project->lines as $line) // $line is a task
{
if ($includetimespent == 1)
{
$timespent = $line->getSummaryOfTimeSpent(0);
}
if ($includetimespent == 1)
{
if ( ! DolibarrApi::_checkAccessToResource('project',$this->project->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
$this->project->getLinesArray(DolibarrApiAccess::$user);
$result = array();
foreach ($this->project->lines as $line) {
// $line is a task
if ($includetimespent == 1) {
$timespent = $line->getSummaryOfTimeSpent(0);
}
if ($includetimespent == 1) {
// TODO
// Add class for timespent records and loop and fill $line->lines with records of timespent
}
array_push($result,$this->_cleanObjectDatas($line));
}
return $result;
}
array_push($result,$this->_cleanObjectDatas($line));
}
return $result;
}
@@ -262,16 +260,16 @@ class Projects extends DolibarrApi
{
global $db;
if(! DolibarrApiAccess::$user->rights->projet->lire) {
if (! DolibarrApiAccess::$user->rights->projet->lire) {
throw new RestException(401);
}
$result = $this->project->fetch($id);
if( ! $result ) {
if ( ! $result ) {
throw new RestException(404, 'Project not found');
}
if( ! DolibarrApi::_checkAccessToResource('project',$this->project->id)) {
if ( ! DolibarrApi::_checkAccessToResource('project',$this->project->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
@@ -305,20 +303,20 @@ class Projects extends DolibarrApi
/*
function postLine($id, $request_data = null)
{
if(! DolibarrApiAccess::$user->rights->projet->creer) {
throw new RestException(401);
}
if(! DolibarrApiAccess::$user->rights->projet->creer) {
throw new RestException(401);
}
$result = $this->project->fetch($id);
if( ! $result ) {
throw new RestException(404, 'Project not found');
}
$result = $this->project->fetch($id);
if( ! $result ) {
throw new RestException(404, 'Project not found');
}
if( ! DolibarrApi::_checkAccessToResource('project',$this->project->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
$request_data = (object) $request_data;
$updateRes = $this->project->addline(
if( ! DolibarrApi::_checkAccessToResource('project',$this->project->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
$request_data = (object) $request_data;
$updateRes = $this->project->addline(
$request_data->desc,
$request_data->subprice,
$request_data->qty,
@@ -344,13 +342,13 @@ class Projects extends DolibarrApi
$request_data->fk_unit,
$this->element,
$request_data->id
);
);
if ($updateRes > 0) {
return $updateRes;
if ($updateRes > 0) {
return $updateRes;
}
return false;
}
return false;
}
*/
@@ -368,20 +366,20 @@ class Projects extends DolibarrApi
/*
function putLine($id, $lineid, $request_data = null)
{
if(! DolibarrApiAccess::$user->rights->projet->creer) {
throw new RestException(401);
}
if(! DolibarrApiAccess::$user->rights->projet->creer) {
throw new RestException(401);
}
$result = $this->project->fetch($id);
if( ! $result ) {
throw new RestException(404, 'Project not found');
}
$result = $this->project->fetch($id);
if( ! $result ) {
throw new RestException(404, 'Project not found');
}
if( ! DolibarrApi::_checkAccessToResource('project',$this->project->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
$request_data = (object) $request_data;
$updateRes = $this->project->updateline(
if( ! DolibarrApi::_checkAccessToResource('project',$this->project->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
$request_data = (object) $request_data;
$updateRes = $this->project->updateline(
$lineid,
$request_data->desc,
$request_data->subprice,
@@ -403,14 +401,14 @@ class Projects extends DolibarrApi
$request_data->special_code,
$request_data->array_options,
$request_data->fk_unit
);
);
if ($updateRes > 0) {
$result = $this->get($id);
unset($result->line);
return $this->_cleanObjectDatas($result);
}
return false;
if ($updateRes > 0) {
$result = $this->get($id);
unset($result->line);
return $this->_cleanObjectDatas($result);
}
return false;
}*/
@@ -425,24 +423,24 @@ class Projects extends DolibarrApi
*/
function put($id, $request_data = null)
{
if(! DolibarrApiAccess::$user->rights->projet->creer) {
throw new RestException(401);
}
if (! DolibarrApiAccess::$user->rights->projet->creer) {
throw new RestException(401);
}
$result = $this->project->fetch($id);
if ($result <= 0) {
throw new RestException(404, 'Project not found');
}
if( ! DolibarrApi::_checkAccessToResource('project',$this->project->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
if ( ! DolibarrApi::_checkAccessToResource('project',$this->project->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
foreach($request_data as $field => $value) {
if ($field == 'id') continue;
$this->project->$field = $value;
}
if($this->project->update(DolibarrApiAccess::$user) >= 0)
if ($this->project->update(DolibarrApiAccess::$user) >= 0)
{
return $this->get($id);
}
@@ -461,19 +459,19 @@ class Projects extends DolibarrApi
*/
function delete($id)
{
if(! DolibarrApiAccess::$user->rights->projet->supprimer) {
throw new RestException(401);
}
if (! DolibarrApiAccess::$user->rights->projet->supprimer) {
throw new RestException(401);
}
$result = $this->project->fetch($id);
if( ! $result ) {
if ( ! $result ) {
throw new RestException(404, 'Project not found');
}
if( ! DolibarrApi::_checkAccessToResource('project',$this->project->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
if ( ! DolibarrApi::_checkAccessToResource('project',$this->project->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
if( ! $this->project->delete(DolibarrApiAccess::$user)) {
if ( ! $this->project->delete(DolibarrApiAccess::$user)) {
throw new RestException(500, 'Error when delete project : '.$this->project->error);
}
@@ -506,24 +504,24 @@ class Projects extends DolibarrApi
function validate($id, $notrigger = 0)
{
if(! DolibarrApiAccess::$user->rights->projet->creer) {
throw new RestException(401);
}
throw new RestException(401);
}
$result = $this->project->fetch($id);
if( ! $result ) {
throw new RestException(404, 'Project not found');
}
if( ! DolibarrApi::_checkAccessToResource('project',$this->project->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
if( ! DolibarrApi::_checkAccessToResource('project',$this->project->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
$result = $this->project->setValid(DolibarrApiAccess::$user, $notrigger);
if ($result == 0) {
throw new RestException(304, 'Error nothing done. May be object is already validated');
}
if ($result < 0) {
throw new RestException(500, 'Error when validating Project: '.$this->project->error);
}
$result = $this->project->setValid(DolibarrApiAccess::$user, $notrigger);
if ($result == 0) {
throw new RestException(304, 'Error nothing done. May be object is already validated');
}
if ($result < 0) {
throw new RestException(500, 'Error when validating Project: '.$this->project->error);
}
return array(
'success' => array(