/** * Return Categories list * @param int $idCat Id of Category, if 0 return Principal cats * @return array Array with categories */ public static function getCategories($idCat = 0) { global $db; switch ($idCat) { case 0: //devolver las categorias con nivel 1 $objCat = new Categorie($db); //$cats=$objCat->get_full_arbo(0); $cats = $objCat->get_full_arbo($idCat); if (sizeof($cats) > 0) { $retarray = array(); foreach ($cats as $key => $val) { if ($val['level'] < 2) { $val['image'] = self::getImageCategory($val['id']); $val['thumb'] = self::getImageCategory($val['id']); $retarray[] = $val; } } return $retarray; } break; case $idCat > 0: $objCat = new Categorie($db); $result = $objCat->fetch($idCat); if ($result > 0) { $cats = $objCat->get_filles($idCat); //$cats = self::get_filles($idCat); if (sizeof($cats) > 0) { $retarray = array(); foreach ($cats as $val) { $cat['id'] = $val->id; $cat['label'] = $val->label; $cat['fulllabel'] = $val->label; $cat['fullpath'] = '_' . $val->id; $cat['image'] = self::getImageCategory($val->id); $cat['thumb'] = self::getImageCategory($val->id); $retarray[] = $cat; } return $retarray; } } break; default: return -1; break; } }
function _categories($fk_parent = 0, $keyword = '') { global $db, $conf; $TFille = array(); if (!empty($keyword)) { $resultset = $db->query("SELECT rowid FROM " . MAIN_DB_PREFIX . "categorie WHERE label LIKE '%" . addslashes($keyword) . "%' ORDER BY label"); while ($obj = $db->fetch_object($resultset)) { $cat = new Categorie($db); $cat->fetch($obj->rowid); $TFille[] = $cat; } } else { $parent = new Categorie($db); if (empty($fk_parent)) { if (empty($conf->global->SPC_DO_NOT_LOAD_PARENT_CAT)) { $TFille = $parent->get_all_categories(0, true); } } else { $parent->fetch($fk_parent); $TFille = $parent->get_filles(); } } return $TFille; }
/** * Get category infos and children * * @param array $authentication Array of authentication information * @param int $id Id of object * @return mixed */ function getCategory($authentication, $id) { global $db, $conf, $langs; dol_syslog("Function: getCategory login="******" id=" . $id); if ($authentication['entity']) { $conf->entity = $authentication['entity']; } $objectresp = array(); $errorcode = ''; $errorlabel = ''; $error = 0; $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel); if (!$error && !$id) { $error++; $errorcode = 'BAD_PARAMETERS'; $errorlabel = "Parameter id must be provided."; } if (!$error) { $fuser->getrights(); if ($fuser->rights->categorie->lire) { $categorie = new Categorie($db); $result = $categorie->fetch($id); if ($result > 0) { $dir = !empty($conf->categorie->dir_output) ? $conf->categorie->dir_output : $conf->service->dir_output; $pdir = get_exdir($categorie->id, 2) . $categorie->id . "/photos/"; $dir = $dir . '/' . $pdir; $cat = array('id' => $categorie->id, 'id_mere' => $categorie->id_mere, 'label' => $categorie->label, 'description' => $categorie->description, 'socid' => $categorie->socid, 'type' => $categorie->type, 'dir' => $pdir, 'photos' => $categorie->liste_photos($dir, $nbmax = 10)); $cats = $categorie->get_filles(); if (count($cats) > 0) { foreach ($cats as $fille) { $dir = !empty($conf->categorie->dir_output) ? $conf->categorie->dir_output : $conf->service->dir_output; $pdir = get_exdir($fille->id, 2) . $fille->id . "/photos/"; $dir = $dir . '/' . $pdir; $cat['filles'][] = array('id' => $fille->id, 'id_mere' => $categorie->id_mere, 'label' => $fille->label, 'description' => $fille->description, 'socid' => $fille->socid, 'type' => $fille->type, 'dir' => $pdir, 'photos' => $fille->liste_photos($dir, $nbmax = 10)); } } // Create $objectresp = array('result' => array('result_code' => 'OK', 'result_label' => ''), 'categorie' => $cat); } else { $error++; $errorcode = 'NOT_FOUND'; $errorlabel = 'Object not found for id=' . $id; } } else { $error++; $errorcode = 'PERMISSION_DENIED'; $errorlabel = 'User does not have permission for this request'; } } if ($error) { $objectresp = array('result' => array('result_code' => $errorcode, 'result_label' => $errorlabel)); } return $objectresp; }