Making WordPress.org


Ignore:
Timestamp:
07/26/2015 04:42:45 PM (11 years ago)
Author:
ocean90
Message:

Rosetta: Update roles plugin to support sub projects.

props folletto for the design idea.
see #1101.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/global.wordpress.org/public_html/wp-content/mu-plugins/roles/class-translation-editors-list-table.php

    r1437 r1786  
    3434         */
    3535        public $projects;
     36
     37        /**
     38         * Holds the list of a project tree.
     39         *
     40         * @var array
     41         */
     42        public $project_tree;
    3643
    3744        /**
    … …  
    5259                $this->project_access_meta_key = $args['project_access_meta_key'];
    5360                $this->projects = $args['projects'];
     61                $this->project_tree = $args['project_tree'];
    5462                $this->user_can_promote = current_user_can( 'promote_users' );
    5563        }
    … …  
    226234                foreach ( $project_access_list as $project_id ) {
    227235                        if ( $this->projects[ $project_id ] ) {
    228                                 $projects[] = esc_html( $this->projects[ $project_id ]->name );
     236                                $parent = $this->get_parent_project( $this->project_tree, $project_id );
     237                                if ( $parent->id != $project_id ) {
     238                                        $name = sprintf(
     239                                                '%s → %s',
     240                                                esc_html( $parent->name ),
     241                                                esc_html( $this->projects[ $project_id ]->name )
     242                                        );
     243                                } else {
     244                                        $name = esc_html( $this->projects[ $project_id ]->name );
     245                                }
     246                                $projects[] = $name;
    229247                        }
    230248                }
    … …  
    232250                echo implode( '<br>', $projects );
    233251        }
     252
     253        /**
     254         * Returns the parent project for a sub project.
     255         *
     256         * @param array $tree The project tree.
     257         * @param int $child_id The project tree.
     258         * @return object The parent project.
     259         */
     260        private function get_parent_project( $tree, $child_id ) {
     261                $parent = null;
     262                foreach ( $tree as $project ) {
     263                        if ( $project->id == $child_id ) {
     264                                $parent = $project;
     265                                break;
     266                        }
     267
     268                        if ( isset( $project->sub_projects ) ) {
     269                                $parent = $this->get_parent_project( $project->sub_projects, $child_id );
     270                                if ( $parent ) {
     271                                        $parent = $project;
     272                                        break;
     273                                }
     274                        }
     275                }
     276
     277                return $parent;
     278        }
    234279}
Note: See TracChangeset for help on using the changeset viewer.