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)); }
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; }
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); } } }
/** * @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); }
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()); } }