/**
  * {@inheritdoc}
  */
 protected function getValue($value)
 {
     if (is_array($value) || $value instanceof \Traversable) {
         $value = null;
     } elseif ($value instanceof \DateTime) {
         $value = $value->format($this->dateTimeFormat);
     } elseif (is_object($value)) {
         $value = (string) $value;
     } elseif (is_bool($value)) {
         $value == true ? $value = $this->translator->trans('label_type_yes', [], 'SonataAdminBundle') : ($value = $this->translator->trans('label_type_no', [], 'SonataAdminBundle'));
     } else {
         $value = $this->translator->trans($value);
     }
     return $value;
 }
 /**
  * Checks logged user is owner of voted post
  * 
  * @param Post $post
  * 
  * @return JsonResponse|RedirectResponse|null
  */
 private function checkOwner(Post $post)
 {
     if ($this->getUser()) {
         if ($post->getAuthor()->getId() == $this->getUser()->getId()) {
             $message = $this->translator->trans('you.can.not.vote.for.your.posts');
             $this->addFlash('danger', $message);
             if ($this->request->isXmlHttpRequest()) {
                 return new JsonResponse(array('result' => false, 'message' => $message));
             }
             return $this->redirect($this->generateUrl('topic_show', array('slug' => $post->getTopic()->getSlug())));
         }
     }
     return null;
 }
 /**
  * Adds Topic to database if form is valid
  * 
  * @param Form  $topicForm
  * @param Topic $topic
  * @param string   $parentSlug
  * 
  * @return RedirectResponse|null
  */
 protected function addTopic(Form $topicForm, Topic $topic, $parentSlug)
 {
     $topicForm->handleRequest($this->request);
     if ($topicForm->isValid()) {
         try {
             $this->getDoctrine()->getManager()->getFilters()->disable('softdeleteable');
             $this->getTopicManager()->update($topic);
             $this->getDoctrine()->getManager()->getFilters()->enable('softdeleteable');
             $this->addFlash('success', $this->translator->trans('topic.has.been.created'));
             return $this->redirect($this->generateUrl('topic_show', array('slug' => $topic->getSlug())));
         } catch (Exception $ex) {
             throw $ex;
             $this->addFlash('danger', $this->translator->trans('topic.has.not.been.created'));
             return $this->redirect($this->generateUrl('forum_index', array('slug' => $parentSlug)));
         }
     }
     return;
 }
 /**
  * Deletes topic by slug
  * 
  * @param string $slug
  * 
  * @return RedirectResponse
  * 
  * @throws Exception
  */
 public function deleteTopicAction($slug)
 {
     $topic = $this->getTopicManager()->findOneBy(array('slug' => $slug));
     if (!$topic) {
         throw $this->createNotFoundException(sprintf('Topic with slug %s does not exists', $slug));
     }
     if (!$this->isLoggedAsAdmin()) {
         $this->denyAccessUnlessGranted('ROLE_FORUM_ADMIN', null, 'Unable to access this page!');
     }
     $parentSlug = $topic->getForum()->getSlug();
     try {
         $this->getTopicManager()->remove($topic);
         $this->addFlash('success', $this->translator->trans('topic.has.been.removed'));
     } catch (Exception $ex) {
         $this->addFlash('danger', $this->translator->trans('topic.has.not.been.removed'));
     }
     return $this->redirect($this->generateUrl('forum_index', array('slug' => $parentSlug)));
 }
 /** Translates a string
  *
  * @param $string
  *
  * @return string
  */
 private function _trans($string)
 {
     return $this->translator->trans($string, array(), 'TrainingScheduleBundle');
 }
Beispiel #6
0
 public function __construct(\Symfony\Component\Translation\DataCollectorTranslator $translator)
 {
     $this->_locale = $translator->getLocale();
     $this->_trad1 = $translator->trans('windsurfdb.matos.form.marque.type_choice.board');
     $this->_trad2 = $translator->trans('windsurfdb.matos.form.marque.type_choice.voile');
 }
 /**
  * @return array Translated week days in array
  */
 public function getWeekNames()
 {
     return array(0 => $this->translator->trans('weekdays.monday', array(), 'TrainingScheduleBundle'), 1 => $this->translator->trans('weekdays.tuesday', array(), 'TrainingScheduleBundle'), 2 => $this->translator->trans('weekdays.wednesday', array(), 'TrainingScheduleBundle'), 3 => $this->translator->trans('weekdays.thursday', array(), 'TrainingScheduleBundle'), 4 => $this->translator->trans('weekdays.friday', array(), 'TrainingScheduleBundle'), 5 => $this->translator->trans('weekdays.saturday', array(), 'TrainingScheduleBundle'), 6 => $this->translator->trans('weekdays.sunday', array(), 'TrainingScheduleBundle'));
 }