| @@ -76,15 +76,11 @@ | ||
| 76 | 76 | global $wpdb; |
| 77 | 77 | $sql = 'SELECT post_id AS employee_id, meta_value AS user_id FROM ' . $wpdb->postmeta . ' wpostmeta' . ' JOIN ' . $wpdb->posts . ' wposts ON wposts.ID = wpostmeta.post_id WHERE wpostmeta.meta_key="user_id" AND wposts.post_type="sh4_employee"'; |
| 78 | 78 | $res = $wpdb->get_results( $sql, ARRAY_A ); |
| 79 | 79 | foreach( $res as $e ){ |
| 80 | - if (!isset($e['user_id'])) { | |
| 81 | - continue; | |
| 82 | - } | |
| 83 | 80 | if( ! $e['employee_id'] ) continue; |
| 84 | - if( ! $e['user_id'] ) continue; | |
| 85 | 81 | $this->repoEmployeeUser[ $e['employee_id'] ] = $e['user_id']; |
| 86 | - $this->repoUserEmployee[ $e['user_id'] ?? '' ] = $e['employee_id']; | |
| 82 | + $this->repoUserEmployee[ $e['user_id'] ] = $e['employee_id']; | |
| 87 | 83 | } |
| 88 | 84 | |
| 89 | 85 | if( $this->repoUserEmployee ){ |
| 90 | 86 | $this->repoUser = $this->usersQuery->findManyById( array_keys($this->repoUserEmployee) ); |
| @@ -515,29 +511,41 @@ | ||
| 515 | 511 | |
| 516 | 512 | return $ret; |
| 517 | 513 | } |
| 518 | 514 | |
| 519 | - public function findEmployeeByUserId( $userId ) | |
| 515 | + public function findEmployeeByUser( HC3_Users_Model $user ) | |
| 520 | 516 | { |
| 521 | 517 | $ret = null; |
| 518 | + | |
| 519 | + $userId = $user->getId(); | |
| 522 | 520 | if( ! $userId ){ |
| 523 | 521 | return $ret; |
| 524 | 522 | } |
| 525 | 523 | |
| 526 | 524 | $employeeId = isset( $this->repoUserEmployee[$userId] ) ? $this->repoUserEmployee[$userId] : null; |
| 525 | + | |
| 526 | + // $crud = $this->crudFactory->make('employee'); | |
| 527 | + // $args = array(); | |
| 528 | + // $args[] = array('user_id', '=', $userId ); | |
| 529 | + // $results = $crud->read( $args ); | |
| 530 | + | |
| 531 | + // if( ! $results ){ | |
| 532 | + // return $ret; | |
| 533 | + // } | |
| 534 | + | |
| 535 | + // $results = array_shift( $results ); | |
| 536 | + // $employeeId = array_key_exists('id', $results) ? $results['id'] : null; | |
| 537 | + | |
| 527 | 538 | if( ! $employeeId ){ |
| 528 | 539 | return $ret; |
| 529 | 540 | } |
| 530 | 541 | |
| 542 | + // $ret = $this->employeesQuery->findById( $employeeId ); | |
| 543 | + | |
| 531 | 544 | if( ! isset($this->repoEmployee[$employeeId]) ){ |
| 532 | 545 | $this->repoEmployee[$employeeId] = $this->employeesQuery->findById( $employeeId ); |
| 533 | 546 | } |
| 534 | - $ret = $this->repoEmployee[$employeeId]; | |
| 547 | + $ret = $this->repoEmployee[$employeeId]; | |
| 535 | 548 | |
| 536 | 549 | return $ret; |
| 537 | - } | |
| 538 | - | |
| 539 | - public function findEmployeeByUser( HC3_Users_Model $user ) | |
| 540 | - { | |
| 541 | - return $this->self->findEmployeeByUserId( $user->getId() ); | |
| 542 | 550 | } |
| 543 | 551 | } |