get_parms( 'sbid' , 'type' , 'id' , 'lng' , 'sortsy' // trier la liste des sy (='1') ou pas , 'debug' , 'root' , 'last' // the node to browse has the 'last' class in the tree, so keep it ); phrasea::headers(200, true, 'application/json', 'UTF-8', false); if ( ! $parm['lng']) { $lng2 = $app['locale']; $lng2 = explode('_', $lng2); if (count($lng2) > 0) $parm['lng'] = $lng2[0]; } $lng = $parm['lng']; if ($parm['debug']) print('
'); $html = ''; $sbid = (int) $parm['sbid']; // root = 'TX_P.' . $xbas_id . '.T .... $tids = explode('.', $parm['id']); $thid = implode('.', $tids); $loaded = false; try { $connbas = connection::getPDOConnection($app, $sbid); $dbname = phrasea::sbas_names($sbid, $app); $t_nrec = array(); $lthid = strlen($thid); // count occurences if ($lthid == 1) { $dthid = str_replace('.', 'd', $thid); $sql = 'SELECT COUNT(DISTINCT record_id) AS n FROM thit WHERE value LIKE :like '; $stmt = $connbas->prepare($sql); $stmt->execute(array(':like' => $dthid . '%')); $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); $stmt->closeCursor(); if ($parm['debug']) printf("/*\n thid=%s\n %s \n */\n", $thid, $sql); foreach ($rs as $rowbas) $t_nrec[$thid] = $rowbas; $sql = 'SELECT SUBSTRING_INDEX(SUBSTR(value, ' . ($lthid + 1) . '), "d", 1) AS k , COUNT(DISTINCT record_id) AS n FROM thit WHERE value LIKE :like GROUP BY k'; $stmt = $connbas->prepare($sql); $stmt->execute(array(':like' => $dthid . '%')); $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); $stmt->closeCursor(); if ($parm['debug']) printf("/*\n thid=%s\n %s \n */\n", $thid, $sql); foreach ($rs as $rowbas) $t_nrec[$thid . $rowbas['k']] = $rowbas; } elseif (strlen($thid) > 1) { $dthid = str_replace('.', 'd', $thid); $sql = 'SELECT SUBSTRING_INDEX(SUBSTR(value, ' . ($lthid) . '), \'d\', 1) AS k , COUNT(DISTINCT record_id) AS n FROM thit WHERE value LIKE :like GROUP BY k'; $stmt = $connbas->prepare($sql); $stmt->execute(array(':like' => $dthid . '%')); $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); $stmt->closeCursor(); if ($parm['debug']) printf("/*\n thid=%s\n %s \n */\n", $thid, $sql); foreach ($rs as $rowbas) $t_nrec[$thid] = $rowbas; $sql = 'SELECT SUBSTRING_INDEX(SUBSTR(value, ' . ($lthid + 2) . '), \'d\', 1) AS k , COUNT(DISTINCT record_id) AS n FROM thit WHERE value LIKE :like GROUP BY k'; $stmt = $connbas->prepare($sql); $stmt->execute(array(':like' => $dthid . '%')); $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); $stmt->closeCursor(); if ($parm['debug']) printf("/*\n thid=%s\n %s \n */\n", $thid, $sql); foreach ($rs as $rowbas) $t_nrec[$thid . '.' . $rowbas['k']] = $rowbas; } if ($parm['debug']) printf("/* %s */\n", var_export($t_nrec, true)); $databox = $app['phraseanet.appbox']->get_databox($sbid); if ($parm['type'] == 'T') { $xqroot = 'thesaurus'; $dom = $databox->get_dom_thesaurus(); } else { // C $xqroot = 'cterms'; $dom = $databox->get_dom_cterms(); } if ($dom) { $term0 = ''; $firstTerm0 = ''; $xpath = new DOMXPath($dom); if ($thid == 'T' || $thid == 'C') { $q = '/' . $xqroot; $term0 = $dbname; } else { $q = '/' . $xqroot . '//te[@id=\'' . $thid . '\']'; } if ($parm['debug']) print("q:" . $q . "
\n"); $nodes = $xpath->query($q); if ($nodes->length > 0) { $node0 = $nodes->item(0); $key0 = null; // key of the sy in the current language (or key of the first sy if we can't find good lng) $nts0 = 0; // count of ts under this term $label = buildLabel($node0, $key0, $nts0); if ($parm['debug']) printf("buildLabel(...)\n label=%s\n key0=%s\n nts0=%s \n", $label, $key0, $nts0); $class = ''; if ($nts0 > 0) $class .= ( $class == '' ? '' : ' ') . 'expandable'; if ($parm['last']) $class .= ( $class == '' ? '' : ' ') . 'last'; $html .= '
%s
%s