public function findByUIDsWithDestinations($uids)
 {
     $criteria = new CDbCriteria();
     $criteria->alias = "t1";
     $criteria->join = 'LEFT JOIN `' . ScheduleTypeReport::model()->tableName() . '` `t2` on `t1`.`ex_schedule_id`=`t2`.`ex_schedule_id`';
     $criteria->with = array('ex_schedule_report', 'send_log.destination');
     foreach ($uids as $uid) {
         $res = self::parseUID($uid);
         $criteria->addCondition('(`t1`.`check_period_start`="' . $res['check_period_start'] . '" AND `t2`.`ex_schedule_ident`="' . $res['ex_schedule_ident'] . '")', 'OR');
     }
     $result = $this->findAll($criteria);
     if (!is_null($result)) {
         foreach ($result as &$item) {
             if (is_object($item->ex_schedule_report)) {
                 $item->setUniqueID($item->ex_schedule_report->ex_schedule_ident);
             }
         }
         $UIDsArray = $this->getUIDsArray($result);
         return array('result' => $result, 'uids' => $UIDsArray);
     }
     return array('result' => array(), 'uids' => array());
 }
 /**
  * @param $uids array
  * @param bool $sent true| false
  * @return array
  */
 public function findByUIDsWithDestinations($uids, $sent = false)
 {
     $criteria = new CDbCriteria();
     $criteria->alias = "t1";
     $criteria->join = '
      LEFT JOIN `' . ScheduleTypeReportProcessed::model()->tableName() . '` `t2` on `t1`.`ex_schedule_processed_id`=`t2`.`ex_schedule_processed_id`
      LEFT JOIN `' . ScheduleTypeReport::model()->tableName() . '` `t3` on `t2`.`ex_schedule_id`=`t3`.`ex_schedule_id`
     ';
     $criteria->with = array('report_processed.ex_schedule_report', 'destination');
     if ($sent == false) {
         $sent_condition = ' AND `t1`.`sent`="0"';
     }
     if ($sent == true) {
         $sent_condition = ' AND `t1`.`sent`="1"';
     }
     if (count($uids)) {
         foreach ($uids as $uid) {
             $res = ScheduleTypeReportProcessed::parseUID($uid['report_uid']);
             $criteria->addCondition('(`t2`.`check_period_start`="' . $res['check_period_start'] . '"
                                 AND `t3`.`ex_schedule_ident`="' . $res['ex_schedule_ident'] . '"
                                 ' . $sent_condition . ')', 'OR');
         }
         $result = $this->findAll($criteria);
         if (!is_null($result)) {
             foreach ($result as &$item) {
                 if (is_object($item->report_processed->ex_schedule_report) && is_object($item->report_processed)) {
                     $item->report_processed->setUniqueID($item->report_processed->ex_schedule_report->ex_schedule_ident);
                 }
             }
             $UIDsArray = $this->getUIDsArray($result);
             return array('result' => $result, 'uids' => $UIDsArray);
         }
     }
     return array('result' => array(), 'uids' => array());
 }
Exemplo n.º 3
0
 public function run($args)
 {
     //        if (!Yii::app()->mutex->lock('ScheduleTypeReports',3600)) {
     //            Yii::app()->end();
     //        }
     //        $synchronization = new Synchronization();
     //        if (!$synchronization->isMaster() and $synchronization->isProcessed())
     //            return;
     $generationTime = time();
     $proper_periods = $this->getProperPeriods($generationTime);
     $this->_logger->log(__METHOD__ . ' proper periods: ' . print_r($proper_periods, 1));
     //        if (count($proper_periods) === 0) {
     //			$this->_logger->log(__METHOD__ . ' Exiting. No proper periods found.' . "\n\n");
     //          Yii::app()->mutex->unlock();
     //			Yii::app()->end();
     //		}
     $criteria = new CDbCriteria();
     $criteria->select = array('ex_schedule_id', 'report_type', 'station_type', 'report_format', 'period', 'aging_time_delay', 'start_datetime', 'next_run_planned');
     $criteria->compare('period', '>0');
     $criteria->addCondition('active=1');
     /** @var array|ScheduleTypeReport[] $scheduledReports */
     $scheduledTypeReports = ScheduleTypeReport::model()->findAll($criteria);
     $this->_logger->log(__METHOD__ . ' $scheduledReports: ' . print_r($scheduledTypeReports, 1));
     if (count($scheduledTypeReports) === 0) {
         //			$this->_logger->log(__METHOD__ . ' Exiting. No proper reports found.' . "\n\n");
         //            Yii::app()->mutex->unlock();
         //			Yii::app()->end();
     }
     /**
      * @var $typeReportItem ScheduleTypeReport
      */
     foreach ($scheduledTypeReports as $typeReportItem) {
         if (strtotime($typeReportItem->next_run_planned_delayed) != mktime(date('H'), date('i'), 0, date('m'), date('d'), date('Y')) && strtotime($typeReportItem->next_run_planned_delayed) > mktime(date('H'), date('i'), 0, date('m'), date('d'), date('Y'))) {
             continue;
         }
         $weatherTypeReport = null;
         switch (strtolower($typeReportItem->report_type)) {
             //                case 'synop' :
             //                    $weatherTypeReport = WeatherTypeReport::create('Synop', $this->_logger);
             //                    break;
             //
             //                case 'bufr' :
             //                    $weatherTypeReport = WeatherTypeReport::create('Bufr', $this->_logger);
             //                    break;
             //
             //                case 'metar' :
             //                    $weatherTypeReport = WeatherTypeReport::create('Metar', $this->_logger);
             //                    break;
             case 'odss':
                 $weatherTypeReport = WeatherTypeReport::create('ODSS', $this->_logger);
                 break;
                 //                default :
                 //                    $weatherTypeReport = WeatherTypeReport::create('Export', $this->_logger);
                 //                    break;
         }
         try {
             $weatherTypeReport->load($typeReportItem);
             $typeReportItem->setTimeStep();
             //                $synchronization = new Synchronization();
             //                if(!$synchronization->isMaster() and $synchronization->isProcessed())
             //                    return;
             //                $weatherTypeReport->deliverReport();
             $weatherTypeReport->newReportAdd();
         } catch (Exteption $e) {
             $this->_logger->log(__METHOD__ . ' Error ', array('err' => $e->getMessage()));
         }
     }
 }
Exemplo n.º 4
0
 public function actionStationTypeDataExport()
 {
     /** @var ScheduleReport $form */
     /** @var ScheduleReportDestination[] $forms_d] */
     if (Yii::app()->request->isPostRequest) {
     }
     TimezoneWork::set('UTC');
     if (isset($_REQUEST['ex_schedule_id']) and (int) $_REQUEST['ex_schedule_id'] and isset($_REQUEST['active'])) {
         $scheduleTypeReportForm = ScheduleTypeReport::model()->findByPk(intval($_REQUEST['ex_schedule_id']));
         $scheduleTypeReportForm->setAttribute('active', $_REQUEST['active']);
         $scheduleTypeReportForm->save();
     }
     $scheduleTypeReportForm = new ScheduleTypeReport();
     if (isset($_REQUEST['ex_delete_id'])) {
         $scheduleTypeReportForm = ScheduleTypeReport::model()->findByPk(intval($_REQUEST['ex_delete_id']));
         if ($scheduleTypeReportForm && $scheduleTypeReportForm->delete()) {
             It::memStatus('schedule_deleted');
             $this->redirect($this->createUrl('site/StationTypeDataExport'));
         }
     }
     //		if (isset($_REQUEST['resend_schedule_id'])) {
     //            $form = ScheduleTypeReport::model()->findByPk(intval($_REQUEST['resend_schedule_id']));
     //        }
     if (isset($_REQUEST['ex_schedule_id']) and (int) $_REQUEST['ex_schedule_id'] and !isset($_REQUEST['active'])) {
         $scheduleTypeReportForm = ScheduleTypeReport::model()->findByPk(intval($_REQUEST['ex_schedule_id']));
     }
     if (isset($scheduleTypeReportForm)) {
         $scheduleTypeReportDestination = ScheduleTypeReportDestination::model()->findAllByAttributes(array('ex_schedule_id' => $scheduleTypeReportForm->ex_schedule_id));
     } else {
         $scheduleTypeReportDestination = array();
     }
     $valid = true;
     if (Yii::app()->request->isPostRequest && isset($_POST['ScheduleTypeReport'])) {
         $scheduleTypeReportForm->attributes = $_POST['ScheduleTypeReport'];
         $valid = $valid & $scheduleTypeReportForm->validate();
         if (isset($_POST['ScheduleTypeReportDestination'])) {
             foreach ($_POST['ScheduleTypeReportDestination'] as $key => $value) {
                 if ($value['ex_schedule_destination_id']) {
                     $scheduleTypeReportDestination[$key] = ScheduleTypeReportDestination::model()->findByPk($value['ex_schedule_destination_id']);
                 } else {
                     $scheduleTypeReportDestination[$key] = new ScheduleTypeReportDestination();
                 }
                 $scheduleTypeReportDestination[$key]->attributes = $value;
                 $valid = $valid & $scheduleTypeReportDestination[$key]->validate();
             }
         }
         if ($valid) {
             // $scheduleTypeReportForm->scenario='admin';
             $scheduleTypeReportForm->save(false);
             foreach ($scheduleTypeReportDestination as $key => $value) {
                 $scheduleTypeReportDestination[$key]->ex_schedule_id = $scheduleTypeReportForm->ex_schedule_id;
                 $scheduleTypeReportDestination[$key]->save();
             }
             //                foreach ($forms_s as $key => $value) {
             //                    $forms_s[$key]->schedule_id = $form->schedule_id;
             //                    $forms_s[$key]->save();
             //                }
             It::memStatus($scheduleTypeReportForm->isNewRecord ? 'schedule_added' : 'schedule_updated');
             $this->redirect($this->createUrl('site/StationTypeDataExport'));
         }
     }
     $str = new ScheduleTypeReport();
     $scheduleTypeReportProcessed = new ScheduleTypeReportProcessed();
     $scheduleTypesReports = $str->getList(10);
     $this->render('schedule_type_report', array('forms_d' => $scheduleTypeReportDestination, 'scheduleTypeReportForm' => $scheduleTypeReportForm, 'scheduleTypesReports' => $scheduleTypesReports, 'scheduleTypeReportProcessed' => $scheduleTypeReportProcessed));
 }