HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/base.komma.pro/vendor/komma/kms/src/Users/Kms/UserService.php
<?php

namespace Komma\KMS\Users\Kms;


use Komma\KMS\Auth\AuthMailServiceInterface;
use Komma\KMS\Core\Attributes\Attribute;
use Komma\KMS\Core\Attributes\Models\Traits\HasThumbnailInterface;
use Komma\KMS\Core\Attributes\Password;
use Komma\KMS\Core\ModelService;
use Komma\KMS\Core\Sections\SideBarListItem;
use Komma\KMS\Users\Models\KmsUser;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;

abstract class UserService extends ModelService
{
    protected $sortable = false;

    function __construct()
    {
        $this->authMailService = app(AuthMailServiceInterface::class);
        parent::__construct();
    }

    /**
     * This method will get all the models.
     * And add these to the sidebarList.
     *
     * @return array $sidebarList
     */
    public function getModelsForSideBar():array
    {
        // Get users based upon your user role
        $users = $this->modelClassName::where('role' , '>=', \Auth::user()->role)->get();

        $sidebarList = [];
        $users = $users->load('documents');
        foreach ($users as $user) {
            //New SidebarListItem
            $sidebarListItem = new SidebarListItem();
            $user->title = $user->email; //used in KmsRepository::setThumbnail
            /** @var HasThumbnailInterface $user */
            $user->generateThumbnail();

            //Set the values for the sidebar
            $sidebarListItem->setId($user->id);
            $sidebarListItem->setStatus(!$user->is_admin);
            $sidebarListItem->setName($user->getDisplayName());
            $sidebarListItem->setThumbnail($user->getThumbnail());
            $sidebarListItem->alsoSearchInAttributesOfModel($user);

            $sidebarList[] = $sidebarListItem;
        }

        return $sidebarList;
    }

    /**
     * This method will save an model
     *
     * @param Model $model or null
     * @param Collection $attributes
     * @return mixed
     */
    public function save(Model $model, Collection $attributes = null): Model
    {
        if($attributes === null) return $model;

        /** @var KmsUser $model */
        $attributes->each(
            function(Attribute $attribute, $key) use($model, &$editedModel) {
                /** @var KmsUser $model */
                $value = $attribute->getValue();

//              if(is_a($attribute, Select::class)) dd($attribute); //debugging helper

                $reference = $attribute->getsValueFromReference();
                switch ($attribute->getsValueFrom()) {
                    case Attribute::ValueFromModel:
                        if ($reference == ($this->modelClassName)::PASSWORD_COLUMN_NAME) {
                            /** @var Password $attribute */
                            if($attribute->isEmpty()) {

                                //Prevents the parent from saving an empty password hash since "valueFromItself" isn't save to the database at all
                                $attribute->setEntity(Attribute::NonInteractiveAttribute);
                            }
                        }
                    break;
                }
            }
        );

        $exists = $model->exists;

        parent::save($model, $attributes);
        $model->save();

        parent::save($model, $attributes);

        return $model;
    }
}