Changeset 2090 for sites/trunk/translate.wordpress.org/includes/gp-plugins/wporg-rosetta-roles/wporg-rosetta-roles.php
- Timestamp:
- 11/18/2015 05:52:19 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/translate.wordpress.org/includes/gp-plugins/wporg-rosetta-roles/wporg-rosetta-roles.php
r1866 r2090 258 258 $projects = array(); 259 259 foreach ( $_projects as $project ) { 260 $project->sub_projects = array(); 260 261 $projects[ $project->id ] = $project; 261 262 } … … 277 278 278 279 $projects = $this->get_all_projects(); 279 $project_tree = $this->_get_project_tree( $projects ); 280 281 $project_tree = array(); 282 foreach ( $projects as $project_id => $project ) { 283 $projects[ $project->parent_project_id ]->sub_projects[ $project_id ] = &$projects[ $project_id ]; 284 if ( ! $project->parent_project_id ) { 285 $project_tree[ $project_id ] = &$projects[ $project_id ]; 286 } 287 } 280 288 281 289 return $project_tree; 282 }283 284 /**285 * Transforms a flat array to a hierarchy tree.286 *287 * @param array $projects The projects288 * @param int $parent_id Optional. Parent ID. Default 0.289 * @param int $max_depth Optional. Max depth to avoid endless recursion. Default 5.290 * @return array The project tree.291 */292 private function _get_project_tree( $projects, $parent_id = 0, $max_depth = 5 ) {293 if ( $max_depth < 0 ) { // Avoid an endless recursion.294 return;295 }296 297 $tree = array();298 foreach ( $projects as $project ) {299 if ( $project->parent_project_id == $parent_id ) {300 $sub_projects = $this->_get_project_tree( $projects, $project->id, $max_depth - 1 );301 if ( $sub_projects ) {302 $project->sub_projects = $sub_projects;303 }304 305 $tree[ $project->id ] = $project;306 }307 }308 return $tree;309 290 } 310 291
Note: See TracChangeset
for help on using the changeset viewer.