. */ namespace SP\Modules\Web\Controllers\UserProfile; use SP\Core\Acl\Acl; use SP\Core\Acl\AclActionsInterface; use SP\Core\Application; use SP\DataModel\ProfileData; use SP\DataModel\UserProfileData; use SP\Domain\CustomField\Ports\CustomFieldServiceInterface; use SP\Domain\User\Ports\UserProfileServiceInterface; use SP\Modules\Web\Controllers\ControllerBase; use SP\Mvc\Controller\ItemTrait; use SP\Mvc\Controller\WebControllerHelper; /** * Class UserProfileViewBase */ abstract class UserProfileViewBase extends ControllerBase { use ItemTrait; private UserProfileServiceInterface $userProfileService; private CustomFieldServiceInterface $customFieldService; public function __construct( Application $application, WebControllerHelper $webControllerHelper, UserProfileServiceInterface $userProfileService, CustomFieldServiceInterface $customFieldService ) { parent::__construct($application, $webControllerHelper); $this->checkLoggedIn(); $this->userProfileService = $userProfileService; $this->customFieldService = $customFieldService; } /** * Sets view data for displaying user profile's data * * @param int|null $profileId * * @throws \SP\Core\Exceptions\ConstraintException * @throws \SP\Core\Exceptions\QueryException * @throws \SP\Core\Exceptions\SPException * @throws \SP\Domain\Common\Services\ServiceException * @throws \SP\Infrastructure\Common\Repositories\NoSuchItemException */ protected function setViewData(?int $profileId = null): void { $this->view->addTemplate('user_profile', 'itemshow'); $profile = $profileId ? $this->userProfileService->getById($profileId) : new UserProfileData(); $this->view->assign('profile', $profile); $this->view->assign('profileData', $profile->getProfile() ?: new ProfileData()); $this->view->assign('nextAction', Acl::getActionRoute(AclActionsInterface::ACCESS_MANAGE)); if ($this->view->isView === true) { $this->view->assign( 'usedBy', $profileId ? $this->userProfileService->getUsersForProfile($profileId) : [] ); $this->view->assign('disabled', 'disabled'); $this->view->assign('readonly', 'readonly'); } else { $this->view->assign('disabled', false); $this->view->assign('readonly', false); } $this->view->assign('showViewCustomPass', $this->acl->checkUserAccess(AclActionsInterface::CUSTOMFIELD_VIEW_PASS)); $this->view->assign( 'customFields', $this->getCustomFieldsForItem(AclActionsInterface::PROFILE, $profileId, $this->customFieldService) ); } }