Skip to content
Snippets Groups Projects

Hotline

Merged Patrick Barroca requested to merge hotline into master
Compare and
4 files
+ 56
14
Preferences
Compare changes
Files
4
@@ -111,6 +111,7 @@ class Class_NoticeDomain extends Storm_Model_Abstract {
$_belongs_to = ['domain' => ['model' => 'Class_Catalogue',
'referenced_in' => 'domain_id'],
'panier_notice' => ['model' => 'Class_PanierNotice',
'referenced_in' => 'panier_id']],
@@ -129,12 +130,23 @@ class Class_NoticeDomain extends Storm_Model_Abstract {
}
public function getNotice() {
return Class_Notice::findFirstBy(['clef_alpha' => $this->getRecordAlphaKey()]);
}
public function updateFacette() {
$this->_withRecordAndDomainDo([$this, '_updateRecordFacets']);
return $this;
}
public function beforeDelete() {
$record = $this->getNotice();
$domain = $this->getDomain();
if(!$record || !$domain)
return;
$this->_withRecordAndDomainDo([$this, '_deleteRecordFacetIfLast']);
}
protected function _deleteRecordFacetIfLast($record, $domain) {
$existing = Class_NoticeDomain::getLoader()
->countBy(['domain_id' => $domain->getId(),
'record_alpha_key' => $this->getRecordAlphaKey()]);
@@ -145,15 +157,17 @@ class Class_NoticeDomain extends Storm_Model_Abstract {
}
public function getNotice() {
return Class_Notice::findFirstBy(['clef_alpha' => $this->getRecordAlphaKey()]);
protected function _updateRecordFacets($record, $domain) {
$record->updateFacette($domain->getFacette())->save();
}
public function updateFacette() {
$this->getNotice()
->updateFacette($this->getDomain()->getFacette())
->save();
return $this;
protected function _withRecordAndDomainDo($callback) {
$record = $this->getNotice();
$domain = $this->getDomain();
if (!$record || !$domain)
return;
return call_user_func($callback, $record, $domain);
}
}
\ No newline at end of file