@@ -7,35 +7,35 @@ |
||
| 7 | 7 | |
| 8 | 8 | class AdminCommentsController extends Controller |
| 9 | 9 | { |
| 10 | - private function gEm() |
|
| 11 | - { |
|
| 12 | - return $this->getDoctrine()->getManager(); |
|
| 13 | - } |
|
| 10 | + private function gEm() |
|
| 11 | + { |
|
| 12 | + return $this->getDoctrine()->getManager(); |
|
| 13 | + } |
|
| 14 | 14 | |
| 15 | - public function deleteWithChildrenAction($model, $model_id, $comment_id, Request $request) |
|
| 16 | - { |
|
| 17 | - $manager = $this->get('mykees.comment.query.manager'); |
|
| 18 | - $comments = $manager->findCommentsByModelAndId($model, $model_id,true); |
|
| 19 | - $children_ids = $manager->getChildren($comments[$comment_id]); |
|
| 15 | + public function deleteWithChildrenAction($model, $model_id, $comment_id, Request $request) |
|
| 16 | + { |
|
| 17 | + $manager = $this->get('mykees.comment.query.manager'); |
|
| 18 | + $comments = $manager->findCommentsByModelAndId($model, $model_id,true); |
|
| 19 | + $children_ids = $manager->getChildren($comments[$comment_id]); |
|
| 20 | 20 | |
| 21 | - array_push($children_ids,$comment_id); |
|
| 21 | + array_push($children_ids,$comment_id); |
|
| 22 | 22 | |
| 23 | - $manager->deleteByCommentIds($children_ids); |
|
| 23 | + $manager->deleteByCommentIds($children_ids); |
|
| 24 | 24 | |
| 25 | - return $this->redirect($request->headers->get('referer')); |
|
| 26 | - } |
|
| 25 | + return $this->redirect($request->headers->get('referer')); |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | 28 | |
| 29 | - public function deleteAction($id, Request $request) |
|
| 30 | - { |
|
| 31 | - $class = $this->container->getParameter('mykees_comment.comment.class'); |
|
| 32 | - $explose_class = explode('\\',$class); |
|
| 33 | - $repository = $explose_class[0].$explose_class[1].':'.$explose_class[3]; |
|
| 34 | - $comment = $this->gEm()->getRepository($repository)->find($id); |
|
| 29 | + public function deleteAction($id, Request $request) |
|
| 30 | + { |
|
| 31 | + $class = $this->container->getParameter('mykees_comment.comment.class'); |
|
| 32 | + $explose_class = explode('\\',$class); |
|
| 33 | + $repository = $explose_class[0].$explose_class[1].':'.$explose_class[3]; |
|
| 34 | + $comment = $this->gEm()->getRepository($repository)->find($id); |
|
| 35 | 35 | |
| 36 | - $this->gEm()->remove($comment); |
|
| 37 | - $this->gEm()->flush(); |
|
| 36 | + $this->gEm()->remove($comment); |
|
| 37 | + $this->gEm()->flush(); |
|
| 38 | 38 | |
| 39 | - return $this->redirect($request->headers->get('referer')); |
|
| 40 | - } |
|
| 39 | + return $this->redirect($request->headers->get('referer')); |
|
| 40 | + } |
|
| 41 | 41 | } |
@@ -8,249 +8,249 @@ |
||
| 8 | 8 | |
| 9 | 9 | class CommentsController extends Controller |
| 10 | 10 | { |
| 11 | - private function gEm() |
|
| 12 | - { |
|
| 13 | - return $this->getDoctrine()->getManager(); |
|
| 14 | - } |
|
| 15 | - |
|
| 16 | - /** |
|
| 17 | - * Manage comment process |
|
| 18 | - * @param Request $request |
|
| 19 | - * @return \Symfony\Component\HttpFoundation\RedirectResponse |
|
| 20 | - * @internal param $bundle |
|
| 21 | - * @internal param $ref |
|
| 22 | - * @internal param $ref_id |
|
| 23 | - */ |
|
| 24 | - public function manageAction(Request $request) |
|
| 25 | - { |
|
| 26 | - $params = [ |
|
| 27 | - 'manager'=>$this->get('mykees.comment.manager'), |
|
| 28 | - 'session'=>$request->getSession(), |
|
| 29 | - 'ref' => $request->request->get('model') ? $request->request->get('model') : $request->request->get('mykees_comment')['model'], |
|
| 30 | - 'ref_id' => $request->request->get('modelId') ? $request->request->get('modelId') : $request->request->get('mykees_comment')['modelId'] |
|
| 31 | - ]; |
|
| 32 | - |
|
| 33 | - $comment_class_name = $this->container->getParameter('mykees_comment.comment.class'); |
|
| 34 | - $comment_class = new $comment_class_name(); |
|
| 35 | - $form = $this->createForm($this->get('mykees.comment.form'),$comment_class); |
|
| 36 | - |
|
| 37 | - if('POST' == $request->getMethod()) { |
|
| 38 | - |
|
| 39 | - if ($form->handleRequest($request)->isValid()) { |
|
| 40 | - |
|
| 41 | - if($request->isXmlHttpRequest()) { |
|
| 42 | - return $this->ajaxInfo($params,$request,$comment_class); |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - $this->postInfo($params, $request, $comment_class, $params['session']); |
|
| 46 | - |
|
| 47 | - }else{ |
|
| 48 | - |
|
| 49 | - if($request->isXmlHttpRequest()) { |
|
| 50 | - return $this->returnAjaxErrors($form); |
|
| 51 | - }else{ |
|
| 52 | - $this->error($request, $params['session']); |
|
| 53 | - } |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - return $this->redirect($request->headers->get('referer') . '#comments_area'); |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @param $params |
|
| 63 | - * @param $request |
|
| 64 | - * @param $comment_class |
|
| 65 | - * @return Response |
|
| 66 | - */ |
|
| 67 | - private function ajaxInfo($params,$request,$comment_class) |
|
| 68 | - { |
|
| 69 | - |
|
| 70 | - $comment = $this->postInfo($params, $request, $comment_class, $params['session']); |
|
| 71 | - $comment_depth = $this->container->getParameter('comment.depth'); |
|
| 72 | - |
|
| 73 | - // Si la profondeur du commentaire parent est inférieure ou égale à la profondeur définis |
|
| 74 | - if($request->request->get('depth') < $comment_depth && $comment_depth >= 1) |
|
| 75 | - { |
|
| 76 | - $comment->setDepthReached($request->request->get('depth') + 1);//On incremente la profondeur max |
|
| 77 | - $comment->setDepth($comment->getId()); //la profondeur de réponse est égale a l'id |
|
| 78 | - $max_depth = false; |
|
| 79 | - }else{ |
|
| 80 | - $comment->setDepthReached($request->request->get('depth'));//On à atteint la profondeur max |
|
| 81 | - $comment->setDepth($comment->getParentId());//la profondeur de réponse est éagle au commentaire parent |
|
| 82 | - $max_depth = true; |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - $template = $this->renderResponse($comment,$request,$max_depth); |
|
| 86 | - $json = json_encode([ |
|
| 87 | - 'template'=>$template, |
|
| 88 | - "parent_id"=>$comment->getParentId(), |
|
| 89 | - 'comment_id'=>$comment->getId(), |
|
| 90 | - 'max_depth'=>$max_depth, |
|
| 91 | - 'success_message'=>$this->get('session')->getFlashBag()->get('comment_success') |
|
| 92 | - ]); |
|
| 93 | - |
|
| 94 | - return new Response($json); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * Return a template |
|
| 99 | - * @param $comment |
|
| 100 | - * @param $request |
|
| 101 | - * @param $max_depth |
|
| 102 | - * @return string |
|
| 103 | - */ |
|
| 104 | - private function renderResponse($comment,$request,$max_depth) |
|
| 105 | - { |
|
| 106 | - if($comment->getParentId() > 0) |
|
| 107 | - { |
|
| 108 | - if( ($request->request->get('response_type') === "true" && $max_depth === true) || |
|
| 109 | - ($request->request->get('response_type') === "false" && $max_depth === true) || |
|
| 110 | - ($request->request->get('response_type') === "true" && $max_depth === false) |
|
| 111 | - ){ |
|
| 112 | - return $this->renderView('MykeesCommentBundle:Comments:unwrap_replies.html.twig',['comment'=>$comment,'recent_reply'=>true]); |
|
| 113 | - }else{ |
|
| 114 | - return $this->renderView('MykeesCommentBundle:Comments:replies.html.twig',['comment'=>$comment,'recent_reply'=>true]); |
|
| 115 | - } |
|
| 116 | - }else{ |
|
| 117 | - return $this->renderView('MykeesCommentBundle:Comments:comment.html.twig',['comment'=>$comment,'recent_reply'=>true]); |
|
| 118 | - } |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * Init/save comment and user info |
|
| 124 | - * @param $request |
|
| 125 | - * @param $comment |
|
| 126 | - * @param $params |
|
| 127 | - * @param $session |
|
| 128 | - * @return |
|
| 129 | - */ |
|
| 130 | - private function postInfo($params, $request, $comment, $session) |
|
| 131 | - { |
|
| 132 | - $this->userInfo($request, $comment); |
|
| 133 | - $this->commentInfo($params,$comment,$request,$params['ref_id']); |
|
| 134 | - |
|
| 135 | - $this->save($comment); |
|
| 136 | - $this->messageFlash($session); |
|
| 137 | - |
|
| 138 | - return $comment; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * Save comment entity |
|
| 143 | - * @param $comment |
|
| 144 | - */ |
|
| 145 | - private function save($comment) |
|
| 146 | - { |
|
| 147 | - $this->gEm()->persist($comment); |
|
| 148 | - $this->gEm()->flush(); |
|
| 149 | - |
|
| 150 | - return $comment; |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * Init comment info |
|
| 155 | - * @param $params |
|
| 156 | - * @param $comment |
|
| 157 | - * @param $request |
|
| 158 | - * @param $ref_id |
|
| 159 | - * @return mixed |
|
| 160 | - */ |
|
| 161 | - private function commentInfo($params,$comment,$request,$ref_id) |
|
| 162 | - { |
|
| 163 | - $comment->setIp($request->getClientIp()); |
|
| 164 | - $comment->setModel($params['ref']); |
|
| 165 | - $comment->setModelId($ref_id); |
|
| 166 | - //Spam ? |
|
| 167 | - $akismet = $this->container->hasParameter('akismet') ? $this->container->getParameter('akismet') : null; |
|
| 168 | - $params['manager']->isSpam($comment,$request,$akismet) ? $comment->setSpam(1) : $comment->setSpam(0); |
|
| 169 | - |
|
| 170 | - return $comment; |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * Init user info |
|
| 175 | - * @param $request |
|
| 176 | - * @param $comment |
|
| 177 | - * @return boo|\Symfony\Component\HttpFoundation\RedirectResponse |
|
| 178 | - */ |
|
| 179 | - private function userInfo($request, $comment) |
|
| 180 | - { |
|
| 181 | - $is_join = method_exists($comment,'getUser') ? true : false; |
|
| 182 | - |
|
| 183 | - if($this->getUser() !== null) |
|
| 184 | - { |
|
| 185 | - if($this->getUser()->getUsername() != $comment->getUsername() || $this->getUser()->getEmail() != $comment->getEmail()) |
|
| 186 | - { |
|
| 187 | - return $this->redirect($request->headers->get('referer') . '#comments_area'); |
|
| 188 | - } |
|
| 189 | - if($is_join) |
|
| 190 | - { |
|
| 191 | - $comment->setUser($this->getUser()); |
|
| 192 | - } |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - return true; |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - /** |
|
| 199 | - * Init message flash |
|
| 200 | - * @param $session |
|
| 201 | - * @return bool |
|
| 202 | - */ |
|
| 203 | - private function messageFlash($session) |
|
| 204 | - { |
|
| 205 | - $html = $session->has('success_message') ? $session->get('success_message') : "<strong>Merci!</strong> Votre message à bien été posté."; |
|
| 206 | - if($this->get('session')->getFlashBag()->has('comment_success')) |
|
| 207 | - { |
|
| 208 | - $this->get('session')->getFlashBag()->set('comment_success',''); |
|
| 209 | - } |
|
| 210 | - $this->get('session')->getFlashBag()->add('comment_success',$html); |
|
| 211 | - |
|
| 212 | - return true; |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * @param $request |
|
| 217 | - * @param $session |
|
| 218 | - */ |
|
| 219 | - private function error($request, $session) |
|
| 220 | - { |
|
| 221 | - $requestData = $request->request->get('mykees_comment'); |
|
| 222 | - if(!empty($requestData)) |
|
| 223 | - { |
|
| 224 | - $session->set('form_comment_data',$request->request->get('mykees_comment')); |
|
| 225 | - } |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - /** |
|
| 229 | - * Get errors form for ajax |
|
| 230 | - * @param $form |
|
| 231 | - * @return array |
|
| 232 | - */ |
|
| 233 | - protected function getErrorsAsArray($form) |
|
| 234 | - { |
|
| 235 | - $errors = array(); |
|
| 236 | - foreach ($form->getErrors() as $error) |
|
| 237 | - $errors[] = $error->getMessage(); |
|
| 238 | - |
|
| 239 | - foreach ($form->all() as $key => $child) { |
|
| 240 | - if ($err = $this->getErrorsAsArray($child)) |
|
| 241 | - $errors[$key] = $err; |
|
| 242 | - } |
|
| 243 | - return $errors; |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - /** |
|
| 247 | - * Error message for Ajax |
|
| 248 | - * @param $form |
|
| 249 | - * @return Response |
|
| 250 | - */ |
|
| 251 | - private function returnAjaxErrors($form) |
|
| 252 | - { |
|
| 253 | - $json = json_encode(['error'=>'error','error_fields'=>$this->getErrorsAsArray($form)]); |
|
| 254 | - return new Response($json); |
|
| 255 | - } |
|
| 11 | + private function gEm() |
|
| 12 | + { |
|
| 13 | + return $this->getDoctrine()->getManager(); |
|
| 14 | + } |
|
| 15 | + |
|
| 16 | + /** |
|
| 17 | + * Manage comment process |
|
| 18 | + * @param Request $request |
|
| 19 | + * @return \Symfony\Component\HttpFoundation\RedirectResponse |
|
| 20 | + * @internal param $bundle |
|
| 21 | + * @internal param $ref |
|
| 22 | + * @internal param $ref_id |
|
| 23 | + */ |
|
| 24 | + public function manageAction(Request $request) |
|
| 25 | + { |
|
| 26 | + $params = [ |
|
| 27 | + 'manager'=>$this->get('mykees.comment.manager'), |
|
| 28 | + 'session'=>$request->getSession(), |
|
| 29 | + 'ref' => $request->request->get('model') ? $request->request->get('model') : $request->request->get('mykees_comment')['model'], |
|
| 30 | + 'ref_id' => $request->request->get('modelId') ? $request->request->get('modelId') : $request->request->get('mykees_comment')['modelId'] |
|
| 31 | + ]; |
|
| 32 | + |
|
| 33 | + $comment_class_name = $this->container->getParameter('mykees_comment.comment.class'); |
|
| 34 | + $comment_class = new $comment_class_name(); |
|
| 35 | + $form = $this->createForm($this->get('mykees.comment.form'),$comment_class); |
|
| 36 | + |
|
| 37 | + if('POST' == $request->getMethod()) { |
|
| 38 | + |
|
| 39 | + if ($form->handleRequest($request)->isValid()) { |
|
| 40 | + |
|
| 41 | + if($request->isXmlHttpRequest()) { |
|
| 42 | + return $this->ajaxInfo($params,$request,$comment_class); |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + $this->postInfo($params, $request, $comment_class, $params['session']); |
|
| 46 | + |
|
| 47 | + }else{ |
|
| 48 | + |
|
| 49 | + if($request->isXmlHttpRequest()) { |
|
| 50 | + return $this->returnAjaxErrors($form); |
|
| 51 | + }else{ |
|
| 52 | + $this->error($request, $params['session']); |
|
| 53 | + } |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + return $this->redirect($request->headers->get('referer') . '#comments_area'); |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @param $params |
|
| 63 | + * @param $request |
|
| 64 | + * @param $comment_class |
|
| 65 | + * @return Response |
|
| 66 | + */ |
|
| 67 | + private function ajaxInfo($params,$request,$comment_class) |
|
| 68 | + { |
|
| 69 | + |
|
| 70 | + $comment = $this->postInfo($params, $request, $comment_class, $params['session']); |
|
| 71 | + $comment_depth = $this->container->getParameter('comment.depth'); |
|
| 72 | + |
|
| 73 | + // Si la profondeur du commentaire parent est inférieure ou égale à la profondeur définis |
|
| 74 | + if($request->request->get('depth') < $comment_depth && $comment_depth >= 1) |
|
| 75 | + { |
|
| 76 | + $comment->setDepthReached($request->request->get('depth') + 1);//On incremente la profondeur max |
|
| 77 | + $comment->setDepth($comment->getId()); //la profondeur de réponse est égale a l'id |
|
| 78 | + $max_depth = false; |
|
| 79 | + }else{ |
|
| 80 | + $comment->setDepthReached($request->request->get('depth'));//On à atteint la profondeur max |
|
| 81 | + $comment->setDepth($comment->getParentId());//la profondeur de réponse est éagle au commentaire parent |
|
| 82 | + $max_depth = true; |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + $template = $this->renderResponse($comment,$request,$max_depth); |
|
| 86 | + $json = json_encode([ |
|
| 87 | + 'template'=>$template, |
|
| 88 | + "parent_id"=>$comment->getParentId(), |
|
| 89 | + 'comment_id'=>$comment->getId(), |
|
| 90 | + 'max_depth'=>$max_depth, |
|
| 91 | + 'success_message'=>$this->get('session')->getFlashBag()->get('comment_success') |
|
| 92 | + ]); |
|
| 93 | + |
|
| 94 | + return new Response($json); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * Return a template |
|
| 99 | + * @param $comment |
|
| 100 | + * @param $request |
|
| 101 | + * @param $max_depth |
|
| 102 | + * @return string |
|
| 103 | + */ |
|
| 104 | + private function renderResponse($comment,$request,$max_depth) |
|
| 105 | + { |
|
| 106 | + if($comment->getParentId() > 0) |
|
| 107 | + { |
|
| 108 | + if( ($request->request->get('response_type') === "true" && $max_depth === true) || |
|
| 109 | + ($request->request->get('response_type') === "false" && $max_depth === true) || |
|
| 110 | + ($request->request->get('response_type') === "true" && $max_depth === false) |
|
| 111 | + ){ |
|
| 112 | + return $this->renderView('MykeesCommentBundle:Comments:unwrap_replies.html.twig',['comment'=>$comment,'recent_reply'=>true]); |
|
| 113 | + }else{ |
|
| 114 | + return $this->renderView('MykeesCommentBundle:Comments:replies.html.twig',['comment'=>$comment,'recent_reply'=>true]); |
|
| 115 | + } |
|
| 116 | + }else{ |
|
| 117 | + return $this->renderView('MykeesCommentBundle:Comments:comment.html.twig',['comment'=>$comment,'recent_reply'=>true]); |
|
| 118 | + } |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * Init/save comment and user info |
|
| 124 | + * @param $request |
|
| 125 | + * @param $comment |
|
| 126 | + * @param $params |
|
| 127 | + * @param $session |
|
| 128 | + * @return |
|
| 129 | + */ |
|
| 130 | + private function postInfo($params, $request, $comment, $session) |
|
| 131 | + { |
|
| 132 | + $this->userInfo($request, $comment); |
|
| 133 | + $this->commentInfo($params,$comment,$request,$params['ref_id']); |
|
| 134 | + |
|
| 135 | + $this->save($comment); |
|
| 136 | + $this->messageFlash($session); |
|
| 137 | + |
|
| 138 | + return $comment; |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * Save comment entity |
|
| 143 | + * @param $comment |
|
| 144 | + */ |
|
| 145 | + private function save($comment) |
|
| 146 | + { |
|
| 147 | + $this->gEm()->persist($comment); |
|
| 148 | + $this->gEm()->flush(); |
|
| 149 | + |
|
| 150 | + return $comment; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * Init comment info |
|
| 155 | + * @param $params |
|
| 156 | + * @param $comment |
|
| 157 | + * @param $request |
|
| 158 | + * @param $ref_id |
|
| 159 | + * @return mixed |
|
| 160 | + */ |
|
| 161 | + private function commentInfo($params,$comment,$request,$ref_id) |
|
| 162 | + { |
|
| 163 | + $comment->setIp($request->getClientIp()); |
|
| 164 | + $comment->setModel($params['ref']); |
|
| 165 | + $comment->setModelId($ref_id); |
|
| 166 | + //Spam ? |
|
| 167 | + $akismet = $this->container->hasParameter('akismet') ? $this->container->getParameter('akismet') : null; |
|
| 168 | + $params['manager']->isSpam($comment,$request,$akismet) ? $comment->setSpam(1) : $comment->setSpam(0); |
|
| 169 | + |
|
| 170 | + return $comment; |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * Init user info |
|
| 175 | + * @param $request |
|
| 176 | + * @param $comment |
|
| 177 | + * @return boo|\Symfony\Component\HttpFoundation\RedirectResponse |
|
| 178 | + */ |
|
| 179 | + private function userInfo($request, $comment) |
|
| 180 | + { |
|
| 181 | + $is_join = method_exists($comment,'getUser') ? true : false; |
|
| 182 | + |
|
| 183 | + if($this->getUser() !== null) |
|
| 184 | + { |
|
| 185 | + if($this->getUser()->getUsername() != $comment->getUsername() || $this->getUser()->getEmail() != $comment->getEmail()) |
|
| 186 | + { |
|
| 187 | + return $this->redirect($request->headers->get('referer') . '#comments_area'); |
|
| 188 | + } |
|
| 189 | + if($is_join) |
|
| 190 | + { |
|
| 191 | + $comment->setUser($this->getUser()); |
|
| 192 | + } |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + return true; |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + /** |
|
| 199 | + * Init message flash |
|
| 200 | + * @param $session |
|
| 201 | + * @return bool |
|
| 202 | + */ |
|
| 203 | + private function messageFlash($session) |
|
| 204 | + { |
|
| 205 | + $html = $session->has('success_message') ? $session->get('success_message') : "<strong>Merci!</strong> Votre message à bien été posté."; |
|
| 206 | + if($this->get('session')->getFlashBag()->has('comment_success')) |
|
| 207 | + { |
|
| 208 | + $this->get('session')->getFlashBag()->set('comment_success',''); |
|
| 209 | + } |
|
| 210 | + $this->get('session')->getFlashBag()->add('comment_success',$html); |
|
| 211 | + |
|
| 212 | + return true; |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * @param $request |
|
| 217 | + * @param $session |
|
| 218 | + */ |
|
| 219 | + private function error($request, $session) |
|
| 220 | + { |
|
| 221 | + $requestData = $request->request->get('mykees_comment'); |
|
| 222 | + if(!empty($requestData)) |
|
| 223 | + { |
|
| 224 | + $session->set('form_comment_data',$request->request->get('mykees_comment')); |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + /** |
|
| 229 | + * Get errors form for ajax |
|
| 230 | + * @param $form |
|
| 231 | + * @return array |
|
| 232 | + */ |
|
| 233 | + protected function getErrorsAsArray($form) |
|
| 234 | + { |
|
| 235 | + $errors = array(); |
|
| 236 | + foreach ($form->getErrors() as $error) |
|
| 237 | + $errors[] = $error->getMessage(); |
|
| 238 | + |
|
| 239 | + foreach ($form->all() as $key => $child) { |
|
| 240 | + if ($err = $this->getErrorsAsArray($child)) |
|
| 241 | + $errors[$key] = $err; |
|
| 242 | + } |
|
| 243 | + return $errors; |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + /** |
|
| 247 | + * Error message for Ajax |
|
| 248 | + * @param $form |
|
| 249 | + * @return Response |
|
| 250 | + */ |
|
| 251 | + private function returnAjaxErrors($form) |
|
| 252 | + { |
|
| 253 | + $json = json_encode(['error'=>'error','error_fields'=>$this->getErrorsAsArray($form)]); |
|
| 254 | + return new Response($json); |
|
| 255 | + } |
|
| 256 | 256 | } |
@@ -44,11 +44,11 @@ discard block |
||
| 44 | 44 | |
| 45 | 45 | $this->postInfo($params, $request, $comment_class, $params['session']); |
| 46 | 46 | |
| 47 | - }else{ |
|
| 47 | + } else{ |
|
| 48 | 48 | |
| 49 | 49 | if($request->isXmlHttpRequest()) { |
| 50 | 50 | return $this->returnAjaxErrors($form); |
| 51 | - }else{ |
|
| 51 | + } else{ |
|
| 52 | 52 | $this->error($request, $params['session']); |
| 53 | 53 | } |
| 54 | 54 | } |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | $comment->setDepthReached($request->request->get('depth') + 1);//On incremente la profondeur max |
| 77 | 77 | $comment->setDepth($comment->getId()); //la profondeur de réponse est égale a l'id |
| 78 | 78 | $max_depth = false; |
| 79 | - }else{ |
|
| 79 | + } else{ |
|
| 80 | 80 | $comment->setDepthReached($request->request->get('depth'));//On à atteint la profondeur max |
| 81 | 81 | $comment->setDepth($comment->getParentId());//la profondeur de réponse est éagle au commentaire parent |
| 82 | 82 | $max_depth = true; |
@@ -110,10 +110,10 @@ discard block |
||
| 110 | 110 | ($request->request->get('response_type') === "true" && $max_depth === false) |
| 111 | 111 | ){ |
| 112 | 112 | return $this->renderView('MykeesCommentBundle:Comments:unwrap_replies.html.twig',['comment'=>$comment,'recent_reply'=>true]); |
| 113 | - }else{ |
|
| 113 | + } else{ |
|
| 114 | 114 | return $this->renderView('MykeesCommentBundle:Comments:replies.html.twig',['comment'=>$comment,'recent_reply'=>true]); |
| 115 | 115 | } |
| 116 | - }else{ |
|
| 116 | + } else{ |
|
| 117 | 117 | return $this->renderView('MykeesCommentBundle:Comments:comment.html.twig',['comment'=>$comment,'recent_reply'=>true]); |
| 118 | 118 | } |
| 119 | 119 | } |
@@ -233,12 +233,14 @@ discard block |
||
| 233 | 233 | protected function getErrorsAsArray($form) |
| 234 | 234 | { |
| 235 | 235 | $errors = array(); |
| 236 | - foreach ($form->getErrors() as $error) |
|
| 237 | - $errors[] = $error->getMessage(); |
|
| 236 | + foreach ($form->getErrors() as $error) { |
|
| 237 | + $errors[] = $error->getMessage(); |
|
| 238 | + } |
|
| 238 | 239 | |
| 239 | 240 | foreach ($form->all() as $key => $child) { |
| 240 | - if ($err = $this->getErrorsAsArray($child)) |
|
| 241 | - $errors[$key] = $err; |
|
| 241 | + if ($err = $this->getErrorsAsArray($child)) { |
|
| 242 | + $errors[$key] = $err; |
|
| 243 | + } |
|
| 242 | 244 | } |
| 243 | 245 | return $errors; |
| 244 | 246 | } |
@@ -1,10 +1,10 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Created by PhpStorm. |
|
| 4 | - * User: Rafidion Michael |
|
| 5 | - * Date: 10/09/2015 |
|
| 6 | - * Time: 00:23 |
|
| 7 | - */ |
|
| 3 | + * Created by PhpStorm. |
|
| 4 | + * User: Rafidion Michael |
|
| 5 | + * Date: 10/09/2015 |
|
| 6 | + * Time: 00:23 |
|
| 7 | + */ |
|
| 8 | 8 | |
| 9 | 9 | namespace Mykees\CommentBundle\DataFixtures\ORM; |
| 10 | 10 | |
@@ -15,51 +15,51 @@ discard block |
||
| 15 | 15 | |
| 16 | 16 | class LoadCommentData implements FixtureInterface,ContainerAwareInterface{ |
| 17 | 17 | |
| 18 | - public $container; |
|
| 18 | + public $container; |
|
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * Sets the Container. |
|
| 22 | - * |
|
| 23 | - * @param ContainerInterface|null $container A ContainerInterface instance or null |
|
| 24 | - * |
|
| 25 | - * @api |
|
| 26 | - */ |
|
| 27 | - public function setContainer(ContainerInterface $container = null) |
|
| 28 | - { |
|
| 29 | - $this->container = $container; |
|
| 30 | - } |
|
| 20 | + /** |
|
| 21 | + * Sets the Container. |
|
| 22 | + * |
|
| 23 | + * @param ContainerInterface|null $container A ContainerInterface instance or null |
|
| 24 | + * |
|
| 25 | + * @api |
|
| 26 | + */ |
|
| 27 | + public function setContainer(ContainerInterface $container = null) |
|
| 28 | + { |
|
| 29 | + $this->container = $container; |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * Load data fixtures with the passed EntityManager |
|
| 34 | - * |
|
| 35 | - * @param ObjectManager $manager |
|
| 36 | - */ |
|
| 37 | - public function load(ObjectManager $manager) |
|
| 38 | - { |
|
| 39 | - $comment_class = $this->container->getParameter('mykees_comment.comment.class'); |
|
| 32 | + /** |
|
| 33 | + * Load data fixtures with the passed EntityManager |
|
| 34 | + * |
|
| 35 | + * @param ObjectManager $manager |
|
| 36 | + */ |
|
| 37 | + public function load(ObjectManager $manager) |
|
| 38 | + { |
|
| 39 | + $comment_class = $this->container->getParameter('mykees_comment.comment.class'); |
|
| 40 | 40 | |
| 41 | - for($i=1; $i<=5 ;$i++) |
|
| 42 | - { |
|
| 43 | - $comment = new $comment_class(); |
|
| 44 | - $comment->setUsername('admin'.$i); |
|
| 45 | - $comment->setEmail("admin-{$i}@gmail.com"); |
|
| 46 | - $comment->setContent('contenu n-'.$i); |
|
| 47 | - $comment->setCreatedAt(new \DateTime()); |
|
| 48 | - $comment->setModel('Post'); |
|
| 49 | - if($i <= 3) |
|
| 50 | - { |
|
| 51 | - $comment->setModelId(1); |
|
| 52 | - }else{ |
|
| 53 | - $comment->setModelId($i); |
|
| 54 | - } |
|
| 55 | - $comment->setParentId(0); |
|
| 56 | - $comment->setSpam(0); |
|
| 57 | - $comment->setIp("192.168.56.1"); |
|
| 58 | - $comment->setDepth(0); |
|
| 59 | - $comment->setDepthReached(0); |
|
| 41 | + for($i=1; $i<=5 ;$i++) |
|
| 42 | + { |
|
| 43 | + $comment = new $comment_class(); |
|
| 44 | + $comment->setUsername('admin'.$i); |
|
| 45 | + $comment->setEmail("admin-{$i}@gmail.com"); |
|
| 46 | + $comment->setContent('contenu n-'.$i); |
|
| 47 | + $comment->setCreatedAt(new \DateTime()); |
|
| 48 | + $comment->setModel('Post'); |
|
| 49 | + if($i <= 3) |
|
| 50 | + { |
|
| 51 | + $comment->setModelId(1); |
|
| 52 | + }else{ |
|
| 53 | + $comment->setModelId($i); |
|
| 54 | + } |
|
| 55 | + $comment->setParentId(0); |
|
| 56 | + $comment->setSpam(0); |
|
| 57 | + $comment->setIp("192.168.56.1"); |
|
| 58 | + $comment->setDepth(0); |
|
| 59 | + $comment->setDepthReached(0); |
|
| 60 | 60 | |
| 61 | - $manager->persist($comment); |
|
| 62 | - $manager->flush(); |
|
| 63 | - } |
|
| 64 | - } |
|
| 61 | + $manager->persist($comment); |
|
| 62 | + $manager->flush(); |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | 65 | } |
| 66 | 66 | \ No newline at end of file |
@@ -49,7 +49,7 @@ |
||
| 49 | 49 | if($i <= 3) |
| 50 | 50 | { |
| 51 | 51 | $comment->setModelId(1); |
| 52 | - }else{ |
|
| 52 | + } else{ |
|
| 53 | 53 | $comment->setModelId($i); |
| 54 | 54 | } |
| 55 | 55 | $comment->setParentId(0); |
@@ -20,19 +20,19 @@ |
||
| 20 | 20 | $treeBuilder = new TreeBuilder(); |
| 21 | 21 | $rootNode = $treeBuilder->root('mykees_comment'); |
| 22 | 22 | |
| 23 | - $rootNode |
|
| 24 | - ->children() |
|
| 25 | - ->scalarNode('comment_class')->isRequired()->cannotBeEmpty()->end() |
|
| 26 | - ->scalarNode('depth')->end() |
|
| 27 | - ->arrayNode('akismet') |
|
| 28 | - ->children() |
|
| 29 | - ->scalarNode('api_key')->end() |
|
| 30 | - ->scalarNode('website')->end() |
|
| 31 | - ->end() |
|
| 32 | - ->end() |
|
| 33 | - ->scalarNode('success_message')->end() |
|
| 34 | - ->end() |
|
| 35 | - ; |
|
| 23 | + $rootNode |
|
| 24 | + ->children() |
|
| 25 | + ->scalarNode('comment_class')->isRequired()->cannotBeEmpty()->end() |
|
| 26 | + ->scalarNode('depth')->end() |
|
| 27 | + ->arrayNode('akismet') |
|
| 28 | + ->children() |
|
| 29 | + ->scalarNode('api_key')->end() |
|
| 30 | + ->scalarNode('website')->end() |
|
| 31 | + ->end() |
|
| 32 | + ->end() |
|
| 33 | + ->scalarNode('success_message')->end() |
|
| 34 | + ->end() |
|
| 35 | + ; |
|
| 36 | 36 | |
| 37 | 37 | return $treeBuilder; |
| 38 | 38 | } |
@@ -23,10 +23,10 @@ |
||
| 23 | 23 | $config = $this->processConfiguration($configuration, $configs); |
| 24 | 24 | |
| 25 | 25 | |
| 26 | - $container->setParameter("mykees_comment.comment.class", isset($config["comment_class"]) ? $config["comment_class"] : null); |
|
| 27 | - $container->setParameter('success_message', !empty($config['success_message']) ? $config['success_message'] : null); |
|
| 28 | - $container->setParameter('akismet', !empty($config['akismet']) ? $config['akismet'] : ''); |
|
| 29 | - $container->setParameter('comment.depth', !empty($config['depth']) ? $config['depth'] : 0); |
|
| 26 | + $container->setParameter("mykees_comment.comment.class", isset($config["comment_class"]) ? $config["comment_class"] : null); |
|
| 27 | + $container->setParameter('success_message', !empty($config['success_message']) ? $config['success_message'] : null); |
|
| 28 | + $container->setParameter('akismet', !empty($config['akismet']) ? $config['akismet'] : ''); |
|
| 29 | + $container->setParameter('comment.depth', !empty($config['depth']) ? $config['depth'] : 0); |
|
| 30 | 30 | |
| 31 | 31 | $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
| 32 | 32 | $loader->load('services.yml'); |
@@ -11,342 +11,342 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | abstract class Comment implements Commentable |
| 13 | 13 | { |
| 14 | - /** |
|
| 15 | - * @var string |
|
| 16 | - * |
|
| 17 | - * @ORM\Column(name="username", type="string", length=100) |
|
| 18 | - * @Assert\NotBlank(message="Vous devez entre un Nom") |
|
| 19 | - */ |
|
| 20 | - private $username; |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * @var string |
|
| 24 | - * |
|
| 25 | - * @ORM\Column(name="email", type="string", length=255) |
|
| 26 | - * @Assert\Email(message="L'Email n'est pas valid") |
|
| 27 | - * @Assert\NotBlank(message="Vous devez préciser un Email.") |
|
| 28 | - */ |
|
| 29 | - private $email; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @var string |
|
| 33 | - * |
|
| 34 | - * @ORM\Column(name="content", type="text") |
|
| 35 | - * @Assert\NotBlank(message="Vous devez entrer un Message.") |
|
| 36 | - */ |
|
| 37 | - private $content; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * @var \DateTime |
|
| 41 | - * |
|
| 42 | - * @ORM\Column(name="created_at", type="datetime") |
|
| 43 | - * @Assert\DateTime() |
|
| 44 | - */ |
|
| 45 | - private $createdAt; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * @var string |
|
| 49 | - * |
|
| 50 | - * @ORM\Column(name="model", type="string", length=60) |
|
| 51 | - */ |
|
| 52 | - private $model; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * @var integer |
|
| 56 | - * |
|
| 57 | - * @ORM\Column(name="model_id", type="integer") |
|
| 58 | - */ |
|
| 59 | - private $modelId; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @var integer |
|
| 63 | - * |
|
| 64 | - * @ORM\Column(name="parent_id", type="integer") |
|
| 65 | - */ |
|
| 66 | - private $parentId; |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * @var boolean |
|
| 70 | - * |
|
| 71 | - * @ORM\Column(name="spam", type="boolean") |
|
| 72 | - */ |
|
| 73 | - private $spam; |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * @var string |
|
| 77 | - * |
|
| 78 | - * @ORM\Column(name="ip", type="string", length=255) |
|
| 79 | - */ |
|
| 80 | - private $ip; |
|
| 81 | - |
|
| 82 | - private $depth = 0; |
|
| 83 | - |
|
| 84 | - private $depthReached; |
|
| 85 | - |
|
| 86 | - |
|
| 87 | - private $children = []; |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * @ORM\PrePersist |
|
| 91 | - */ |
|
| 92 | - public function updateDate() |
|
| 93 | - { |
|
| 94 | - $this->setCreatedAt(new \DateTime()); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * Set username |
|
| 99 | - * |
|
| 100 | - * @param string $username |
|
| 101 | - * @return Comment |
|
| 102 | - */ |
|
| 103 | - public function setUsername($username) |
|
| 104 | - { |
|
| 105 | - $this->username = $username; |
|
| 106 | - |
|
| 107 | - return $this; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * Get username |
|
| 112 | - * |
|
| 113 | - * @return string |
|
| 114 | - */ |
|
| 115 | - public function getUsername() |
|
| 116 | - { |
|
| 117 | - return $this->username; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * Set email |
|
| 122 | - * |
|
| 123 | - * @param string $email |
|
| 124 | - * @return Comment |
|
| 125 | - */ |
|
| 126 | - public function setEmail($email) |
|
| 127 | - { |
|
| 128 | - $this->email = $email; |
|
| 129 | - |
|
| 130 | - return $this; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * Get email |
|
| 135 | - * |
|
| 136 | - * @return string |
|
| 137 | - */ |
|
| 138 | - public function getEmail() |
|
| 139 | - { |
|
| 140 | - return $this->email; |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * Set content |
|
| 145 | - * |
|
| 146 | - * @param string $content |
|
| 147 | - * @return Comment |
|
| 148 | - */ |
|
| 149 | - public function setContent($content) |
|
| 150 | - { |
|
| 151 | - $this->content = $content; |
|
| 152 | - |
|
| 153 | - return $this; |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * Get content |
|
| 158 | - * |
|
| 159 | - * @return string |
|
| 160 | - */ |
|
| 161 | - public function getContent() |
|
| 162 | - { |
|
| 163 | - return $this->content; |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * Set createdAt |
|
| 168 | - * |
|
| 169 | - * @param \DateTime $createdAt |
|
| 170 | - * @return Comment |
|
| 171 | - */ |
|
| 172 | - public function setCreatedAt($createdAt) |
|
| 173 | - { |
|
| 174 | - $this->createdAt = $createdAt; |
|
| 175 | - |
|
| 176 | - return $this; |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - /** |
|
| 180 | - * Get createdAt |
|
| 181 | - * |
|
| 182 | - * @return \DateTime |
|
| 183 | - */ |
|
| 184 | - public function getCreatedAt() |
|
| 185 | - { |
|
| 186 | - return $this->createdAt; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * Set model |
|
| 191 | - * |
|
| 192 | - * @param string $model |
|
| 193 | - * @return Comment |
|
| 194 | - */ |
|
| 195 | - public function setModel($model) |
|
| 196 | - { |
|
| 197 | - $this->model = $model; |
|
| 198 | - |
|
| 199 | - return $this; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * Get model |
|
| 204 | - * |
|
| 205 | - * @return string |
|
| 206 | - */ |
|
| 207 | - public function getModel() |
|
| 208 | - { |
|
| 209 | - return $this->model; |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * Set modelId |
|
| 214 | - * |
|
| 215 | - * @param integer $modelId |
|
| 216 | - * @return Comment |
|
| 217 | - */ |
|
| 218 | - public function setModelId($modelId) |
|
| 219 | - { |
|
| 220 | - $this->modelId = $modelId; |
|
| 221 | - |
|
| 222 | - return $this; |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - /** |
|
| 226 | - * Get modelId |
|
| 227 | - * |
|
| 228 | - * @return integer |
|
| 229 | - */ |
|
| 230 | - public function getModelId() |
|
| 231 | - { |
|
| 232 | - return $this->modelId; |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - /** |
|
| 236 | - * Set parentId |
|
| 237 | - * |
|
| 238 | - * @param integer $parentId |
|
| 239 | - * @return Comment |
|
| 240 | - */ |
|
| 241 | - public function setParentId($parentId) |
|
| 242 | - { |
|
| 243 | - $this->parentId = $parentId; |
|
| 244 | - |
|
| 245 | - return $this; |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - /** |
|
| 249 | - * Get parentId |
|
| 250 | - * |
|
| 251 | - * @return integer |
|
| 252 | - */ |
|
| 253 | - public function getParentId() |
|
| 254 | - { |
|
| 255 | - return $this->parentId; |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - /** |
|
| 259 | - * Set spam |
|
| 260 | - * |
|
| 261 | - * @param boolean $spam |
|
| 262 | - * @return Comment |
|
| 263 | - */ |
|
| 264 | - public function setSpam($spam) |
|
| 265 | - { |
|
| 266 | - $this->spam = $spam; |
|
| 267 | - |
|
| 268 | - return $this; |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - /** |
|
| 272 | - * Get spam |
|
| 273 | - * |
|
| 274 | - * @return boolean |
|
| 275 | - */ |
|
| 276 | - public function getSpam() |
|
| 277 | - { |
|
| 278 | - return $this->spam; |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - /** |
|
| 282 | - * Set ip |
|
| 283 | - * |
|
| 284 | - * @param string $ip |
|
| 285 | - * @return Comment |
|
| 286 | - */ |
|
| 287 | - public function setIp($ip) |
|
| 288 | - { |
|
| 289 | - $this->ip = $ip; |
|
| 290 | - |
|
| 291 | - return $this; |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - /** |
|
| 295 | - * Get ip |
|
| 296 | - * |
|
| 297 | - * @return string |
|
| 298 | - */ |
|
| 299 | - public function getIp() |
|
| 300 | - { |
|
| 301 | - return $this->ip; |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - /** |
|
| 305 | - * @return mixed |
|
| 306 | - */ |
|
| 307 | - public function getChildren() |
|
| 308 | - { |
|
| 309 | - return $this->children; |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - /** |
|
| 313 | - * @param mixed $children |
|
| 314 | - */ |
|
| 315 | - public function setChildren(Comment $children) |
|
| 316 | - { |
|
| 317 | - array_unshift($this->children,$children); |
|
| 318 | - } |
|
| 319 | - |
|
| 320 | - /** |
|
| 321 | - * @return int |
|
| 322 | - */ |
|
| 323 | - public function getDepth() |
|
| 324 | - { |
|
| 325 | - return $this->depth; |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - /** |
|
| 329 | - * @param int $depth |
|
| 330 | - */ |
|
| 331 | - public function setDepth($depth) |
|
| 332 | - { |
|
| 333 | - $this->depth = $depth; |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - /** |
|
| 337 | - * @return mixed |
|
| 338 | - */ |
|
| 339 | - public function getDepthReached() |
|
| 340 | - { |
|
| 341 | - return $this->depthReached; |
|
| 342 | - } |
|
| 343 | - |
|
| 344 | - /** |
|
| 345 | - * @param mixed $depthReached |
|
| 346 | - */ |
|
| 347 | - public function setDepthReached($depthReached) |
|
| 348 | - { |
|
| 349 | - $this->depthReached = $depthReached; |
|
| 350 | - } |
|
| 14 | + /** |
|
| 15 | + * @var string |
|
| 16 | + * |
|
| 17 | + * @ORM\Column(name="username", type="string", length=100) |
|
| 18 | + * @Assert\NotBlank(message="Vous devez entre un Nom") |
|
| 19 | + */ |
|
| 20 | + private $username; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * @var string |
|
| 24 | + * |
|
| 25 | + * @ORM\Column(name="email", type="string", length=255) |
|
| 26 | + * @Assert\Email(message="L'Email n'est pas valid") |
|
| 27 | + * @Assert\NotBlank(message="Vous devez préciser un Email.") |
|
| 28 | + */ |
|
| 29 | + private $email; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @var string |
|
| 33 | + * |
|
| 34 | + * @ORM\Column(name="content", type="text") |
|
| 35 | + * @Assert\NotBlank(message="Vous devez entrer un Message.") |
|
| 36 | + */ |
|
| 37 | + private $content; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * @var \DateTime |
|
| 41 | + * |
|
| 42 | + * @ORM\Column(name="created_at", type="datetime") |
|
| 43 | + * @Assert\DateTime() |
|
| 44 | + */ |
|
| 45 | + private $createdAt; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * @var string |
|
| 49 | + * |
|
| 50 | + * @ORM\Column(name="model", type="string", length=60) |
|
| 51 | + */ |
|
| 52 | + private $model; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * @var integer |
|
| 56 | + * |
|
| 57 | + * @ORM\Column(name="model_id", type="integer") |
|
| 58 | + */ |
|
| 59 | + private $modelId; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @var integer |
|
| 63 | + * |
|
| 64 | + * @ORM\Column(name="parent_id", type="integer") |
|
| 65 | + */ |
|
| 66 | + private $parentId; |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * @var boolean |
|
| 70 | + * |
|
| 71 | + * @ORM\Column(name="spam", type="boolean") |
|
| 72 | + */ |
|
| 73 | + private $spam; |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * @var string |
|
| 77 | + * |
|
| 78 | + * @ORM\Column(name="ip", type="string", length=255) |
|
| 79 | + */ |
|
| 80 | + private $ip; |
|
| 81 | + |
|
| 82 | + private $depth = 0; |
|
| 83 | + |
|
| 84 | + private $depthReached; |
|
| 85 | + |
|
| 86 | + |
|
| 87 | + private $children = []; |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * @ORM\PrePersist |
|
| 91 | + */ |
|
| 92 | + public function updateDate() |
|
| 93 | + { |
|
| 94 | + $this->setCreatedAt(new \DateTime()); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * Set username |
|
| 99 | + * |
|
| 100 | + * @param string $username |
|
| 101 | + * @return Comment |
|
| 102 | + */ |
|
| 103 | + public function setUsername($username) |
|
| 104 | + { |
|
| 105 | + $this->username = $username; |
|
| 106 | + |
|
| 107 | + return $this; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * Get username |
|
| 112 | + * |
|
| 113 | + * @return string |
|
| 114 | + */ |
|
| 115 | + public function getUsername() |
|
| 116 | + { |
|
| 117 | + return $this->username; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * Set email |
|
| 122 | + * |
|
| 123 | + * @param string $email |
|
| 124 | + * @return Comment |
|
| 125 | + */ |
|
| 126 | + public function setEmail($email) |
|
| 127 | + { |
|
| 128 | + $this->email = $email; |
|
| 129 | + |
|
| 130 | + return $this; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * Get email |
|
| 135 | + * |
|
| 136 | + * @return string |
|
| 137 | + */ |
|
| 138 | + public function getEmail() |
|
| 139 | + { |
|
| 140 | + return $this->email; |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * Set content |
|
| 145 | + * |
|
| 146 | + * @param string $content |
|
| 147 | + * @return Comment |
|
| 148 | + */ |
|
| 149 | + public function setContent($content) |
|
| 150 | + { |
|
| 151 | + $this->content = $content; |
|
| 152 | + |
|
| 153 | + return $this; |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * Get content |
|
| 158 | + * |
|
| 159 | + * @return string |
|
| 160 | + */ |
|
| 161 | + public function getContent() |
|
| 162 | + { |
|
| 163 | + return $this->content; |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * Set createdAt |
|
| 168 | + * |
|
| 169 | + * @param \DateTime $createdAt |
|
| 170 | + * @return Comment |
|
| 171 | + */ |
|
| 172 | + public function setCreatedAt($createdAt) |
|
| 173 | + { |
|
| 174 | + $this->createdAt = $createdAt; |
|
| 175 | + |
|
| 176 | + return $this; |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + /** |
|
| 180 | + * Get createdAt |
|
| 181 | + * |
|
| 182 | + * @return \DateTime |
|
| 183 | + */ |
|
| 184 | + public function getCreatedAt() |
|
| 185 | + { |
|
| 186 | + return $this->createdAt; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * Set model |
|
| 191 | + * |
|
| 192 | + * @param string $model |
|
| 193 | + * @return Comment |
|
| 194 | + */ |
|
| 195 | + public function setModel($model) |
|
| 196 | + { |
|
| 197 | + $this->model = $model; |
|
| 198 | + |
|
| 199 | + return $this; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * Get model |
|
| 204 | + * |
|
| 205 | + * @return string |
|
| 206 | + */ |
|
| 207 | + public function getModel() |
|
| 208 | + { |
|
| 209 | + return $this->model; |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * Set modelId |
|
| 214 | + * |
|
| 215 | + * @param integer $modelId |
|
| 216 | + * @return Comment |
|
| 217 | + */ |
|
| 218 | + public function setModelId($modelId) |
|
| 219 | + { |
|
| 220 | + $this->modelId = $modelId; |
|
| 221 | + |
|
| 222 | + return $this; |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + /** |
|
| 226 | + * Get modelId |
|
| 227 | + * |
|
| 228 | + * @return integer |
|
| 229 | + */ |
|
| 230 | + public function getModelId() |
|
| 231 | + { |
|
| 232 | + return $this->modelId; |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + /** |
|
| 236 | + * Set parentId |
|
| 237 | + * |
|
| 238 | + * @param integer $parentId |
|
| 239 | + * @return Comment |
|
| 240 | + */ |
|
| 241 | + public function setParentId($parentId) |
|
| 242 | + { |
|
| 243 | + $this->parentId = $parentId; |
|
| 244 | + |
|
| 245 | + return $this; |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + /** |
|
| 249 | + * Get parentId |
|
| 250 | + * |
|
| 251 | + * @return integer |
|
| 252 | + */ |
|
| 253 | + public function getParentId() |
|
| 254 | + { |
|
| 255 | + return $this->parentId; |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + /** |
|
| 259 | + * Set spam |
|
| 260 | + * |
|
| 261 | + * @param boolean $spam |
|
| 262 | + * @return Comment |
|
| 263 | + */ |
|
| 264 | + public function setSpam($spam) |
|
| 265 | + { |
|
| 266 | + $this->spam = $spam; |
|
| 267 | + |
|
| 268 | + return $this; |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + /** |
|
| 272 | + * Get spam |
|
| 273 | + * |
|
| 274 | + * @return boolean |
|
| 275 | + */ |
|
| 276 | + public function getSpam() |
|
| 277 | + { |
|
| 278 | + return $this->spam; |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + /** |
|
| 282 | + * Set ip |
|
| 283 | + * |
|
| 284 | + * @param string $ip |
|
| 285 | + * @return Comment |
|
| 286 | + */ |
|
| 287 | + public function setIp($ip) |
|
| 288 | + { |
|
| 289 | + $this->ip = $ip; |
|
| 290 | + |
|
| 291 | + return $this; |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + /** |
|
| 295 | + * Get ip |
|
| 296 | + * |
|
| 297 | + * @return string |
|
| 298 | + */ |
|
| 299 | + public function getIp() |
|
| 300 | + { |
|
| 301 | + return $this->ip; |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + /** |
|
| 305 | + * @return mixed |
|
| 306 | + */ |
|
| 307 | + public function getChildren() |
|
| 308 | + { |
|
| 309 | + return $this->children; |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + /** |
|
| 313 | + * @param mixed $children |
|
| 314 | + */ |
|
| 315 | + public function setChildren(Comment $children) |
|
| 316 | + { |
|
| 317 | + array_unshift($this->children,$children); |
|
| 318 | + } |
|
| 319 | + |
|
| 320 | + /** |
|
| 321 | + * @return int |
|
| 322 | + */ |
|
| 323 | + public function getDepth() |
|
| 324 | + { |
|
| 325 | + return $this->depth; |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + /** |
|
| 329 | + * @param int $depth |
|
| 330 | + */ |
|
| 331 | + public function setDepth($depth) |
|
| 332 | + { |
|
| 333 | + $this->depth = $depth; |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + /** |
|
| 337 | + * @return mixed |
|
| 338 | + */ |
|
| 339 | + public function getDepthReached() |
|
| 340 | + { |
|
| 341 | + return $this->depthReached; |
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + /** |
|
| 345 | + * @param mixed $depthReached |
|
| 346 | + */ |
|
| 347 | + public function setDepthReached($depthReached) |
|
| 348 | + { |
|
| 349 | + $this->depthReached = $depthReached; |
|
| 350 | + } |
|
| 351 | 351 | |
| 352 | 352 | } |
@@ -14,50 +14,50 @@ |
||
| 14 | 14 | |
| 15 | 15 | class CommentFormEditType extends AbstractType { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * @param FormBuilderInterface $builder |
|
| 19 | - * @param array $options |
|
| 20 | - */ |
|
| 21 | - public function buildForm(FormBuilderInterface $builder, array $options) |
|
| 22 | - { |
|
| 23 | - $builder |
|
| 24 | - ->add('username') |
|
| 25 | - ->add('email') |
|
| 26 | - ->add('content') |
|
| 27 | - ->add('model',"text",[ |
|
| 28 | - 'required'=>false |
|
| 29 | - ]) |
|
| 30 | - ->add('modelId',"text",[ |
|
| 31 | - 'required'=>false |
|
| 32 | - ]) |
|
| 33 | - ->add('parentId',"text",[ |
|
| 34 | - 'required'=>false |
|
| 35 | - ]) |
|
| 36 | - ->add('spam',"text",[ |
|
| 37 | - 'required'=>false, |
|
| 38 | - 'data'=>0 |
|
| 39 | - ]) |
|
| 40 | - ->add('ip',"text",[ |
|
| 41 | - 'required'=>false |
|
| 42 | - ]) |
|
| 43 | - ; |
|
| 44 | - } |
|
| 17 | + /** |
|
| 18 | + * @param FormBuilderInterface $builder |
|
| 19 | + * @param array $options |
|
| 20 | + */ |
|
| 21 | + public function buildForm(FormBuilderInterface $builder, array $options) |
|
| 22 | + { |
|
| 23 | + $builder |
|
| 24 | + ->add('username') |
|
| 25 | + ->add('email') |
|
| 26 | + ->add('content') |
|
| 27 | + ->add('model',"text",[ |
|
| 28 | + 'required'=>false |
|
| 29 | + ]) |
|
| 30 | + ->add('modelId',"text",[ |
|
| 31 | + 'required'=>false |
|
| 32 | + ]) |
|
| 33 | + ->add('parentId',"text",[ |
|
| 34 | + 'required'=>false |
|
| 35 | + ]) |
|
| 36 | + ->add('spam',"text",[ |
|
| 37 | + 'required'=>false, |
|
| 38 | + 'data'=>0 |
|
| 39 | + ]) |
|
| 40 | + ->add('ip',"text",[ |
|
| 41 | + 'required'=>false |
|
| 42 | + ]) |
|
| 43 | + ; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * @param OptionsResolverInterface $resolver |
|
| 48 | - */ |
|
| 49 | - public function setDefaultOptions(OptionsResolverInterface $resolver) |
|
| 50 | - { |
|
| 51 | - $resolver->setDefaults(array( |
|
| 52 | - 'data_class' => 'Mykees\CommentBundle\Entity\Comment' |
|
| 53 | - )); |
|
| 54 | - } |
|
| 46 | + /** |
|
| 47 | + * @param OptionsResolverInterface $resolver |
|
| 48 | + */ |
|
| 49 | + public function setDefaultOptions(OptionsResolverInterface $resolver) |
|
| 50 | + { |
|
| 51 | + $resolver->setDefaults(array( |
|
| 52 | + 'data_class' => 'Mykees\CommentBundle\Entity\Comment' |
|
| 53 | + )); |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * @return string |
|
| 58 | - */ |
|
| 59 | - public function getName() |
|
| 60 | - { |
|
| 61 | - return 'mykees_comment_edit'; |
|
| 62 | - } |
|
| 56 | + /** |
|
| 57 | + * @return string |
|
| 58 | + */ |
|
| 59 | + public function getName() |
|
| 60 | + { |
|
| 61 | + return 'mykees_comment_edit'; |
|
| 62 | + } |
|
| 63 | 63 | } |
@@ -10,53 +10,53 @@ |
||
| 10 | 10 | class CommentFormType extends AbstractType |
| 11 | 11 | { |
| 12 | 12 | |
| 13 | - protected $tokenStorage; |
|
| 14 | - public $user; |
|
| 15 | - public $username; |
|
| 16 | - public $email; |
|
| 17 | - public $content; |
|
| 13 | + protected $tokenStorage; |
|
| 14 | + public $user; |
|
| 15 | + public $username; |
|
| 16 | + public $email; |
|
| 17 | + public $content; |
|
| 18 | 18 | |
| 19 | - public function __construct(TokenStorageInterface $tokenStorage) |
|
| 20 | - { |
|
| 21 | - $this->tokenStorage = $tokenStorage->getToken(); |
|
| 22 | - $this->user = method_exists($this->tokenStorage,'getUser') ? $this->tokenStorage->getUser() : array(); |
|
| 23 | - } |
|
| 19 | + public function __construct(TokenStorageInterface $tokenStorage) |
|
| 20 | + { |
|
| 21 | + $this->tokenStorage = $tokenStorage->getToken(); |
|
| 22 | + $this->user = method_exists($this->tokenStorage,'getUser') ? $this->tokenStorage->getUser() : array(); |
|
| 23 | + } |
|
| 24 | 24 | /** |
| 25 | 25 | * @param FormBuilderInterface $builder |
| 26 | 26 | * @param array $options |
| 27 | 27 | */ |
| 28 | 28 | public function buildForm(FormBuilderInterface $builder, array $options) |
| 29 | 29 | { |
| 30 | - if(empty($this->user) || $this->user == 'anon.') |
|
| 31 | - { |
|
| 32 | - $builder |
|
| 33 | - ->add('username','text',[ |
|
| 34 | - 'label'=> $this->username |
|
| 35 | - ]) |
|
| 36 | - ->add('email','text',[ |
|
| 37 | - 'label'=> $this->email |
|
| 38 | - ]) |
|
| 39 | - ->add('content','textarea',[ |
|
| 40 | - 'label'=> $this->content |
|
| 41 | - ]) |
|
| 42 | - ->add('parentId','hidden',['data'=>0]) |
|
| 43 | - ->add('model','hidden') |
|
| 44 | - ->add('modelId','hidden') |
|
| 45 | - ; |
|
| 46 | - }else{ |
|
| 47 | - $builder |
|
| 48 | - ->add('username','hidden',[ |
|
| 49 | - 'data'=>$this->user->getUsername() |
|
| 50 | - ]) |
|
| 51 | - ->add('email','hidden',[ |
|
| 52 | - 'data'=>$this->user->getEmail() |
|
| 53 | - ]) |
|
| 54 | - ->add('content') |
|
| 55 | - ->add('parentId','hidden',['data'=>0]) |
|
| 56 | - ->add('model','hidden') |
|
| 57 | - ->add('modelId','hidden') |
|
| 58 | - ; |
|
| 59 | - } |
|
| 30 | + if(empty($this->user) || $this->user == 'anon.') |
|
| 31 | + { |
|
| 32 | + $builder |
|
| 33 | + ->add('username','text',[ |
|
| 34 | + 'label'=> $this->username |
|
| 35 | + ]) |
|
| 36 | + ->add('email','text',[ |
|
| 37 | + 'label'=> $this->email |
|
| 38 | + ]) |
|
| 39 | + ->add('content','textarea',[ |
|
| 40 | + 'label'=> $this->content |
|
| 41 | + ]) |
|
| 42 | + ->add('parentId','hidden',['data'=>0]) |
|
| 43 | + ->add('model','hidden') |
|
| 44 | + ->add('modelId','hidden') |
|
| 45 | + ; |
|
| 46 | + }else{ |
|
| 47 | + $builder |
|
| 48 | + ->add('username','hidden',[ |
|
| 49 | + 'data'=>$this->user->getUsername() |
|
| 50 | + ]) |
|
| 51 | + ->add('email','hidden',[ |
|
| 52 | + 'data'=>$this->user->getEmail() |
|
| 53 | + ]) |
|
| 54 | + ->add('content') |
|
| 55 | + ->add('parentId','hidden',['data'=>0]) |
|
| 56 | + ->add('model','hidden') |
|
| 57 | + ->add('modelId','hidden') |
|
| 58 | + ; |
|
| 59 | + } |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | /** |
@@ -43,7 +43,7 @@ |
||
| 43 | 43 | ->add('model','hidden') |
| 44 | 44 | ->add('modelId','hidden') |
| 45 | 45 | ; |
| 46 | - }else{ |
|
| 46 | + } else{ |
|
| 47 | 47 | $builder |
| 48 | 48 | ->add('username','hidden',[ |
| 49 | 49 | 'data'=>$this->user->getUsername() |
@@ -1,42 +1,42 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Created by PhpStorm. |
|
| 4 | - * User: Rafidion Michael |
|
| 5 | - * Date: 03/09/2015 |
|
| 6 | - * Time: 10:33 |
|
| 7 | - */ |
|
| 3 | + * Created by PhpStorm. |
|
| 4 | + * User: Rafidion Michael |
|
| 5 | + * Date: 03/09/2015 |
|
| 6 | + * Time: 10:33 |
|
| 7 | + */ |
|
| 8 | 8 | |
| 9 | 9 | namespace Mykees\CommentBundle\Interfaces; |
| 10 | 10 | |
| 11 | 11 | |
| 12 | 12 | interface Commentable { |
| 13 | 13 | |
| 14 | - public function setUsername($username); |
|
| 14 | + public function setUsername($username); |
|
| 15 | 15 | |
| 16 | - public function getUsername(); |
|
| 16 | + public function getUsername(); |
|
| 17 | 17 | |
| 18 | - public function setEmail($email); |
|
| 18 | + public function setEmail($email); |
|
| 19 | 19 | |
| 20 | - public function getEmail(); |
|
| 20 | + public function getEmail(); |
|
| 21 | 21 | |
| 22 | - public function setContent($content); |
|
| 22 | + public function setContent($content); |
|
| 23 | 23 | |
| 24 | - public function getContent(); |
|
| 24 | + public function getContent(); |
|
| 25 | 25 | |
| 26 | - public function setCreatedAt($createdAt); |
|
| 26 | + public function setCreatedAt($createdAt); |
|
| 27 | 27 | |
| 28 | - public function getCreatedAt(); |
|
| 28 | + public function getCreatedAt(); |
|
| 29 | 29 | |
| 30 | - public function setModel($model); |
|
| 30 | + public function setModel($model); |
|
| 31 | 31 | |
| 32 | - public function getModel(); |
|
| 32 | + public function getModel(); |
|
| 33 | 33 | |
| 34 | - public function setModelId($modelId); |
|
| 34 | + public function setModelId($modelId); |
|
| 35 | 35 | |
| 36 | - public function getModelId(); |
|
| 36 | + public function getModelId(); |
|
| 37 | 37 | |
| 38 | - public function setParentId($parentId); |
|
| 38 | + public function setParentId($parentId); |
|
| 39 | 39 | |
| 40 | - public function getParentId(); |
|
| 40 | + public function getParentId(); |
|
| 41 | 41 | |
| 42 | 42 | } |