| author | ymh <ymh.work@gmail.com> |
| Fri, 25 Nov 2011 18:55:42 +0100 | |
| changeset 42 | 0e57c730bb18 |
| parent 37 | 9ba15af20acc |
| child 57 | 186c4121c7b3 |
| permissions | -rwxr-xr-x |
| 2 | 1 |
<?php |
2 |
||
3 |
namespace IRI\Bundle\WikiTagBundle\Entity; |
|
4 |
||
|
42
0e57c730bb18
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
37
diff
changeset
|
5 |
use IRI\Bundle\WikiTagBundle\Model\DocumentInterface; |
|
0e57c730bb18
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
37
diff
changeset
|
6 |
|
| 2 | 7 |
use Doctrine\ORM\EntityRepository; |
| 18 | 8 |
use IRI\Bundle\WikiTagBundle\Entity\Document; |
| 29 | 9 |
use Doctrine\ORM\Query\ResultSetMapping; |
| 18 | 10 |
use \ReflectionClass; |
|
30
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
11 |
use Doctrine\ORM\AbstractQuery; |
|
37
9ba15af20acc
make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents:
34
diff
changeset
|
12 |
use Doctrine\ORM\Mapping\ClassMetadataInfo; |
|
42
0e57c730bb18
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
37
diff
changeset
|
13 |
use IRI\Bundle\WikiTagBundle\Model\ModelException; |
| 2 | 14 |
|
15 |
/** |
|
16 |
* DocumentRepository |
|
17 |
* |
|
18 |
* This class was generated by the Doctrine ORM. Add your own custom |
|
19 |
* repository methods below. |
|
20 |
*/ |
|
21 |
class DocumentRepository extends EntityRepository |
|
22 |
{ |
|
| 18 | 23 |
/** |
|
42
0e57c730bb18
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
37
diff
changeset
|
24 |
* The cache for the host document class |
| 18 | 25 |
* @var ReflectionClass |
26 |
*/ |
|
27 |
private $reflection_class; |
|
|
42
0e57c730bb18
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
37
diff
changeset
|
28 |
|
|
0e57c730bb18
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
37
diff
changeset
|
29 |
/** |
|
0e57c730bb18
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
37
diff
changeset
|
30 |
* The cache for the wikitag document class |
|
0e57c730bb18
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
37
diff
changeset
|
31 |
* @var ReflectionClass |
|
0e57c730bb18
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
37
diff
changeset
|
32 |
*/ |
| 18 | 33 |
private $reflection_doc_class; |
34 |
private $set_methods = array(); |
|
35 |
private $get_methods = array(); |
|
|
42
0e57c730bb18
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
37
diff
changeset
|
36 |
|
|
0e57c730bb18
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
37
diff
changeset
|
37 |
/** |
|
0e57c730bb18
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
37
diff
changeset
|
38 |
* Find one wikitagRepository by its externalId i.e. the host document id. |
|
0e57c730bb18
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
37
diff
changeset
|
39 |
* @param $external_id |
|
0e57c730bb18
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
37
diff
changeset
|
40 |
*/ |
|
0e57c730bb18
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
37
diff
changeset
|
41 |
public function findOneByExternalId($external_id) |
|
5
45378793512a
Correct tag insert + external id on doc
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
42 |
{ |
| 18 | 43 |
return $this->findOneBy(array("externalId" => $external_id)); |
44 |
} |
|
45 |
||
|
42
0e57c730bb18
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
37
diff
changeset
|
46 |
|
| 18 | 47 |
private function reflectionSetField($object, $method_name, $value) |
48 |
{ |
|
49 |
if(isset($this->set_methods[$method_name])) |
|
50 |
{ |
|
51 |
$set_method = $this->set_methods[$method_name]; |
|
52 |
} |
|
53 |
||
54 |
if(!isset($set_method) || is_null($set_method)) |
|
55 |
{ |
|
56 |
if(is_null($this->reflection_doc_class)) |
|
57 |
{ |
|
58 |
$this->reflection_doc_class = new ReflectionClass(get_class($object)); |
|
59 |
} |
|
60 |
||
61 |
$set_method = NULL; |
|
62 |
if($this->reflection_doc_class->hasMethod($method_name)) |
|
63 |
{ |
|
64 |
$set_method = $this->reflection_doc_class->getMethod($method_name); |
|
65 |
} |
|
66 |
if(!is_null($set_method)) |
|
67 |
{ |
|
68 |
$this->set_methods[$method_name]=$set_method; |
|
69 |
} |
|
70 |
} |
|
71 |
||
72 |
if(!isset($set_method) || is_null($set_method) || !$set_method->isPublic()) |
|
73 |
{ |
|
74 |
throw new \Exception("setter method unknown $method_name"); |
|
75 |
} |
|
76 |
||
77 |
//set value |
|
78 |
$set_method->invoke($object, $value); |
|
79 |
||
|
5
45378793512a
Correct tag insert + external id on doc
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
80 |
} |
| 3 | 81 |
|
| 18 | 82 |
private function reflectionGetField($document, $accessor) |
83 |
{ |
|
84 |
||
85 |
if(!isset($this->get_methods[$accessor]) || is_null($this->get_methods[$accessor])) |
|
86 |
{ |
|
87 |
if(is_null($this->reflection_class)) |
|
88 |
{ |
|
89 |
$this->reflection_class = new \ReflectionClass(get_class($document)); |
|
90 |
} |
|
91 |
||
92 |
//look at properties |
|
93 |
if($this->reflection_class->hasProperty($accessor)) |
|
94 |
{ |
|
95 |
$get_object = $this->reflection_class->getProperty($accessor); |
|
96 |
if(!$get_object->isPublic()) |
|
97 |
{ |
|
98 |
$get_object = NULL; |
|
99 |
} |
|
100 |
} |
|
101 |
||
102 |
if((!isset($get_object) || is_null($get_object)) && $this->reflection_class->hasMethod($accessor)) |
|
103 |
{ |
|
104 |
$get_object = $this->reflection_class->getMethod($accessor); |
|
105 |
if(!$get_object->isPublic()) |
|
106 |
{ |
|
107 |
$get_object = NULL; |
|
108 |
} |
|
109 |
} |
|
110 |
||
111 |
if((!isset($get_object) || is_null($get_object)) && $this->reflection_class->hasMethod("get".ucfirst($accessor))) |
|
112 |
{ |
|
113 |
$get_object = $this->reflection_class->getMethod("get".ucfirst($accessor)); |
|
114 |
if(!$get_object->isPublic()) |
|
115 |
{ |
|
116 |
$get_object = NULL; |
|
117 |
} |
|
118 |
} |
|
119 |
||
120 |
if(isset($get_object) && !is_null($get_object)) |
|
121 |
{ |
|
122 |
$this->get_methods[$accessor] = $get_object; |
|
123 |
} |
|
124 |
} |
|
125 |
||
126 |
if(isset($this->get_methods[$accessor])) |
|
127 |
{ |
|
128 |
$get_object = $this->get_methods[$accessor]; |
|
129 |
if(!is_null($get_object)) |
|
130 |
{ |
|
131 |
if(is_a($get_object,"\ReflectionMethod")) |
|
132 |
{ |
|
133 |
return $get_object->invoke($document); |
|
134 |
} |
|
135 |
elseif(is_a($get_object,"\ReflectionProperty")) |
|
136 |
{ |
|
137 |
return $get_object->getValue($document); |
|
138 |
} |
|
139 |
else |
|
140 |
{ |
|
|
42
0e57c730bb18
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
37
diff
changeset
|
141 |
throw new ModelException("Bad reflection object type"); |
| 18 | 142 |
} |
143 |
} |
|
144 |
} |
|
145 |
||
|
42
0e57c730bb18
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
37
diff
changeset
|
146 |
throw new ModelException("Unknown accessor $accessor"); |
| 18 | 147 |
} |
148 |
||
|
37
9ba15af20acc
make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents:
34
diff
changeset
|
149 |
|
|
9ba15af20acc
make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents:
34
diff
changeset
|
150 |
private function getColumnName($field_name) |
|
9ba15af20acc
make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents:
34
diff
changeset
|
151 |
{ |
|
9ba15af20acc
make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents:
34
diff
changeset
|
152 |
if(isset($this->getClassMetadata()->columnNames[$field_name])) |
|
9ba15af20acc
make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents:
34
diff
changeset
|
153 |
{ |
|
9ba15af20acc
make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents:
34
diff
changeset
|
154 |
return $this->getClassMetadata()->columnNames[$field_name]; |
|
9ba15af20acc
make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents:
34
diff
changeset
|
155 |
} |
|
9ba15af20acc
make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents:
34
diff
changeset
|
156 |
|
|
9ba15af20acc
make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents:
34
diff
changeset
|
157 |
$res = $field_name; |
|
9ba15af20acc
make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents:
34
diff
changeset
|
158 |
if(isset($this->getClassMetadata()->associationMappings[$field_name])) |
|
9ba15af20acc
make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents:
34
diff
changeset
|
159 |
{ |
|
9ba15af20acc
make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents:
34
diff
changeset
|
160 |
$association_mapping = $this->getClassMetadata()->associationMappings[$field_name]; |
|
9ba15af20acc
make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents:
34
diff
changeset
|
161 |
if( |
|
9ba15af20acc
make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents:
34
diff
changeset
|
162 |
isset($association_mapping['type']) |
|
9ba15af20acc
make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents:
34
diff
changeset
|
163 |
&& ( $association_mapping['type'] === ClassMetadataInfo::ONE_TO_ONE || $association_mapping['type'] === ClassMetadataInfo::MANY_TO_ONE) |
|
9ba15af20acc
make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents:
34
diff
changeset
|
164 |
&& count($association_mapping['joinColumns']) > 0 |
|
9ba15af20acc
make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents:
34
diff
changeset
|
165 |
) |
|
9ba15af20acc
make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents:
34
diff
changeset
|
166 |
{ |
|
9ba15af20acc
make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents:
34
diff
changeset
|
167 |
$res = $association_mapping['joinColumns'][0]['name']; |
|
9ba15af20acc
make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents:
34
diff
changeset
|
168 |
} |
|
9ba15af20acc
make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents:
34
diff
changeset
|
169 |
} |
|
9ba15af20acc
make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents:
34
diff
changeset
|
170 |
|
|
9ba15af20acc
make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents:
34
diff
changeset
|
171 |
return $res; |
|
9ba15af20acc
make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents:
34
diff
changeset
|
172 |
} |
|
9ba15af20acc
make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents:
34
diff
changeset
|
173 |
|
|
42
0e57c730bb18
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
37
diff
changeset
|
174 |
/** |
|
0e57c730bb18
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
37
diff
changeset
|
175 |
* Write a wikitag document given the host document and the field list. |
|
0e57c730bb18
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
37
diff
changeset
|
176 |
* @param $document The source document |
|
0e57c730bb18
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
37
diff
changeset
|
177 |
* @param $document_id_column the name of the source document id column |
|
0e57c730bb18
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
37
diff
changeset
|
178 |
* @param $fields The list of field definition. This is an associative array [<field name>=><field definition>]. |
|
0e57c730bb18
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
37
diff
changeset
|
179 |
* See the @IRI\Bundle\WikiTagBundle\DependencyInjection\Configuration documentation |
|
0e57c730bb18
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
37
diff
changeset
|
180 |
*/ |
|
37
9ba15af20acc
make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents:
34
diff
changeset
|
181 |
public function writeDocument($document, $document_id_column, $fields) |
| 3 | 182 |
{ |
|
23
b435f8055cb4
improve dynamic docs. create and lad class dynamically
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
183 |
// get document from id |
|
b435f8055cb4
improve dynamic docs. create and lad class dynamically
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
184 |
|
| 18 | 185 |
$docid = $this->reflectionGetField($document, $document_id_column); |
186 |
$baseDocument = $this->findOneByExternalId($docid); |
|
| 3 | 187 |
|
188 |
if(is_null($baseDocument)) |
|
189 |
{ |
|
190 |
$baseDocument = new Document(); |
|
|
23
b435f8055cb4
improve dynamic docs. create and lad class dynamically
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
191 |
$baseDocument->setExternalId($document); |
| 3 | 192 |
} |
| 18 | 193 |
|
194 |
foreach ($fields as $name => $field_def) { |
|
195 |
if(isset($field_def['accessor'])) |
|
196 |
{ |
|
197 |
$accessor = $field_def['accessor']; |
|
198 |
} |
|
199 |
else |
|
200 |
{ |
|
201 |
$accessor = NULL; |
|
202 |
} |
|
203 |
if(is_null($accessor)) |
|
204 |
{ |
|
205 |
$accessor = $name; |
|
206 |
} |
|
207 |
||
208 |
$value = strval($this->reflectionGetField($document,$accessor)); |
|
209 |
||
210 |
$method_name = "set".ucfirst($name); |
|
211 |
||
212 |
$this->reflectionSetField($baseDocument, $method_name, $value); |
|
213 |
||
214 |
} |
|
| 3 | 215 |
|
216 |
$this->getEntityManager()->persist($baseDocument); |
|
217 |
$this->getEntityManager()->flush(); |
|
218 |
return $baseDocument; |
|
219 |
||
220 |
} |
|
221 |
||
|
42
0e57c730bb18
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
37
diff
changeset
|
222 |
/** |
|
0e57c730bb18
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
37
diff
changeset
|
223 |
* Remove a Wikitag doument given the host docuument. |
|
0e57c730bb18
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
37
diff
changeset
|
224 |
* @param $document The host document |
|
0e57c730bb18
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
37
diff
changeset
|
225 |
* @param string $document_id_column The host document id column name |
|
0e57c730bb18
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
37
diff
changeset
|
226 |
*/ |
|
0e57c730bb18
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
37
diff
changeset
|
227 |
public function removeDocument($document, $document_id_column) |
| 3 | 228 |
{ |
| 18 | 229 |
$docid = $this->reflectionGetField($document, $document_id_column); |
230 |
$baseDocument = $this->findOneByExternalId($docid); |
|
|
5
45378793512a
Correct tag insert + external id on doc
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
231 |
if(!is_null($baseDocument)) |
|
45378793512a
Correct tag insert + external id on doc
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
232 |
{ |
| 3 | 233 |
$this->getEntityManager()->remove($baseDocument); |
234 |
} |
|
235 |
} |
|
236 |
||
|
42
0e57c730bb18
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
37
diff
changeset
|
237 |
|
|
0e57c730bb18
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
37
diff
changeset
|
238 |
/** |
|
0e57c730bb18
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
37
diff
changeset
|
239 |
* return the list of a wikitag documents the tags label. |
|
0e57c730bb18
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
37
diff
changeset
|
240 |
* @param DocumentInterface $document the wikitag document |
|
0e57c730bb18
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
37
diff
changeset
|
241 |
* @return array |
|
0e57c730bb18
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
37
diff
changeset
|
242 |
*/ |
|
0e57c730bb18
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
37
diff
changeset
|
243 |
public function getTagsStr($document) |
| 27 | 244 |
{ |
245 |
$em = $this->getEntityManager(); |
|
246 |
$query = $em->createQuery("SELECT t.label FROM WikiTagBundle:DocumentTag dt JOIN dt.tag t WHERE dt.document = :docid"); |
|
247 |
$query = $query->setParameter("docid", $document); |
|
248 |
$result = $query->getScalarResult(); |
|
249 |
$tagstr = array(); |
|
250 |
foreach ($result as $res) { |
|
251 |
$tagstr[] = $res['label']; |
|
252 |
} |
|
253 |
return $tagstr; |
|
254 |
} |
|
255 |
||
|
42
0e57c730bb18
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
37
diff
changeset
|
256 |
/** |
|
0e57c730bb18
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
37
diff
changeset
|
257 |
* Update a wikitag document tags string. |
|
0e57c730bb18
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
37
diff
changeset
|
258 |
* @param DocumentInterface $document the wikitag document |
|
0e57c730bb18
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
37
diff
changeset
|
259 |
*/ |
|
0e57c730bb18
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
37
diff
changeset
|
260 |
function updateTagsStr(DocumentInterface $document) |
|
23
b435f8055cb4
improve dynamic docs. create and lad class dynamically
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
261 |
{ |
| 27 | 262 |
|
263 |
$tagstr = $this->getTagsStr($document); |
|
|
23
b435f8055cb4
improve dynamic docs. create and lad class dynamically
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
264 |
|
| 27 | 265 |
$document->setTagsStr(implode(",",$tagstr)); |
266 |
$this->getEntityManager()->persist($document); |
|
|
23
b435f8055cb4
improve dynamic docs. create and lad class dynamically
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
267 |
} |
| 29 | 268 |
|
| 34 | 269 |
|
| 29 | 270 |
/** |
|
42
0e57c730bb18
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
37
diff
changeset
|
271 |
* Search wikitag documents using the index. |
| 29 | 272 |
* |
| 34 | 273 |
* @param array $values : key: the fields to search into, value : array('value'=>value, 'weight'=>weight) |
274 |
* @param array $conditions : array : key : field name, value : simple value (operator is "=") or array(valuea, value2,...) (operatr is IN) or array("operator"=>"", "value"=>value) |
|
|
42
0e57c730bb18
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
37
diff
changeset
|
275 |
* @return array [["id" => <the wikitag document id>, "externalId" => <the host document ids>, "score" => <the score for this document>]] |
| 29 | 276 |
*/ |
277 |
function search(array $values, array $conditions=NULL) |
|
278 |
{ |
|
|
30
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
279 |
$em = $this->getEntityManager(); |
| 29 | 280 |
|
281 |
$rsm = new ResultSetMapping(); |
|
|
30
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
282 |
$rsm->addEntityResult("IRI\Bundle\WikiTagBundle\Entity\Document", "d"); |
| 29 | 283 |
$rsm->addFieldResult("d", "id", "id"); |
|
30
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
284 |
$rsm->addScalarResult("score", "score"); |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
285 |
$rsm->addMetaResult("d", "external_id", "externalId"); |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
286 |
|
| 29 | 287 |
|
|
30
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
288 |
$score = array(); |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
289 |
$i = 0; |
| 29 | 290 |
foreach ($values as $fielddef) { |
|
30
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
291 |
$i++; |
|
37
9ba15af20acc
make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents:
34
diff
changeset
|
292 |
$field_list = explode(",", $fielddef["columns"]); |
|
9ba15af20acc
make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents:
34
diff
changeset
|
293 |
$column_list = array(); |
|
9ba15af20acc
make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents:
34
diff
changeset
|
294 |
foreach($field_list as $field_name) |
|
9ba15af20acc
make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents:
34
diff
changeset
|
295 |
{ |
|
9ba15af20acc
make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents:
34
diff
changeset
|
296 |
$column_list[] = $this->getColumnName(trim($field_name)); |
|
9ba15af20acc
make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents:
34
diff
changeset
|
297 |
} |
|
9ba15af20acc
make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents:
34
diff
changeset
|
298 |
$columns = join(",", $column_list); |
|
9ba15af20acc
make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents:
34
diff
changeset
|
299 |
|
| 29 | 300 |
$value = $fielddef["value"]; |
|
30
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
301 |
$weight = isset($fielddef["weight"])?$fielddef["weight"]:1.0; |
| 29 | 302 |
|
|
30
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
303 |
$score[] = "(MATCH($columns) AGAINST (:value_$i))*:weight_$i"; |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
304 |
$parameters["value_$i"] = $value; |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
305 |
$parameters["weight_$i"] = $weight; |
| 29 | 306 |
} |
307 |
||
|
30
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
308 |
$score_def = "(".implode("+", $score).")"; |
| 29 | 309 |
|
|
30
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
310 |
$conditions_str = ""; |
| 29 | 311 |
|
|
30
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
312 |
if(!is_null($conditions)) |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
313 |
{ |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
314 |
$conditions_array = array(); |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
315 |
$i = 0; |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
316 |
foreach ($conditions as $field => $conddef) |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
317 |
{ |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
318 |
$i++; |
|
37
9ba15af20acc
make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents:
34
diff
changeset
|
319 |
$col = $this->getColumnName($field); |
|
30
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
320 |
if(is_array($conddef) && isset($conddef['operator'])) |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
321 |
{ |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
322 |
$operator = $conddef["operator"]; |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
323 |
$values = $conddef["value"]; |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
324 |
} |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
325 |
elseif(is_array($conddef)) |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
326 |
{ |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
327 |
$operator = "IN"; |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
328 |
$values = $conddef; |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
329 |
} |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
330 |
else |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
331 |
{ |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
332 |
$operator = "="; |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
333 |
$values = $conddef; |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
334 |
} |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
335 |
|
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
336 |
if($operator === "IN") |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
337 |
{ |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
338 |
$in_parameters = array(); |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
339 |
for ($j = 0; $j < count($values); $j++) { |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
340 |
$parameters["cond_val_$i_$j"] = $values[$j]; |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
341 |
$in_parameters[] = ":cond_val_$i_$j"; |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
342 |
} |
|
37
9ba15af20acc
make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents:
34
diff
changeset
|
343 |
$cond = "($col IN (".implode(",",$in_parameters)."))"; |
|
30
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
344 |
} |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
345 |
else |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
346 |
{ |
|
37
9ba15af20acc
make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents:
34
diff
changeset
|
347 |
$cond = "($col $operator :cond_val_$i)"; |
|
30
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
348 |
$parameters["cond_val_$i"] = $values; |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
349 |
} |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
350 |
$conditions_array[] = $cond; |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
351 |
} |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
352 |
|
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
353 |
if(count($conditions_array) > 0) |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
354 |
{ |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
355 |
$conditions_str = " AND ".implode(" AND ", $conditions_array); |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
356 |
} |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
357 |
|
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
358 |
} |
| 29 | 359 |
|
|
30
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
360 |
$query = $em->createNativeQuery("SELECT d.id, d.external_id, $score_def AS score FROM wikitag_document d WHERE $score_def > 0 $conditions_str ORDER BY score DESC", $rsm); |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
361 |
|
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
362 |
$query->setParameters($parameters); |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
363 |
|
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
364 |
$res = $query->getResult(); |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
365 |
|
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
366 |
return $res; |
| 29 | 367 |
} |
|
23
b435f8055cb4
improve dynamic docs. create and lad class dynamically
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
368 |
|
| 2 | 369 |
} |