Нет описания

StatisticsForms.php 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace MailPoet\Models;
  3. if (!defined('ABSPATH')) exit;
  4. /**
  5. * @deprecated This model is deprecated. Use MailPoet\Statistics\StatisticsFormsRepository and respective Doctrine entities instead.
  6. * This class can be removed after 2021-10-02
  7. */
  8. class StatisticsForms extends Model {
  9. public static $_table = MP_STATISTICS_FORMS_TABLE; // phpcs:ignore PSR2.Classes.PropertyDeclaration
  10. public static function getTotalSignups($formId = false) {
  11. self::deprecationError(__FUNCTION__);
  12. return self::where('form_id', $formId)->count();
  13. }
  14. public static function record($formId, $subscriberId) {
  15. self::deprecationError(__FUNCTION__);
  16. if ($formId > 0 && $subscriberId > 0) {
  17. // check if we already have a record for today
  18. $record = self::where('form_id', $formId)
  19. ->where('subscriber_id', $subscriberId)
  20. ->findOne();
  21. if ($record === false) {
  22. // create a new entry
  23. $record = self::create();
  24. $record->hydrate([
  25. 'form_id' => $formId,
  26. 'subscriber_id' => $subscriberId,
  27. ]);
  28. $record->save();
  29. }
  30. return $record;
  31. }
  32. return false;
  33. }
  34. /**
  35. * @deprecated This is here for displaying the deprecation warning for properties.
  36. */
  37. public function __get($key) {
  38. self::deprecationError('property "' . $key . '"');
  39. return parent::__get($key);
  40. }
  41. /**
  42. * @deprecated This is here for displaying the deprecation warning for static calls.
  43. */
  44. public static function __callStatic($name, $arguments) {
  45. self::deprecationError($name);
  46. return parent::__callStatic($name, $arguments);
  47. }
  48. private static function deprecationError($methodName) {
  49. trigger_error('Calling ' . $methodName . ' is deprecated and will be removed. Use MailPoet\Statistics\StatisticsFormsRepository and respective Doctrine entities instead.', E_USER_DEPRECATED);
  50. }
  51. }