Changeset 9686
- Timestamp:
- 04/03/2015 04:22:14 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-xprofile/bp-xprofile-template.php
r9685 r9686 12 12 13 13 class BP_XProfile_Data_Template { 14 14 15 /** 15 16 * The loop iterator. … … 102 103 public $user_id; 103 104 104 function __construct( $user_id, $profile_group_id, $hide_empty_groups = false, $fetch_fields = false, $fetch_field_data = false, $exclude_groups = false, $exclude_fields = false, $hide_empty_fields = false, $fetch_visibility_level = false, $update_meta_cache = true ) { 105 $this->groups = bp_xprofile_get_groups( array( 106 'profile_group_id' => $profile_group_id, 107 'user_id' => $user_id, 108 'hide_empty_groups' => $hide_empty_groups, 109 'hide_empty_fields' => $hide_empty_fields, 110 'fetch_fields' => $fetch_fields, 111 'fetch_field_data' => $fetch_field_data, 112 'fetch_visibility_level' => $fetch_visibility_level, 113 'exclude_groups' => $exclude_groups, 114 'exclude_fields' => $exclude_fields, 115 'update_meta_cache' => $update_meta_cache, 105 /** 106 * Get activity items, as specified by parameters 107 * 108 * @param array $args { 109 * An array of arguments. All items are optional. 110 * 111 * @type int $user_id Fetch field data for this user ID 112 * @type int $profile_group_id Field group to fetch fields & data for 113 * @type int|bool $hide_empty_groups Should empty field groups be skipped 114 * @type int|bool $fetch_fields Fetch fields for field group 115 * @type int|bool $fetch_field_data Fetch field data for fields in group 116 * @type array $exclude_groups Exclude these field groups 117 * @type array $exclude_fields Exclude these fields 118 * @type int|bool $hide_empty_fields Should empty fields be skipped 119 * @type int|bool $fetch_visibility_level Fetch visibility levels 120 * @type int|bool $update_meta_cache Should metadata cache be updated 121 * } 122 * @return array The array returned has two keys: 123 * - 'total' is the count of located activities 124 * - 'activities' is an array of the located activities 125 */ 126 public function __construct( $args = '' ) { 127 128 // Backward compatibility with old method of passing arguments 129 if ( ! is_array( $args ) || func_num_args() > 1 ) { 130 _deprecated_argument( __METHOD__, '2.3.0', sprintf( __( 'Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress' ), __METHOD__, __FILE__ ) ); 131 132 $old_args_keys = array( 133 0 => 'user_id', 134 1 => 'profile_group_id', 135 2 => 'hide_empty_groups', 136 3 => 'fetch_fields', 137 4 => 'fetch_field_data', 138 5 => 'exclude_groups', 139 6 => 'exclude_fields', 140 7 => 'hide_empty_fields', 141 8 => 'fetch_visibility_level', 142 9 => 'update_meta_cache' 143 ); 144 145 $func_args = func_get_args(); 146 $args = bp_core_parse_args_array( $old_args_keys, $func_args ); 147 } 148 149 $r = wp_parse_args( $args, array( 150 'profile_group_id' => false, 151 'user_id' => false, 152 'hide_empty_groups' => false, 153 'hide_empty_fields' => false, 154 'fetch_fields' => false, 155 'fetch_field_data' => false, 156 'fetch_visibility_level' => false, 157 'exclude_groups' => false, 158 'exclude_fields' => false, 159 'update_meta_cache' => true 116 160 ) ); 117 161 118 $this->group_count = count($this->groups); 119 $this->user_id = $user_id; 120 } 121 122 function has_groups() { 123 if ( $this->group_count ) 162 $this->groups = bp_xprofile_get_groups( $r ); 163 $this->group_count = count( $this->groups ); 164 $this->user_id = $r['user_id']; 165 } 166 167 public function has_groups() { 168 if ( ! empty( $this->group_count ) ) { 124 169 return true; 170 } 125 171 126 172 return false; 127 173 } 128 174 129 function next_group() {175 public function next_group() { 130 176 $this->current_group++; 131 177 132 $this->group = $this->groups[ $this->current_group];178 $this->group = $this->groups[ $this->current_group ]; 133 179 $this->field_count = 0; 134 180 135 if ( ! empty( $this->group->fields ) ) {181 if ( ! empty( $this->group->fields ) ) { 136 182 137 183 /** … … 150 196 } 151 197 152 function rewind_groups() {198 public function rewind_groups() { 153 199 $this->current_group = -1; 154 200 if ( $this->group_count > 0 ) { … … 157 203 } 158 204 159 function profile_groups() {205 public function profile_groups() { 160 206 if ( $this->current_group + 1 < $this->group_count ) { 161 207 return true; … … 167 213 * @since BuddyPress (1.1.0) 168 214 */ 169 do_action('xprofile_template_loop_end'); 215 do_action( 'xprofile_template_loop_end' ); 216 170 217 // Do some cleaning up after the loop 171 218 $this->rewind_groups(); … … 176 223 } 177 224 178 function the_profile_group() {225 public function the_profile_group() { 179 226 global $group; 180 227 … … 182 229 $group = $this->next_group(); 183 230 184 if ( 0 == $this->current_group ) // loop has just started 231 // loop has just started 232 if ( 0 === $this->current_group ) { 185 233 186 234 /** … … 189 237 * @since BuddyPress (1.1.0) 190 238 */ 191 do_action('xprofile_template_loop_start'); 192 } 193 194 /**** FIELDS ****/ 195 196 function next_field() { 239 do_action( 'xprofile_template_loop_start' ); 240 } 241 } 242 243 /** Fields ****************************************************************/ 244 245 public function next_field() { 197 246 $this->current_field++; 198 247 199 $this->field = $this->group->fields[$this->current_field]; 248 $this->field = $this->group->fields[ $this->current_field ]; 249 200 250 return $this->field; 201 251 } 202 252 203 function rewind_fields() {253 public function rewind_fields() { 204 254 $this->current_field = -1; 205 255 if ( $this->field_count > 0 ) { … … 208 258 } 209 259 210 function has_fields() {260 public function has_fields() { 211 261 $has_data = false; 212 262 213 263 for ( $i = 0, $count = count( $this->group->fields ); $i < $count; ++$i ) { 214 $field = &$this->group->fields[ $i];215 216 if ( ! empty( $field->data ) && $field->data->value != null) {264 $field = &$this->group->fields[ $i ]; 265 266 if ( ! empty( $field->data ) && ( $field->data->value != null ) ) { 217 267 $has_data = true; 218 268 } 219 269 } 220 270 221 if ( $has_data ) 222 return true; 223 224 return false; 225 } 226 227 function profile_fields() { 271 return $has_data; 272 } 273 274 public function profile_fields() { 228 275 if ( $this->current_field + 1 < $this->field_count ) { 229 276 return true; … … 236 283 } 237 284 238 function the_profile_field() {285 public function the_profile_field() { 239 286 global $field; 240 287 … … 242 289 243 290 // Valid field values of 0 or '0' get caught by empty(), so we have an extra check for these. See #BP5731 244 if ( ! empty( $field->data ) && ( ! empty( $field->data->value ) || '0' == $field->data->value) ) {291 if ( ! empty( $field->data ) && ( ! empty( $field->data->value ) || ( '0' === $field->data->value ) ) ) { 245 292 $value = maybe_unserialize( $field->data->value ); 246 293 } else { … … 248 295 } 249 296 250 if ( ! empty( $value ) || '0' == $value) {297 if ( ! empty( $value ) || ( '0' === $value ) ) { 251 298 $this->field_has_data = true; 252 299 } else { … … 295 342 296 343 // Populate the template loop global 297 $profile_template = new BP_XProfile_Data_Template( 298 $r['user_id'], 299 $r['profile_group_id'], 300 $r['hide_empty_groups'], 301 $r['fetch_fields'], 302 $r['fetch_field_data'], 303 $r['exclude_groups'], 304 $r['exclude_fields'], 305 $r['hide_empty_fields'], 306 $r['fetch_visibility_level'], 307 $r['update_meta_cache'] 308 ); 344 $profile_template = new BP_XProfile_Data_Template( $r ); 309 345 310 346 /**
Note: See TracChangeset
for help on using the changeset viewer.