Metrics.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace app\models\entity;
  3. use yii\db\ActiveRecord;
  4. /**
  5. * Class Metrics
  6. * @package app\models\entity
  7. *
  8. * @property int $id
  9. * @property int $type
  10. * @property string $stamp
  11. * @property int $num
  12. * @property string $desc
  13. * @property-read string $typeString
  14. */
  15. class Metrics extends ActiveRecord
  16. {
  17. public static function tableName()
  18. {
  19. return 'metrics';
  20. }
  21. public static function log(int $type = 1, int $num = null, string $desc = null)
  22. {
  23. $log = new self();
  24. $log->type = $type;
  25. $log->stamp = (new \DateTime())->format('Y-m-d H:i:s');
  26. $log->num = $num;
  27. $log->desc = $desc;
  28. $log->save();
  29. }
  30. public function getTypeString()
  31. {
  32. switch ($this->type) {
  33. case 1: return 'Запрос от МП в SMoPP';
  34. case 2: return 'Запрос в ЕИПП';
  35. case 3: return 'Ответ от ЕИПП';
  36. case 4: return 'Ответ СМоПП в МП';
  37. default: return '';
  38. }
  39. }
  40. }