class-wc-customer-download-log.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. /**
  3. * Class for customer download logs.
  4. *
  5. * @package WooCommerce/Classes
  6. * @version 3.3.0
  7. * @since 3.3.0
  8. */
  9. defined( 'ABSPATH' ) || exit;
  10. /**
  11. * Customer download log class.
  12. */
  13. class WC_Customer_Download_Log extends WC_Data {
  14. /**
  15. * This is the name of this object type.
  16. *
  17. * @var string
  18. */
  19. protected $object_type = 'customer_download_log';
  20. /**
  21. * Download Log Data array.
  22. *
  23. * @var array
  24. */
  25. protected $data = array(
  26. 'timestamp' => null,
  27. 'permission_id' => 0,
  28. 'user_id' => null,
  29. 'user_ip_address' => null,
  30. );
  31. /**
  32. * Constructor.
  33. *
  34. * @param int|object|array $download_log Download log ID.
  35. */
  36. public function __construct( $download_log = 0 ) {
  37. parent::__construct( $download_log );
  38. if ( is_numeric( $download_log ) && $download_log > 0 ) {
  39. $this->set_id( $download_log );
  40. } elseif ( $download_log instanceof self ) {
  41. $this->set_id( $download_log->get_id() );
  42. } elseif ( is_object( $download_log ) && ! empty( $download_log->download_log_id ) ) {
  43. $this->set_id( $download_log->download_log_id );
  44. $this->set_props( (array) $download_log );
  45. $this->set_object_read( true );
  46. } else {
  47. $this->set_object_read( true );
  48. }
  49. $this->data_store = WC_Data_Store::load( 'customer-download-log' );
  50. if ( $this->get_id() > 0 ) {
  51. $this->data_store->read( $this );
  52. }
  53. }
  54. /*
  55. |--------------------------------------------------------------------------
  56. | Getters
  57. |--------------------------------------------------------------------------
  58. */
  59. /**
  60. * Get timestamp.
  61. *
  62. * @param string $context Get context.
  63. * @return WC_DateTime|null Object if the date is set or null if there is no date.
  64. */
  65. public function get_timestamp( $context = 'view' ) {
  66. return $this->get_prop( 'timestamp', $context );
  67. }
  68. /**
  69. * Get permission id.
  70. *
  71. * @param string $context Get context.
  72. * @return integer
  73. */
  74. public function get_permission_id( $context = 'view' ) {
  75. return $this->get_prop( 'permission_id', $context );
  76. }
  77. /**
  78. * Get user id.
  79. *
  80. * @param string $context Get context.
  81. * @return integer
  82. */
  83. public function get_user_id( $context = 'view' ) {
  84. return $this->get_prop( 'user_id', $context );
  85. }
  86. /**
  87. * Get user ip address.
  88. *
  89. * @param string $context Get context.
  90. * @return string
  91. */
  92. public function get_user_ip_address( $context = 'view' ) {
  93. return $this->get_prop( 'user_ip_address', $context );
  94. }
  95. /*
  96. |--------------------------------------------------------------------------
  97. | Setters
  98. |--------------------------------------------------------------------------
  99. */
  100. /**
  101. * Set timestamp.
  102. *
  103. * @param string|integer|null $date UTC timestamp, or ISO 8601 DateTime. If the DateTime string has no timezone or offset, WordPress site timezone will be assumed. Null if their is no date.
  104. */
  105. public function set_timestamp( $date = null ) {
  106. $this->set_date_prop( 'timestamp', $date );
  107. }
  108. /**
  109. * Set permission id.
  110. *
  111. * @param int $value Value to set.
  112. */
  113. public function set_permission_id( $value ) {
  114. $this->set_prop( 'permission_id', absint( $value ) );
  115. }
  116. /**
  117. * Set user id.
  118. *
  119. * @param int $value Value to set.
  120. */
  121. public function set_user_id( $value ) {
  122. $this->set_prop( 'user_id', absint( $value ) );
  123. }
  124. /**
  125. * Set user ip address.
  126. *
  127. * @param string $value Value to set.
  128. */
  129. public function set_user_ip_address( $value ) {
  130. $this->set_prop( 'user_ip_address', $value );
  131. }
  132. }