Doc = $Doc; $this->DBObj = SiteMap::getObj('Invoice/Send/Send.php'); $this->_send(); exit; } protected function _getEmailObject() { $this->DBObj->initFromDB(); $data = $this->DBObj->getData(); if (empty($data)) { die('ERROR Email data is empty (id = ' . $this->DBObj->id . ')'); } $emailObject = $this->DBObj->prepareEmail($data, &$this->Doc); return $emailObject; } protected function _send() { $invoicesIds = $this->DBObj->getInvoices4Send(); $startTime = time(); foreach ($invoicesIds as $invoiceId) { $this->DBObj->id = $invoiceId; $this->_sendEmail(); if ($startTime + $this->lifeTime < time()) { break; } } $invoicesIds = $this->DBObj->getInvoices4Send(); if (!empty($invoicesIds)) { die('CONTINUE'); } die('DONE'); } protected function _sendEmail() { if (!($emailObject = $this->_getEmailObject())) { die('ERROR Invalid Email Object'); } //vdie(!$this->DBObj->_data['customer']['email']); if (!$this->DBObj->_data['customer']['email'] || false === $emailObject->send(array($this->DBObj->_data['customer']['email']))) { $data = array('senderror' => 'y'); } else { $data = array('sent' => 'y'); } $data['date_sent'] = date('Y-m-d'); //vdie($data); $this->DBObj->update($data); } }