<?php
 class CustomUserModel {
 public $id = null;
 public $name = null;
 public $username = null;
 public $staffId = null;
 public $groupId = null;
 public $branchID = null;
 public $storeID = null;
 public $avatar = null;
 private $branchsID = null;
 public function copy($user) {
 $this->id = $user->id;
 $this->name = $user->name;
 $this->username = $user->username;
 $this->staffId = $user->staffId;
 $this->groupId = $user->groupId;
 $this->branchID = $user->branchID;
 $this->storeID = $user->storeID;
 if(!empty($user->avatar)) {
 $this->avatar = $user->avatar;
 }
 else {
 $userModel = \Model::load('UserModel');
 \Model::add('StaffsModel', \VnChocola\Model\StaffsModel::class, true);
 $staffModel = \Model::load('StaffsModel');
 $staff = $staffModel->select('image')->find($user->staffId);
 if($staff) {
 $this->avatar = $staff->image;
 $userModel->update([ 'id' => $user->id, 'avatar' => $this->avatar ]);
 }
 else {
 $userModel->update([ 'id' => $user->id, 'avatar' => '/elFinder/files/user.png' ]);
 }
 }
 }
 public function getBranchsId() {
 if($this->branchsID !== null) {
 return $this->branchsID;
 }
 \Model::add('BranchsModel', \VnChocola\Model\BranchsModel::class, true);
 $branchModel = Model::load('BranchsModel');
 $branchs = $branchModel->select('id', 'code')->where('storeID', $this->storeID)->toList();
 $this->branchsID = [];
 foreach($branchs as $b) {
 $this->branchsID[] = $b->id . '';
 }
 if(!$this->branchsID) throw new \TCMS\TException("Người dùng không thuốc chi nhánh nào!", 500);
 return $this->branchsID;
 }
 }
