Example #1
0
 /**
  * Check if the Layouts by this theme is in used by message.
  * If layout in used, return where and can´t delete the theme.
  *
  * @param GetOperationButtonEvent $event The event.
  *
  * @return void
  */
 public function deleteInformation(GetOperationButtonEvent $event)
 {
     $command = $event->getCommand();
     $environment = $event->getEnvironment();
     $dataDefinition = $environment->getDataDefinition();
     if ($dataDefinition->getName() !== 'orm_avisota_theme' || $command->getName() !== 'delete') {
         return;
     }
     $themeEntity = $event->getModel()->getEntity();
     $layoutCollection = $themeEntity->getLayouts();
     $information = '';
     while ($layoutEntity = $layoutCollection->current()) {
         $currentInformation = $this->getLayoutUsedInformation($layoutEntity, $environment);
         if (!$currentInformation) {
             $layoutCollection->next();
             continue;
         }
         $information .= $currentInformation;
         $layoutCollection->next();
     }
     if (!$information) {
         return;
     }
     $translator = $environment->getTranslator();
     $information = $translator->translate('delete.information.theme', 'MCE') . $information;
     $event->setAttributes('onclick="alert(\'' . $information . '\'); Backend.getScrollOffset(); return false;"');
 }
Example #2
0
 /**
  * Check if the Layout is in used by message.
  * If this in used, return where and can´t delete it.
  *
  * @param GetOperationButtonEvent $event The event.
  *
  * @return void
  */
 public function deleteInformation(GetOperationButtonEvent $event)
 {
     $command = $event->getCommand();
     $environment = $event->getEnvironment();
     $dataDefinition = $environment->getDataDefinition();
     if ($dataDefinition->getName() !== 'orm_avisota_layout' || $command->getName() !== 'delete') {
         return;
     }
     $entity = $event->getModel()->getEntity();
     $dataProvider = $environment->getDataProvider();
     $entityManager = $dataProvider->getEntityManager();
     $repository = $entityManager->getRepository('Avisota\\Contao:Message');
     $messageResult = $repository->findBy(array('layout' => $entity->getId()), array('subject' => 'ASC'));
     if (count($messageResult) < 1) {
         return;
     }
     $translator = $environment->getTranslator();
     $information = $translator->translate('delete.information.layout', 'MCE');
     foreach ($messageResult as $message) {
         $information .= "\\n";
         $information .= $message->getCategory()->getTitle();
         $information .= ' => ';
         $information .= $message->getSubject();
     }
     $event->setAttributes('onclick="alert(\'' . $information . '\'); Backend.getScrollOffset(); return false;"');
 }