/** * * @param Zend_Db_Table_Row $campaign */ protected function _sendSms($campaign) { // Get the current SMS Config $mapperConfig = new Admin_Model_Mapper_SmsConfig(); $smsConfig = $mapperConfig->getConfig(); $dbCampaign = App_Model_DbTable_Factory::get('Campaign'); $dbContactSend = App_Model_DbTable_Factory::get('CampaignSent'); // Fetch All contacts to be sent $contactsToSend = $this->_mapperCampaign->listContactsToSend($campaign->id_campaign, 300); // Format Sms Content $contentCampaign = $this->_formatSmsContent($campaign, $smsConfig); foreach ($contactsToSend as $contact) { // Check if the department has credit yet if (!$this->_checkDepartment($campaign)) { return false; } $number = App_General_String::validateNumber($contact->number); $data = array('id_campaign_sent' => $contact->id_campaign_sent, 'attempts' => ++$contact->attempts, 'fk_id_sms_config' => $smsConfig->id_sms_config, 'fk_id_campaign' => $campaign->id_campaign, 'fk_id_sms_group_contact' => $contact->id_sms_group_contact, 'target' => $number); // Check if the number to be sent is valid if (empty($number)) { $data['status'] = 'E'; $data['log'] = 'KONTATU IDA NE\'E HO NUMERO SALA'; } else { // Prepare the parameters to be sent $toSend = array('to' => $number, 'msg' => $contentCampaign, 'id' => implode('|', array($campaign->id_campaign, $contact->id_sms_group_contact))); // Try to send the Sms try { $result = App_Util_Sms::send($smsConfig->gateway_url, $toSend); $data['status'] = (bool) $result['status'] ? 'S' : 'E'; $data['log'] = (bool) $result['status'] ? '' : $result['msgerror']; $data['source'] = $result['source']; } catch (Exception $e) { $data['status'] = 'E'; $data['log'] = $e->getMessage(); } } $this->_data = $data; parent::_simpleSave($dbContactSend, false); } // Fetch All contacts to be sent $contactsToSend = $this->_mapperCampaign->listContactsToSend($campaign->id_campaign); if ($contactsToSend->count() < 1) { $this->_finishCampaign($campaign->id_campaign); } else { // Set the campaign as initied $data = array('status' => Sms_Model_Mapper_Campaign::STATUS_INITIED); $where = array('id_campaign = ?' => $campaign->id_campaign); $dbCampaign->update($data, $where); } }