/includes/skip/elements/forms/values.php

  1. <?php 
  2.  
  3. /** 
  4. * <pre>skip_values( $form )</pre> 
  5. *  
  6. * Get all Values of a form. 
  7. *  
  8. * <b>Default Usage</b> 
  9. * <code> 
  10. * $value = skip_value( 'myformname', 'fieldname' ); 
  11. * </code> 
  12. *  
  13. * <b>Parameters</b> 
  14. *  
  15. * <code> 
  16. * $form // (string) (required) The name of the form. 
  17. * </code> 
  18. *  
  19. * <b>Example</b> 
  20. *  
  21. * Getting back all data from 'myformname' form. 
  22. * <code> 
  23. * $values = skip_values( 'myformname' ); 
  24. * skip_print( $values ); // Printing out all values of the form. 
  25. * </code> 
  26. *  
  27. * @param string $form The name of the form 
  28. * @package Skip\Forms 
  29. * @since 1.0 
  30. */ 
  31.  
  32. namespace skip\v1_0_0; 
  33.  
  34. function values( $form_name ) { 
  35. global $wpdb; 
  36.  
  37. $rows = $wpdb->get_results( $wpdb->prepare( "SELECT option_name, option_value FROM $wpdb->options WHERE option_name LIKE %s ", 'skip_framework_value_' . $form_name . '%' ) ); 
  38.  
  39. $start_field = strlen( 'skip_framework_value_' . $form_name . '_' ); 
  40.  
  41. $values = array(); 
  42.  
  43. foreach( $rows AS $row ): 
  44. $values_new = array(); 
  45. $length_field = strlen( $row->option_name ); 
  46. $field_name = substr( $row->option_name, $start_field, $length_field ); 
  47. $fieldname_array = split( SKIP_DELIMITER, $field_name ); 
  48.  
  49. $values_new[ $fieldname_array[ 0 ] ] = _reconstruct_value( $fieldname_array, $row->option_value ); 
  50. $values = array_merge_recursive_distinct( $values, $values_new ); 
  51. endforeach; 
  52.  
  53. return $values; 
  54. /** 
  55. * _skip_reconstruct_value() 
  56. * 
  57. * Reconstructs Array read from Options table. 
  58. * 
  59. * @package Skip\Tools 
  60. * @param mixed $fieldname_array The array structure got from the option name 
  61. * @param string $value The value to add to the array structure 
  62. * @param int $i Internal integer for running array 
  63. * @since 1.0 
  64. * @ignore 
  65. */ 
  66. function _skip_reconstruct_value( $fieldname_array, $value, $i = 1 ) { 
  67.  
  68. if( array_key_exists( $i, $fieldname_array ) ): 
  69. $array[ $fieldname_array[ $i ] ] = _reconstruct_value( $fieldname_array, $value, $i+1 ); 
  70. $value = $array; 
  71. endif; 
  72.  
  73. return $value; 
  74. /** 
  75. * <pre>skip_value( $form_name, $field_name )</pre> 
  76. *  
  77. * Geting a specific value of a form. 
  78. * 
  79. * <b>Default Usage</b> 
  80. * <code> 
  81. * $value = skip_value( 'myformname', 'fieldname' ); 
  82. * </code> 
  83. *  
  84. * <b>Parameters</b> 
  85. *  
  86. * <code> 
  87. * $form_name // (string) (required) The name of the form. 
  88. * $field_name // (string) (required) The name of the field. 
  89. * </code> 
  90. *  
  91. * @param string $form_name The name of the form. 
  92. * @param string $field_name The name of the value to get. 
  93. * @package Skip\Forms 
  94. * @since 1.0 
  95. */ 
  96. function value( $form_name, $field_name ) { 
  97. return get_option( 'skip_framework_value_' . $form_name . '_' . $field_name ); 
  98. /** 
  99. * <pre>skip_delete_value( $form, $name )</pre> 
  100. *  
  101. * Deleting a Value from DB. 
  102. *  
  103. * <b>Default Usage</b> 
  104. * <code> 
  105. * skip_delete_value( 'myformname', 'fieldname' ); 
  106. * </code> 
  107. * Deletes the field 'fieldname' from 'myformname' form. 
  108. *  
  109. * <b>Parameters</b> 
  110. *  
  111. * <code> 
  112. * $form // (string) (required) The name of the form. 
  113. * $name // (string) (required) The name of the field. 
  114. * </code> 
  115. *  
  116. * @param string $form_name The name of the form 
  117. * @param string $field_name The name of the value 
  118. * @package Skip\Forms 
  119. * @since 1.0 
  120. */ 
  121. function delete_value( $form_name, $field_name ) { 
  122. return delete_option( 'skip_framework_value_' . $form_name . '_' . $field_name ); 
  123. /** 
  124. * <pre>skip_delete_form_values( $form_name )</pre> 
  125. *  
  126. * Deleting a Values of a Form from DB. 
  127. *  
  128. * <b>Default Usage</b> 
  129. * <code> 
  130. * skip_delete_form_values( 'myformname' ); 
  131. * </code> 
  132. * Deletes all fields of form 'myformname' form. 
  133. *  
  134. * <b>Parameters</b> 
  135. *  
  136. * <code> 
  137. * $form_name // (string) (required) The name of the form. 
  138. * </code> 
  139. *  
  140. * @param string $form_name The name of the form 
  141. * @package Skip\Forms 
  142. * @since 1.0 
  143. */ 
  144. function delete_form_values( $form_name ) { 
  145. global $wpdb; 
  146. $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->options WHERE option_name LIKE %s ", 'skip_framework_value_' . $form_name . '%' ) ); 
.