mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2026-02-07 16:41:48 +01:00
code syntax fichinter directory
This commit is contained in:
@@ -32,7 +32,7 @@ class Interventions extends DolibarrApi
|
||||
/**
|
||||
* @var array $FIELDS Mandatory fields, checked when create and update object
|
||||
*/
|
||||
static $FIELDS = array(
|
||||
public static $FIELDS = array(
|
||||
'socid',
|
||||
'fk_project',
|
||||
'description',
|
||||
@@ -41,7 +41,7 @@ class Interventions extends DolibarrApi
|
||||
/**
|
||||
* @var array $FIELDS Mandatory fields, checked when create and update object
|
||||
*/
|
||||
static $FIELDSLINE = array(
|
||||
public static $FIELDSLINE = array(
|
||||
'description',
|
||||
'date',
|
||||
'duree',
|
||||
@@ -117,27 +117,37 @@ class Interventions extends DolibarrApi
|
||||
|
||||
// If the internal user must only see his customers, force searching by him
|
||||
$search_sale = 0;
|
||||
if (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) $search_sale = DolibarrApiAccess::$user->id;
|
||||
if (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) {
|
||||
$search_sale = DolibarrApiAccess::$user->id;
|
||||
}
|
||||
|
||||
$sql = "SELECT t.rowid";
|
||||
if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects)
|
||||
if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) {
|
||||
$sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects)
|
||||
}
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."fichinter as t";
|
||||
|
||||
if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale
|
||||
if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale
|
||||
}
|
||||
|
||||
$sql .= ' WHERE t.entity IN ('.getEntity('intervention').')';
|
||||
if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= " AND t.fk_soc = sc.fk_soc";
|
||||
if ($socids) $sql .= " AND t.fk_soc IN (".$socids.")";
|
||||
if ($search_sale > 0) $sql .= " AND t.rowid = sc.fk_soc"; // Join for the needed table to filter by sale
|
||||
if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) {
|
||||
$sql .= " AND t.fk_soc = sc.fk_soc";
|
||||
}
|
||||
if ($socids) {
|
||||
$sql .= " AND t.fk_soc IN (".$socids.")";
|
||||
}
|
||||
if ($search_sale > 0) {
|
||||
$sql .= " AND t.rowid = sc.fk_soc"; // Join for the needed table to filter by sale
|
||||
}
|
||||
// Insert sale filter
|
||||
if ($search_sale > 0) {
|
||||
$sql .= " AND sc.fk_user = ".$search_sale;
|
||||
}
|
||||
// Add sql filters
|
||||
if ($sqlfilters)
|
||||
{
|
||||
if (!DolibarrApi::_checkFilters($sqlfilters))
|
||||
{
|
||||
if ($sqlfilters) {
|
||||
if (!DolibarrApi::_checkFilters($sqlfilters)) {
|
||||
throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
|
||||
}
|
||||
$regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
|
||||
@@ -146,8 +156,7 @@ class Interventions extends DolibarrApi
|
||||
|
||||
$sql .= $this->db->order($sortfield, $sortorder);
|
||||
if ($limit) {
|
||||
if ($page < 0)
|
||||
{
|
||||
if ($page < 0) {
|
||||
$page = 0;
|
||||
}
|
||||
$offset = $limit * $page;
|
||||
@@ -158,13 +167,11 @@ class Interventions extends DolibarrApi
|
||||
dol_syslog("API Rest request");
|
||||
$result = $this->db->query($sql);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
if ($result) {
|
||||
$num = $this->db->num_rows($result);
|
||||
$min = min($num, ($limit <= 0 ? $num : $limit));
|
||||
$i = 0;
|
||||
while ($i < $min)
|
||||
{
|
||||
while ($i < $min) {
|
||||
$obj = $this->db->fetch_object($result);
|
||||
$fichinter_static = new Fichinter($this->db);
|
||||
if ($fichinter_static->fetch($obj->rowid)) {
|
||||
@@ -216,28 +223,28 @@ class Interventions extends DolibarrApi
|
||||
* @return int
|
||||
*/
|
||||
/* TODO
|
||||
public function getLines($id)
|
||||
{
|
||||
if(! DolibarrApiAccess::$user->rights->ficheinter->lire) {
|
||||
throw new RestException(401);
|
||||
}
|
||||
public function getLines($id)
|
||||
{
|
||||
if(! DolibarrApiAccess::$user->rights->ficheinter->lire) {
|
||||
throw new RestException(401);
|
||||
}
|
||||
|
||||
$result = $this->fichinter->fetch($id);
|
||||
if( ! $result ) {
|
||||
throw new RestException(404, 'Intervention not found');
|
||||
}
|
||||
$result = $this->fichinter->fetch($id);
|
||||
if( ! $result ) {
|
||||
throw new RestException(404, 'Intervention not found');
|
||||
}
|
||||
|
||||
if( ! DolibarrApi::_checkAccessToResource('fichinter',$this->fichinter->id)) {
|
||||
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
||||
}
|
||||
$this->fichinter->getLinesArray();
|
||||
$result = array();
|
||||
foreach ($this->fichinter->lines as $line) {
|
||||
array_push($result,$this->_cleanObjectDatas($line));
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
*/
|
||||
if( ! DolibarrApi::_checkAccessToResource('fichinter',$this->fichinter->id)) {
|
||||
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
||||
}
|
||||
$this->fichinter->getLinesArray();
|
||||
$result = array();
|
||||
foreach ($this->fichinter->lines as $line) {
|
||||
array_push($result,$this->_cleanObjectDatas($line));
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Add a line to given intervention
|
||||
@@ -270,11 +277,11 @@ class Interventions extends DolibarrApi
|
||||
}
|
||||
|
||||
$updateRes = $this->fichinter->addLine(
|
||||
DolibarrApiAccess::$user,
|
||||
$id,
|
||||
$this->fichinter->description,
|
||||
$this->fichinter->date,
|
||||
$this->fichinter->duree
|
||||
DolibarrApiAccess::$user,
|
||||
$id,
|
||||
$this->fichinter->description,
|
||||
$this->fichinter->date,
|
||||
$this->fichinter->duree
|
||||
);
|
||||
|
||||
if ($updateRes > 0) {
|
||||
@@ -369,8 +376,7 @@ class Interventions extends DolibarrApi
|
||||
*/
|
||||
public function closeFichinter($id)
|
||||
{
|
||||
if (!DolibarrApiAccess::$user->rights->ficheinter->creer)
|
||||
{
|
||||
if (!DolibarrApiAccess::$user->rights->ficheinter->creer) {
|
||||
throw new RestException(401, "Insuffisant rights");
|
||||
}
|
||||
$result = $this->fichinter->fetch($id);
|
||||
@@ -408,8 +414,9 @@ class Interventions extends DolibarrApi
|
||||
{
|
||||
$fichinter = array();
|
||||
foreach (Interventions::$FIELDS as $field) {
|
||||
if (!isset($data[$field]))
|
||||
if (!isset($data[$field])) {
|
||||
throw new RestException(400, "$field field missing");
|
||||
}
|
||||
$fichinter[$field] = $data[$field];
|
||||
}
|
||||
return $fichinter;
|
||||
@@ -447,8 +454,9 @@ class Interventions extends DolibarrApi
|
||||
{
|
||||
$fichinter = array();
|
||||
foreach (Interventions::$FIELDSLINE as $field) {
|
||||
if (!isset($data[$field]))
|
||||
if (!isset($data[$field])) {
|
||||
throw new RestException(400, "$field field missing");
|
||||
}
|
||||
$fichinter[$field] = $data[$field];
|
||||
}
|
||||
return $fichinter;
|
||||
|
||||
Reference in New Issue
Block a user