/** * List skeletons * * Get a list of skeletons * * @param int $mode Use this param to filter list * @param string $sortfield Sort field * @param string $sortorder Sort order * @param int $limit Limit for list * @param int $page Page number * * @return array Array of skeleton objects * * @url GET /skeletons/ */ function getList($mode, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) { global $db, $conf; $obj_ret = array(); $socid = DolibarrApiAccess::$user->societe_id ? DolibarrApiAccess::$user->societe_id : ''; // If the internal user must only see his customers, force searching by him if (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) { $search_sale = DolibarrApiAccess::$user->id; } $sql = "SELECT s.rowid"; if (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid || $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 . "skeleton as s"; if (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid || $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 .= ", " . MAIN_DB_PREFIX . "c_stcomm as st"; $sql .= " WHERE s.fk_stcomm = st.id"; // Example of use $mode //if ($mode == 1) $sql.= " AND s.client IN (1, 3)"; //if ($mode == 2) $sql.= " AND s.client IN (2, 3)"; $sql .= ' AND s.entity IN (' . getEntity('skeleton', 1) . ')'; if (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid || $search_sale > 0) { $sql .= " AND s.fk_soc = sc.fk_soc"; } if ($socid) { $sql .= " AND s.fk_soc = " . $socid; } if ($search_sale > 0) { $sql .= " AND s.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; } $nbtotalofrecords = 0; if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { $result = $db->query($sql); $nbtotalofrecords = $db->num_rows($result); } $sql .= $db->order($sortfield, $sortorder); if ($limit) { if ($page < 0) { $page = 0; } $offset = $limit * $page; $sql .= $db->plimit($limit + 1, $offset); } $result = $db->query($sql); if ($result) { $num = $db->num_rows($result); while ($i < $num) { $obj = $db->fetch_object($result); $skeleton_static = new Skeleton($db); if ($skeleton_static->fetch($obj->rowid)) { $obj_ret[] = parent::_cleanObjectDatas($skeleton_static); } $i++; } } else { throw new RestException(503, 'Error when retrieve skeleton list'); } if (!count($obj_ret)) { throw new RestException(404, 'No skeleton found'); } return $obj_ret; }
/** * List contacts * * Get a list of contacts * * @param int $socid ID of thirdparty to filter list * @param string $sortfield Sort field * @param string $sortorder Sort order * @param int $limit Limit for list * @param int $page Page number * @return array Array of contact objects * * @url GET /contact/list * @url GET /contact/list/{socid} * @url GET /thirdparty/{socid}/contacts * * @throws RestException */ function getList($socid = 0, $sortfield = "c.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) { global $db, $conf; $obj_ret = array(); if (!$socid) { $socid = DolibarrApiAccess::$user->societe_id ? DolibarrApiAccess::$user->societe_id : ''; } // If the internal user must only see his customers, force searching by him if (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) { $search_sale = DolibarrApiAccess::$user->id; } $sql = "SELECT c.rowid"; $sql .= " FROM " . MAIN_DB_PREFIX . "socpeople as c"; if (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid || $search_sale > 0) { // We need this table joined to the select in order to filter by sale $sql .= ", " . MAIN_DB_PREFIX . "societe_commerciaux as sc"; } $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe as s ON c.fk_soc = s.rowid"; $sql .= ' WHERE c.entity IN (' . getEntity('contact', 1) . ')'; if ($socid) { $sql .= " AND c.fk_soc = " . $socid; } if (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid || $search_sale > 0) { $sql .= " AND c.fk_soc = sc.fk_soc"; } if ($search_sale > 0) { $sql .= " AND s.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; } $nbtotalofrecords = 0; if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { $result = $db->query($sql); $nbtotalofrecords = $db->num_rows($result); } $sql .= $db->order($sortfield, $sortorder); if ($limit) { if ($page < 0) { $page = 0; } $offset = $limit * $page; $sql .= $db->plimit($limit + 1, $offset); } $result = $db->query($sql); if ($result) { $num = $db->num_rows($result); while ($i < $num) { $obj = $db->fetch_object($result); $contact_static = new Contact($db); if ($contact_static->fetch($obj->rowid)) { $obj_ret[] = parent::_cleanObjectDatas($contact_static); } $i++; } } else { throw new RestException(503, 'Error when retreive contacts : ' . $sql); } if (!count($obj_ret)) { throw new RestException(404, 'Contacts not found'); } return $obj_ret; }
/** * List products * * Get a list of products * * @param int $mode Use this param to filter list (0 for all, 1 for only product, 2 for only service) * @param mixed $to_sell Filter products to sell (1) or not to sell (0) * @param mixed $to_buy Filter products to nuy (1) or not to buy (0) * @param string $sortfield Sort field * @param string $sortorder Sort order * @param int $limit Limit for list * @param int $page Page number * * @return array Array of product objects * * @url GET /product/list */ function getList($mode = 0, $to_sell = '', $to_buy = '', $sortfield = "p.ref", $sortorder = 'ASC', $limit = 0, $page = 0) { global $db, $conf; $obj_ret = array(); $socid = DolibarrApiAccess::$user->societe_id ? DolibarrApiAccess::$user->societe_id : ''; $sql = "SELECT rowid, ref, ref_ext"; $sql .= " FROM " . MAIN_DB_PREFIX . "product as p"; $sql .= ' WHERE p.entity IN (' . getEntity('product', 1) . ')'; // Show products if ($mode == 1) { $sql .= " AND p.fk_product_type = 0"; } // Show services if ($mode == 2) { $sql .= " AND p.fk_product_type = 1"; } // Show product on sell if ($to_sell) { $sql .= " AND p.to_sell = " . $db->escape($to_sell); } // Show product on buy if ($to_buy) { $sql .= " AND p.to_nuy = " . $db->escape($to_nuy); } $nbtotalofrecords = 0; if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { $result = $db->query($sql); $nbtotalofrecords = $db->num_rows($result); } $sql .= $db->order($sortfield, $sortorder); if ($limit) { if ($page < 0) { $page = 0; } $offset = $limit * $page; $sql .= $db->plimit($limit + 1, $offset); } $result = $db->query($sql); if ($result) { $num = $db->num_rows($result); while ($i < $num) { $obj = $db->fetch_object($result); $product_static = new Product($db); if ($product_static->fetch($obj->rowid)) { $obj_ret[] = parent::_cleanObjectDatas($product_static); } $i++; } } else { throw new RestException(503, 'Error when retrieve product list'); } if (!count($obj_ret)) { throw new RestException(404, 'No product found'); } return $obj_ret; }
/** * List categories * * Get a list of categories * * @param string $type Type of category ('member', 'customer', 'supplier', 'product', 'contact') * @param string $sortfield Sort field * @param string $sortorder Sort order * @param int $limit Limit for list * @param int $page Page number * @return array Array of category objects * * @url GET /category/list */ function getList($type = 'product', $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) { global $db, $conf; $obj_ret = array(); if (!DolibarrApiAccess::$user->rights->categorie->lire) { throw new RestException(401); } $sql = "SELECT s.rowid"; $sql .= " FROM " . MAIN_DB_PREFIX . "categorie as s"; $sql .= ' WHERE s.entity IN (' . getEntity('categorie', 1) . ')'; $sql .= ' AND s.type=' . array_search($type, CategoryApi::$TYPES); $nbtotalofrecords = 0; if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { $result = $db->query($sql); $nbtotalofrecords = $db->num_rows($result); } $sql .= $db->order($sortfield, $sortorder); if ($limit) { if ($page < 0) { $page = 0; } $offset = $limit * $page; $sql .= $db->plimit($limit + 1, $offset); } $result = $db->query($sql); if ($result) { $num = $db->num_rows($result); while ($i < $num) { $obj = $db->fetch_object($result); $category_static = new Categorie($db); if ($category_static->fetch($obj->rowid)) { $obj_ret[] = parent::_cleanObjectDatas($category_static); } $i++; } } else { throw new RestException(503, 'Error when retrieve category list : ' . $category_static->error); } if (!count($obj_ret)) { throw new RestException(404, 'No category found'); } return $obj_ret; }