Skip to content

Instantly share code, notes, and snippets.

@andronex
Last active March 1, 2018 00:27
Show Gist options
  • Save andronex/a6502210e68c964aba26f1c48b36635d to your computer and use it in GitHub Desktop.
Save andronex/a6502210e68c964aba26f1c48b36635d to your computer and use it in GitHub Desktop.
Расширение класса xPDOSimpleObject и изменение метода ::save() для алгоритма управления через таблицу MIGX
<?php
class EvacuatorsPaidsBeznal extends xPDOSimpleObject {
/** {inheritDoc} */
public function save($cacheFlag = null) {
if($this->get('status') == true && isset($this->_dirty['status']) && !$this->isNew()){
$this->set('published', 0);
$table = $this->xpdo->getTableName('EvacuatorsBalance');
//плюсуем на счёт сумму из выставленного ранее и оплаченного счёта
$this->xpdo->exec("UPDATE {$table} SET `amount` = `amount` + {$this->amount} WHERE `user_id` = {$this->user_id};");
$path_pdf = $this->xpdo->getOption('assets_path') . 'receipts/';
$innerPath_pdf = $this->user_id;
//если счёт была в PDF сгенерирован, то удаляем файл счёта за ненадобностью
if(file_exists($path_pdf . $innerPath_pdf . '/' . $this->order_id .'.pdf')){
unlink($path_pdf . $innerPath_pdf . '/' . $this->order_id .'.pdf');
}
}
//не даём сменить статус обратно на неоплаченный
if($this->get('status') == false && isset($this->_dirty['status']) && !$this->isNew()){
$this->xpdo->lexicon->load('Evacuators:default');
return false;
}
return parent::save($cacheFlag);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment