19 use Luracast\Restler\RestException;
43 public $knowledgerecord;
71 public function get($id)
73 if (!DolibarrApiAccess::$user->hasRight(
'knowledgemanagement',
'knowledgerecord',
'read')) {
74 throw new RestException(401);
77 $result = $this->knowledgerecord->fetch($id);
79 throw new RestException(404,
'KnowledgeRecord not found');
83 throw new RestException(401,
'Access to instance id='.$this->knowledgerecord->id.
' of object not allowed for login '.DolibarrApiAccess::$user->login);
102 public function getCategories($id, $sortfield =
"s.rowid", $sortorder =
'ASC', $limit = 0, $page = 0)
104 if (!DolibarrApiAccess::$user->rights->categorie->lire) {
105 throw new RestException(401);
110 $result = $categories->getListForItem($id,
'knowledgemanagement', $sortfield, $sortorder, $limit, $page);
112 if (empty($result)) {
113 throw new RestException(404,
'No category found');
117 throw new RestException(503,
'Error when retrieve category list : '.join(
',', array_merge(array($categories->error), $categories->errors)));
140 public function index($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $category = 0, $sqlfilters =
'')
147 if (!DolibarrApiAccess::$user->hasRight(
'knowledgemanagement',
'knowledgerecord',
'read')) {
148 throw new RestException(401);
151 $socid = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid :
'';
153 $restrictonsocid = 0;
157 if ($restrictonsocid && !DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) {
158 $search_sale = DolibarrApiAccess::$user->id;
161 $sql =
"SELECT t.rowid";
162 if ($restrictonsocid && (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) {
163 $sql .=
", sc.fk_soc, sc.fk_user";
165 $sql .=
" FROM ".MAIN_DB_PREFIX.$tmpobject->table_element.
" AS t LEFT JOIN ".MAIN_DB_PREFIX.$tmpobject->table_element.
"_extrafields AS ef ON (ef.fk_object = t.rowid)";
167 if ($restrictonsocid && (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) {
168 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
171 $sql .=
", ".$this->db->prefix().
"categorie_knowledgemanagement as c";
173 $sql .=
" WHERE 1 = 1";
179 if ($tmpobject->ismultientitymanaged) {
180 $sql .=
' AND t.entity IN ('.getEntity($tmpobject->element).
')';
182 if ($restrictonsocid && (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) {
183 $sql .=
" AND t.fk_soc = sc.fk_soc";
185 if ($restrictonsocid && $socid) {
186 $sql .=
" AND t.fk_soc = ".((int) $socid);
188 if ($restrictonsocid && $search_sale > 0) {
189 $sql .=
" AND t.rowid = sc.fk_soc";
192 if ($restrictonsocid && $search_sale > 0) {
193 $sql .=
" AND sc.fk_user = ".((int) $search_sale);
197 $sql .=
" AND c.fk_categorie = ".((int) $category);
198 $sql .=
" AND c.fk_knowledgemanagement = t.rowid";
204 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
208 $sql .= $this->db->order($sortfield, $sortorder);
213 $offset = $limit * $page;
215 $sql .= $this->db->plimit($limit + 1, $offset);
218 $result = $this->db->query(
$sql);
221 $num = $this->db->num_rows($result);
223 $obj = $this->db->fetch_object($result);
225 if ($tmp_object->fetch($obj->rowid)) {
231 throw new RestException(503,
'Error when retrieving knowledgerecord list: '.$this->db->lasterror());
233 if (!count($obj_ret)) {
234 throw new RestException(404,
'No knowledgerecord found');
249 public function post($request_data =
null)
251 if (!DolibarrApiAccess::$user->hasRight(
'knowledgemanagement',
'knowledgerecord',
'write')) {
252 throw new RestException(401);
256 $result = $this->
_validate($request_data);
258 foreach ($request_data as $field => $value) {
259 $this->knowledgerecord->$field = $this->
_checkValForAPI($field, $value, $this->knowledgerecord);
265 if ($this->knowledgerecord->create(DolibarrApiAccess::$user)<0) {
266 throw new RestException(500,
"Error creating KnowledgeRecord", array_merge(array($this->knowledgerecord->error), $this->knowledgerecord->errors));
268 return $this->knowledgerecord->id;
282 public function put($id, $request_data =
null)
284 if (!DolibarrApiAccess::$user->hasRight(
'knowledgemanagement',
'knowledgerecord',
'write')) {
285 throw new RestException(401);
288 $result = $this->knowledgerecord->fetch($id);
290 throw new RestException(404,
'KnowledgeRecord not found');
294 throw new RestException(401,
'Access to instance id='.$this->knowledgerecord->id.
' of object not allowed for login '.DolibarrApiAccess::$user->login);
297 foreach ($request_data as $field => $value) {
298 if ($field ==
'id') {
301 $this->knowledgerecord->$field = $this->
_checkValForAPI($field, $value, $this->knowledgerecord);
307 if ($this->knowledgerecord->update(DolibarrApiAccess::$user,
false) > 0) {
308 return $this->
get($id);
310 throw new RestException(500, $this->knowledgerecord->error);
324 public function delete($id)
326 if (!DolibarrApiAccess::$user->hasRight(
'knowledgemanagement',
'knowledgerecord',
'delete')) {
327 throw new RestException(401);
329 $result = $this->knowledgerecord->fetch($id);
331 throw new RestException(404,
'KnowledgeRecord not found');
335 throw new RestException(401,
'Access to instance id='.$this->knowledgerecord->id.
' of object not allowed for login '.DolibarrApiAccess::$user->login);
338 if (!$this->knowledgerecord->delete(DolibarrApiAccess::$user)) {
339 throw new RestException(500,
'Error when deleting KnowledgeRecord : '.$this->knowledgerecord->error);
345 'message' =>
'KnowledgeRecord deleted'
361 $object = parent::_cleanObjectDatas($object);
363 unset($object->rowid);
364 unset($object->canvas);
401 if (isset($object->lines) && is_array($object->lines) && count($object->lines) > 0) {
402 $nboflines = count($object->lines);
403 for ($i = 0; $i < $nboflines; $i++) {
406 unset($object->lines[$i]->lines);
407 unset($object->lines[$i]->note);
424 $knowledgerecord = array();
425 foreach ($this->knowledgerecord->fields as $field => $propfield) {
426 if (in_array($field, array(
'rowid',
'entity',
'date_creation',
'tms',
'fk_user_creat')) || $propfield[
'notnull'] != 1) {
429 if (!isset($data[$field])) {
430 throw new RestException(400,
"$field field missing");
432 $knowledgerecord[$field] = $data[$field];
434 return $knowledgerecord;
Class to manage categories.
static _checkAccessToResource($resource, $resource_id=0, $dbtablename='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid')
Check access by user to a given resource.
_checkValForAPI($field, $value, $object)
Check and convert a string depending on its type/name.
post($request_data=null)
Create knowledgerecord object.
index($sortfield="t.rowid", $sortorder='ASC', $limit=100, $page=0, $category=0, $sqlfilters='')
List knowledgerecords.
_validate($data)
Validate fields before create or update object.
getCategories($id, $sortfield="s.rowid", $sortorder='ASC', $limit=0, $page=0)
Get categories for a knowledgerecord object.
put($id, $request_data=null)
Update knowledgerecord.
__construct()
Constructor.
_cleanObjectDatas($object)
Clean sensible object datas.
Class for KnowledgeRecord.
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.