public function actionMassBookings() { $model = new MassBooking(); if (isset($_POST['period'])) { $dt = $_POST['MassBooking']['mass_dt']; $dt = date('Y-m-d', CDateTimeParser::parse($dt, Yii::app()->locale->getDateFormat('short'))); header("Content-Type: application/vnd.ms-excel; charset=utf-8"); header("Content-Disposition: inline; filename=\"mass-bookings-report-{$dt}.xls\""); $period = $_POST['period']; $cond = "mass_dt BETWEEN '{$dt}' AND '{$dt}' + INTERVAL 1 {$period} ORDER BY mass_dt, mass.time, type"; Yii::trace("R.massBookings dt={$dt}, period={$period}, cond={$cond}", 'application.controllers.ReportController'); $crit = new CDbCriteria(); $crit->mergeWith(array('join' => 'INNER JOIN masses mass ON mass.id = t.mass_id', 'condition' => $cond)); $dataProvider = new CActiveDataProvider('MassBooking', array('criteria' => $crit)); $dataProvider->pagination = false; $fields = array('mass_dt', 'mass' => array('time', 'language'), 'type', 'intention', 'booked_by'); $labels = $model->attributeLabels(); $fval = array(); foreach ($fields as $key => $val) { if (!preg_match('/^\\d+$/', $key)) { foreach ($val as $field) { array_push($fval, ucfirst($field)); } } else { array_push($fval, $labels[$val]); } } echo implode("\t", $fval) . "\n"; $last_dt = ''; $last_mass = 0; $last_type = ''; foreach ($dataProvider->data as $data) { $fval = array(); $this_dt = $data->mass_dt; $this_mass = $data->mass_id; $this_type = $data->type; $same_mass = false; $same_type = false; if ($this_dt == $last_dt and $this_mass == $last_mass) { $same_mass = true; if ($this_type == $last_type) { $same_type = true; } } foreach ($fields as $key => $val) { if (!preg_match('/^\\d+$/', $key)) { foreach ($val as $field) { if ($same_mass) { $value = ''; } elseif ('language' == $field) { $value = FieldNames::value('languages', $data->{$key}->{$field}); } else { $value = $data->{$key}->{$field}; } array_push($fval, $value); } } else { if ($this_dt == $last_dt and 'mass_dt' == $val) { $value = ''; } elseif ($same_type and 'type' == $val) { $value = ''; } else { $value = $data->{$val}; } array_push($fval, $value); } } $last_dt = $this_dt; $last_mass = $this_mass; $last_type = $this_type; echo implode("\t", $fval) . "\n"; } Yii::app()->end(); return; } $this->render('mass-bookings', array('model' => $model)); }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return MassBooking the loaded model * @throws CHttpException */ public function loadModel($id) { $model = MassBooking::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }