<?php
namespace Incoviba\common;

use Incoviba\Common\Alias\OldModel as Model;

/**
 *
 * @author Aldarien
 * @property int $id
 * @property int $type length=1
 * @property int $ext_id
 * @property Action $action_id
 * @property int $status
 * ---NULL---
 * @property int $location null foreign=locations.id
 * @property int $all length=1 default=0
 * @property int $access length=1 default=0
 *
 */
class Permission extends Model
{
  public static $_table = 'permissions';

  /*protected $locations = null;
  public function location()
  {
  	if ($this->all == 0) {
  		return $this->belongsTo(Location::class, 'location')->findOne();
  	}
  	if ($this->locations == null) {
  		$this->locations = \Model::factory(Location::class)->findMany();
  	}
  	return $this->locations;
  }*/
  public function who()
  {
  	switch ($this->type) {
  		case 1:
  			return $this->belongsTo(User::class, 'ext_id')->findOne();
  		case 2:
  			return $this->belongsTo(Role::class, 'ext_id')->findOne();
  	}
  }
  public function action()
  {
    return $this->belongsTo(Action::class, 'action_id')->findOne();
  }
}
?>
