| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- <?php
- namespace app\controllers;
- use app\models\Trade;
- use Yii;
- use app\models\Eventlog;
- use app\models\EventlogSearch;
- use yii\web\Controller;
- use yii\web\NotFoundHttpException;
- use yii\filters\VerbFilter;
- /**
- * EventlogController implements the CRUD actions for Eventlog model.
- */
- class EventlogController extends Controller
- {
- public function behaviors()
- {
- return [
- 'verbs' => [
- 'class' => VerbFilter::className(),
- 'actions' => [
- 'delete' => ['post'],
- ],
- ],
- ];
- }
- /**
- * Lists all Eventlog models.
- * @return mixed
- */
- public function init()
- {
- if(Yii::$app->user->isGuest)
- {
- return $this->redirect('/user/login');
- }
- if(!Yii::$app->user->can("admin"))
- {
- return $this->redirect('/site/index');
- }
- }
- public function actionIndex()
- {
- $searchModel = new EventlogSearch();
- $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
- //print_r($dataProvider); die();
- return $this->render('index', [
- 'searchModel' => $searchModel,
- 'dataProvider' => $dataProvider,
- ]);
- }
- /**
- * Displays a single Eventlog model.
- * @param integer $id
- * @return mixed
- */
- public function actionView($id)
- {
- return $this->render('view', [
- 'model' => $this->findModel($id),
- ]);
- }
- /**
- * Creates a new Eventlog model.
- * If creation is successful, the browser will be redirected to the 'view' page.
- * @return mixed
- */
- public function actionCreate()
- {
- $model = new Eventlog();
- if ($model->load(Yii::$app->request->post()) && $model->save()) {
- return $this->redirect(['view', 'id' => $model->id]);
- } else {
- return $this->render('create', [
- 'model' => $model,
- ]);
- }
- }
- /**
- * Updates an existing Eventlog model.
- * If update is successful, the browser will be redirected to the 'view' page.
- * @param integer $id
- * @return mixed
- */
- public function actionUpdate($id)
- {
- $model = $this->findModel($id);
- if ($model->load(Yii::$app->request->post()) && $model->save()) {
- return $this->redirect(['view', 'id' => $model->id]);
- } else {
- return $this->render('update', [
- 'model' => $model,
- ]);
- }
- }
- public function actionTradelog($id,$user_id)
- {
- $query = Yii::$app->db->createCommand('SELECT * FROM trade_logs WHERE auk_id=:id AND user_id=:user_id');
- $query->bindValues([':id' => $id, ':user_id' => $user_id]);
- $result = $query->queryAll();
- $filename = "../uploads/temp/tradelog-".$id.$user_id.date('Ymdhis').".doc";
- $file = fopen($filename,'w+');
- foreach ($result as $item => $value)
- {
- fputs($file,$value['date']." ".$value['comment']."\n");
- }
- fclose($file);
- Yii::$app->response->xSendFile($filename);
- }
- /**
- * Deletes an existing Eventlog model.
- * If deletion is successful, the browser will be redirected to the 'index' page.
- * @param integer $id
- * @return mixed
- */
- public function actionDelete($id)
- {
- $this->findModel($id)->delete();
- return $this->redirect(['index']);
- }
- /**
- * Finds the Eventlog model based on its primary key value.
- * If the model is not found, a 404 HTTP exception will be thrown.
- * @param integer $id
- * @return Eventlog the loaded model
- * @throws NotFoundHttpException if the model cannot be found
- */
- protected function findModel($id)
- {
- if (($model = Eventlog::findOne($id)) !== null) {
- return $model;
- } else {
- throw new NotFoundHttpException('The requested page does not exist.');
- }
- }
- }
|