PluginProbe
ERP: Complete HR, Accounting & CRM Suite Built for WooCommerce / 1.3.13
ERP: Complete HR, Accounting & CRM Suite Built for WooCommerce v1.3.13
1.17.10 1.17.9 1.17.8 1.17.7 1.17.6 1.17.5 1.17.4 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.3.0 1.3.1 1.3.11 1.3.12 1.3.13 1.3.14 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 All 144 releases
erp / modules / hrm / includes / class-department.php

class-department.php in ERP: Complete HR, Accounting & CRM Suite Built for WooCommerce 1.3.13, at modules/hrm/includes/class-department.php

69 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace WeDevs\ERP\HRM;
3
4 /**
5 * The department class
6 */
7 class Department extends \WeDevs\ERP\Item {
8
9
10 /**
11 * Get a company by ID
12 *
13 * @param int company id
14 *
15 * @return object wpdb object
16 */
17 protected function get_by_id( $department_id ) {
18 return \WeDevs\ERP\HRM\Models\Department::find( $department_id );
19 }
20
21 /**
22 * Get number of employee belongs to this department
23 *
24 * @return int
25 */
26 public function num_of_employees() {
27 return \WeDevs\ERP\HRM\Models\Employee::where( array( 'status' => 'active', 'department' => $this->id ) )->count();
28 }
29
30 /**
31 * Get the name of department lead
32 *
33 * @return string
34 */
35 public function get_lead() {
36
37 $employee = new Employee( intval( $this->lead ) );
38
39 if ( ! $employee->get_user_id() ) {
40 return false;
41 }
42
43 return $employee;
44 }
45
46 /**
47 * Get the name of department lead
48 *
49 * @return string
50 */
51 public function get_depth( $department, $max_depth = 5 ) {
52 $depth = 0;
53 $parent_id = $department->parent;
54 while( $parent_id > 0 ){
55
56 if ( $depth > $max_depth ) {
57 continue;
58 }
59 $parent_id = $this->get_parent_id( $parent_id );
60 $depth++;
61 }
62
63 return $depth;
64 }
65
66 function get_parent_id( $parent_id ) {
67 return \WeDevs\ERP\HRM\Models\Department::select( array( 'parent' ) )->find( $parent_id )->parent;
68 }
69 }