2022-01-14 10:09:02 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace common\services;
|
|
|
|
|
|
|
|
use common\models\Manager;
|
|
|
|
use common\models\ManagerEmployee;
|
|
|
|
|
|
|
|
class ProfileService
|
|
|
|
{
|
|
|
|
private $searcherID;
|
|
|
|
private $id;
|
|
|
|
|
|
|
|
public function __construct($searcherID, $id)
|
|
|
|
{
|
|
|
|
$this->searcherID = $searcherID;
|
|
|
|
$this->id = $id;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function checkReportePermission()
|
|
|
|
{
|
|
|
|
if ($this->isMyProfile() or $this->isMyEmployee()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function isMyProfile()
|
|
|
|
{
|
2022-01-14 12:56:39 +03:00
|
|
|
if ($this->id == $this->searcherID) {
|
2022-01-14 10:09:02 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function isMyEmployee()
|
|
|
|
{
|
|
|
|
if (!$this->amIManager()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-01-14 12:56:39 +03:00
|
|
|
if ($this->isMyEmploee()) {
|
2022-01-14 10:09:02 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function amIManager()
|
|
|
|
{
|
2022-01-14 12:56:39 +03:00
|
|
|
if (Manager::find()->where(['user_card_id' => $this->searcherID])->exists()) {
|
2022-01-14 10:09:02 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-01-14 12:56:39 +03:00
|
|
|
private function isMyEmploee()
|
2022-01-14 10:09:02 +03:00
|
|
|
{
|
2022-01-14 12:56:39 +03:00
|
|
|
$manager = Manager::find()->where(['user_card_id' => $this->searcherID])->one();
|
2022-01-14 10:09:02 +03:00
|
|
|
$exist = ManagerEmployee::find()
|
2022-01-14 12:56:39 +03:00
|
|
|
->where(['manager_id' => $manager->id, 'user_card_id' => $this->id])
|
2022-01-14 10:09:02 +03:00
|
|
|
->exists();
|
|
|
|
|
|
|
|
if ($exist) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|