コード例 #1
0
 public function diff(Twig_Environment $environment, Terms $terms, Terms $with_terms)
 {
     $view_name = $this->getTermsViewName();
     $terms_content = $environment->render($view_name, array('root' => $terms->getRoot()));
     $with_terms_content = $environment->render($view_name, array('root' => $with_terms->getRoot()));
     $granularity = new Sentence();
     $diff = new Diff($granularity);
     return html_entity_decode($diff->render($terms_content, $with_terms_content, $granularity));
 }
コード例 #2
0
ファイル: Terms.php プロジェクト: coopers-peele/CPTermsBundle
 public function getClone()
 {
     $clone = new Terms();
     $clone->setVersion(sprintf('Cloned from %s on %s', $this->getVersion(), date('Y-m-d H:i:s')));
     $clone->setClonedFrom($this);
     $clone->setClonedAt(new DateTime());
     $section = SectionQuery::create()->findRoot($this->getId());
     $section->getClone($clone);
     return $clone;
 }
コード例 #3
0
 public function validate($value, Constraint $constraint)
 {
     $terms = Terms::getLatest();
     if ($terms->getId() !== $value) {
         if ($this->context instanceof ExecutionContextInterface) {
             $this->context->buildViolation($constraint->message)->addViolation();
         } else {
             // 2.4 API
             $this->context->addViolation($constraint->message);
         }
     }
 }
コード例 #4
0
 /**
  * @Route("/diff", name="cp_terms_diff")
  * @Template()
  */
 public function diffAction(Request $request)
 {
     if ($this->container->has('cp_terms.entity_finder')) {
         $entity_finder = $this->container->get('cp_terms.entity_finder');
         $entity = $entity_finder->findEntity();
     } else {
         throw $this->createNotFoundException('Page not found.');
     }
     $terms_last_agreed = $entity->getLastAgreedTerms();
     $terms_latest = Terms::getLatest();
     if (!$terms_last_agreed || $terms_last_agreed == $terms_latest) {
         // users don't get here unless direct url to this page is entered
         return $this->redirect($this->generateUrl('cp_terms'));
     }
     $theme = $this->container->getParameter('cp_terms.diff.theme');
     return array('terms' => $terms_last_agreed, 'terms_latest' => $terms_latest, 'theme' => $theme);
 }
コード例 #5
0
 protected function createLabel(Terms $terms)
 {
     $translator = $this->getTranslator();
     if ($terms->isFinal()) {
         $formatter = new IntlDateFormatter($this->getLocale(), IntlDateFormatter::LONG, IntlDateFormatter::LONG);
         $formatter->setPattern($this->getDateFormat());
         $finalized_at = $formatter->format($terms->getFinalizedAt(null));
         return $translator->trans('form.type.terms_choice.final.label', array('%version%' => $terms->getVersion(), '%finalized_at%' => $finalized_at), 'CPTermsBundle', $this->getLocale());
     } else {
         return $translator->trans('form.type.terms_choice.drafts.label', array('%version%' => $terms->getVersion()), 'CPTermsBundle', $this->getLocale());
     }
 }