function testRegister()
 {
     $app = \Bootstrap::getApp();
     $dm = $app['odm.dm'];
     /* @var DocumentManager $dm */
     $post = new Post();
     $post->setContent("content of the post");
     $post->setTitle("title of the post");
     $post->setAuthor("author of the post");
     $post->setCreated(new \DateTime());
     $dm->persist($post);
     $dm->flush();
     $this->assertNotNull($post->getId());
     $count = $dm->getRepository('Entity\\Post')->findAll()->count();
     $this->assertEquals(1, $count);
     $dm->remove($post);
     $dm->flush();
 }
Exemple #2
0
<?php

require_once '../before.php';
use Entity\Post;
if (isset($_POST['submit'])) {
    $post = new Post();
    $post->setSubject($_POST['subject']);
    $post->setMessage($_POST['message']);
    $post->setAuthor($user);
    $entityManager->persist($post);
    $entityManager->flush($post);
}
if (isset($_GET['search'])) {
    $posts = $entityManager->getRepository('Entity\\Post')->searchSubject($_GET['search']);
} else {
    $posts = $entityManager->getRepository('Entity\\Post')->findBy(array(), array('date' => 'DESC'));
}
?>


<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>Les posts</title>
    </head>
    <body>
        <form method="GET" action="post.php">
            <label>
                Rechercher
                <input type="text" name="search"/>
Exemple #3
0
 /**
  * Renvoie une représentation html complête de l'entité
  * Cela comprend un lien vers la publication.
  * @param \Entity\Post $post
  * @param string $prefix pronom utilisé à la place de ceux par défaut (pour le posséssif : votre ...)
  * @return string html
  */
 private function get_accuracy_target_for_like($post, $prefix = null)
 {
     $target = '<a href="' . $post->get_publication_url(true) . '">';
     if (is_null($post->getAlbum()) && is_null($post->getImage())) {
         $target .= is_null($prefix) ? 'la' : $prefix;
         $target .= ' publication</a>';
     } else {
         if (is_null($post->getImage())) {
             $target .= is_null($prefix) ? 'l\'' : $prefix;
             $target .= ' album</a>';
         } else {
             $target .= is_null($prefix) ? 'la' : $prefix;
             $target .= ' photo</a>';
         }
     }
     return $target;
 }