ReportController::actionApplications PHP Method

actionApplications() public method

public actionApplications ( )
    public function actionApplications()
    {
        $date_from = date(Helper::NHS_DATE_FORMAT, strtotime('-1 year'));
        $date_to = date(Helper::NHS_DATE_FORMAT);
        if (isset($_GET['yt0'])) {
            $firm = null;
            if (@$_GET['firm_id'] && (int) $_GET['firm_id']) {
                $firm_id = (int) $_GET['firm_id'];
                if (!($firm = Firm::model()->findByPk($firm_id))) {
                    throw new CException("Unknown firm {$firm_id}");
                }
            }
            if (@$_GET['date_from'] && date('Y-m-d', strtotime($_GET['date_from']))) {
                $date_from = date('Y-m-d', strtotime($_GET['date_from']));
            }
            if (@$_GET['date_to'] && date('Y-m-d', strtotime($_GET['date_to']))) {
                $date_to = date('Y-m-d', strtotime($_GET['date_to']));
            }
            $results = $this->getApplications($date_from, $date_to, $firm);
            $filename = 'therapyapplication_report_' . date('YmdHis') . '.csv';
            $this->sendCsvHeaders($filename);
            echo $this->array2Csv($results);
        } else {
            $subspecialty = Subspecialty::model()->find('ref_spec=:ref_spec', array(':ref_spec' => 'MR'));
            $context = array('firms' => Firm::model()->getList($subspecialty->id), 'date_from' => $date_from, 'date_to' => $date_to);
            $this->render('applications', $context);
        }
    }