door manager

This commit is contained in:
Schneider Roland
2022-05-04 19:41:18 +02:00
parent fb39d6599e
commit 946799a598
20 changed files with 8872 additions and 220 deletions

View File

@@ -18,6 +18,12 @@ use yii\i18n\Formatter;
class DateUtil
{
public static function fromUnixTimeStamp($timestamp){
$dt = DateUtil::utcDate();
$dt->setTimestamp($timestamp);
return $dt;
}
/**
* Get UTC today @00:00:00 .
* Helper method to generate date for mysql
@@ -25,13 +31,49 @@ class DateUtil
* @return DateTime
* @throws Exception
*/
public static function todayStart( ){
$d2 = new DateTime();
public static function todayStart(){
$d2 = new DateTime();
return DateUtil::utcDate($d2);
}
/**
* @param $date \DateTime optional. The date to set as utc date. If not set, new DateTime() will be used
* @return DateTime the datetime object with time reset and utc timezone
*/
public static function utcDate($date = null){
$d2 = isset($date ) ? $date : new DateTime();
$d2 = DateUtil::withTimeZoneUTC($d2);
return DateUtil::resetTime($d2);
}
/**
* @param $date \DateTime optional. If not set,defaults to : new DateTime() .
* @return DateTime
*/
public static function utcDateTime($date = null){
$d2 = isset($date ) ? $date : new DateTime();
return DateUtil::withTimeZoneUTC($d2);
}
/**
* @param $date \DateTime
* @return DateTime
*/
public static function withTimeZoneUTC( $date = null){
$d2 = isset($date ) ? $date : new DateTime();
$d2->setTimezone( new DateTimeZone('UTC') );
$d2->setTime(0, 0);
return $d2;
}
/**
* @param $dateTime \DateTime
* @return \DateTime
*/
public static function resetTime($dateTime){
$dateTime->setTime(0, 0);
return $dateTime;
}
/**
* Get UTC t @00:00:00 .
* Helper method to generate date for mysql
@@ -39,16 +81,12 @@ class DateUtil
* @return DateTime
* @throws Exception
*/
public static function tomorrowStart( ){
$d2 = new DateTime();
public static function tomorrowStart( $date = null){
$d2 = isset($date) ? $date : new DateTime();
$d2->add(new DateInterval('P1D'));
$d2->setTimezone( new DateTimeZone('UTC') );
$d2->setTime(0, 0);
return $d2;
return DateUtil::utcDate($d2);
}
public static function addMonth($timestamp, $monthCount = 1)
{
@@ -99,7 +137,7 @@ class DateUtil
* @return string
* @throws InvalidConfigException
*/
public static function formatUtc($dateTimeObject)
public static function formatDateTimeUtc($dateTimeObject)
{
$formatter = new Formatter;
$formatter->datetimeFormat = 'php:Y-m-d H:i:s';
@@ -127,6 +165,10 @@ class DateUtil
return $date;
}
public static function parseDateTime($dateTimeString){
return DateTime::createFromFormat('Y-m-d H:i:s', $dateTimeString, new DateTimeZone( 'UTC'));
}
/**
* @param integer $weekDay Numeric representation of the day of the week. @See https://www.php.net/manual/en/function.date.php
* @return string

View File

@@ -0,0 +1,352 @@
<?php
namespace common\manager;
use common\components\DateUtil;
use common\components\Helper;
use common\models\Card;
use common\models\CardEventRegistrationForm;
use common\models\Customer;
use common\models\DoorLog;
use common\models\DoorLogForTest;
use common\models\Event;
use common\models\EventRegistration;
use common\models\Log;
use common\models\MobileDevice;
use common\models\Ticket;
use customerapi\models\available\EventInterval;
use customerapi\models\registrations\EventRegistrationAvailable;
use customerapi\models\details\EventRegistrationView;
use Exception;
use Yii;
use yii\base\BaseObject;
use yii\db\ActiveRecord;
use yii\db\Query;
use yii\web\BadRequestHttpException;
use yii\web\NotFoundHttpException;
use yii\web\ServerErrorHttpException;
/**
* Created by IntelliJ IDEA.
* User: rocho
* Date: 2018.12.17.
* Time: 6:12
*/
class DoorManager extends BaseObject
{
/**
* @param $cardNumber
* @param $device
* @param $direction
* @param $createdAt number unix timestamp , override createdAt for doorLogs
* @param $date number unix timestamp, override date for validation check 'now'
* @return void
* @throws BadRequestHttpException
* @throws \yii\base\InvalidConfigException
*/
public function move($cardNumber, $device, $direction, $createdAt = null, $date = null )
{
if ( isset($createdAt)){
$createdAt = DateUtil::parseDateTime($createdAt);
}else{
$createdAt = DateUtil::utcDateTime();
}
$createdAtStr = DateUtil::formatDateTimeUtc($createdAt);
if ( isset($date)){
$date = DateUtil::parseDateTime($date);
}else{
$date = DateUtil::utcDate();
}
$dateStr = DateUtil::formatDateUtc($date);
$doorLog = new DoorLog();
$doorLog->direction = $direction;
$doorLog->source_app = $device;
$doorLog->created_at = $createdAtStr;
/**
* emergency- no card needed
*/
if ($direction == DoorLog::$DIRECTION_ALL_EMERGENCY) {
$doorLog->save(false);
Log::log(
[
'type' => Log::$TYPE_INFO,
'message' => 'Ajtó nyitás: vészhelyzet',
'id_door_log' => $doorLog->id_door_log
]
);
\Yii::$app->response->statusCode = 204;
return;
}
$card = Card::readCard(Helper::fixAsciiChars($cardNumber));
/*
* in any other cases, the door needs a card
*/
if (!isset($card)) {
throw new BadRequestHttpException('Card not found with number: ' . $cardNumber);
}
$doorLog->id_card = $card->id_card;
$doorLog->card_flag = $card->flag;
/**
* if the card type is employee, neither customer nor ticket is needed.
* Free to enter/leave
*/
if ($card->type == Card::TYPE_EMPLOYEE) {
$doorLog->save(false);
\Yii::$app->response->statusCode = 204;
return;
}
//otherwise ticket is required
$activeTickets = Ticket::readActive($card, clone $date);
\Yii::error('active ticket count:' . count($activeTickets));
$ticket = null;
if (isset($activeTickets) && count($activeTickets) > 0) {
$ticket = $activeTickets[0];
}
$doorLog->id_ticket_current = $ticket->id_ticket;
if (!isset($ticket)) {
throw new BadRequestHttpException("No active ticket found for:" . $card->number);
}
\Yii::error("active ticket: " . $ticket->id_ticket);
// customer is also required
$customer = $card->customer;
if (!isset($customer)) {
throw new BadRequestHttpException("Customer not found for:" . $card->number);
}
$doorLog->id_customer = $customer->id_customer;
// save the door log
$doorLog->save(false);
// if direction is in
if ($direction == DoorLog::$DIRECTION_IN || $direction == DoorLog::$DIRECTION_IN_WITHOUT_MOVE) {
$countDoorLogsForTicketSince = $this->getCountDoorLogsForTicketSince($ticket->id_ticket, DateUtil::utcDate( clone $date));
// if the current event is the first door log today
if ($countDoorLogsForTicketSince == 1) {
// increase the ticket usage count with 1
$usageCount = $ticket->usage_count;
$ticket->usage_count += 1;
$ticket->save(false);
Log::log(
[
'type' => Log::$TYPE_TICKET_USAGE_FIRST,
'message' => 'Bérlet használat(előtte: ' . $usageCount . ' -> utána: ' . $ticket->usage_count,
'id_ticket' => $ticket->id_ticket,
'id_door_log' => $doorLog->id_door_log
]
);
} else {
// we have already a door log for today, other than this
// Now we split the day into 3hour intervalls, starting with the createdAt value of the first event.
// If the actual event happens in an interval, in which still now doorlog event happend, we increase
// the usage count with 1
// 3 óránként 1-et levonunk
$startOfDay = DateUtil::utcDate(clone $date);
$startOfTomorrow = DateUtil::tomorrowStart(clone $date);
$allDoorLogToday = DoorLog::find()
->andWhere(['>=', 'door_log.created_at', DateUtil::formatDateUtc($startOfDay)])
->andWhere(['<', 'door_log.created_at', DateUtil::formatDateUtc($startOfTomorrow)])
->andWhere(['id_ticket_current' => $ticket->id_ticket])
->andWhere(['in', 'direction', [DoorLog::$DIRECTION_IN_WITHOUT_MOVE, DoorLog::$DIRECTION_IN]])
->orderBy(['door_log.created_at' => SORT_ASC])
->all();
\Yii::error("new door log: ".$doorLog->id_door_log.";".$doorLog->created_at.";".$doorLog->type);
foreach ($allDoorLogToday as $log){
\Yii::error("all log: ".$log->id_door_log.";".$log->created_at.";".$log->type);
}
$firstInToday = $allDoorLogToday[0];
if (isset($firstInToday)) {
$firstEntryDateTimeToday = DateUtil::parseDateTime($firstInToday->created_at);
$interval = \DateInterval::createFromDateString('3 hours');
$daterange = new \DatePeriod($firstEntryDateTimeToday, $interval ,$startOfTomorrow);
$intervals = [];
$intervalStart = null;
foreach($daterange as $intervalEnd){
if ( isset($intervalStart)){
$intervals[] = $this->createTicketUsageInterval($intervalStart,$intervalEnd,$allDoorLogToday,$doorLog);
}
$intervalStart = clone $intervalEnd;
}
if ( $intervalStart < $startOfTomorrow ){
$intervals[] = $this->createTicketUsageInterval($intervalStart,$startOfTomorrow,$allDoorLogToday,$doorLog);
}
$activeInterval = $this->getActiveInterval($intervals,$createdAt);
if ( !isset($activeInterval)){
throw new ServerErrorHttpException("Active Interval not found");
}
$logCountInActiveInterval = count($activeInterval['logs']);
if ( $logCountInActiveInterval == 1){
$ticket->usage_count = $ticket->usage_count+1;
$ticket->save(false);
}
}
// select min(created_at) + INTERVAL (3 * FLOOR( ( ( HOUR( TIMEDIFF( min(created_at) , now() ) ) /3 ) ) ) ) hour as last_date
// into @p_from
// from door_log
// where created_at > CURDATE() and id_customer is not null and id_ticket_current = NEW.id_ticket_current and ( direction = 7 or direction = 3);
// select count(*) into @p_count_all_2 from door_log where created_at >= @p_from and id_ticket_current = New.id_ticket_current and ( direction = 7 or direction = 3);
// INSERT INTO devlog ( msg) values(CONCAT( 'Bel<65>p<EFBFBD>sek sz<73>ma az aktu<74>lis 3 <20>r<EFBFBD>s intervalumban: ', @p_count_all_2) );
// IF @p_count_all_2 = 1
// THEN
// INSERT INTO devlog ( msg) values( 'Az aktu<74>lis intervallumban ez az els? bel<65>p<EFBFBD>s, usage_count n<>vel<65>se' );
//
// select usage_count, max_usage_count into @p_usage_count ,@p_max_usage_count from ticket where id_ticket = NEW.id_ticket_current;
//
// update ticket set usage_count = usage_count +1 where id_ticket = New.id_ticket_current;
//
// INSERT INTO log (type,message, app, id_ticket, id_door_log,created_at, updated_at)
// values(
// 40, concat('B<>rlet haszn<7A>lat/egy nap tobbszori (elotte: ',@p_usage_count, ' > utana: ' , @p_usage_count +1 , ' max: ', @p_max_usage_count, ')' ), ' trigger_inc_ticket',New.id_ticket_current, New.id_door_log,now(),now());
// END IF;
}
//
//
//
\Yii::error("finished");
}
}
function getActiveInterval($intervals,$date){
foreach ($intervals as $interval ){
$start = $interval['start'];
$end = $interval['end'];
if ( $start <= $date && $date < $end ){
return $interval;
}
}
return null;
}
function createTicketUsageInterval($start,$end, $allLogs, $actualDoorLog){
$result = ['start' => $start, 'end' => $end , 'logs' =>[] ];
foreach ($allLogs as $log){
$createdAt = DateUtil::parseDateTime($log->created_at);
if ( $createdAt >= $start && $createdAt < $end){
$result['logs'][] = $log;
}
}
return $result;
}
function getCountDoorLogsForTicketSince($idTicket, $since)
{
\Yii::error("getting door log count for today");
return DoorLog::find()
->innerJoinWith('card')
->andWhere(['card.id_ticket_current' => $idTicket])
->andWhere(['in', 'door_log.direction', [DoorLog::$DIRECTION_IN, DoorLog::$DIRECTION_IN_WITHOUT_MOVE]])
->andWhere(['>=', 'door_log.created_at', DateUtil::formatDateUtc($since)])
->count();
}
public function readActive($cardNumber)
{
$card = Card::readCard($cardNumber);
return Ticket::readActive($card);
}
public function resetLogs($cardNumber)
{
$card = Card::readCard($cardNumber);
DoorLog::deleteAll(
['id_card' => $card->id_card]
);
}
public function getLogs($cardNumber)
{
return DoorLog::findAll(
['id_card' => $cardNumber]
);
}
public function getInfo($cardNumber)
{
$card = Card::readCard($cardNumber);
return [
'card' => $card,
'customer' => $card->customer,
'tickets' => Ticket::readActive($card),
'doorLogs' => DoorLog::findAll(
['id_card' => $card->id_card]
),
'lastDoorLog' => DoorLog::find()->orderBy(['id_door_log' => SORT_DESC])->limit(1)->one(),
'doorLogCount' => DoorLog::find()->count()
];
}
//
// public function createDoorLog($direction, $idCard, $idTicket, $createdAt)
// {
// $doorLog = new DoorLog();
// $doorLog->id_card = $idCard;
// $doorLog->direction = $direction;
// $doorLog->id_ticket_current = $idTicket;
//
// $doorLog->save(false);
// // update the created at flag
// \Yii::$app->db->createCommand('update door_log set created_at = :created_at where id_door_log = :id ')
// ->bindValue("created_at", $createdAt)
// ->bindValue("id", $doorLog->id_door_log)
// ->execute();
// }
public function createLog()
{
\Yii::error("Post create log:". \Yii::$app->request->method);
if (\Yii::$app->request->isPost) {
$log = new DoorLogForTest();
if ($log->load(\Yii::$app->request->post(), "")) {
if ($log->validate()) {
\Yii::error("Door log saving:".$log->created_at);
$log->save(false);
return $log;
}else{
throw new BadRequestHttpException(print_r($log->getErrors(),true));
}
} else {
\Yii::error("validated" . print_r($log->errors, true));
throw new BadRequestHttpException();
}
}
throw new BadRequestHttpException('Not a Post');
}
}

View File

@@ -25,9 +25,25 @@ use yii\helpers\ArrayHelper;
*/
class DoorLog extends \yii\db\ActiveRecord
{
public static $SOURCE_APP_FORGO_VILLA = "forgo_villa";
public static $SOURCE_APP_FITNESS_ADMIN = "fitness_admin";
public static $SOURCE_APP_FORGO_VILLA = "forgo_villa";
public static $SOURCE_APP_FITNESS_ADMIN = "fitness_admin";
public static $DIRECTION_OUT_MANUAL_READ_KEY_ASSIGNED = -2; // "Kézi olvasás/Kulcs ki",
public static $DIRECTION_IN_MANUAL_READ_KEY_UNASSIGNED = -1; // "Kézi olvasás/Kulcs vissza",
public static $DIRECTION_ALL_MANUAL_READ = 0; // "Kézi olvasás",
public static $DIRECTION_OUT_WITHOUT_MOVE = 1; // "KI olvastatás mozgás nélkül",
public static $DIRECTION_IN_WITHOUT_MOVE = 3; // "BE olvastatás mozgás nélkül",
public static $DIRECTION_OUT_ = 5; // "KI mozgás",
public static $DIRECTION_IN = 7; // "BE mozgás",
public static $DIRECTION_OUT_ERROR_KEY_ASSIGNED = 9; // "KI olvastatás, van érvényes öltöző kulcs (nem enged)",
public static $DIRECTION_IN_ERROR_KEY_MISSING = 11; // "BE olvastatás, nincs érvényes öltöző kulcs (nem enged)",
public static $DIRECTION_OUT_NO_TICKET = 17; // "Bérlet érvényességi időn kívüli KI olvastatás (nem enged)",
public static $DIRECTION_IN_NO_TICKET = 19; // "Bérlet érvényességi időn kívüli BE olvastatás (nem enged)",
public static $DIRECTION_ALL_EMERGENCY = 128; // "Vésznyitás",
public static $DIRECTION_ALL_CARD_BLOCKED = 256; // "Kártya tiltva -> információ mező",
/**
* @inheritdoc
*/
@@ -35,16 +51,21 @@ class DoorLog extends \yii\db\ActiveRecord
{
return 'door_log';
}
public function behaviors()
{
return ArrayHelper::merge( [
[
'class' => TimestampBehavior::className(),
'value' => function(){ return date('Y-m-d H:i:s' ); },
'updatedAtAttribute' => false,
]
], parent::behaviors());
return ArrayHelper::merge([
[
'class' => TimestampBehavior::className(),
'value' => function ($event) {
if ( isset($event->sender->created_at) ){
return $event->sender->created_at;
}
return date('Y-m-d H:i:s');
},
'updatedAtAttribute' => false,
]
], parent::behaviors());
}
/**
@@ -75,133 +96,147 @@ class DoorLog extends \yii\db\ActiveRecord
'source_app' => Yii::t('common/door_log', 'Eszköz'),
];
}
public function getCustomer(){
return $this->hasOne( Customer::className(), ["id_customer" =>"id_customer" ] );
}
public function getCustomerName(){
$result = "";
if (isset($this->customer)){
$result = $this->customer->name;
}
return $result;
}
public function getCard(){
return $this->hasOne( Card::className(), ["id_card" =>"id_card" ] );
}
public function getCardNumber(){
$result = "";
if (isset($this->card)){
$result = $this->card->number;
}
return $result;
}
public function getKey(){
return $this->hasOne( Key::className(), ["id_key" =>"id_key" ] );
}
public function getKeyNumber(){
$result = "";
if (isset($this->key)){
$result = $this->key->number;
}
return $result;
}
public function getDirectionName(){
$result = "";
if ( $this->source_app == 'forgo_villa'){
if (isset($this->direction)){
$result = Helper::getArrayValue(self::getDirectionTypes() , $this->direction, "-");
}
}else{
$result = "Kézi olvasás";
}
return $result;
}
public static function getSourceAppName($source_app){
$result = "";
switch ($source_app){
case self::$SOURCE_APP_FITNESS_ADMIN :
$result = "Recepciós alkalmazás";
break;
case self::$SOURCE_APP_FORGO_VILLA:
$result = "Forgó villa";
break;
}
return $result;
}
public static function getDirectionTypes( ){
return [
-2 => "Kézi olvasás/Kulcs ki",
-1 => "Kézi olvasás/Kulcs vissza",
0 => "Kézi olvasás",
1 => "KI olvastatás mozgás nélkül",
3 => "BE olvastatás mozgás nélkül",
5 => "KI mozgás",
7 => "BE mozgás",
9 => "KI olvastatás, van érvényes öltöző kulcs (nem enged)",
11 => "BE olvastatás, nincs érvényes öltöző kulcs (nem enged)",
17 => "Bérlet érvényességi időn kívüli KI olvastatás (nem enged)",
19 => "Bérlet érvényességi időn kívüli BE olvastatás (nem enged)",
128 => "Vésznyitás",
256 => "Kártya tiltva -> információ mező",
];
}
public static function getCardFlagTexts( ){
return [
0 => "Kártya érvényes bérlettel",
1 => "Nincs érvényes bérlet",
2 => "Kártya inaktív/Érvényes bérlet",
3 => "Kártya inaktív/Nincs érvényes bérlet"
];
}
public function getCustomer()
{
return $this->hasOne(Customer::className(), ["id_customer" => "id_customer"]);
}
public static function mkDoorLog($direction,$card,$customer = null,$key = null){
public function getCustomerName()
{
$result = "";
if (isset($this->customer)) {
$result = $this->customer->name;
}
return $result;
}
if ( !Helper::isKeyToggleDoorLogEnabled() ){
return;
public function getCard()
{
return $this->hasOne(Card::className(), ["id_card" => "id_card"]);
}
public function getCardNumber()
{
$result = "";
if (isset($this->card)) {
$result = $this->card->number;
}
return $result;
}
public function getKey()
{
return $this->hasOne(Key::className(), ["id_key" => "id_key"]);
}
public function getKeyNumber()
{
$result = "";
if (isset($this->key)) {
$result = $this->key->number;
}
return $result;
}
public function getDirectionName()
{
$result = "";
if ($this->source_app == 'forgo_villa') {
if (isset($this->direction)) {
$result = Helper::getArrayValue(self::getDirectionTypes(), $this->direction, "-");
}
} else {
$result = "Kézi olvasás";
}
return $result;
}
public static function getSourceAppName($source_app)
{
$result = "";
switch ($source_app) {
case self::$SOURCE_APP_FITNESS_ADMIN :
$result = "Recepciós alkalmazás";
break;
case self::$SOURCE_APP_FORGO_VILLA:
$result = "Forgó villa";
break;
}
return $result;
}
public static function getDirectionTypes()
{
return [
-2 => "Kézi olvasás/Kulcs ki",
-1 => "Kézi olvasás/Kulcs vissza",
0 => "Kézi olvasás",
1 => "KI olvastatás mozgás nélkül",
3 => "BE olvastatás mozgás nélkül",
5 => "KI mozgás",
7 => "BE mozgás",
9 => "KI olvastatás, van érvényes öltöző kulcs (nem enged)",
11 => "BE olvastatás, nincs érvényes öltöző kulcs (nem enged)",
17 => "Bérlet érvényességi időn kívüli KI olvastatás (nem enged)",
19 => "Bérlet érvényességi időn kívüli BE olvastatás (nem enged)",
128 => "Vésznyitás",
256 => "Kártya tiltva -> információ mező",
];
}
public static function getCardFlagTexts()
{
return [
0 => "Kártya érvényes bérlettel",
1 => "Nincs érvényes bérlet",
2 => "Kártya inaktív/Érvényes bérlet",
3 => "Kártya inaktív/Nincs érvényes bérlet"
];
}
public static function mkDoorLog($direction, $card, $customer = null, $key = null)
{
if (!Helper::isKeyToggleDoorLogEnabled()) {
return;
}
$dlog = new DoorLog();
$dlog->id_card = $card->id_card;
$dlog = new DoorLog();
$dlog->id_card = $card->id_card;
if ( isset($customer)){
$dlog->id_customer = $customer->id_customer;
}
if (isset($customer)) {
$dlog->id_customer = $customer->id_customer;
}
if ( isset($key)){
$dlog->id_key = $key->id_key;
}
$dlog->direction = $direction;
$dlog->type = $card->type;
$dlog->source_app = DoorLog::$SOURCE_APP_FITNESS_ADMIN;
if (isset($key)) {
$dlog->id_key = $key->id_key;
}
$dlog->direction = $direction;
$dlog->type = $card->type;
$dlog->source_app = DoorLog::$SOURCE_APP_FITNESS_ADMIN;
$dlog->id_account = Account::readDefault();
$dlog->id_account = Account::readDefault();
if ( $dlog->direction == 0){
$dlog->card_flag = $card->validity;
}else{
$dlog->card_flag = -1;
}
if ($dlog->direction == 0) {
$dlog->card_flag = $card->validity;
} else {
$dlog->card_flag = -1;
}
$dlog->created_at = date('Y-m-d H:i:s');
$dlog->save(false);
}
$dlog->created_at = date('Y-m-d H:i:s');
$dlog->save(false);
}
}

View File

@@ -0,0 +1,49 @@
<?php
namespace common\models;
use Yii;
use common\components\Helper;
use yii\behaviors\TimestampBehavior;
use yii\helpers\ArrayHelper;
/**
* This is the model class for table "door_log".
*
* @property integer $id_door_log
* @property integer $id_card
* @property integer $id_customer
* @property integer $id_key
* @property integer $direction
* @property integer $type
* @property integer $id_account
* @property string $created_at
* @property string $source_app
* @property integer id_ticket_current
* @property integer card_flag
* @property integer flag_out
*/
class DoorLogForTest extends DoorLog
{
public function behaviors()
{
return [];
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[
['id_card', 'id_customer', 'id_key', 'direction', 'type', 'id_ticket_current'], 'integer'
],
[['created_at'], 'string'],
[['created_at'], 'required'],
];
}
}

View File

@@ -26,7 +26,7 @@ class User extends ActiveRecord implements IdentityInterface
{
const STATUS_DELETED = 0;
const STATUS_ACTIVE = 10;
const ROLE_RECEPTION = 'receptionist';
/**
@@ -192,18 +192,18 @@ class User extends ActiveRecord implements IdentityInterface
{
$this->password_reset_token = null;
}
public function getUserAccountAssignments(){
return $this->hasMany(UserAccountAssignment::className(), ['id_user' =>'id']);
}
static function statuses() {
return [
self::STATUS_ACTIVE => Yii::t('app', 'Aktív'),
self::STATUS_DELETED => Yii::t('app', 'Inaktív'),
] ;
}
public function getStatusHuman(){
$result = null;
$s = self::statuses($this->status);
@@ -212,8 +212,8 @@ class User extends ActiveRecord implements IdentityInterface
}
return $result;
}
public function attributeLabels(){
return [
'status' => 'Státusz',
@@ -224,14 +224,14 @@ class User extends ActiveRecord implements IdentityInterface
'statusHuman' => Yii::t('backend/user', 'Status'),
];
}
/**
*
*
*
*
* @return \yii\rbac\Role[]*/
public function getRoles(){
$roles = \Yii::$app->authManager->getRolesByUser($this->id );
return $roles;
return $roles;
}
/**
@@ -239,28 +239,28 @@ class User extends ActiveRecord implements IdentityInterface
* */
public function getRoleString(){
$roles = \Yii::$app->authManager->getRolesByUser($this->id );
return implode(', ', array_map(function ($role) { return sprintf("%s", RoleDefinition::getRoleLabel($role->name)); }, $roles ));
}
/**
* $param int $forceIncludeAccount id warehouse, that should be included in list, even if it is inactive
* */
public static function read($forceIncludeObjectWithId = null){
$users = null;
$query = User::find();
if ( RoleDefinition::isReception()){
$query->andWhere(['id' => Yii::$app->user->id ]);
}
if ( $forceIncludeObjectWithId == null){
$users = $query->andWhere(['status' => User::STATUS_ACTIVE])->all();
}else{
$users = $query->andWhere( ['or', ['status' => User::STATUS_ACTIVE], ['id' => $forceIncludeObjectWithId ] ])->all();
}
return $users;
}
}