--- a/Controller/WikiTagController.php Mon Oct 17 17:17:14 2011 +0200
+++ b/Controller/WikiTagController.php Tue Oct 18 10:32:30 2011 +0200
@@ -218,7 +218,7 @@
$tag_label = $this->getRequest()->request->get('value');
// We get the DocumentTags
$em = $this->getDoctrine()->getEntityManager();
- $tags = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findBy(array('document' => $id_doc));
+ $tags = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findByDocumentExternalId($id_doc);
$nb_tags = count($tags);
$found = false;
$i = 0;
@@ -241,7 +241,7 @@
$revision_id = $ar[1];
$created = $ar[2];
- $tags = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findBy(array('document' => $id_doc, 'tag'=>$tag->getId()));
+ $tags = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findByDocumentExternalId($id_doc, array('tag'=>$tag->getId()));
$nb_tags = count($tags);
if($created==true || $nb_tags==0){
@@ -251,8 +251,7 @@
$new_order = intval(reset($a1)) + 1;
// TODO: use a factory that returns an DocumentTagInterface
$new_DT = new DocumentTag();
- //return new Response(var_dump($this->getDoctrine()->getRepository('WikiTagBundle:WikiTagDocument')->findOneBy(array('id' => $idDoc))));
- $new_DT->setDocument($this->getDoctrine()->getRepository('WikiTagBundle:Document')->findOneBy(array('id' => $id_doc)));
+ $new_DT->setDocument($this->getDoctrine()->getRepository('WikiTagBundle:Document')->findOneByExternalId($id_doc));
$new_DT->setTag($tag);
$new_DT->setOriginalOrder($new_order);
$new_DT->setTagOrder($new_order);
@@ -295,7 +294,8 @@
$em->persist($un_tag);
}
// We associate the unsemantized tag to the DocumentTag and save datas
- $dt = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOneBy(array('document' => $idDoc, 'tag' => $idTag));
+ // TODO: do the request on external id of document
+ $dt = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOneByDocumentExternalId($id_doc, array('tag' => $idTag));
$dt->setTag($un_tag);
$em->flush();
@@ -306,6 +306,7 @@
/**
*
* TODO : Enter description here ...
+ * TODO : implement
* @return \Symfony\Bundle\FrameworkBundle\Controller\Response
*/
public function updateTagAliasAction()
--- a/Entity/DocumentRepository.php Mon Oct 17 17:17:14 2011 +0200
+++ b/Entity/DocumentRepository.php Tue Oct 18 10:32:30 2011 +0200
@@ -13,16 +13,20 @@
*/
class DocumentRepository extends EntityRepository
{
+ function findOneByExternalId($external_id)
+ {
+ return $this->findOneBy(array("externalId" => strval($external_id)));
+ }
function writeDocument(DocumentInterface $document)
{
# get document from id
- $baseDocument = $this->findOneBy(array("externalId" => $document->getId()));
+ $baseDocument = $this->findOneByExternalId($document->getId());
if(is_null($baseDocument))
{
$baseDocument = new Document();
- $baseDocument->setExternalId($document->getId());
+ $baseDocument->setExternalId(strval($document->getId()));
}
$baseDocument->setDescription($document->getDescription());
$baseDocument->setTitle($document->getTitle());
@@ -35,8 +39,9 @@
function removeDocument(DocumentInterface $document)
{
- $baseDocument = $this->findOneBy(array("externalId" => $document->getId()));
- if(!is_null($baseDocument)) {
+ $baseDocument = $this->findOneByExternalId($document->getId());
+ if(!is_null($baseDocument))
+ {
$this->getEntityManager()->remove($baseDocument);
}
}
--- a/Entity/DocumentTagRepository.php Mon Oct 17 17:17:14 2011 +0200
+++ b/Entity/DocumentTagRepository.php Tue Oct 18 10:32:30 2011 +0200
@@ -2,7 +2,12 @@
namespace IRI\Bundle\WikiTagBundle\Entity;
+use Doctrine\ORM\Query;
+
+use Doctrine\ORM\QueryBuilder;
+
use Doctrine\ORM\EntityRepository;
+use Doctrine\ORM\NoResultException;
/**
* DocumentTagRepository
@@ -18,8 +23,8 @@
public function findOrderedTagsForDoc($doc_id)
{
return $this->getEntityManager()
- ->createQuery("SELECT doctag FROM WikiTagBundle:DocumentTag doctag WHERE doctag.document=:doc_id ORDER BY doctag.tagOrder ASC")
- ->setParameter("doc_id", $doc_id)
+ ->createQuery("SELECT doctag FROM WikiTagBundle:DocumentTag doctag JOIN doctag.document doc WHERE doc.externalId=:doc_id ORDER BY doctag.tagOrder ASC")
+ ->setParameter("doc_id", strval($doc_id))
->getResult();
}
@@ -29,9 +34,53 @@
public function getMaxOrder($doc_id)
{
return $this->getEntityManager()
- ->createQuery("SELECT MAX(doctag.tagOrder) FROM WikiTagBundle:DocumentTag doctag WHERE doctag.document= :doc_id")
- ->setParameter("doc_id", $doc_id)
+ ->createQuery("SELECT MAX(doctag.tagOrder) FROM WikiTagBundle:DocumentTag doctag JOIN doctag.document doc WHERE doc.externalId= :doc_id")
+ ->setParameter("doc_id", strval($doc_id))
->getResult();
}
+
+ /**
+ *
+ * Enter description here ...
+ * @param unknown_type $external_id
+ * @param array $filter_array
+ * @return QueryBuilder
+ */
+ private function createQueryBuilderByDocumentExternalId($external_id, array $filter_array=null) {
+ $qb = $this->createQueryBuilder("dt")
+ ->join('dt.document', 'd')
+ ->where('d.externalId = :external_id');
+
+ $params = array("external_id"=>strval($external_id));
+
+ if(!is_null($filter_array)) {
+ foreach ($filter_array as $key => $value) {
+ $qb = $qb->where("dt.$key = :p_$key");
+ $params["p_$key"] = $value;
+ }
+ }
+
+ $qb = $qb->setParameters($params);
+
+ return $qb;
+ }
+
+ public function findByDocumentExternalId($external_id, array $filter_array=null)
+ {
+ $qb = $this->createQueryBuilderByDocumentExternalId($external_id, $filter_array);
+ return $qb->getQuery()->getResult();
+ }
+
+ public function findOneByDocumentExternalId($external_id, array $filter_array=null) {
+
+ $qb = $this->createQueryBuilderByDocumentExternalId($external_id, $filter_array)->setMaxResults(1);
+
+ try {
+ return $qb->getQuery()->getSingleResult();
+ } catch (NoResultException $e) {
+ return null;
+ }
+ }
+
}
\ No newline at end of file
--- a/Model/Tag.php Mon Oct 17 17:17:14 2011 +0200
+++ b/Model/Tag.php Tue Oct 18 10:32:30 2011 +0200
@@ -218,6 +218,26 @@
{
return $this->urlStatus;
}
+
+ /**
+ * Get UrlStatusText
+ *
+ * @return string
+ */
+ public function getUrlStatusText()
+ {
+ switch ($this->getUrlStatus()) {
+ case 0:
+ return "null_result";
+ case 1:
+ return "redirection";
+ case 2:
+ return "homonyme";
+ case 3:
+ return "match";
+ }
+ }
+
/**
* Set dbpediaUri
@@ -259,6 +279,25 @@
return $this->popularity;
}
-
+ /**
+ * Set category
+ *
+ * @param object $category
+ */
+ public function setCategory($category)
+ {
+ $this->category = $category;
+ }
+
+ /**
+ * Get category
+ *
+ * @return object
+ */
+ function getCategory()
+ {
+ return $this->category;
+ }
+
}
\ No newline at end of file
--- a/Model/TagInterface.php Mon Oct 17 17:17:14 2011 +0200
+++ b/Model/TagInterface.php Tue Oct 18 10:32:30 2011 +0200
@@ -119,6 +119,14 @@
function getUrlStatus();
/**
+ * Get UrlStatusText
+ *
+ * @return string
+ */
+ function getUrlStatusText();
+
+
+ /**
* Set dbpediaUri
*
* @param string $dbpediaUri
@@ -146,5 +154,20 @@
*/
function getPopularity();
+
+ /**
+ * Set category
+ *
+ * @param object $category
+ */
+ function setCategory($category);
+
+ /**
+ * Get category
+ *
+ * @return object
+ */
+ function getCategory();
+
}
\ No newline at end of file