Example #1
0
 public function init()
 {
     $this->setAttrib('class', 'horizontal-form')->setName('search');
     $elements = array();
     $elements[] = $this->createElement('text', 'campaign_title')->setDecorators($this->getDefaultElementDecorators())->addFilter('StringTrim')->addFilter('StringToUpper')->setAttrib('maxlength', 200)->setAttrib('class', 'm-wrap span12 focused')->setLabel('Naran Kampanha');
     $dbCampaignType = App_Model_DbTable_Factory::get('CampaignType');
     $rows = $dbCampaignType->fetchAll(array(), array('campaign_type'));
     $optCampaignType[''] = '';
     foreach ($rows as $row) {
         $optCampaignType[$row->id_campaign_type] = $row->campaign_type;
     }
     $elements[] = $this->createElement('select', 'fk_id_campaign_type')->setDecorators($this->getDefaultElementDecorators())->setLabel('Tipu Kampanha')->addMultiOptions($optCampaignType)->setAttrib('class', 'm-wrap span12 chosen');
     $mapperDepartment = new Admin_Model_Mapper_Department();
     $rows = $mapperDepartment->fetchAll();
     $optDepartment[''] = '';
     foreach ($rows as $row) {
         $optDepartment[$row->id_department] = $row->name;
     }
     $elements[] = $this->createElement('select', 'fk_id_department')->setDecorators($this->getDefaultElementDecorators())->setAttrib('class', 'm-wrap span12 chosen')->setLabel('Departamentu')->addMultiOptions($optDepartment);
     $mapperGroup = new Sms_Model_Mapper_Group();
     $rows = $mapperGroup->fetchAll();
     $optGroups = array();
     foreach ($rows as $row) {
         $optGroups[$row['id_sms_group']] = $row['sms_group_name'];
     }
     $elements[] = $this->createElement('multiCheckbox', 'group')->setDecorators(array('ViewHelper'))->addMultiOptions($optGroups)->setAttrib('class', 'group-sending')->setRequired(true)->setSeparator('');
     $view = $this->getView();
     $optStatuses = $view->campaign()->getStatuses();
     array_unshift($optStatuses, '');
     $elements[] = $this->createElement('select', 'status')->setDecorators($this->getDefaultElementDecorators())->addMultiOptions($optStatuses)->setLabel('Status')->setAttrib('class', 'm-wrap span12');
     $this->addElements($elements);
 }
Example #2
0
 public function init()
 {
     $this->setAttrib('class', 'horizontal-form');
     $elements = array();
     $elements[] = $this->createElement('hidden', 'id_campaign')->setDecorators(array('ViewHelper'));
     $elements[] = $this->createElement('hidden', 'fk_id_department')->setDecorators(array('ViewHelper'));
     $elements[] = $this->createElement('text', 'campaign_title')->setDecorators($this->getDefaultElementDecorators())->addFilter('StringTrim')->addFilter('StringToUpper')->setAttrib('maxlength', 200)->setAttrib('class', 'm-wrap span12 focused')->setLabel('Naran Kampanha')->setRequired(true);
     $mapperConfig = new Admin_Model_Mapper_SmsConfig();
     $config = $mapperConfig->getConfig();
     $maxLength = $config->max_length - (strlen($config->sms_prefix) + strlen($config->sms_sufix) + 16);
     $elements[] = $this->createElement('textarea', 'content')->setDecorators($this->getDefaultElementDecorators())->addFilter('StringTrim')->setAttrib('class', 'm-wrap span12')->setAttrib('rows', 3)->setAttrib('maxlength', $maxLength)->setLabel('Mensajem')->setRequired(true);
     $elements[] = $this->createElement('text', 'date_scheduled')->setDecorators($this->getDefaultElementDecorators())->setAttrib('maxlength', 10)->setAttrib('class', 'm-wrap span12 date-mask date')->setLabel('Data atu haruka');
     $dbCampaignType = App_Model_DbTable_Factory::get('CampaignType');
     $rows = $dbCampaignType->fetchAll(array(), array('campaign_type'));
     $optCampaignType[''] = '';
     foreach ($rows as $row) {
         $optCampaignType[$row->id_campaign_type] = $row->campaign_type;
     }
     $elements[] = $this->createElement('select', 'fk_id_campaign_type')->setDecorators($this->getDefaultElementDecorators())->setLabel('Tipu Kampanha')->addMultiOptions($optCampaignType)->setRequired(true)->setAttrib('class', 'm-wrap span12 chosen');
     $mapperGroup = new Sms_Model_Mapper_Group();
     $rows = $mapperGroup->listGroupWithTotals();
     $optGroups = array();
     foreach ($rows as $row) {
         $optGroups[$row['id_sms_group']] = $row['sms_group_name'] . ' (' . $row['total'] . ')';
     }
     $elements[] = $this->createElement('multiCheckbox', 'group')->setDecorators(array('ViewHelper'))->addMultiOptions($optGroups)->setAttrib('onchange', 'Sms.Campaign.calcTotalSending( this );')->setAttrib('class', 'group-sending')->setRequired(true)->setSeparator('');
     $optWaitResponse['0'] = 'Lae';
     $optWaitResponse['1'] = 'Loos';
     $elements[] = $this->createElement('select', 'wait_response')->setDecorators($this->getDefaultElementDecorators())->setLabel('Hein Resposta')->addMultiOptions($optWaitResponse)->setValue('0')->setRequired(true)->setAttrib('class', 'm-wrap span12');
     $this->addElements($elements);
     App_Form_Toolbar::build($this, self::ID);
     $this->setDecorators($this->getDefaultFormDecorators());
 }
Example #3
0
 /**
  * 
  * @return boolean
  */
 protected function _validateCampaign()
 {
     if (empty($this->_group)) {
         return true;
     }
     $campaigns = $this->_mapper->listCampaignsRelated($this->_group->id_sms_group);
     if ($campaigns->count() > 0) {
         $this->addMessage('Grupu ida ne\'e usa dadaun iha kampanha ida. Keta edita.');
         return false;
     }
     return true;
 }
Example #4
0
 /**
  * 
  */
 public function removeItemAction()
 {
     $return = $this->_mapper->setData($this->_getAllParams())->removeItem();
     $message = $this->_mapper->getMessage()->toArray();
     $result = array('status' => (bool) $return, 'description' => empty($message) ? null : $message[0]);
     $this->_helper->json($result);
 }
Example #5
0
 /**
  * 
  */
 public function calcSendingAction()
 {
     $user = Zend_Auth::getInstance()->getIdentity();
     // Get the User department
     $mapperDepartment = new Admin_Model_Mapper_Department();
     $department = $mapperDepartment->getDepartmentByUser($user->id_sysuser);
     // Get the groups with totals
     $mapperGroupsSms = new Sms_Model_Mapper_Group();
     $groups = $mapperGroupsSms->listGroupWithTotals();
     // Get the current sms config
     $mapperConfig = new Admin_Model_Mapper_SmsConfig();
     $config = $mapperConfig->getConfig();
     $groupsSelected = $this->_getParam('groups');
     $total = 0;
     $percent = 100;
     if (!empty($groupsSelected)) {
         foreach ($groups as $group) {
             if (in_array($group['id_sms_group'], $groupsSelected)) {
                 $total += (int) $group['total'];
             }
         }
     }
     $totalCurrency = $total * (double) $config->sms_unit_cost;
     if (!empty($department['balance'])) {
         $percent = $totalCurrency * 100 / $department['balance'];
     }
     $return = array('total' => $total, 'release' => $totalCurrency <= $department['balance'], 'percent' => $percent);
     $this->_helper->json($return);
 }
Example #6
0
 /**
  * 
  * @param int $id
  * @return Zend_Db_Table_Rowset
  */
 public function listContactsToSend($id, $limit = false)
 {
     $mapperGroupSms = new Sms_Model_Mapper_Group();
     $selectContacts = $mapperGroupSms->getSelectContacts();
     // Get the SMS Config
     $mapperConfig = new Admin_Model_Mapper_SmsConfig();
     $config = $mapperConfig->getConfig();
     $dbCampainGroup = App_Model_DbTable_Factory::get('CampaignHasSmsGroup');
     $dbCampainSent = App_Model_DbTable_Factory::get('CampaignSent');
     $selectContacts->join(array('cg' => $dbCampainGroup), 'cg.fk_id_sms_group = t.fk_id_sms_group', array())->joinLeft(array('cs' => $dbCampainSent), 'cs.fk_id_campaign = cg.fk_id_campaign ' . 'AND cs.fk_id_sms_group_contact = t.id_sms_group_contact', array('id_campaign_sent', 'attempts'))->where('cg.fk_id_campaign = ?', $id)->where('( cs.id_campaign_sent IS NULL')->orWhere('cs.status = ?', 'E')->where('cs.attempts < ? )', $config->error_attempts);
     if (!empty($limit)) {
         $selectContacts->limit($limit);
     }
     return $this->_dbTable->fetchAll($selectContacts);
 }
Example #7
0
 /**
  * 
  * @return array
  */
 public function incomingReport()
 {
     $filters = $this->_data;
     $dbSmsIncoming = App_Model_DbTable_Factory::get('SmsIncoming');
     $dbCampaign = App_Model_DbTable_Factory::get('Campaign');
     $mapperGroupSms = new Sms_Model_Mapper_Group();
     $selectContact = $mapperGroupSms->getSelectContacts();
     $selectContact->reset(Zend_Db_Select::COLUMNS)->columns(array('contact', 'type', 'number'))->join(array('si' => $dbSmsIncoming), 'si.fk_id_sms_group_contact = t.id_sms_group_contact', array('date_time', 'content', 'target', 'source'))->join(array('c' => $dbCampaign), 'c.id_campaign = si.fk_id_campaign', array('campaign_title'));
     if (!empty($filters['fk_id_department'])) {
         $selectContact->where('c.fk_id_department = ?', $filters['fk_id_department']);
     }
     if (!empty($filters['fk_id_campaign'])) {
         $selectContact->where('si.fk_id_campaign = ?', $filters['fk_id_campaign']);
     }
     $selectNonData = $dbSmsIncoming->select()->from(array('si' => $dbSmsIncoming), array('contact' => new Zend_Db_Expr('"La identifika"'), 'type' => new Zend_Db_Expr('"La identifika"'), 'number' => 'source', 'date_time', 'content', 'target', 'source', 'campaign_title' => new Zend_Db_Expr('"La identifika"')))->where('si.fk_id_sms_group_contact IS NULL')->where('si.fk_id_campaign IS NULL');
     $selectNonContact = $dbSmsIncoming->select()->setIntegrityCheck(false)->from(array('si' => $dbSmsIncoming), array('contact' => new Zend_Db_Expr('"La identifika"'), 'type' => new Zend_Db_Expr('"La identifika"'), 'number' => 'source', 'date_time', 'content', 'target', 'source'))->join(array('c' => $dbCampaign), 'c.id_campaign = si.fk_id_campaign', array('campaign_title'))->where('si.fk_id_sms_group_contact IS NULL')->where('si.fk_id_campaign IS NOT NULL');
     $selectNonCampaign = $dbSmsIncoming->select()->setIntegrityCheck(false)->from(array('si' => $dbSmsIncoming), array('contact' => new Zend_Db_Expr('source'), 'type' => new Zend_Db_Expr('"La identifika"'), 'number' => 'source', 'date_time', 'content', 'target', 'source', 'campaign_title' => new Zend_Db_Expr('"La identifika"')))->where('si.fk_id_sms_group_contact IS NOT NULL')->where('si.fk_id_campaign IS NULL');
     $union = array($selectContact, $selectNonContact, $selectNonCampaign);
     if (empty($filters['fk_id_campaign'])) {
         $union[] = $selectNonData;
     }
     $selectUnion = $dbSmsIncoming->select()->union($union)->setIntegrityCheck(false)->order(array('date_time DESC'));
     $selectFinal = $dbSmsIncoming->select()->from(array('t' => new Zend_Db_Expr('(' . $selectUnion . ')')))->setIntegrityCheck(false);
     $date = new Zend_Date();
     if (!empty($filters['date_start'])) {
         $selectFinal->where('DATE(t.date_time) >= ?', $date->set($filters['date_start'])->toString('yyyy-MM-dd'));
     }
     if (!empty($filters['date_finish'])) {
         $selectFinal->where('DATE(t.date_time) <= ?', $date->set($filters['date_finish'])->toString('yyyy-MM-dd'));
     }
     $rows = $dbSmsIncoming->fetchAll($selectFinal);
     return array('rows' => $rows);
 }