notification.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <?php if ( ! defined( 'ABSPATH' ) ) exit;
  2. /**
  3. * Notification
  4. *
  5. * Single notification object.
  6. * This object lets us call it like: Ninja_Forms()->notification( 33 )->methods()
  7. *
  8. * @package Ninja Forms
  9. * @subpackage Classes/Notifications
  10. * @copyright Copyright (c) 2014, WPNINJAS
  11. * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
  12. * @since 2.8
  13. */
  14. class NF_Notification
  15. {
  16. /**
  17. * @var notification id
  18. */
  19. var $id = '';
  20. /**
  21. * @var type
  22. */
  23. var $type = '';
  24. /**
  25. * @var active
  26. * Holds a boolean value.
  27. */
  28. var $active = '';
  29. /**
  30. * @var form_id
  31. * Holds the id of our form.
  32. */
  33. var $form_id = '';
  34. /**
  35. * Get things rolling
  36. *
  37. * @since 2.8
  38. * @return void
  39. */
  40. function __construct( $id ) {
  41. $this->id = $id;
  42. $this->type = nf_get_object_meta_value( $id, 'type' );
  43. $this->active = ( nf_get_object_meta_value( $id, 'active' ) == 1 ) ? true : false;
  44. $this->form_id = nf_get_object_parent( $id );
  45. }
  46. /**
  47. * Ouptut our admin screen
  48. *
  49. * @access public
  50. * @since 2.8
  51. * @return void
  52. */
  53. public function edit_screen() {
  54. $type = $this->type;
  55. // Call our type edit screen.
  56. Ninja_Forms()->notification_types[ $type ]->edit_screen( $this->id );
  57. }
  58. /**
  59. * Delete our notification
  60. *
  61. * @access public
  62. * @since 2.8
  63. * @return void
  64. */
  65. public function delete() {
  66. nf_delete_notification( $this->id );
  67. }
  68. /**
  69. * Activate our notification
  70. *
  71. * @access public
  72. * @since 2.8
  73. * @return void
  74. */
  75. public function activate() {
  76. nf_update_object_meta( $this->id, 'active', 1 );
  77. $this->active = true;
  78. }
  79. /**
  80. * Deactivate our notification
  81. *
  82. * @access public
  83. * @since 2.8
  84. * @return void
  85. */
  86. public function deactivate() {
  87. nf_update_object_meta( $this->id, 'active', 0 );
  88. $this->active = false;
  89. }
  90. /**
  91. * Duplicate our notification
  92. *
  93. * @access public
  94. * @since 2.8
  95. * @return int $n_id
  96. */
  97. public function duplicate() {
  98. $n_id = Ninja_Forms()->notifications->create( $this->form_id );
  99. $meta = nf_get_notification_by_id( $this->id );
  100. foreach ( $meta as $meta_key => $meta_value ) {
  101. nf_update_object_meta( $n_id, $meta_key, $meta_value );
  102. }
  103. $name = nf_get_object_meta_value( $n_id, 'name' ) . ' - ' . __( 'duplicate', 'ninja-forms' );
  104. nf_update_object_meta( $n_id, 'name', $name );
  105. }
  106. /**
  107. * Run our notification processing function
  108. *
  109. * @access public
  110. * @since 2.8
  111. * @return void
  112. */
  113. public function process() {
  114. $type = $this->type;
  115. if ( isset ( Ninja_Forms()->notification_types[ $type ] ) && is_object( Ninja_Forms()->notification_types[ $type ] ) ) {
  116. Ninja_Forms()->notification_types[ $type ]->process( $this->id );
  117. }
  118. }
  119. /**
  120. * Get a notification setting
  121. *
  122. * @access public
  123. * @since 2.8
  124. * @return string $meta_value
  125. */
  126. public function get_setting( $meta_key ) {
  127. return nf_get_object_meta_value( $this->id, $meta_key );
  128. }
  129. /**
  130. * Update a notification setting
  131. *
  132. * @access public
  133. * @since 2.8
  134. * @return bool
  135. */
  136. public function update_setting( $meta_key, $meta_value ) {
  137. nf_update_object_meta( $this->id, $meta_key, $meta_value );
  138. return true;
  139. }
  140. /**
  141. * Get our notification type name
  142. *
  143. * @access public
  144. * @since 2.9
  145. * @return string $name
  146. */
  147. public function type_name() {
  148. $type = $this->type;
  149. // Call our type edit screen.
  150. return Ninja_Forms()->notification_types[ $type ]->name;
  151. }
  152. }