| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * Circles - Bring cloud-users closer together. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * This file is licensed under the Affero General Public License version 3 or | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * later. See the COPYING file. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * @author Maxence Lange <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * @copyright 2021 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * @license GNU AGPL version 3 or any later version | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * This program is free software: you can redistribute it and/or modify | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * it under the terms of the GNU Affero General Public License as | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * published by the Free Software Foundation, either version 3 of the | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * License, or (at your option) any later version. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  * This program is distributed in the hope that it will be useful, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  * GNU Affero General Public License for more details. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  * You should have received a copy of the GNU Affero General Public License | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  * along with this program.  If not, see <http://www.gnu.org/licenses/>. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | namespace OCA\Circles\Command; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | use daita\MySmallPhpTools\Exceptions\InvalidItemException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | use daita\MySmallPhpTools\Exceptions\ItemNotFoundException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | use daita\MySmallPhpTools\Exceptions\RequestNetworkException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | use daita\MySmallPhpTools\Exceptions\SignatoryException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | use daita\MySmallPhpTools\Exceptions\UnknownTypeException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | use daita\MySmallPhpTools\Model\Nextcloud\nc21\NC21TreeNode; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | use daita\MySmallPhpTools\Model\SimpleDataStore; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | use daita\MySmallPhpTools\Traits\Nextcloud\nc21\TNC21ConsoleTree; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | use daita\MySmallPhpTools\Traits\TArrayTools; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | use OC\Core\Command\Base; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | use OCA\Circles\Db\MemberRequest; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | use OCA\Circles\Db\MembershipRequest; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | use OCA\Circles\Exceptions\CircleNotFoundException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | use OCA\Circles\Exceptions\FederatedUserException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | use OCA\Circles\Exceptions\FederatedUserNotFoundException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | use OCA\Circles\Exceptions\MemberNotFoundException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | use OCA\Circles\Exceptions\OwnerNotFoundException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  | use OCA\Circles\Exceptions\RemoteInstanceException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | use OCA\Circles\Exceptions\RemoteNotFoundException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | use OCA\Circles\Exceptions\RemoteResourceNotFoundException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | use OCA\Circles\Exceptions\UnknownRemoteException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  | use OCA\Circles\Exceptions\UserTypeNotFoundException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | use OCA\Circles\Model\Circle; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | use OCA\Circles\Model\FederatedUser; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | use OCA\Circles\Model\Member; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | use OCA\Circles\Service\ConfigService; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | use OCA\Circles\Service\FederatedUserService; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | use OCA\Circles\Service\MembershipService; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | use OCP\IUserManager; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | use Symfony\Component\Console\Input\InputArgument; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | use Symfony\Component\Console\Input\InputInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | use Symfony\Component\Console\Input\InputOption; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | use Symfony\Component\Console\Output\OutputInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |  * Class CirclesMembershipsIndex | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |  * @package OCA\Circles\Command | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 73 |  |  |  */ | 
            
                                                                        
                            
            
                                    
            
            
                | 74 |  |  | class CirclesMemberships extends Base { | 
            
                                                                        
                            
            
                                    
            
            
                | 75 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 76 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 77 |  |  | 	use TArrayTools; | 
            
                                                                        
                            
            
                                    
            
            
                | 78 |  |  | 	use TNC21ConsoleTree; | 
            
                                                                        
                            
            
                                    
            
            
                | 79 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 80 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 81 |  |  | 	/** @var IUserManager */ | 
            
                                                                        
                            
            
                                    
            
            
                | 82 |  |  | 	private $userManager; | 
            
                                                                        
                            
            
                                    
            
            
                | 83 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 84 |  |  | 	/** @var MemberRequest */ | 
            
                                                                        
                            
            
                                    
            
            
                | 85 |  |  | 	private $memberRequest; | 
            
                                                                        
                            
            
                                    
            
            
                | 86 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 87 |  |  | 	/** @var MembershipRequest */ | 
            
                                                                        
                            
            
                                    
            
            
                | 88 |  |  | 	private $membershipRequest; | 
            
                                                                        
                            
            
                                    
            
            
                | 89 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 90 |  |  | 	/** @var FederatedUserService */ | 
            
                                                                        
                            
            
                                    
            
            
                | 91 |  |  | 	private $federatedUserService; | 
            
                                                                        
                            
            
                                    
            
            
                | 92 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 93 |  |  | 	/** @var MembershipService */ | 
            
                                                                        
                            
            
                                    
            
            
                | 94 |  |  | 	private $membershipsService; | 
            
                                                                        
                            
            
                                    
            
            
                | 95 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 96 |  |  | 	/** @var ConfigService */ | 
            
                                                                        
                            
            
                                    
            
            
                | 97 |  |  | 	private $configService; | 
            
                                                                        
                            
            
                                    
            
            
                | 98 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 99 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 100 |  |  | 	/** @var array */ | 
            
                                                                        
                            
            
                                    
            
            
                | 101 |  |  | 	private $memberships = []; | 
            
                                                                        
                            
            
                                    
            
            
                | 102 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 103 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 104 |  |  | 	/** | 
            
                                                                        
                            
            
                                    
            
            
                | 105 |  |  | 	 * CirclesList constructor. | 
            
                                                                        
                            
            
                                    
            
            
                | 106 |  |  | 	 * | 
            
                                                                        
                            
            
                                    
            
            
                | 107 |  |  | 	 * @param IUserManager $userManager | 
            
                                                                        
                            
            
                                    
            
            
                | 108 |  |  | 	 * @param MembershipRequest $membershipRequest | 
            
                                                                        
                            
            
                                    
            
            
                | 109 |  |  | 	 * @param MemberRequest $memberRequest | 
            
                                                                        
                            
            
                                    
            
            
                | 110 |  |  | 	 * @param MembershipService $membershipsService | 
            
                                                                        
                            
            
                                    
            
            
                | 111 |  |  | 	 * @param FederatedUserService $federatedUserService | 
            
                                                                        
                            
            
                                    
            
            
                | 112 |  |  | 	 * @param ConfigService $configService | 
            
                                                                        
                            
            
                                    
            
            
                | 113 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  | 	public function __construct( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  | 		IUserManager $userManager, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  | 		MembershipRequest $membershipRequest, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  | 		MemberRequest $memberRequest, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  | 		MembershipService $membershipsService, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  | 		FederatedUserService $federatedUserService, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  | 		ConfigService $configService | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  | 	) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  | 		parent::__construct(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  | 		$this->userManager = $userManager; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  | 		$this->memberRequest = $memberRequest; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  | 		$this->membershipRequest = $membershipRequest; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  | 		$this->membershipsService = $membershipsService; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  | 		$this->federatedUserService = $federatedUserService; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  | 		$this->configService = $configService; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 129 |  |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 130 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 131 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 132 |  |  | 	/** | 
            
                                                                        
                            
            
                                    
            
            
                | 133 |  |  | 	 * | 
            
                                                                        
                            
            
                                    
            
            
                | 134 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  | 	protected function configure() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  | 		parent::configure(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  | 		$this->setName('circles:memberships') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  | 			 ->setDescription('index and display memberships for local and federated users') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  | 			 ->addArgument('userId', InputArgument::REQUIRED, 'userId to generate memberships') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  | 			 ->addOption( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  | 				 'type', '', InputOption::VALUE_REQUIRED, 'type of the user', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  | 				 Member::$DEF_TYPE[Member::TYPE_USER] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  | 			 ); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 144 |  |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 145 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 146 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 147 |  |  | 	/** | 
            
                                                                        
                            
            
                                    
            
            
                | 148 |  |  | 	 * @param InputInterface $input | 
            
                                                                        
                            
            
                                    
            
            
                | 149 |  |  | 	 * @param OutputInterface $output | 
            
                                                                        
                            
            
                                    
            
            
                | 150 |  |  | 	 * | 
            
                                                                        
                            
            
                                    
            
            
                | 151 |  |  | 	 * @return int | 
            
                                                                        
                            
            
                                    
            
            
                | 152 |  |  | 	 * @throws CircleNotFoundException | 
            
                                                                        
                            
            
                                    
            
            
                | 153 |  |  | 	 * @throws FederatedUserException | 
            
                                                                        
                            
            
                                    
            
            
                | 154 |  |  | 	 * @throws FederatedUserNotFoundException | 
            
                                                                        
                            
            
                                    
            
            
                | 155 |  |  | 	 * @throws InvalidItemException | 
            
                                                                        
                            
            
                                    
            
            
                | 156 |  |  | 	 * @throws MemberNotFoundException | 
            
                                                                        
                            
            
                                    
            
            
                | 157 |  |  | 	 * @throws OwnerNotFoundException | 
            
                                                                        
                            
            
                                    
            
            
                | 158 |  |  | 	 * @throws RemoteInstanceException | 
            
                                                                        
                            
            
                                    
            
            
                | 159 |  |  | 	 * @throws RemoteNotFoundException | 
            
                                                                        
                            
            
                                    
            
            
                | 160 |  |  | 	 * @throws RemoteResourceNotFoundException | 
            
                                                                        
                            
            
                                    
            
            
                | 161 |  |  | 	 * @throws RequestNetworkException | 
            
                                                                        
                            
            
                                    
            
            
                | 162 |  |  | 	 * @throws SignatoryException | 
            
                                                                        
                            
            
                                    
            
            
                | 163 |  |  | 	 * @throws UnknownRemoteException | 
            
                                                                        
                            
            
                                    
            
            
                | 164 |  |  | 	 * @throws UserTypeNotFoundException | 
            
                                                                        
                            
            
                                    
            
            
                | 165 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  | 	protected function execute(InputInterface $input, OutputInterface $output): int { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  | 		$userId = $input->getArgument('userId'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  | 		$type = Member::parseTypeString($input->getOption('type')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  | 		$federatedUser = $this->federatedUserService->getFederatedUser($userId, (int)$type); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  | 		$output->writeln('Id: <info>' . $federatedUser->getUserId() . '</info>'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  | 		$output->writeln('Instance: <info>' . $federatedUser->getInstance() . '</info>'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  | 		$output->writeln('Type: <info>' . Member::$DEF_TYPE[$federatedUser->getUserType()] . '</info>'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  | 		$output->writeln('SingleId: <info>' . $federatedUser->getSingleId() . '</info>'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  | 		$output->writeln(''); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  | 		$output->writeln('Memberships:'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  | 		$count = $this->membershipsService->onMemberUpdate($federatedUser); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  | 		if ($count === 0) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  | 			$output->writeln('(database not updated)'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  | 		} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  | 			$output->writeln('(' . $count . ' entries generated/updated in the database)'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  | 		foreach ($federatedUser->getMemberships() as $membership) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  | 			$this->memberships[$membership->getCircleId()] = $membership; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  | 			$output->writeln( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  | 				'- <info>' . $membership->getCircleId() . '</info> (' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  | 				. Member::$DEF_LEVEL[$membership->getLevel()] . ')' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  | 			); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  | 		$output->writeln(''); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  | 		$tree = new NC21TreeNode(null, new SimpleDataStore(['federatedUser' => $federatedUser])); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  | 		$this->generateTree($federatedUser->getSingleId(), $tree); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  | 		$this->drawTree( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  | 			$tree, [$this, 'displayLeaf'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 |  |  | 			[ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  | 				'height'       => 3, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 |  |  | 				'node-spacing' => 0, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  | 				'item-spacing' => 1, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  | 			] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 207 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 |  |  | 		return 0; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 209 |  |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 210 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 211 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 212 |  |  | 	/** | 
            
                                                                        
                            
            
                                    
            
            
                | 213 |  |  | 	 * @param string $id | 
            
                                                                        
                            
            
                                    
            
            
                | 214 |  |  | 	 * @param NC21TreeNode $tree | 
            
                                                                        
                            
            
                                    
            
            
                | 215 |  |  | 	 * @param array $knownIds | 
            
                                                                        
                            
            
                                    
            
            
                | 216 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 217 |  |  | 	private function generateTree(string $id, NC21TreeNode $tree, array $knownIds = []) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 218 |  |  | 		if (in_array($id, $knownIds)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 219 |  |  | 			return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 220 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 221 |  |  | 		$knownIds[] = $id; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 222 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 223 |  |  | 		$members = $this->memberRequest->getMembersBySingleId($id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 224 |  |  | 		foreach ($members as $member) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 225 |  |  | 			$item = new NC21TreeNode( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 226 |  |  | 				$tree, new SimpleDataStore( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 227 |  |  | 						 [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 228 |  |  | 							 'member'  => $member, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 229 |  |  | 							 'cycling' => in_array($member->getCircleId(), $knownIds) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 230 |  |  | 						 ] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 231 |  |  | 					 ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 232 |  |  | 			); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 233 |  |  | 			$this->generateTree($member->getCircleId(), $item, $knownIds); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 234 |  |  | 		} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 235 |  |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 236 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 237 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 238 |  |  | 	/** | 
            
                                                                        
                            
            
                                    
            
            
                | 239 |  |  | 	 * @param SimpleDataStore $data | 
            
                                                                        
                            
            
                                    
            
            
                | 240 |  |  | 	 * @param int $lineNumber | 
            
                                                                        
                            
            
                                    
            
            
                | 241 |  |  | 	 * | 
            
                                                                        
                            
            
                                    
            
            
                | 242 |  |  | 	 * @return string | 
            
                                                                        
                            
            
                                    
            
            
                | 243 |  |  | 	 * @throws OwnerNotFoundException | 
            
                                                                        
                            
            
                                    
            
            
                | 244 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 245 |  |  | 	public function displayLeaf(SimpleDataStore $data, int $lineNumber): string { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 246 |  |  | 		if ($lineNumber === 3) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 247 |  |  | 			return ($data->gBool('cycling')) ? '<comment>(loop detected)</comment>' : ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 248 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 249 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 250 |  |  | 		try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 251 |  |  | 			$line = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 252 |  |  | 			if ($data->hasKey('federatedUser')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 253 |  |  | 				/** @var FederatedUser $federatedUser */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 254 |  |  | 				$federatedUser = $data->gObj('federatedUser', FederatedUser::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 255 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 256 |  |  | 				if ($lineNumber === 2) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 257 |  |  | 					return ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 258 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 259 |  |  | 				$line .= '<info>' . $federatedUser->getSingleId() . '</info>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 260 |  |  | 				if (!$this->configService->isLocalInstance($federatedUser->getInstance())) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 261 |  |  | 					$line .= '@' . $federatedUser->getInstance(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 262 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 263 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 264 |  |  | 				return $line; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 265 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 266 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 267 |  |  | 			if ($data->hasKey('member')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 268 |  |  | 				/** @var Member $member */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 269 |  |  | 				$member = $data->gObj('member', Member::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 270 |  |  | 				$circle = $member->getCircle(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 271 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 272 |  |  | 				if ($lineNumber === 1) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 273 |  |  | 					$line .= '<info>' . $circle->getId() . '</info>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 274 |  |  | 					if (!$this->configService->isLocalInstance($circle->getInstance())) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 275 |  |  | 						$line .= '@' . $circle->getInstance(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 276 |  |  | 					} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 277 |  |  | 					$line .= ' (' . $circle->getName() . ')'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 278 |  |  | 					$line .= ' <info>Level</info>: ' . Member::$DEF_LEVEL[$member->getLevel()]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 279 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 280 |  |  | 					$knownMembership = $this->memberships[$member->getCircleId()]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 281 |  |  | 					if ($member->getLevel() !== $knownMembership->getLevel()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 282 |  |  | 						$line .= ' (' . Member::$DEF_LEVEL[$knownMembership->getLevel()] . ')'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 283 |  |  | 					} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 284 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 285 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 286 |  |  | 				if ($lineNumber === 2) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 287 |  |  | 					$owner = $circle->getOwner(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 288 |  |  | 					$line .= '<info>Owner</info>: ' . $owner->getUserId() . '@' . $owner->getInstance() . ' '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 289 |  |  | 					$type = implode(", ", Circle::getCircleTypes($circle, Circle::TYPES_LONG)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 290 |  |  | 					$line .= ($type === '') ? '' : '<info>Config</info>: ' . $type; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 291 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 292 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 293 |  |  | 				return $line; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 294 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 295 |  |  | 		} catch (InvalidItemException | ItemNotFoundException | UnknownTypeException $e) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 296 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 297 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 298 |  |  | 		return ''; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 299 |  |  | 	} | 
            
                                                        
            
                                    
            
            
                | 300 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 301 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 302 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 303 |  |  |  |