/**
  * @Route("/add", name="icap_badge_admin_badges_add")
  *
  * @Template()
  */
 public function addAction(Request $request)
 {
     $this->checkOpen();
     $badge = new Badge();
     $locales = $this->get('claroline.manager.locale_manager')->getAvailableLocales();
     foreach ($locales as $locale) {
         $translation = new BadgeTranslation();
         $translation->setLocale($locale);
         $badge->addTranslation($translation);
     }
     /** @var \Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface $sessionFlashBag */
     $sessionFlashBag = $this->get('session')->getFlashBag();
     /** @var \Symfony\Component\Translation\TranslatorInterface $translator */
     $translator = $this->get('translator');
     try {
         if ($this->get('icap_badge.form_handler.badge')->handleAdd($badge)) {
             $sessionFlashBag->add('success', $translator->trans('badge_add_success_message', [], 'icap_badge'));
             return $this->redirect($this->generateUrl('icap_badge_admin_badges'));
         }
     } catch (\Exception $exception) {
         $sessionFlashBag->add('error', $translator->trans('badge_add_error_message', [], 'icap_badge'));
         return $this->redirect($this->generateUrl('icap_badge_admin_badges'));
     }
     return ['form' => $this->get('icap_badge.form.badge')->createView(), 'badge' => $badge];
 }
Beispiel #2
0
 public function __get($name)
 {
     $translationName = 'Translation';
     if (preg_match(sprintf('/%s$/', $translationName), $name)) {
         $searchedLocale = substr($name, 0, -strlen($translationName));
         $translation = $this->getTranslationForLocale($searchedLocale);
         if (null === $translation) {
             $translation = new BadgeTranslation();
             $translation->setLocale($searchedLocale)->setBadge($this);
         }
         return $translation;
     } elseif (preg_match('/Name|Description|Criteria$/', $name, $matches)) {
         //Usefull for badge rule form when wanted frName on a badge
         $searchedLocale = substr($name, 0, -strlen($matches[0]));
         $translation = $this->getTranslationForLocale($searchedLocale);
         if (null !== $translation) {
             return $translation->{'get' . $matches[0]}();
         }
         return;
     }
     $trace = debug_backtrace();
     trigger_error('Undefined property via __get(): ' . $name . ' in ' . $trace[0]['file'] . ' on line ' . $trace[0]['line'], E_USER_NOTICE);
     return;
 }