addOptions(array( new sfCommandOption('application', null, sfCommandOption::PARAMETER_REQUIRED, 'The application name', 'zakaznik'), new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'prod'), new sfCommandOption('connection', null, sfCommandOption::PARAMETER_REQUIRED, 'The connection name', 'propel'), )); $this->namespace = ''; $this->name = 'sendDocumentEvents'; $this->briefDescription = ''; $this->detailedDescription = ''; } protected function execute($arguments = array(), $options = array()) { // initialize the database connection $databaseManager = new sfDatabaseManager($this->configuration); $connection = $databaseManager->getDatabase($options['connection'] ? $options['connection'] : null)->getConnection(); //$this->configuration = sfProjectConfiguration::getApplicationConfiguration('zakaznik', 'dev', true); sfContext::createInstance($this->configuration); $zakaznici = Doctrine::getTable('Zakaznik')->findAll(); foreach($zakaznici as $zakaznik) { $pomocnici = $zakaznik->getPomocnici_personalisty_list(); if(count($pomocnici)) { $zasilat = $pomocnici->getFirst()->getEmailDokumenty(); } else { $zasilat = false; } if($zasilat) { if($zakaznik->getDocumentEventsYesterdayQuery()->count() > 0) { $html = $this->getHtmlContent($zakaznik); foreach($zakaznik->getPersonalista_list() as $personalista) { $mail = array(); $mail['sendNow'] = true; $mail['name'] = $personalista->getJmeno(); $mail['email'] = $personalista->getEmail(); //$mail['email'] = 'podpora@jakobson.cz'; //$mail['email'] = 'tomas@naibrt.cz'; $mail['subject'] = 'Včerejší změny v dokumentech'; $mail['html'] = $html; $jnEmail = new jnEmailFront($mail); $this->logSection('send', $personalista->getJmeno().', '.$mail['email']); } } } } } protected function getHtmlContent(Zakaznik $zakaznik) { $this->configuration->loadHelpers(array('Url', 'Tag')); $yesterday = date('d.m.Y', strtotime('-1 day')); $result = '

Včera '.$yesterday.' byly provedeny následující změny v dokumentech (zakaznik: '.$zakaznik->getNazev().'):

'; $deleted = $zakaznik->getDocumentEventsYesterdayQuery()->addWhere('action = ?', DocumentEvent::ACTION_DELETE)->execute(); if(count($deleted)) { $result .= '

Smazané dokumenty:

'; $result .= ''; } $created = $zakaznik->getDocumentEventsYesterdayQuery()->addWhere('action = ?', DocumentEvent::ACTION_CREATE)->execute(); if(count($created)) { $result .= '

Vytvořené dokumenty dokumenty:

'; $result .= ''; } return $result; } }