Skip to content
Snippets Groups Projects
Commit a8d9d4c0 authored by Sebastien ANDRE's avatar Sebastien ANDRE
Browse files

opti get facet label

parent f491830d
No related merge requests found
Pipeline #34600 failed with stage
in 18 minutes and 34 seconds
This commit is part of merge request !4999. Comments created here will be created in the context of that merge request.
......@@ -93,17 +93,20 @@ class Class_CodifAnnexe extends Storm_Model_Abstract {
'no_pickup' => 0,
'date_maj' => ''];
protected $_belongs_to = [
'bib' => ['model' => 'Class_Bib',
'referenced_in' => 'id_bib'],
'int_bib' => ['through' => 'bib']];
public static function facetLabelFor($id) {
return ($annexe = static::findFirstBy(['code' => addslashes($id)]))
? $annexe->getLibelle()
protected $_belongs_to = ['bib' => ['model' => 'Class_Bib',
'referenced_in' => 'id_bib'],
'int_bib' => ['through' => 'bib']];
public static function facetLabelFor(string $id): string
{
$rows = static::query()
->select('libelle')
->eq('code', addslashes($id))
->beBasic()
->fetchFirst();
return $rows
? ($rows['libelle'] ?? '')
: '';
}
......
......@@ -125,13 +125,6 @@ class Class_CodifDeweyLoader extends Storm_Model_Loader {
}
public function getLibelleOf($indice) {
return ($dewey = Class_CodifDewey::find($indice))
? $dewey->getLibelle()
: Class_CodifDewey::newInstance(['id_dewey' => $indice])->formatIndice();
}
public function getIndices(string $pere) : array {
$query = Class_CodifDewey::query()
->eq(Storm_Query_Key::length('id_dewey'),
......@@ -177,9 +170,11 @@ class Class_CodifDewey extends Storm_Model_Abstract {
protected $_loader_class = 'Class_CodifDeweyLoader';
protected $_fixed_id = true;
public static function facetLabelFor($id) {
return static::getLoader()->getLibelleOf($id);
public static function facetLabelFor(string $id): string
{
return ($label = parent::facetLabelFor($id))
? $label
: Class_CodifDewey::newInstance(['id_dewey' => $id])->formatIndice();
}
......
......@@ -69,14 +69,6 @@ class Class_CodifLangue extends Storm_Model_Abstract {
}
public static function facetLabelFor($id) {
return ($model = static::find($id))
? $model->getLibelle()
: '';
}
public function getCategorie() {
return;
}
......
......@@ -88,13 +88,6 @@ class Class_CodifPcdm4Loader extends Storm_Model_Loader {
}
public function getLibelleOf($indice) {
return ($pcdm4 = Class_CodifPcdm4::find($indice))
? $pcdm4->getLibelle()
: $indice;
}
public function filtreIndice($indice) {
$indice=trim($indice);
if(!is_numeric(substr($indice,0,1)))
......@@ -156,9 +149,11 @@ class Class_CodifPcdm4 extends Storm_Model_Abstract {
$_loader_class = 'Class_CodifPcdm4Loader',
$_fixed_id = true;
public static function facetLabelFor($id) {
return static::getLoader()->getLibelleOf($id);
public static function facetLabelFor(string $id): string
{
return ($label = parent::facetLabelFor($id))
? $label
: $id;
}
......
......@@ -48,10 +48,18 @@ class Class_CodifThesaurus extends Storm_Model_Abstract {
protected $_list_rules;
public static function facetLabelFor($id) {
return ($thesaurus = static::getLoader()->findFirstBy(['id_thesaurus' => $id]))
? $thesaurus->getLibelleFacette()
: '';
public static function facetLabelFor(string $id): string
{
if ( ! ($rows = static::query()
->select(['libelle_facette', 'libelle'])
->eq('id_thesaurus', $id)
->beBasic()
->fetchFirst()))
return '';
return ($label = $rows['libelle_facette'] ?? '')
? $label
: $rows['libelle'] ?? '';
}
......
......@@ -337,6 +337,8 @@ class Class_TypeDoc extends Storm_Model_Abstract {
protected $_belongs_to = ['codif_type_doc' =>
['model' => 'Class_CodifTypeDoc',
'referenced_in' => 'id' ]];
protected string $_label_field = 'label';
const
UNKNOWN = 0,
LIVRE = 1,
......@@ -367,7 +369,6 @@ class Class_TypeDoc extends Storm_Model_Abstract {
SOUNDCLOUD = 117,
CITEDELAMUSIQUE = 119;
public static function getDefaultTypeDocs() {
$instance = new Class_TypeDoc;
return [self::LIVRE => $instance->_('Livres'),
......@@ -463,13 +464,6 @@ class Class_TypeDoc extends Storm_Model_Abstract {
}
public static function facetLabelFor($id) {
return ($type_doc = static::find($id))
? $type_doc->getLabel()
: '';
}
public function getCodifTypeDoc() {
if ($codif=parent::_get('codif_type_doc'))
return $codif;
......
......@@ -20,22 +20,37 @@
*/
trait Trait_Facetable {
/** @return string */
public static function facetLabelFor($id) {
return ($model = static::find((int)$id))
? $model->getLibelle()
trait Trait_Facetable
{
public static function facetLabelFor(string $id): string
{
$rows = static::query()
->select($this->_labelField())
->eq($this->_table_primary, $id)
->beBasic()
->fetchFirst();
return $rows
? ($rows[$this->_labelField()] ?? '')
: '';
}
/** @return string */
public function asFacet() {
public function asFacet(): string
{
return static::CODE_FACETTE . $this->getId();
}
public function getFacetCode() {
public function getFacetCode(): string
{
return $this->asFacet();
}
}
\ No newline at end of file
protected function _labelField(): string
{
return $this->_label_field ??= 'libelle';
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment