WordPress.org

Making WordPress.org

Changeset 6684


Ignore:
Timestamp:
02/18/2018 02:52:17 PM (3 years ago)
Author:
ocean90
Message:

Rosetta Roles: Move get_parent_project() to the main class.

See #1613.

Location:
sites/trunk/global.wordpress.org/public_html/wp-content/mu-plugins/roles
Files:
2 edited

Legend:

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

    r6683 r6684  
    339339        foreach ( $project_access_list as $project_id ) {
    340340            if ( $this->projects[ $project_id ] ) {
    341                 $parent = $this->get_parent_project( $this->project_tree, $project_id );
     341                $parent = $this->rosetta_roles->get_parent_project( $this->project_tree, $project_id );
    342342                if ( $parent->id != $project_id ) {
    343343                    $name = sprintf(
     
    363363        echo implode( '<br>', $projects );
    364364    }
    365 
    366     /**
    367      * Returns the parent project for a sub project.
    368      *
    369      * @param array $tree The project tree.
    370      * @param int $child_id The project tree.
    371      * @return object The parent project.
    372      */
    373     private function get_parent_project( $tree, $child_id ) {
    374         $parent = null;
    375         foreach ( $tree as $project ) {
    376             if ( $project->id == $child_id ) {
    377                 $parent = $project;
    378                 break;
    379             }
    380 
    381             if ( isset( $project->sub_projects ) ) {
    382                 $parent = $this->get_parent_project( $project->sub_projects, $child_id );
    383                 if ( $parent ) {
    384                     $parent = $project;
    385                     break;
    386                 }
    387             }
    388         }
    389 
    390         return $parent;
    391     }
    392365}
  • sites/trunk/global.wordpress.org/public_html/wp-content/mu-plugins/roles/rosetta-roles.php

    r6453 r6684  
    745745    }
    746746
     747    /**
     748     * Returns the parent project for a sub project.
     749     *
     750     * @param array $tree The project tree.
     751     * @param int $child_id The project tree.
     752     * @return object The parent project.
     753     */
     754    public function get_parent_project( $tree, $child_id ) {
     755        $parent = null;
     756        foreach ( $tree as $project ) {
     757            if ( $project->id == $child_id ) {
     758                $parent = $project;
     759                break;
     760            }
     761
     762            if ( isset( $project->sub_projects ) ) {
     763                $parent = $this->get_parent_project( $project->sub_projects, $child_id );
     764                if ( $parent ) {
     765                    $parent = $project;
     766                    break;
     767                }
     768            }
     769        }
     770
     771        return $parent;
     772    }
     773
    747774    private function _sort_name_callback( $a, $b ) {
    748775        return strnatcasecmp( $a->name, $b->name );
Note: See TracChangeset for help on using the changeset viewer.