Proyectos de Subversion LeadersLinked - Backend

Rev

Autoría | Ultima modificación | Ver Log |

<?php

declare(strict_types=1);

namespace LeadersLinked\Form\KnowledgeArea;

use Laminas\Form\Form;
use Laminas\Db\Adapter\AdapterInterface;

use LeadersLinked\Mapper\UserMapper;
use LeadersLinked\Model\KnowledgeAreaCategory;
use LeadersLinked\Model\KnowledgeAreaCategoryUser;



class KnowledgeAreaCategoryUserForm extends Form
{

    /**
     * 
     * @param AdapterInterface $adapter
     * @param int $company_id
     * @param string $privacy
     */
    public function __construct($adapter, $company_id, $privacy) {
        parent::__construct();
        $this->setInputFilter(new KnowledgeAreaCategoryUserFilter());

        
        if($privacy == KnowledgeAreaCategory::PRIVACY_COMPANY) {
            $roles = [
               KnowledgeAreaCategoryUser::ROLE_USER => 'LABEL_USER',
               KnowledgeAreaCategoryUser::ROLE_EDITOR => 'LABEL_EDITOR',
               KnowledgeAreaCategoryUser::ROLE_ADMINISTRATOR => 'LABEL_ADMINISTRATOR',
            ];
        } else {
            $roles = [ 
               KnowledgeAreaCategoryUser::ROLE_EDITOR => 'LABEL_EDITOR',
               KnowledgeAreaCategoryUser::ROLE_ADMINISTRATOR => 'LABEL_ADMINISTRATOR',
            ];
        }
        


        
        
        $this->add([
            'name' => 'user_id',
            'type' => \Laminas\Form\Element\Select::class,
            'attributes' => [
                'id' =>  'user_id',
            ],
            'options' => [
                //'disable_inarray_validator' => true,
                'value_options' =>  $this->getUsers($adapter, $company_id)
            ]
        ]);
        
        
        
        $this->add([
            'name' => 'role',
            'type' => \Laminas\Form\Element\Select::class,
            'attributes' => [
                'id' =>  'role',
            ],
            'options' => [
                //'disable_inarray_validator' => true,
                'value_options' => $roles
            ]
        ]);
        

        
    }
    
    private function getUsers($adapter, $company_id)
    {
        $items = [];
        $userMapper = UserMapper::getInstance($adapter);
        $records = $userMapper->fetchAllByCompanyId($company_id);
        
        foreach($records as $record)
        {
            $items[ $record->uuid ] = $record->first_name . ' ' . $record->last_name . ' (' . $record->email . ')';
        }
        
        return $items;
    }


}