Esempio n. 1
0
 /**
  * Set name
  *
  * @param  string                             $name
  * @return \ServerGrove\KbBundle\Document\Url
  */
 public function setName($name)
 {
     $this->name = $name;
     if (is_null($this->slug)) {
         $this->setSlug(Sluggable::urlize($this->name));
     }
     return $this;
 }
 /**
  * Generate a document id
  *
  * @param \ServerGrove\KbBundle\Document\ArticleFile $document
  * @param object                                     $parent
  *
  * @return string
  */
 public function generateId($document, $parent = null)
 {
     /** @var $session \PHPCR\SessionInterface */
     $session = $this->getDocumentManager()->getPhpcrSession();
     $root = $session->getNode('/');
     if (!$root->hasNode('articles-files')) {
         $root->addNode('articles-files');
     }
     return '/articles-files/' . Sluggable::urlize($document->getPath());
 }
Esempio n. 3
0
 /**
  * @Route("/", name="sgkb_index")
  * @Route("/{_locale}", name="sgkb_index_locale", requirements={"_locale"="en|es|pt"})
  * @return array
  */
 public function indexAction()
 {
     $categoryName = $this->get('service_container')->getParameter('server_grove_kb.article.front_page_category');
     /** @var $category \ServerGrove\KbBundle\Document\Category */
     $category = $this->getCategoryRepository()->find(sprintf('/categories/%s', Sluggable::urlize($categoryName)));
     if ($category && $category->getArticles()->count()) {
         $keyword = $this->get('service_container')->getParameter('server_grove_kb.article.front_page_keyword');
         $article = $category->getArticles()->filter(function (Article $article) use($keyword) {
             return in_array($keyword, $article->getKeywords()->toArray());
         })->first();
         if (!$article) {
             $article = $category->getArticles()->first();
         }
         return $this->forward('ServerGroveKbBundle:Articles:view', array('article' => $article, 'category' => $article->getDefaultCategory(), 'registerView' => false, 'searchForm' => true, 'showComments' => false));
     }
     return $this->forward('ServerGroveKbBundle:Categories:index');
 }
 public function testUploaderAction()
 {
     $client = $this->getClient();
     $crawler = $client->request('GET', $this->generateUrl('sgkb_admin_articles_files_uploader'));
     $this->assertEquals(200, $client->getResponse()->getStatusCode(), $this->getErrorMessage($client));
     $form = $crawler->selectButton('Submit')->form();
     $form['article_file[path]']->upload($file = __FILE__);
     $date = date('YmdHi');
     $client->submit($form);
     $this->assertEquals(200, $client->getResponse()->getStatusCode(), $this->getErrorMessage($client));
     $this->assertFileExists($createdFile = $client->getKernel()->getRootDir() . '/../web/uploads/' . $date . '-' . basename(__FILE__));
     $client->request('GET', $this->generateUrl('sgkb_admin_articles_files_all', array('_format' => 'json')));
     $this->assertEquals(200, $client->getResponse()->getStatusCode(), $this->getErrorMessage($client));
     $json = (array) json_decode($client->getResponse()->getContent());
     $this->assertArrayHasKey($key = '/articles-files/uploads-' . Sluggable::urlize(strtolower(basename($createdFile))), $json);
     $this->assertObjectHasAttribute('path', $json[$key]);
     $this->assertEquals(str_replace(dirname(dirname($createdFile)), '', $createdFile), $json[$key]->path);
     unlink($createdFile);
 }
 /**
  * @Route("/check-article.{_format}", name="sgkb_admin_articles_check", requirements={"_format"="json"})
  * @Method("post")
  *
  * @throws \Symfony\Component\HttpKernel\Exception\HttpException
  * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function checkArticleAction()
 {
     $request = $this->getRequest();
     if (!$request->isXmlHttpRequest()) {
         throw $this->createNotFoundException();
     }
     if (!$request->request->has('title')) {
         throw new HttpException(400, 'Missing title');
     }
     /** @var $translator \Symfony\Bundle\FrameworkBundle\Translation\Translator */
     $translator = $this->get('translator');
     $message = $translator->trans('The article does not exists');
     $result = true;
     $article = $this->getArticleRepository()->findOneBySlug(\ServerGrove\KbBundle\Util\Sluggable::urlize($request->request->get('title')));
     if ($article) {
         $message = $translator->trans('The article already exists');
         $result = false;
     }
     return new Response(json_encode(array('result' => $result, 'message' => $message)), 200, array('Content-type' => 'application/json'));
 }
 /**
  * @depends testEditAction
  */
 public function testUpdateAction()
 {
     $client = $this->getClient();
     $client->request('POST', $this->generateUrl('sgkb_admin_urls_update', array('slug' => Sluggable::urlize($this->name))));
     $this->assertEquals(400, $client->getResponse()->getStatusCode(), $this->getErrorMessage($client));
 }
 /**
  * @depends testNewAction
  */
 public function testDeleteAction()
 {
     $client = $this->getClient();
     $crawler = $client->request('GET', $this->generateUrl('sgkb_admin_articles_edit', array('slug' => $slug = Sluggable::urlize($this->title))));
     $this->assertEquals(200, $client->getResponse()->getStatusCode(), $this->getErrorMessage($client));
     $this->markTestIncomplete();
     $this->assertGreaterThan(0, $crawler->filter('button#btn_sgkb_admin_articles_delete')->count());
     $form = $crawler->selectButton('btn_sgkb_admin_articles_delete')->form();
     $client->submit($form);
     $this->assertEquals(302, $client->getResponse()->getStatusCode(), $this->getErrorMessage($client));
     /** @var $article \ServerGrove\KbBundle\Document\Article */
     $article = $this->getArticleRepository()->find('/articles/' . $slug);
     $this->assertNotInstanceOf('ServerGrove\\KbBundle\\Document\\Article', $article);
 }
Esempio n. 8
0
 /**
  * @param $title
  *
  * @return \ServerGrove\KbBundle\Document\Article
  */
 public function setTitle($title)
 {
     $this->title = $title;
     if (is_null($this->slug)) {
         $this->setSlug(Sluggable::urlize($title));
     }
     return $this;
 }