NF_Abstracts_Action

Class NF_Abstracts_Action.

Defined (1)

The class is defined in the following location(s).

/includes/Abstracts/Action.php  
  1. abstract class NF_Abstracts_Action 
  2. /** 
  3. * @var string 
  4. */ 
  5. protected $_name = ''; 
  6.  
  7. /** 
  8. * @var string 
  9. */ 
  10. protected $_nicename = ''; 
  11.  
  12. /** 
  13. * @var string 
  14. */ 
  15. protected $_section = 'installed'; 
  16.  
  17. /** 
  18. * @var string 
  19. */ 
  20. protected $_image = ''; 
  21.  
  22. /** 
  23. * @var array 
  24. */ 
  25. protected $_tags = array(); 
  26.  
  27. /** 
  28. * @var string 
  29. */ 
  30. protected $_timing = 'normal'; 
  31.  
  32. /** 
  33. * @var int 
  34. */ 
  35. protected $_priority = '10'; 
  36.  
  37. /** 
  38. * @var array 
  39. */ 
  40. protected $_settings = array(); 
  41.  
  42. /** 
  43. * @var array 
  44. */ 
  45. protected $_settings_all = array( 'label', 'active' ); 
  46.  
  47. /** 
  48. * @var array 
  49. */ 
  50. protected $_settings_exclude = array(); 
  51.  
  52. /** 
  53. * @var array 
  54. */ 
  55. protected $_settings_only = array(); 
  56.  
  57. /** 
  58. * Constructor 
  59. */ 
  60. public function __construct() 
  61. $this->_settings_all = apply_filters( 'ninja_forms_actions_settings_all', $this->_settings_all ); 
  62.  
  63. if( ! empty( $this->_settings_only ) ) { 
  64.  
  65. $this->_settings = array_merge( $this->_settings, $this->_settings_only ); 
  66. } else { 
  67.  
  68. $this->_settings = array_merge( $this->_settings_all, $this->_settings ); 
  69. $this->_settings = array_diff( $this->_settings, $this->_settings_exclude ); 
  70.  
  71. $this->_settings = $this->load_settings( $this->_settings ); 
  72.  
  73. //----------------------------------------------------- 
  74. // Public Methods 
  75. //----------------------------------------------------- 
  76.  
  77. /** 
  78. * Save 
  79. */ 
  80. public function save( $action_settings ) 
  81. // This section intentionally left blank. 
  82.  
  83. /** 
  84. * Process 
  85. */ 
  86. public abstract function process( $action_id, $form_id, $data ); 
  87.  
  88. /** 
  89. * Get Timing 
  90. * Returns the timing for an action. 
  91. * @return mixed 
  92. */ 
  93. public function get_timing() 
  94. $timing = array( 'early' => -1, 'normal' => 0, 'late' => 1 ); 
  95.  
  96. return intval( $timing[ $this->_timing ] ); 
  97.  
  98. /** 
  99. * Get Priority 
  100. * Returns the priority for an action. 
  101. * @return int 
  102. */ 
  103. public function get_priority() 
  104. return intval( $this->_priority ); 
  105.  
  106. /** 
  107. * Get Name 
  108. * Returns the name of an action. 
  109. * @return string 
  110. */ 
  111. public function get_name() 
  112. return $this->_name; 
  113.  
  114. /** 
  115. * Get Nicename 
  116. * Returns the nicename of an action. 
  117. * @return string 
  118. */ 
  119. public function get_nicename() 
  120. return $this->_nicename; 
  121.  
  122. /** 
  123. * Get Section 
  124. * Returns the drawer section for an action. 
  125. * @return string 
  126. */ 
  127. public function get_section() 
  128. return $this->_section; 
  129.  
  130. /** 
  131. * Get Image 
  132. * Returns the url of a branded action's image. 
  133. * @return string 
  134. */ 
  135. public function get_image() 
  136. return $this->_image; 
  137.  
  138. /** 
  139. * Get Settings 
  140. * Returns the settings for an action. 
  141. * @return array|mixed 
  142. */ 
  143. public function get_settings() 
  144. return $this->_settings; 
  145.  
  146. /** 
  147. * Sort Actions 
  148. * A static method for sorting two actions by timing, then priority. 
  149. * @param $a 
  150. * @param $b 
  151. * @return int 
  152. */ 
  153. public static function sort_actions( $a, $b ) 
  154. if( ! isset( Ninja_Forms()->actions[ $a->get_setting( 'type' ) ] ) ) return 1; 
  155. if( ! isset( Ninja_Forms()->actions[ $b->get_setting( 'type' ) ] ) ) return 1; 
  156.  
  157. $a->timing = Ninja_Forms()->actions[ $a->get_setting( 'type' ) ]->get_timing(); 
  158. $a->priority = Ninja_Forms()->actions[ $a->get_setting( 'type' ) ]->get_priority(); 
  159.  
  160. $b->timing = Ninja_Forms()->actions[ $b->get_setting( 'type' ) ]->get_timing(); 
  161. $b->priority = Ninja_Forms()->actions[ $b->get_setting( 'type' ) ]->get_priority(); 
  162.  
  163. // Compare Priority if Timing is the same 
  164. if( $a->timing == $b->timing) 
  165. return $a->priority > $b->priority ? 1 : -1; 
  166.  
  167. // Compare Timing 
  168. return $a->timing < $b->timing ? 1 : -1; 
  169.  
  170. protected function load_settings( $only_settings = array() ) 
  171. $settings = array(); 
  172.  
  173. // Loads a settings array from the FieldSettings configuration file. 
  174. $all_settings = Ninja_Forms::config( 'ActionSettings' ); 
  175.  
  176. foreach( $only_settings as $setting ) { 
  177.  
  178. if( isset( $all_settings[ $setting ]) ) { 
  179.  
  180. $settings[ $setting ] = $all_settings[ $setting ]; 
  181.  
  182. return $settings; 
  183.  
  184. } // END CLASS NF_Abstracts_Action