public static function logAction($actionType, $message, $topUpValue, $batch, $logDate) { if (empty($batch) || is_null($batch)) { $batch = uniqid(); } if (empty($logDate) || is_null($logDate)) { $logDate = time(); } $newRecod = new ViciLogAction(); $newRecod->action_type = $actionType; $newRecod->message = $message; $newRecod->topUpValue = $topUpValue; $newRecod->batch = $batch; $newRecod->logDate = $logDate; if (!$newRecod->save()) { throw new Exception("Cant save log due to : " . CHtml::errorSummary($newRecod)); } }
public function actionExportRange($dateFrom, $dateTo) { $fileName = 'logs-export-range'; header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private", false); header("Content-Type: application/octet-stream"); header("Content-Disposition: attachment; filename=\"{$fileName}.csv\";"); header("Content-Transfer-Encoding: binary"); $criteria = new CDbCriteria(); $criteria->compare("action_type", 'SUB_ACCOUNT_TOPUP'); $criteria->addBetweenCondition("logDate", date("Y-m-d H:i:s", strtotime($dateFrom)), date("Y-m-d H:i:s", strtotime($dateTo))); $criteria->order = "logDate DESC"; $allResult = ViciLogAction::model()->findAll($criteria); //header echo sprintf("%s,%s,%s\n", "Message", "Value", "Date"); foreach ($allResult as $key => $value) { echo sprintf("%s,%s,%s\n", $value->message, $value->topUpValue, $value->logDate); } Yii::app()->end(); }
/** * 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 ViciLogAction the loaded model * @throws CHttpException */ public function loadModel($id) { $model = ViciLogAction::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }