Bugfix.
authorhiroto
Tue, 03 Sep 2013 19:08:40 +0900
changeset 16 578281db0b11
parent 15 374dcdd84e6f
child 17 6a0371e8bb51
Bugfix.
autotweet-php/app/config/routing.yml
autotweet-php/src/Org/W3/AutotweetBundle/Controller/DefaultController.php
autotweet-php/src/Org/W3/AutotweetBundle/Entity/PostRepository.php
autotweet-php/src/Org/W3/AutotweetBundle/Entity/Talk.php
autotweet-php/src/Org/W3/AutotweetBundle/Resources/views/Default/post.html.twig
js/w3c_talks.js
--- a/autotweet-php/app/config/routing.yml	Tue Sep 03 18:40:33 2013 +0900
+++ b/autotweet-php/app/config/routing.yml	Tue Sep 03 19:08:40 2013 +0900
@@ -1,5 +1,3 @@
 org_w3_autotweet:
-    resource: "@OrgW3AutotweetBundle/Controller/"
-    type:     annotation
+    resource: "@OrgW3AutotweetBundle/Resources/config/routing.yml"
     prefix:   /
-
--- a/autotweet-php/src/Org/W3/AutotweetBundle/Controller/DefaultController.php	Tue Sep 03 18:40:33 2013 +0900
+++ b/autotweet-php/src/Org/W3/AutotweetBundle/Controller/DefaultController.php	Tue Sep 03 19:08:40 2013 +0900
@@ -20,13 +20,27 @@
     }
     public function postAction(Request $request)
     {
-
+        header("Access-Control-Allow-Origin: *");
         if ($request->getMethod() == 'POST')
         {
-            $this->get('request')->request->get('name');
-            $this->tweet($name);
+            
+        foreach ($this->get('request')->request->all() as $key => $val)
+        {
+            $data[$key]=$val;
         }
-        return $this->render('OrgW3EventRegAdminBundle:Default:onsite_input.html.twig', array('form' => $form->createView(), 'QaireNo' => $QaireNo));
+            $key=$data['key'];
+            $msg=$data['msg'];
+
+            //$key=$this->get('request')->request->get('key');
+            //$msg=$this->get('request')->request->get('msg');
+            $talk = $this->getDoctrine()->getRepository('OrgW3AutotweetBundle:Talk')->findOneBy(array('key'=>$key));
+            $post = $this->getDoctrine()->getRepository('OrgW3AutotweetBundle:Post')->findBy(array('talk' =>$talk, 'content'=>$msg));
+            if(0==count($post)){
+                $newpost = $this->getDoctrine()->getRepository('OrgW3AutotweetBundle:Post')->addnew($talk,$msg);
+                $this->tweet($msg);
+            }
+        }
+        return $this->render('OrgW3AutotweetBundle:Default:post.html.twig', array());
     }
     private function tweet($msg)
     {
--- a/autotweet-php/src/Org/W3/AutotweetBundle/Entity/PostRepository.php	Tue Sep 03 18:40:33 2013 +0900
+++ b/autotweet-php/src/Org/W3/AutotweetBundle/Entity/PostRepository.php	Tue Sep 03 19:08:40 2013 +0900
@@ -12,4 +12,22 @@
  */
 class PostRepository extends EntityRepository
 {
+           public function addNew($talk, $msg)
+    {
+           $em_default = $this->getEntityManager('default'); 
+           //$talk=$em_default->getRepository('OrgW3AutotweetBundle:Talk')->find($talk->getId());
+//echo $attendee->getUuid();
+//exit;
+         
+            $now = new \DateTime('now');
+            $post= new Post();
+            $post->setTalk($talk);
+            $post->setContent($msg);
+            $post->setName('Test');
+            $post->setPostedAt($now);
+            $em_default->persist($post);
+            $em_default->flush();    
+            return $post;
+    }
 }
+
--- a/autotweet-php/src/Org/W3/AutotweetBundle/Entity/Talk.php	Tue Sep 03 18:40:33 2013 +0900
+++ b/autotweet-php/src/Org/W3/AutotweetBundle/Entity/Talk.php	Tue Sep 03 19:08:40 2013 +0900
@@ -36,9 +36,9 @@
     /**
      * @var string
      *
-     * @ORM\Column(name="kay", type="string", length=255)
+     * @ORM\Column(name="key", type="string", length=255)
      */
-    private $kay;
+    private $key;
     
     /**
      * @var string
@@ -173,25 +173,25 @@
     }
 
     /**
-     * Set kay
+     * Set key
      *
-     * @param string $kay
+     * @param string $key
      * @return Talk
      */
-    public function setKay($kay)
+    public function setKey($key)
     {
-        $this->kay = $kay;
+        $this->key = $key;
     
         return $this;
     }
 
     /**
-     * Get kay
+     * Get key
      *
      * @return string 
      */
-    public function getKay()
+    public function getKey()
     {
-        return $this->kay;
+        return $this->key;
     }
 }
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/autotweet-php/src/Org/W3/AutotweetBundle/Resources/views/Default/post.html.twig	Tue Sep 03 19:08:40 2013 +0900
@@ -0,0 +1,1 @@
+OK
\ No newline at end of file
--- a/js/w3c_talks.js	Tue Sep 03 18:40:33 2013 +0900
+++ b/js/w3c_talks.js	Tue Sep 03 19:08:40 2013 +0900
@@ -67,7 +67,7 @@
     }
 
     // Global variables for tweet posting
-    var url = 'http://www.vodstock.com/w3c_talks/w3c_talks.php';
+    var url = 'http://localhost:8888/~hiroto/autotweet/app_dev.php/post';
     var hashtag = getMetaTag('hashtag');
     var author = getMetaTag('author');
     var title = document.title;
@@ -108,7 +108,9 @@
             if (httpRequest.readyState === 4) {
                 if (httpRequest.status !== 200) {
                     console.log('There was a problem with the XHR action.');
-                }
+                }else{
+                    console.log(httpRequest.response);
+		}
             }
         };
         httpRequest.open('POST', url);