CodifThesaurus.php 18.5 KB
Newer Older
1 2 3 4
<?php
/**
 * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
 *
Laurent's avatar
Laurent committed
5
 * BOKEH is free software; you can redistribute it and/or modify
6 7 8 9 10 11
 * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
 * the Free Software Foundation.
 *
 * There are special exceptions to the terms and conditions of the AGPL as it
 * is applied to this software (see README file).
 *
Laurent's avatar
Laurent committed
12
 * BOKEH is distributed in the hope that it will be useful,
13 14 15 16 17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
 *
 * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
Laurent's avatar
Laurent committed
18
 * along with BOKEH; if not, write to the Free Software
Alex Arnaud's avatar
Alex Arnaud committed
19
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
20 21
 */

Ghislain Loas's avatar
Ghislain Loas committed
22 23 24
class CodifThesaurusLoader extends Storm_Model_Loader {
  use Trait_Translator;

25 26 27 28 29 30 31
  const
    SUGGEST_HIERARCHY_CONTAINS = 1,
    SUGGEST_LABEL_STARTS_WITH = 2,
    SUGGEST_LABEL_CONTAINS = 3,
    SUGGEST_INDEX_STARTS_WITH = 4;


32 33 34 35 36 37 38 39
  protected $_fixed = [];

  public function __construct($class) {
    parent::__construct($class);

    $this->_fixed = Class_CodifThesaurusFixed::getAll();
  }

Ghislain Loas's avatar
Ghislain Loas committed
40

Patrick Barroca's avatar
Patrick Barroca committed
41
  public function findThesaurusForCatalogue($catalogue_id) {
42 43
    return Class_CodifThesaurus::getLoader()
      ->findFirstBy(['id_origine'=> $catalogue_id,
44 45 46 47 48 49 50 51 52 53
                     'code' => Class_CodifThesaurus::fixedCodeOf('Domain')]);
  }


  public function collectForModelsUnderFixed($fixed_name, $models, $closure) {
    if (!isset($this->_fixed[$fixed_name]))
      return;

    foreach($models as $model)
      $closure($this->_ensureForModelUnderRoot($model, $this->_fixed[$fixed_name]));
54 55 56
  }


57
  public function findLibraryNoveltyFor($library_id) {
58 59 60 61 62 63
    return ($library = Class_Bib::find((int)$library_id))
      ? $this->_ensureLibraryNoveltyThesaurus($library)
      : null;
  }


64 65 66 67 68
  protected function _ensureForModelUnderRoot($model, $definition) {
    return ($root = Class_CodifThesaurus::findRootOfId($definition->getId(),
                                                       $definition->getCode(),
                                                       $definition->getLabel()))
      ? $root->getOrCreateChild($model->getId(), $model->getLibelle())
69
      : null;
70 71 72
  }


73 74 75 76 77 78 79 80 81 82
  protected function _ensureLibraryNoveltyThesaurus($model) {
    return $this->_ensureForModelUnderRoot($model, $this->_fixed['LibraryNovelty']);
  }


  protected function _ensureAnnexeNoveltyThesaurus($model) {
    return $this->_ensureForModelUnderRoot($model, $this->_fixed['AnnexeNovelty']);
  }


83
  public function findForCustomField($field) {
84 85 86 87 88 89 90 91 92 93
    return Class_CodifThesaurus::findForCustomFieldMeta($field->getMeta());
  }


  public function getOrCreateForCustomField($field) {
    return Class_CodifThesaurus::getOrCreateForCustomFieldMeta($field->getMeta());
  }


  public function findForCustomFieldMeta($meta) {
94
    return Class_CodifThesaurus::getLoader()
95
      ->findFirstBy(['id_origine' => $meta->getId(),
96
                     'code' => Class_CodifThesaurus::fixedCodeOf('CustomField')]);
97 98 99
  }


100 101
  public function getOrCreateForCustomFieldMeta($meta) {
    return Class_CodifThesaurus::findCustomFieldsRoot()
102
      ->getOrCreateChild($meta->getId(), $meta->getLabel());
103 104 105
  }


106
  public function findCustomFieldsRoot() {
107 108 109 110 111
    $definition = $this->_fixed['CustomField'];
    return Class_CodifThesaurus::findRootOfId($definition->getId(),
                                              $definition->getCode(),
                                              $definition->getLabel());
  }
112

Ghislain Loas's avatar
Ghislain Loas committed
113

114 115 116
  public function findForItemLibraryNovelty($item) {
    if(!$library = $item->getBib())
      return null;
117

118 119 120
    return ($item = $this->_ensureForModelUnderRoot($library, $this->_fixed['LibraryNovelty']))
      ? $item->getFacetteIndex()
      : '';
Patrick Barroca's avatar
Patrick Barroca committed
121 122 123
  }


124 125
  public function findForItemAnnexeNovelty($item) {
    if(!$model = $item->getCodifAnnexe())
Ghislain Loas's avatar
Ghislain Loas committed
126 127
      return null;

128 129 130
    return ($item = $this->_ensureForModelUnderRoot($model, $this->_fixed['AnnexeNovelty']))
      ? $item->getFacetteIndex()
      : '';
Ghislain Loas's avatar
Ghislain Loas committed
131 132 133
  }


134 135
  public function findRootOfId($id, $code, $label) {
    if ($codif = Class_CodifThesaurus::findFirstBy(['id_thesaurus' => $id]))
Ghislain Loas's avatar
Ghislain Loas committed
136 137
      return $codif;

138 139 140
    $attributes = ['id_thesaurus' => $id,
                   'libelle' => $label,
                   'code' => $code];
Ghislain Loas's avatar
Ghislain Loas committed
141 142

    $codif = Class_CodifThesaurus::newInstance($attributes);
143 144

    return $codif->save() ? $codif : null;
Ghislain Loas's avatar
Ghislain Loas committed
145 146 147
  }


Patrick Barroca's avatar
Patrick Barroca committed
148 149 150 151 152 153 154 155 156 157 158 159 160 161
  public function addFacetForSigb($facet_name, $facet_rules, $comm_sigb) {
    if (!Class_IntBib::findFirstBy(['comm_sigb' => $comm_sigb])
        || Class_CodifThesaurus::findFirstBy(['rules' => json_encode(['label' => $facet_rules])]))
      return ;
    $thesaurus = Class_CodifThesaurus::newInstance(['libelle' => $facet_name,
                                                    'libelle_facette' => $facet_name,
                                                    'rules' => json_encode(['label' => $facet_rules])]);
    $thesaurus->save();
  }


  public function getLibelleHierarchique($enreg) {
    if (!$enreg)
      return '';
162 163

    if (!$parent = Class_CodifThesaurus::findParent($enreg->getIdThesaurus()))
Patrick Barroca's avatar
Patrick Barroca committed
164 165
      return $enreg->getLibelle();

166 167
    if (strlen($parent->getIdThesaurus()) <= 8)
      return $parent->getLibelle() . ' : ' . $enreg->getLibelle();
Patrick Barroca's avatar
Patrick Barroca committed
168

169
    return $this->getLibelleHierarchique($parent) . ' : ' . $enreg->getLibelle();
Patrick Barroca's avatar
Patrick Barroca committed
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
  }


  public function findParent($id_thesaurus) {
    $parent_str=substr($id_thesaurus,0,strlen($id_thesaurus)-(4-strlen($id_thesaurus)%4));
    if (!$parent_str)
      return null;

    $parent = Class_CodifThesaurus::findFirstBy(['where' => 'id_thesaurus like "'.$parent_str.'%" and LENGTH(id_thesaurus)<'.strlen($id_thesaurus),
                                                 'order' => 'id_thesaurus desc']);
    if (!$parent)
      return $this->findParent($parent_str);

    return $parent;
  }


  /** @return string */
  public function findNextThesaurusChildId($code, $parentid_thesaurus) {
    Class_CodifThesaurus::clearCache();
    $last_thesaurus = Class_CodifThesaurus::findFirstBy(['code' => $code,
                                                         'where' => 'id_thesaurus like "'.$parentid_thesaurus.'%"',
                                                         'order' => 'id_thesaurus desc']);
    if (!$last_thesaurus)
      return $parentid_thesaurus.'0001';
195

Patrick Barroca's avatar
Patrick Barroca committed
196 197
    if (strlen($parentid_thesaurus) >=strlen($last_thesaurus->getIdThesaurus()))
      return $parentid_thesaurus.'0001';
198

Patrick Barroca's avatar
Patrick Barroca committed
199 200 201 202 203 204 205 206 207 208 209 210 211 212
    return $this->incrementId(substr($last_thesaurus->getIdThesaurus(),0, strlen($parentid_thesaurus)+4)) ;
  }


  public function incrementId($id) {
    $last=substr($id,strlen($id)-4);
    $first_part=substr($id,0,strlen($id)-4);
    $last++;
    return $first_part.$this->getCodeSur4Chiffres($last,true);
  }


  public function findNextRacineCatalogue() {
    $last_thesaurus = Class_CodifThesaurus::findFirstBy(['where' => 'code like "catalogue" and LENGTH(id_thesaurus) in (1,8)',
213
                                                         'order' => 'id_thesaurus desc']);
Patrick Barroca's avatar
Patrick Barroca committed
214

215 216 217
    return $last_thesaurus
      ? $this->incrementId($last_thesaurus->getIdThesaurus())
      : Class_CodifThesaurus::fixedIdOf('Domain') . '0001';
Patrick Barroca's avatar
Patrick Barroca committed
218 219 220
  }


221 222 223 224 225 226 227 228 229 230 231
  public function deleteAllWithIdOrigineAndCode($id_origine, $code_thesaurus) {
    foreach (Class_CodifThesaurus::findAllBy(['id_origine' => $id_origine,
                                              'code' => $code_thesaurus ])
             as $thesaurus)
      Class_CodifThesaurus::deleteAllFrom($thesaurus);
  }


  public function deleteAllFrom($thesaurus) {
    if ($thesaurus && '' != $thesaurus->getIdThesaurus())
      sqlExecute('delete from codif_thesaurus where id_thesaurus like "' . $thesaurus->getIdThesaurus() . '%"');
Patrick Barroca's avatar
Patrick Barroca committed
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
  }


  /**
   * @param int
   * $return Class_CodifThesaurus
   */
  public function findByIdOrigineAndCode($id_origine,$code_thesaurus) {
    if ($thesaurus = Class_CodifThesaurus::findFirstBy(['id_origine' => $id_origine,
                                                        'code' => $code_thesaurus ]))
      return $thesaurus;
    return Class_CodifThesaurus::findFirstBy(['id_origine' => $id_origine]);
  }


  public static function getCodeSur4Chiffres($code,$before=false) {
    $length=strlen($code);
    while (strlen($code) %4 != 0)  {
      if ($before)
        $code = '0'.$code;
      else
        $code .='0';
    }
    return $code;
  }


259
  public function getIndices($pere, $all = false ) {
260 261 262
    if(Class_CodifThesaurus::CODE_ROOT != $pere) {
      $pere = $this->getCodeSur4Chiffres($pere);
      $length = strlen($pere);
263

264 265
      return Class_CodifThesaurus::findAllBy(['where' => 'id_thesaurus like "'.$pere.'%" and LENGTH(id_thesaurus) in ('.($length+1).','.($length+4).')',
                                              'order'=> 'id_thesaurus']);
Patrick Barroca's avatar
Patrick Barroca committed
266 267
    }

268
    $where = '';
269

270 271 272
    // while search result do not handle item novelty correctly
    $to_exclude = [$this->fixedCodeOf('LibraryNovelty'),
                   $this->fixedCodeOf('AnnexeNovelty')];
273
    if (!$all)
274 275 276
      $to_exclude[] = $this->fixedCodeOf('Domain');

    $where = sprintf('code not in ("%s") and ', implode('", "', $to_exclude));
277

278
    $where .= 'LENGTH(id_thesaurus) in (1,4)';
279 280

    return Class_CodifThesaurus::findAllBy(['where' => $where,
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
                                            'order' => 'id_thesaurus']);
  }


  public function fixedCodeOf($name) {
    return isset($this->_fixed[$name]) ? $this->_fixed[$name]->getCode() : '';
  }


  public function fixedIdOf($name) {
    return isset($this->_fixed[$name]) ? $this->_fixed[$name]->getId() : '';
  }


  public function fixedLabelOf($name) {
    return isset($this->_fixed[$name]) ? $this->_fixed[$name]->getLabel() : '';
Patrick Barroca's avatar
Patrick Barroca committed
297 298 299 300
  }


  public function getFacettesIndex() {
301
    return array_map(function($item) { return $item->getFacetteIndex(); },
302 303 304 305 306 307
                     Class_CodifThesaurus::getFacettesThesauri());
  }


  public function getFacettesThesauri() {
    $filter = function($item) {
308
      return Class_CodifThesaurus::fixedIdOf('CustomField') != $item->getIdThesaurus();
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328
    };

    $thesauri = array_filter(Class_CodifThesaurus::getIndices('root', true), $filter);

    foreach(Class_CodifThesaurus::findCustomFieldsRoot()->getChildren() as $item)
      $thesauri[] = $item;

    return $thesauri;
  }


  public function findChildrenOf($parent) {
    if (!$parent || !$id_thesaurus = $parent->getIdThesaurus())
      return [];

    $where = sprintf('id_thesaurus like "%s%%" and LENGTH(id_thesaurus) = %s',
                     $id_thesaurus, strlen($id_thesaurus) + 4);

    return Class_CodifThesaurus::findAllBy(['where' => $where,
                                            'order' => 'libelle']);
Patrick Barroca's avatar
Patrick Barroca committed
329
  }
330 331 332


  public function getFacetGroup($facet) {
Patrick Barroca's avatar
Patrick Barroca committed
333
    return substr($facet, 0, $this->isCustomFieldsFacet($facet) ? 9 : 5);
334 335 336 337 338 339 340 341 342 343 344 345 346 347
  }


  protected function isCustomFieldsFacet($facet) {
    return $this->startsWith($facet, $this->getCustomFieldsFacetPrefix());
  }


  protected function startsWith($value, $prefix) {
    return $prefix == substr($value, 0, strlen($prefix));
  }


  protected function getCustomFieldsFacetPrefix() {
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414
    return Class_CodifThesaurus::CODE_FACETTE . Class_CodifThesaurus::fixedIdOf('CustomField');
  }


  public function suggestFrom($recherche, $mode, $limite_resultat, $theme) {
    if (!$req = $this->_suggestQueryFor((int)$mode, $theme, $recherche, $limite_resultat))
      return [];

    $resultat=fetchAll($req);

    if (!$resultat)
      return [];

    foreach($resultat as $enreg) {
      $thesaurus = Class_CodifThesaurus::find($enreg["id"]);
      $libelle = Class_CodifThesaurus::getLibelleHierarchique($thesaurus);
      $liste[] = [$enreg["id_thesaurus"],
                  $enreg["id_origine"]." : ".$libelle];
    }

    return $liste;
  }


  protected function _suggestQueryFor($mode, $parent, $term, $limit) {
    $parent_clause = $this->_fieldStartsWith('id_thesaurus', $parent);

    if (static::SUGGEST_HIERARCHY_CONTAINS == $mode) {
      return (3 <= strlen($term))
        ? $this->_orderAndLimit("select distinct(id), id, id_thesaurus, id_origine "
                                ."from codif_thesaurus where id_thesaurus regexp (select group_concat(concat(id_thesaurus,'.*') separator '|') from codif_thesaurus where ". $parent_clause ." and id_origine is not null and " . $this->_fieldContains('libelle', $term) . ")",
                                $limit)
        : null;
    }

    $basic_select = "select id, id_thesaurus, id_origine from codif_thesaurus where ". $parent_clause;
    if (static::SUGGEST_LABEL_STARTS_WITH == $mode)
      return $this->_orderAndLimit($basic_select . ' and ' . $this->_fieldStartsWith('libelle', $term),
                                   $limit);

    if (static::SUGGEST_LABEL_CONTAINS == $mode)
      return $this->_orderAndLimit($basic_select . ' and ' . $this->_fieldContains('libelle', $term),
                                   $limit);

    if (static::SUGGEST_INDEX_STARTS_WITH == $mode)
      return $this->_orderAndLimit($basic_select . ' and ' . $this->_fieldStartsWith('id_origine', $term),
                                   $limit);
  }


  protected function _orderAndLimit($sql, $limit) {
    return $sql . ' order by id_thesaurus limit ' . $limit;
  }


  protected function _fieldStartsWith($field, $value) {
    return $this->_like($field, addslashes($value) . '%');
  }


  protected function _fieldContains($field, $value) {
    return $this->_like($field, '%' . addslashes($value) . '%');
  }


  protected function _like($field, $clause) {
    return $field . ' like \''. $clause . '\'';
415
  }
Ghislain Loas's avatar
Ghislain Loas committed
416 417 418 419 420 421 422 423 424 425 426 427


  public function getDynamicCodes() {
    $dynamic_facets = Class_CodifThesaurus::findAllBy(['rules not' => null,
                                                       'code not' => null,
                                                       'id_thesaurus not' => null]);
    $params = [];
    foreach($dynamic_facets as $facet)
      $params [] =  $facet->getCode();

    return array_unique($params);
  }
428
}
llaffont's avatar
llaffont committed
429 430 431 432




433
class Class_CodifThesaurus extends Storm_Model_Abstract {
434
  use Trait_Translator, Trait_MemoryCleaner;
Patrick Barroca's avatar
Patrick Barroca committed
435

436
  const
437 438
    CODE_ROOT = 'root',

439
    COLUMN_ORIGIN_SIZE = 20,
440
    ID_KEY_LENGTH = 4,
441

442
    CODE_FACETTE = 'H';
443

Ghislain Loas's avatar
Ghislain Loas committed
444
  protected $_loader_class = 'CodifThesaurusLoader';
445
  protected $_table_name = 'codif_thesaurus';
446
  protected $_table_primary = 'id';
Patrick Barroca's avatar
Patrick Barroca committed
447 448
  protected $_default_attribute_values = ['libelle_facette' => '',
                                          'id_thesaurus' =>null,
449
                                          'id_origine' => null,
Patrick Barroca's avatar
Patrick Barroca committed
450
                                          'rules' => null];
451

452 453
  public function getListeSuggestion($recherche, $mode, $limite_resultat, $theme) {
    return $this->getLoader()->suggestFrom($recherche, $mode, $limite_resultat, $theme);
Patrick Barroca's avatar
Patrick Barroca committed
454
  }
llaffont's avatar
llaffont committed
455

Alex Arnaud's avatar
Alex Arnaud committed
456

Patrick Barroca's avatar
Patrick Barroca committed
457
  public function getLibelleFacette() {
458 459
    return $this->_get('libelle_facette') && $this->_get('libelle_facette') != '' ?
      $this->_get('libelle_facette') : $this->getLibelle();
Patrick Barroca's avatar
Patrick Barroca committed
460
  }
461 462


Patrick Barroca's avatar
Patrick Barroca committed
463
  public function getFacetteIndex() {
464
    return self::CODE_FACETTE . $this->getIdThesaurus();
Patrick Barroca's avatar
Patrick Barroca committed
465
  }
Laurent's avatar
Laurent committed
466 467


Patrick Barroca's avatar
Patrick Barroca committed
468 469
  public function newChildEntry() {
    $code = $this->getCode();
Ghislain Loas's avatar
Ghislain Loas committed
470 471
    return Class_CodifThesaurus::getLoader()->newInstance(['code' => $code,
                                                           'id_thesaurus' => Class_CodifThesaurus::getLoader()->findNextThesaurusChildId(
472 473
                                                                                                                                         $code,
                                                                                                                                         $this->getIdThesaurus())]);
Patrick Barroca's avatar
Patrick Barroca committed
474
  }
Laurent's avatar
Laurent committed
475 476


Patrick Barroca's avatar
Patrick Barroca committed
477
  public function getOrCreateChild($id_origine, $label) {
Ghislain Loas's avatar
Ghislain Loas committed
478
    $entry = Class_CodifThesaurus::getLoader()->findFirstBy(['code' => $this->getCode(),
479 480 481 482
                                                             'id_origine' => mb_substr($id_origine,
                                                                                       0,
                                                                                       self::COLUMN_ORIGIN_SIZE,
                                                                                       'UTF-8')]);
483 484 485 486 487 488
    if ($entry)
      return $entry;

    $entry = $this
      ->newChildEntry()
      ->updateAttributes(['id_origine' => $id_origine,
Ghislain Loas's avatar
Ghislain Loas committed
489
                          'libelle' => $label]);
490

Patrick Barroca's avatar
Patrick Barroca committed
491
    return $entry->save() ? $entry : null;
Patrick Barroca's avatar
Patrick Barroca committed
492
  }
Laurent's avatar
Laurent committed
493 494


Patrick Barroca's avatar
Patrick Barroca committed
495 496 497 498 499 500
  public function withLabelRulesDo($closure) {
    $rules = json_decode($this->getRules());
    list($field, $subfield) = explode('$',$rules->label);
    return $closure(sprintf('%03d', trim($field)),
                    trim($subfield));
  }
Laurent's avatar
Laurent committed
501

502

Patrick Barroca's avatar
Patrick Barroca committed
503 504 505
  public function getRulesLabel() {
    return json_decode($this->getRules())->label;
  }
Laurent's avatar
Laurent committed
506

507

Patrick Barroca's avatar
Patrick Barroca committed
508
  public function validate() {
Patrick Barroca's avatar
Patrick Barroca committed
509 510 511
    $this->_validateIdThesaurus();

    $this->checkAttribute('libelle', '' != $this->getLibelle(), $this->_('Vous devez définir le libellé'));
Patrick Barroca's avatar
Patrick Barroca committed
512 513
    if (!$this->getRules())
      return true;
Laurent's avatar
Laurent committed
514

Patrick Barroca's avatar
Patrick Barroca committed
515
    $this->check('' != $this->getRules(), $this->_('Vous devez définir au moins une règle'));
Patrick Barroca's avatar
Patrick Barroca committed
516 517
    $regles = str_replace(' ', '', $this->getRulesLabel());
    $this->check(preg_match('/^[0-9]{1,3}\$[a-z0-9]$/', $regles),
Patrick Barroca's avatar
Patrick Barroca committed
518
                 $this->_('La règle n\'est pas de la forme 686$a'));
Patrick Barroca's avatar
Patrick Barroca committed
519
  }
520 521


Patrick Barroca's avatar
Patrick Barroca committed
522 523 524 525 526 527 528 529 530 531 532
  protected function _validateIdThesaurus() {
    $my_key = substr($this->getIdThesaurus(), -self::ID_KEY_LENGTH);
    $empty_key = str_repeat('0', self::ID_KEY_LENGTH);

    $this->checkAttribute('id_thesaurus',
                          $my_key != $empty_key,
                          $this->_('Nombre maximum d\'élément à ce niveau déjà atteint (%s)',
                                   str_repeat('9', self::ID_KEY_LENGTH)));
  }


533
  public function deleteMeAndMyChildren() {
534
    $this->cleanRecords();
535
    $this->getLoader()->deleteAllFrom($this);
536 537 538 539
    return $this;
  }


540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555
  public function cleanRecords() {
    $facets = [];
    foreach($this->getLoader()->findChildrenOf($this) as $child)
      $facets[] = $child->getFacetteIndex();

    if (empty($facets))
      return $this;

    $facets = implode(' ', $facets);
    while ($records = Class_Notice::findAllBy(['where' => 'match(facettes) against(\'' . $facets . '\')',
                                               'limit' => 100])) {
      foreach($records as $record) {
        $record->deleteFacettes($facets)
               ->save();
      }

556
      $this->_cleanMemory();
557 558 559 560 561 562
    }

    return $this;
  }


563
  public function getOrCreateCustomFieldValueChild($value) {
564 565
    return $this->getOrCreateChild($this->getLoader()->fixedIdOf('CustomField') . hash('crc32b', $value),
                                   $value);
566 567 568
  }


569 570
  public function getChildren() {
    return $this->getLoader()->findChildrenOf($this);
571
  }
572
}