/**
  * Serialize data object to id.
  *
  * @param VisitorInterface $visitor
  * @param object           $data
  * @param array            $type
  * @param Context          $context
  *
  * @return int|null
  */
 public function serializeObjectToId(VisitorInterface $visitor, $data, array $type, Context $context)
 {
     $className = $this->manager->getClass();
     if ($data instanceof $className) {
         return $visitor->visitInteger($data->getId(), $type, $context);
     }
     return;
 }
Beispiel #2
0
 /**
  * {@inheritdoc}
  */
 protected function configureFormFields(FormMapper $formMapper)
 {
     if (!$this->isChild()) {
         $formMapper->add('post', 'sonata_type_model_list');
         //            $formMapper->add('post', 'sonata_type_admin', array(), array('edit' => 'inline'));
     }
     $commentClass = $this->commentManager->getClass();
     $formMapper->add('name')->add('email')->add('url', null, array('required' => false))->add('message')->add('status', 'choice', array('choices' => $commentClass::getStatusList(), 'expanded' => true, 'multiple' => false));
 }
Beispiel #3
0
 /**
  * Update the number of comment for a comment
  *
  * @param null|\Sonata\NewsBundle\Model\PostInterface $post
  *
  * @return void
  */
 public function updateCommentsCount(PostInterface $post = null)
 {
     $commentTableName = $this->getObjectManager()->getClassMetadata($this->getClass())->table['name'];
     $postTableName = $this->getObjectManager()->getClassMetadata($this->postManager->getClass())->table['name'];
     $this->getConnection()->beginTransaction();
     $this->getConnection()->query(sprintf('UPDATE %s p SET p.comments_count = 0', $postTableName));
     $this->getConnection()->query(sprintf('UPDATE %s p, (SELECT c.post_id, count(*) as total FROM %s as c WHERE c.status = 1 GROUP BY c.post_id) as count_comment
         SET p.comments_count = count_comment.total
         WHERE p.id = count_comment.post_id', $postTableName, $commentTableName));
     $this->getConnection()->commit();
 }
 /**
  * Update the number of comment for a comment.
  *
  * @param null|\Sonata\NewsBundle\Model\PostInterface $post
  */
 public function updateCommentsCount(PostInterface $post = null)
 {
     $commentTableName = $this->getObjectManager()->getClassMetadata($this->getClass())->table['name'];
     $postTableName = $this->getObjectManager()->getClassMetadata($this->postManager->getClass())->table['name'];
     $this->getConnection()->beginTransaction();
     $this->getConnection()->query($this->getCommentsCountResetQuery($postTableName));
     $this->getConnection()->query($this->getCommentsCountQuery($postTableName, $commentTableName));
     $this->getConnection()->commit();
 }
Beispiel #5
0
 /**
  * {@inheritdoc}
  */
 protected function configureFormFields(FormMapper $formMapper)
 {
     $commentClass = $this->commentManager->getClass();
     $formMapper->with('General')->add('enabled', null, array('required' => false))->add('author', 'sonata_type_model_list')->add('collection', 'sonata_type_model_list', array('required' => false))->add('title')->add('abstract', null, array('attr' => array('class' => 'span6', 'rows' => 5)))->add('content', 'sonata_formatter_type', array('event_dispatcher' => $formMapper->getFormBuilder()->getEventDispatcher(), 'format_field' => 'contentFormatter', 'source_field' => 'rawContent', 'source_field_options' => array('attr' => array('class' => 'span10', 'rows' => 20)), 'target_field' => 'content', 'listener' => true))->end()->with('Tags')->add('tags', 'sonata_type_model', array('required' => false, 'expanded' => true, 'multiple' => true))->end()->with('Options')->add('publicationDateStart')->add('commentsCloseAt')->add('commentsEnabled', null, array('required' => false))->add('commentsDefaultStatus', 'choice', array('choices' => $commentClass::getStatusList(), 'expanded' => true))->end();
 }