PodsBuilderModuleList

The Pods - Custom Content Types and Fields PodsBuilderModuleList class.

Defined (1)

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

/components/Builder/modules/list/PodsBuilderModuleList.php  
  1. class PodsBuilderModuleList extends LayoutModule { 
  2.  
  3. var $_name = ''; 
  4. var $_var = 'pods-builder-list'; 
  5. var $_description = ''; 
  6. var $_editor_width = 500; 
  7. var $_can_remove_wrappers = true; 
  8.  
  9. /** 
  10. * Register the Module 
  11. */ 
  12. public function PodsBuilderModuleList () { 
  13. $this->_name = __( 'Pods - List Items', 'pods' ); 
  14. $this->_description = __( 'Display multiple Pod items', 'pods' ); 
  15. $this->module_path = dirname( __FILE__ ); 
  16.  
  17. $this->LayoutModule(); 
  18.  
  19. /** 
  20. * Set default variables 
  21. * @param $defaults 
  22. * @return mixed 
  23. */ 
  24. function _get_defaults ( $defaults ) { 
  25. $new_defaults = array( 
  26. 'pod_type' => '',  
  27. 'template' => '',  
  28. 'template_custom' => '',  
  29. 'limit' => 15,  
  30. 'orderby' => '',  
  31. 'where' => '',  
  32. 'expires' => ( 60 * 5 ),  
  33. 'cache_mode' => 'transient',  
  34. 'sidebar' => 'none' 
  35. ); 
  36.  
  37. return ITUtility::merge_defaults( $new_defaults, $defaults ); 
  38.  
  39. /** 
  40. * Output something before the table form 
  41. * @param object $form Form class 
  42. * @param bool $results 
  43. */ 
  44. function _before_table_edit ( $form, $results = true ) { 
  45. ?> 
  46. <p><?php echo $this->_description; ?></p> 
  47. <?php 
  48.  
  49. /** 
  50. * Output something at the start of the table form 
  51. * @param object $form Form class 
  52. * @param bool $results 
  53. */ 
  54. function _start_table_edit ( $form, $results = true ) { 
  55. $api = pods_api(); 
  56. $all_pods = $api->load_pods( array( 'names' => true ) ); 
  57.  
  58. $pod_types = array(); 
  59.  
  60. foreach ( $all_pods as $pod_name => $pod_label ) { 
  61. $pod_types[ $pod_name ] = $pod_label . ' (' . $pod_name . ')'; 
  62. ?> 
  63. <tr> 
  64. <td valign="top"> 
  65. <label for="pod_type"><?php _e( 'Pod', 'pods' ); ?></label> 
  66. </td> 
  67. <td> 
  68. <?php 
  69. if ( 0 < count( $all_pods ) ) 
  70. $form->add_drop_down( 'pod_type', $pod_types ); 
  71. else 
  72. echo '<strong class="red">' . __( 'None Found', 'pods' ) . '</strong>'; 
  73. ?> 
  74. </td> 
  75. </tr> 
  76.  
  77. <?php 
  78. if ( class_exists( 'Pods_Templates' ) ) { 
  79. $all_templates = (array) $api->load_templates( array() ); 
  80.  
  81. $templates = array( 
  82. '' => '- ' . __( 'Custom Template', 'pods' ) . ' -' 
  83. ); 
  84.  
  85. foreach ( $all_templates as $template ) { 
  86. $templates[ $template[ 'name' ] ] = $template[ 'name' ]; 
  87. ?> 
  88. <tr> 
  89. <td valign="top"> 
  90. <label for="template"><?php _e( 'Template', 'pods' ); ?></label> 
  91. </td> 
  92. <td> 
  93. <?php 
  94. if ( 0 < count( $all_templates ) ) 
  95. $form->add_drop_down( 'template', $templates ); 
  96. else 
  97. echo '<strong class="red">' . __( 'None Found', 'pods' ) . '</strong>'; 
  98. ?> 
  99. </td> 
  100. </tr> 
  101. <?php 
  102. else { 
  103. ?> 
  104. <tr> 
  105. <td valign="top"> 
  106. <label for="template"><?php _e( 'Template', 'pods' ); ?></label> 
  107. </td> 
  108. <td> 
  109. <?php $form->add_text_box( 'template' ); ?> 
  110. </td> 
  111. </tr> 
  112. <?php 
  113. ?> 
  114.  
  115. <tr> 
  116. <td valign="top"> 
  117. <label for="template_custom"><?php _e( 'Custom Template', 'pods' ); ?></label> 
  118. </td> 
  119. <td> 
  120. <?php $form->add_text_area( 'template_custom', array( 'style' => 'width:90%; max-width:100%; min-height:100px;', 'rows' => '8' ) ); ?> 
  121. </td> 
  122. </tr> 
  123. <tr> 
  124. <td valign="top"> 
  125. <label for="limit"><?php _e( 'Limit', 'pods' ); ?></label> 
  126. </td> 
  127. <td> 
  128. <?php $form->add_text_box( 'limit' ); ?> 
  129. </td> 
  130. </tr> 
  131. <tr> 
  132. <td valign="top"> 
  133. <label for="orderby"><?php _e( 'Order By', 'pods' ); ?></label> 
  134. </td> 
  135. <td> 
  136. <?php $form->add_text_box( 'orderby' ); ?> 
  137. </td> 
  138. </tr> 
  139. <tr> 
  140. <td valign="top"> 
  141. <label for="where"><?php _e( 'Where', 'pods' ); ?></label> 
  142. </td> 
  143. <td> 
  144. <?php $form->add_text_box( 'where' ); ?> 
  145. </td> 
  146. </tr> 
  147. <tr> 
  148. <td valign="top"> 
  149. <label for="cache_mode"><?php _e( 'Cache Type', 'pods' ); ?></label> 
  150. </td> 
  151. <td> 
  152. <?php 
  153. $cache_modes = array( 
  154. 'none' => __( 'Disable Caching', 'pods' ),  
  155. 'cache' => __( 'Object Cache', 'pods' ),  
  156. 'transient' => __( 'Transient', 'pods' ),  
  157. 'site-transient' => __( 'Site Transient', 'pods' ) 
  158. ); 
  159.  
  160. $form->add_drop_down( 'cache_mode', $cache_modes ); 
  161. ?> 
  162. </td> 
  163. </tr> 
  164. <tr> 
  165. <td valign="top"> 
  166. <label for="expires"><?php _e( 'Cache Expiration (in seconds)', 'pods' ); ?></label> 
  167. </td> 
  168. <td> 
  169. <?php $form->add_text_box( 'expires' ); ?> 
  170. </td> 
  171. </tr> 
  172. <?php 
  173.  
  174. /** 
  175. * Module Output 
  176. */ 
  177. function _render ( $fields ) { 
  178. $args = array( 
  179. 'name' => trim( pods_var_raw( 'pod_type', $fields[ 'data' ], '' ) ),  
  180. 'template' => trim( pods_var_raw( 'template', $fields[ 'data' ], '' ) ),  
  181. 'limit' => (int) pods_var_raw( 'limit', $fields[ 'data' ], 15, null, true ),  
  182. 'orderby' => trim( pods_var_raw( 'orderby', $fields[ 'data' ], '' ) ),  
  183. 'where' => trim( pods_var_raw( 'where', $fields[ 'data' ], '' ) ),  
  184. 'expires' => (int) trim( pods_var_raw( 'expires', $fields[ 'data' ], ( 60 * 5 ) ) ),  
  185. 'cache_mode' => trim( pods_var_raw( 'cache_mode', $fields[ 'data' ], 'transient', null, true ) ) 
  186. ); 
  187.  
  188. $content = trim( pods_var_raw( 'template_custom', $fields[ 'data' ], '' ) ); 
  189.  
  190. if ( 0 < strlen( $args[ 'name' ] ) && ( 0 < strlen( $args[ 'template' ] ) || 0 < strlen( $content ) ) ) 
  191. echo pods_shortcode( $args, ( isset( $content ) ? $content : null ) ); 
  192.