/modules/Comment/Form.php

https://gitlab.com/dram1008/galaxysss · PHP · 83 lines · 69 code · 11 blank · 3 comment · 6 complexity · 394a01376fb187bfb61adcb7d41bb9b5 MD5 · raw file

  1. <?php
  2. namespace app\modules\Comment;
  3. use app\models\NewsItem;
  4. use app\models\User;
  5. use cs\services\Str;
  6. use cs\services\VarDumper;
  7. use Yii;
  8. use cs\Widget\FileUpload2\FileUpload;
  9. use yii\db\Query;
  10. use yii\helpers\ArrayHelper;
  11. use yii\helpers\Html;
  12. /**
  13. * ContactForm is the model behind the contact form.
  14. */
  15. class Form extends \cs\base\BaseForm
  16. {
  17. const TABLE = 'gs_comments';
  18. public $id;
  19. public $type_id;
  20. public $row_id;
  21. public $content;
  22. public $date_insert;
  23. public $user_id;
  24. public $verifyCode;
  25. function __construct($fields = [])
  26. {
  27. static::$fields = [
  28. [
  29. 'content',
  30. 'Название',
  31. 1,
  32. 'string'
  33. ],
  34. ];
  35. parent::__construct($fields);
  36. }
  37. public function insert($fieldsCols = null)
  38. {
  39. return parent::insert([
  40. 'beforeInsert' => function ($fields) {
  41. if (Str::pos('<', $fields['content']) === false) {
  42. $rows = explode("\r", $fields['content']);
  43. $rows2 = [];
  44. foreach ($rows as $row) {
  45. if (trim($row) != '') $rows2[] = Html::tag('p', trim($row));
  46. }
  47. $fields['content'] = join("\r\r", $rows2);
  48. }
  49. $fields['date_insert'] = gmdate('YmdHis');
  50. $fields['id_string'] = Str::rus2translit($fields['header']);
  51. $fields['date'] = gmdate('Y-m-d');
  52. return $fields;
  53. }
  54. ]);
  55. }
  56. public function update($fieldsCols = null)
  57. {
  58. return parent::update([
  59. 'beforeUpdate' => function ($fields) {
  60. if (Str::pos('<', $fields['content']) === false) {
  61. $rows = explode("\r", $fields['content']);
  62. $rows2 = [];
  63. foreach ($rows as $row) {
  64. if (trim($row) != '') $rows2[] = Html::tag('p', trim($row));
  65. }
  66. $fields['content'] = join("\r\r", $rows2);
  67. }
  68. return $fields;
  69. }
  70. ]);
  71. }
  72. }