in api added methods: document created and get profile with reports permission

This commit is contained in:
iIronside
2022-01-14 10:09:02 +03:00
parent 920aa2e751
commit b123d250e1
10 changed files with 3921 additions and 20 deletions

View File

@ -110,4 +110,13 @@ class Document extends \yii\db\ActiveRecord
{
return $this->hasMany(DocumentFieldValue::className(), ['document_id' => 'id']);
}
public static function getDocument($document_id)
{
return self::find()
->joinWith(['documentFieldValues.field'])
->where(['document.id' => $document_id])
->asArray()
->all();
}
}

View File

@ -4,6 +4,7 @@ namespace common\models;
use Yii;
use yii\db\ActiveQuery;
use yii\db\StaleObjectException;
/**
* This is the model class for table "manager".
@ -48,6 +49,10 @@ class Manager extends \yii\db\ActiveRecord
];
}
/**
* @throws StaleObjectException
* @throws \Throwable
*/
public function beforeDelete()
{
foreach ($this->managerEmployees as $employee){

View File

@ -120,16 +120,4 @@ class Template extends \yii\db\ActiveRecord
{
return $this->title;
}
//TODO no need, delete
public function getDocumentFields()
{
$fieldsArray = [];
foreach ($this->templateDocumentFields as $templateDocField) {
$fieldsArray[] = $templateDocField->field;
}
return $fieldsArray;
}
}

View File

@ -0,0 +1,69 @@
<?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()
{
if ($this->id === $this->searcherID) {
return true;
}
return false;
}
private function isMyEmployee()
{
if (!$this->amIManager()) {
return false;
}
if ($this->findEmploee()) {
return true;
}
return false;
}
private function amIManager()
{
if (Manager::findOne($this->searcherID)) {
return true;
}
return false;
}
private function findEmploee()
{
$exist = ManagerEmployee::find()
->where(['manager_id' => $this->searcherID, 'user_card_id' => $this->id])
->exists();
if ($exist) {
return true;
}
return false;
}
}