예제 #1
0
 /**
  * This action is used to send mails to employees for passport expiry,and credit card expiry(personal details screen)
  */
 public function empdocsexpiryAction()
 {
     $this->_helper->viewRenderer->setNoRender(true);
     $this->_helper->layout()->disableLayout();
     $email_model = new Default_Model_EmailLogs();
     $cron_model = new Default_Model_Cronstatus();
     $cron_status = $cron_model->getActiveCron('Emp docs expiry');
     if ($cron_status == 'yes') {
         try {
             //updating cron status table to in-progress
             $cron_data = array('cron_status' => 1, 'cron_type' => 'Emp docs expiry', 'started_at' => gmdate("Y-m-d H:i:s"));
             $cron_id = $cron_model->SaveorUpdateCronStatusData($cron_data, '');
             if ($cron_id != '') {
                 $calc_date = new DateTime(date('Y-m-d'));
                 $calc_date->add(new DateInterval('P1M'));
                 $print_date = $calc_date->format(DATEFORMAT_PHP);
                 $calc_date = $calc_date->format('Y-m-d');
                 $mail_data = $email_model->getEmpDocExpiryData($calc_date);
                 if (count($mail_data) > 0) {
                     foreach ($mail_data as $mdata) {
                         $view = $this->getHelper('ViewRenderer')->view;
                         $this->view->emp_name = $mdata['name'];
                         $this->view->docs_arr = $mdata['docs'];
                         $this->view->expiry_date = $print_date;
                         $text = $view->render('mailtemplates/empdocsexpirycron.phtml');
                         $options['subject'] = APPLICATION_NAME . ': Documents expiry';
                         $options['header'] = 'Greetings from ' . APPLICATION_NAME;
                         $options['toEmail'] = $mdata['email'];
                         $options['toName'] = $mdata['name'];
                         $options['message'] = $text;
                         sapp_Global::_sendEmail($options);
                     }
                 }
                 $cron_data = array('cron_status' => 0, 'completed_at' => gmdate("Y-m-d H:i:s"));
                 $cron_id = $cron_model->SaveorUpdateCronStatusData($cron_data, "id = " . $cron_id);
             }
             //end of cron status id if
         } catch (Exception $e) {
         }
     }
     //end of cron status if
 }