111 public function index($sortfield =
"t.ref", $sortorder =
'ASC', $limit = 100, $page = 0, $sqlfilters =
'', $properties =
'')
115 if (!DolibarrApiAccess::$user->rights->workstation->workstation->read) {
116 throw new RestException(403);
121 $socid = DolibarrApiAccess::$user->socid ?:
'';
123 $sql =
"SELECT t.rowid, t.ref";
124 $sql .=
" FROM ".$this->db->prefix().
"workstation_workstation as t";
131 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
136 $sqlTotals = str_replace(
'SELECT t.rowid, t.ref',
'SELECT count(t.rowid) as total', $sql);
138 $sql .= $this->db->order($sortfield, $sortorder);
143 $offset = $limit * $page;
145 $sql .= $this->db->plimit($limit + 1, $offset);
148 $result = $this->db->query($sql);
150 $num = $this->db->num_rows($result);
151 $min = min($num, ($limit <= 0 ? $num : $limit));
154 $obj = $this->db->fetch_object($result);
156 if ($workstation_static->fetch($obj->rowid)) {
162 throw new RestException(503,
'Error when retrieve workstation list : '.$this->db->lasterror());
167 $totalsResult = $this->db->query($sqlTotals);
168 $total = $this->db->fetch_object($totalsResult)->total;
173 $obj_ret[
'data'] = $tmp;
174 $obj_ret[
'pagination'] = array(
175 'total' => (
int) $total,
177 'page_count' => (
int) ceil((
int) $total / $limit),