芝麻web文件管理V1.00
编辑当前文件:/home/mgatv524/cms.mgaplay.com.br/lib/Listener/OnUserDelete/PlaylistListener.php
. */ namespace Xibo\Listener\OnUserDelete; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Xibo\Entity\User; use Xibo\Event\UserDeleteEvent; use Xibo\Factory\ModuleFactory; use Xibo\Factory\PlaylistFactory; use Xibo\Listener\ListenerLoggerTrait; class PlaylistListener implements OnUserDeleteInterface { use ListenerLoggerTrait; /** @var PlaylistFactory */ private $playlistFactory; /** * @var ModuleFactory */ private $moduleFactory; public function __construct(PlaylistFactory $playlistFactory, ModuleFactory $moduleFactory) { $this->playlistFactory = $playlistFactory; $this->moduleFactory = $moduleFactory; } /** * @inheritDoc */ public function __invoke(UserDeleteEvent $event, $eventName, EventDispatcherInterface $dispatcher) { $user = $event->getUser(); $function = $event->getFunction(); $newUser = $event->getNewUser(); $systemUser = $event->getSystemUser(); if ($function === 'delete') { $this->deleteChildren($user, $dispatcher, $systemUser); } elseif ($function === 'reassignAll') { $this->reassignAllTo($user, $newUser, $systemUser); } elseif ($function === 'countChildren') { $event->setReturnValue($event->getReturnValue() + $this->countChildren($user)); } } /** * @inheritDoc */ public function deleteChildren($user, EventDispatcherInterface $dispatcher, User $systemUser) { // Delete Playlists owned by this user foreach ($this->playlistFactory->getByOwnerId($user->userId) as $playlist) { $playlist->setModuleFactory($this->moduleFactory); $playlist->delete(); } } /** * @inheritDoc */ public function reassignAllTo(User $user, User $newUser, User $systemUser) { $this->getLogger()->debug(sprintf('There are %d Playlist children', $this->countChildren($user))); // Reassign playlists and widgets foreach ($this->playlistFactory->getByOwnerId($user->userId) as $playlist) { $playlist->setOwner($newUser->userId); $playlist->save(); } $this->getLogger()->debug(sprintf('Finished reassign Playlist, there are %d children', $this->countChildren($user))); } /** * @inheritDoc */ public function countChildren($user) { $playlists = $this->playlistFactory->getByOwnerId($user->userId); $count = count($playlists); $this->getLogger()->debug(sprintf('Counted Children Playlist on User ID %d, there are %d', $user->userId, $count)); return $count; } }