Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

97 lines
3.1KB

  1. <?php
  2. namespace backend\controllers;
  3. use Yii;
  4. use common\models\User;
  5. use yii\data\ActiveDataProvider;
  6. use yii\web\Controller;
  7. use yii\web\NotFoundHttpException;
  8. use yii\filters\VerbFilter;
  9. use yii\filters\AccessControl;
  10. use kartik\mpdf\Pdf;
  11. use common\models\Etablissement;
  12. /**
  13. * UserController implements the CRUD actions for User model.
  14. */
  15. class CommuniquerController extends BackendController {
  16. public function behaviors() {
  17. return [
  18. 'verbs' => [
  19. 'class' => VerbFilter::className(),
  20. 'actions' => [
  21. 'delete' => ['post'],
  22. ],
  23. ],
  24. 'access' => [
  25. 'class' => AccessControl::className(),
  26. 'rules' => [
  27. [
  28. 'allow' => true,
  29. 'roles' => ['@'],
  30. 'matchCallback' => function ($rule, $action) {
  31. return Yii::$app->user->identity->status == USER::STATUS_ADMIN || Yii::$app->user->identity->status == USER::STATUS_BOULANGER;
  32. }
  33. ]
  34. ],
  35. ],
  36. ];
  37. }
  38. public function actionIndex() {
  39. $etablissement = Etablissement::findOne(['id' => Yii::$app->user->identity->id_etablissement]);
  40. return $this->render('index', [
  41. 'etablissement' => $etablissement,
  42. ]);
  43. }
  44. public function actionModeemploi() {
  45. $etablissement = Etablissement::findOne(['id' => Yii::$app->user->identity->id_etablissement]);
  46. // get your HTML raw content without any layouts or scripts
  47. $content = $this->renderPartial('mode_emploi_multi', [
  48. 'pdf' => true,
  49. 'etablissement' => $etablissement
  50. ]);
  51. $pdf = new Pdf([
  52. // set to use core fonts only
  53. 'mode' => Pdf::MODE_UTF8,
  54. // A4 paper format
  55. 'format' => Pdf::FORMAT_A4,
  56. // portrait orientation
  57. 'orientation' => Pdf::ORIENT_PORTRAIT,
  58. // stream to browser inline
  59. 'destination' => Pdf::DEST_BROWSER,
  60. // your html content input
  61. 'content' => $content,
  62. 'marginRight' => 0,
  63. 'marginLeft' => 0,
  64. 'marginTop' => 0,
  65. 'marginBottom' => 0,
  66. // format content from your own css file if needed or use the
  67. // enhanced bootstrap css built by Krajee for mPDF formatting
  68. //'cssFile' => '@vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.min.css',
  69. 'cssFile' => '@app/web/css/screen.css',
  70. // any css to be embedded if required
  71. //'cssInline' => '.kv-heading-1{font-size:18px}',
  72. // set mPDF properties on the fly
  73. //'options' => ['title' => 'Krajee Report Title'],
  74. // call mPDF methods on the fly
  75. /* 'methods' => [
  76. 'SetHeader'=>['Commandes du '.$date_str],
  77. 'SetFooter'=>['{PAGENO}'],
  78. ] */
  79. ]);
  80. // return the pdf output as per the destination setting
  81. return $pdf->render();
  82. }
  83. }