Exemplo n.º 1
0
 /**
  * 
  * @param Zend_Db_Table_Row $campaign
  * @return boolean
  */
 protected function _checkDepartment($campaign)
 {
     $dbCampaign = App_Model_DbTable_Factory::get('Campaign');
     $mapperDepartment = new Admin_Model_Mapper_Department();
     // Fetch the department
     $department = $mapperDepartment->detailDepartment($campaign->fk_id_department);
     // Check if the department has balance
     if ($department['balance'] <= 0) {
         $this->saveLog('DEPARTAMENTU: ' . $campaign->fk_id_department . ' NIA PULSA HOTU ONA ATU HARUKA KAMPANHA: ' . $campaign->id_campaign);
         $this->_mapperCampaign->saveLog('DEPARTAMENTU: ' . $campaign->fk_id_department . ' NIA PULSA HOTU ONA ATU HARUKA KAMPANHA', $campaign->id_campaign);
         // 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);
         $noteMapper = new Default_Model_Mapper_Note();
         $noteModelMapper = new Default_Model_Mapper_NoteModel();
         // Search the user who must receive notes when a department credit is over
         $noteTypeMapper = new Admin_Model_Mapper_NoteType();
         $users = $noteTypeMapper->getUsersByNoteType(Admin_Model_Mapper_NoteType::DEPARTMENT_CREDIT);
         $users[] = $department['fk_id_sysuser'];
         // save the warning to the user responsible of the department
         $dataNote = array('title' => 'DEPARTAMETNU-NIA PULSA HOTU ONA', 'level' => 0, 'message' => $noteModelMapper->getDepartmentCredit($department), 'users' => $users);
         $noteMapper->setData($dataNote)->saveNote();
         return false;
     }
     return $department;
 }