in advance to all who helps.? Using the function declaration below, explain whether or not the function has any errors in it, what its purpose is and any optimizations you think can be made. Be sure to include descriptions of the passed arguments and function output, if any. Be sure to state your assumptions.
1 function get_employees_by_hierarchy( $_employee_id = 0,$_depth = 0,$_org_array = array() ) {
2 if ( $this->org_depth < $_depth ) {
3 $this->org_depth = $_depth;
4 }
5 $_depth++;
6 $_query = "SELECT * FROM employees WHERE ";
7 if ( !$_employee_id ) {
8 $_query .= "employee_manager_id IS NULL OR employee_manager_id = 0";
9 }
10 else {
11 $_query .= "employee_manager_id = " . $this->dbh->quoteSmart( $_employee_id );
12 }
13 $_result = $this->query( $_query );
14
15 while ( $_row = $_result->fetchRow() ) {
16 $_row['depth'] = $_depth;
17 array_push( $_org_array, $_row );
18 $_org_array = $this->get_employees_by_hierarchy(
19 $_row['employee_manager_id'],
20 $_depth,
21 $_org_array
22 );
23 }
24 return $_org_array;
25 }
Follow Up Questions:
2.Speculate why lines 2 – 4 are necessary.
3.Speculate why line 16 is necessary.
1 function get_employees_by_hierarchy( $_employee_id = 0,$_depth = 0,$_org_array = array() ) {
2 if ( $this->org_depth < $_depth ) {
3 $this->org_depth = $_depth;
4 }
5 $_depth++;
6 $_query = "SELECT * FROM employees WHERE ";
7 if ( !$_employee_id ) {
8 $_query .= "employee_manager_id IS NULL OR employee_manager_id = 0";
9 }
10 else {
11 $_query .= "employee_manager_id = " . $this->dbh->quoteSmart( $_employee_id );
12 }
13 $_result = $this->query( $_query );
14
15 while ( $_row = $_result->fetchRow() ) {
16 $_row['depth'] = $_depth;
17 array_push( $_org_array, $_row );
18 $_org_array = $this->get_employees_by_hierarchy(
19 $_row['employee_manager_id'],
20 $_depth,
21 $_org_array
22 );
23 }
24 return $_org_array;
25 }
Follow Up Questions:
2.Speculate why lines 2 – 4 are necessary.
3.Speculate why line 16 is necessary.