Advertisement
Guest User

Untitled

a guest
Aug 12th, 2017
458
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.54 KB | None | 0 0
  1. <?php
  2.  
  3. namespace app\controllers;
  4.  
  5. use Yii;
  6. use app\models\StudentBooking;
  7. use app\models\StudentBookingSearch;
  8. use yii\web\Controller;
  9. use yii\web\NotFoundHttpException;
  10. use yii\filters\VerbFilter;
  11. use app\models\PersonBooking;
  12. use yii\web\UploadedFile;
  13. use yii\helpers\Url;
  14. use yii\helpers\Html;
  15. /**
  16. * StudentBookingController implements the CRUD actions for StudentBooking model.
  17. */
  18. class StudentBookingController extends Controller
  19. {
  20. /**
  21. * @inheritdoc
  22. */
  23. public function behaviors()
  24. {
  25. return [
  26. 'verbs' => [
  27. 'class' => VerbFilter::className(),
  28. 'actions' => [
  29. 'delete' => ['POST'],
  30. ],
  31. ],
  32. ];
  33. }
  34.  
  35.  
  36. /**
  37. * Creates a new StudentBooking model.
  38. * If creation is successful, the browser will be redirected to the 'view' page.
  39. * @return mixed
  40. */
  41. public function actionCreate()
  42. {
  43.  
  44.  
  45. $this->layout = 'register';
  46. $model = new StudentBooking();
  47. $model_person = new PersonBooking();
  48.  
  49.  
  50.  
  51. if ($model->load(Yii::$app->request->post())){
  52. $model_person->load(Yii::$app->request->post());
  53.  
  54.  
  55.  
  56. // $value = Yii::$app->mailer->compose(
  57. // [
  58. // 'html' => 'form_body'
  59. // ],
  60. // [
  61. // 'model' => $model_person,
  62. // 'logo' => 'reservation2/web/uploads/web_img/logo.jpg',
  63. // ])
  64. // ->setFrom(['system.riskivector@gmail.com' => 'Incoming student form'])
  65. // ->setTo('system.riskivector@gmail.com')
  66. // ->setSubject('SYSTEM Student form')
  67. // ->send();
  68. //
  69.  
  70. $PhotoName = $model_person->name;
  71. $model_person->file = UploadedFile::getInstance($model_person,'file');
  72. $model_person->file->saveAs('uploads/persons_id/'.$PhotoName.'.'.$model_person->file->extension);
  73. $model_person->photo = $PhotoName.'.'.$model_person->file->extension;
  74.  
  75.  
  76. $flag = $model_person->save();
  77.  
  78. if($flag){
  79. $model->person_booking_id = $model_person->id;
  80. $model->arrival_date = date('Y-m-d',strtotime($model->arrival_date));
  81. $model->date = date('Y-m-d');
  82. //$model->arrival_date = 0;
  83. //$model->date = 0;
  84. $model->validated = 0;
  85.  
  86. $flag = $model->save();
  87. if($model->validate() || $model_person->validate()){
  88. // echo '<pre>';
  89. // print_r($model);
  90. // print_r("++++++ ".$flag);
  91. // echo '</pre>';
  92. // die();
  93.  
  94. if($flag){
  95. // $body = 'test';
  96. // $value = Yii::$app->mailer->compose()
  97. // ->setFrom(['marcin.wlodarczyk@riskivector.com' => 'Incoming student form'])
  98. // ->setTo('marcin.wlodarczyk@gmail.com')
  99. // ->setSubject('SYSTEM Student form')
  100. // ->setHtmlBody($body)
  101. // ->send();
  102. }
  103. }
  104. Yii::$app->session->setFlash('Form Submitted!');
  105. }
  106. return $this->render('create', [
  107. 'model' => $model,
  108. 'model_person' => $model_person
  109. ]);
  110. } else {
  111. return $this->render('create', [
  112. 'model' => $model,
  113. 'model_person' => $model_person
  114. ]);
  115. }
  116. }
  117.  
  118. /**
  119. * Finds the StudentBooking model based on its primary key value.
  120. * If the model is not found, a 404 HTTP exception will be thrown.
  121. * @param integer $id
  122. * @return StudentBooking the loaded model
  123. * @throws NotFoundHttpException if the model cannot be found
  124. */
  125. protected function findModel($id)
  126. {
  127. if (($model = StudentBooking::findOne($id)) !== null) {
  128. return $model;
  129. } else {
  130. throw new NotFoundHttpException('The requested page does not exist.');
  131. }
  132. }
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement