19 require_once(BASE.
"wcmf/lib/core/class.WCMFException.php");
20 require_once(BASE.
"wcmf/lib/persistence/class.PersistenceMapper.php");
21 require_once(BASE.
"wcmf/lib/persistence/converter/class.DataConverter.php");
22 require_once(BASE.
"wcmf/lib/model/class.Node.php");
23 require_once(BASE.
"wcmf/lib/util/class.InifileParser.php");
24 require_once(BASE.
"wcmf/3rdparty/adodb/adodb.inc.php");
29 define(
"DATATYPE_DONTCARE", 0);
30 define(
"DATATYPE_ATTRIBUTE", 1);
31 define(
"DATATYPE_ELEMENT", 2);
32 define(
"DATATYPE_IGNORE", 3);
36 define(
"BUILDDEPTH_INFINITE", -1);
37 define(
"BUILDDEPTH_SINGLE", -2);
38 define(
"BUILDDEPTH_GROUPED", -3);
39 define(
"BUILDDEPTH_REQUIRED", -4);
41 define(
"BUILDTYPE_COMPLETE", -1);
42 define(
"BUILDTYPE_NOPROPS", -2);
72 if (array_key_exists(
'dbType', $params) && array_key_exists(
'dbHostName', $params) && array_key_exists(
'dbUserName', $params) &&
73 array_key_exists(
'dbPassword', $params) && array_key_exists(
'dbName', $params))
76 $this->_conn = &ADONewConnection($params[
'dbType']);
77 $connected = $this->_conn->PConnect($params[
'dbHostName'],$params[
'dbUserName'],$params[
'dbPassword'],$params[
'dbName']);
81 $this->_conn->replaceQuote =
"\'";
82 $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
83 define(ADODB_OUTP,
"gError");
86 $this->_dbPrefix = $params[
'dbPrefix'];
90 if (($logSQL = $parser->getValue(
'logSQL',
'cms')) ===
false)
92 $this->_conn->LogSQL($logSQL);
94 elseif (array_key_exists(
'dbConnection', $params))
97 $this->_conn = $params[
'dbConnection'];
118 $nodeDef = $persistenceFacade->decomposeOID($oid);
121 $sqlStr =
"SELECT ".$this->_dbPrefix.
"nodes.*, ".$this->_dbPrefix.
"elements.id as eid, ".$this->_dbPrefix.
"elements.element_name, ".$this->_dbPrefix.
"elements.visible,
122 ".$this->_dbPrefix.
"elements.editable, ".$this->_dbPrefix.
"elements.alt, ".$this->_dbPrefix.
"elements.hint, ".$this->_dbPrefix.
"elements.display_value,
123 ".$this->_dbPrefix.
"elements.input_type, ".$this->_dbPrefix.
"elements.restrictions, ".$this->_dbPrefix.
"elements.defaultval, ".$this->_dbPrefix.
"data_types.data_type
124 FROM ".$this->_dbPrefix.
"nodes, ".$this->_dbPrefix.
"elements LEFT JOIN ".$this->_dbPrefix.
"data_types
125 ON ".$this->_dbPrefix.
"elements.fk_data_types_id=".$this->_dbPrefix.
"data_types.id
126 WHERE ".$this->_dbPrefix.
"nodes.id=".$nodeDef[
'id'].
" AND ".$this->_dbPrefix.
"nodes.fk_n_elements_id=".$this->_dbPrefix.
"elements.id;";
128 $rs = &$this->_conn->Execute($sqlStr);
132 $nodeData = $rs->FetchRow();
140 $this->_rootElementId = $nodeData[
'fk_n_elements_id'];
141 $this->_rootId = $nodeDef[
'id'];
145 $node =
new Node($nodeData[
'element_name'], $oid);
146 $node->setMapper($this);
150 $node->setProperty(
'visible', $nodeData[
'visible']);
151 $node->setProperty(
'editable', $nodeData[
'editable']);
152 $node->setProperty(
'alt', $nodeData[
'alt']);
153 $node->setProperty(
'hint', $nodeData[
'hint']);
154 $node->setProperty(
'display_value', $nodeData[
'display_value']);
155 $node->setProperty(
'input_type', $nodeData[
'input_type']);
156 $node->setProperty(
'elementid', $nodeData[
'eid']);
157 if ($nodeData[
'fk_nodes_id'] !=
'')
158 $node->setProperty(
'parentoid', $persistenceFacade->composeOID(array(
'type' => $this->_type,
'id' => $nodeData[
'fk_nodes_id'])));
159 $node->setProperty(
'rootoid', null);
163 if (isset($nodeData[
'data_type']))
166 $nodeValue = $this->_dataConverter->convertStorageToApplication($nodeData[$nodeData[
'data_type']], $nodeData[
'data_type'], $nodeData[
'element_name']);
167 if ($nodeValue ==
'')
168 $nodeValue = $nodeData[
'defaultval'];
173 $elementProperties = array(
'visible' => $nodeData[
'visible'],
174 'restrictions' => stripslashes($nodeData[
'restrictions']),
175 'defaultval' => $nodeData[
'defaultval'],
176 'editable' => $nodeData[
'editable'],
177 'alt' => $nodeData[
'alt'],
178 'hint' => $nodeData[
'hint'],
179 'input_type' => $nodeData[
'input_type'],
180 'data_type' => $nodeData[
'data_type'],
181 'id'=> $nodeData[
'eid']);
182 $node->setValueProperties($nodeData[
'element_name'], $elementProperties,
DATATYPE_ELEMENT);
187 $sqlStr =
"SELECT ".$this->_dbPrefix.
"attribs.*, ".$this->_dbPrefix.
"attrib_def.id as aid, ".$this->_dbPrefix.
"attrib_def.attrib_name, ".$this->_dbPrefix.
"attrib_def.optional,
188 ".$this->_dbPrefix.
"attrib_def.restrictions, ".$this->_dbPrefix.
"attrib_def.defaultval, ".$this->_dbPrefix.
"attrib_def.visible, ".$this->_dbPrefix.
"attrib_def.editable,
189 ".$this->_dbPrefix.
"attrib_def.alt, ".$this->_dbPrefix.
"attrib_def.hint, ".$this->_dbPrefix.
"attrib_def.input_type, ".$this->_dbPrefix.
"data_types.data_type
190 FROM ".$this->_dbPrefix.
"attribs, ".$this->_dbPrefix.
"attrib_def, ".$this->_dbPrefix.
"data_types
191 WHERE ".$this->_dbPrefix.
"attribs.fk_nodes_id=".$nodeDef[
'id'].
" AND ".$this->_dbPrefix.
"attribs.fk_attrib_def_id=".$this->_dbPrefix.
"attrib_def.id
192 AND ".$this->_dbPrefix.
"attrib_def.fk_data_types_id=".$this->_dbPrefix.
"data_types.id ORDER BY ".$this->_dbPrefix.
"attrib_def.sort_key;";
193 $rs = &$this->_conn->Execute($sqlStr);
194 while ($rs && $nodeAttributes = $rs->FetchRow())
197 $attributeValue = $this->_dataConverter->convertStorageToApplication($nodeAttributes[$nodeAttributes[
'data_type']], $nodeAttributes[
'data_type'], $nodeAttributes[
'attrib_name']);
198 if ($attributeValue ==
'')
199 $attributeValue = $nodeAttributes[
'defaultval'];
204 $attributeProperties = array(
'visible' => $nodeAttributes[
'visible'],
205 'restrictions' => $nodeAttributes[
'restrictions'],
206 'defaultval' => $nodeAttributes[
'defaultval'],
207 'editable' => $nodeAttributes[
'editable'],
208 'alt' => $nodeAttributes[
'alt'],
209 'optional' => $nodeAttributes[
'optional'],
210 'hint' => $nodeAttributes[
'hint'],
211 'input_type' => $nodeAttributes[
'input_type'],
212 'data_type' => $nodeAttributes[
'data_type'],
213 'id' => $nodeAttributes[
'aid']);
214 $node->setValueProperties($nodeAttributes[
'attrib_name'], $attributeProperties,
DATATYPE_ATTRIBUTE);
222 $childoids = array();
223 $sqlStr =
"SELECT ".$this->_dbPrefix.
"nodes.id, ".$this->_dbPrefix.
"nodes.fk_n_elements_id FROM ".$this->_dbPrefix.
"nodes
224 WHERE ".$this->_dbPrefix.
"nodes.fk_nodes_id=".$nodeDef[
'id'].
" ORDER BY sort_key;";
225 $rs = &$this->_conn->Execute($sqlStr);
226 while ($rs && $childData = $rs->FetchRow())
228 $childoid = $persistenceFacade->composeOID(array(
'type' => $this->_type,
'id' => $childData[
'id']));
229 array_push($childoids, $childoid);
231 ( ($depth < $buildDepth) ||
233 ( ($buildDepth ==
BUILDDEPTH_GROUPED) && $this->
isGroupChild($childData[
'fk_n_elements_id'], $nodeData[
'fk_n_elements_id'], $this->_rootElementId) )
237 $childNode = &$persistenceFacade->load($childoid, $buildDepth, $buildType, $depth+1);
238 $childNode->setMapper($this);
239 if ($this->
isGroupChild($childData[
'fk_n_elements_id'], $nodeData[
'fk_n_elements_id'], $this->_rootElementId))
242 if ($this->_rootId !=
'')
244 $rootoid = $persistenceFacade->composeOID(array(
'type' => $this->_type,
'id' => $this->_rootId));
245 $childNode->setProperty(
'rootoid', $rootoid);
248 $node->addChild($childNode);
252 $node->setProperty(
'childoids', $childoids);
271 if ($type ==
'*') $type =
'';
276 $sqlStr =
"SELECT ".$this->_dbPrefix.
"elements.id, ".$this->_dbPrefix.
"elements.visible, ".$this->_dbPrefix.
"elements.editable, ".$this->_dbPrefix.
"elements.alt,
277 ".$this->_dbPrefix.
"elements.hint, ".$this->_dbPrefix.
"elements.display_value, ".$this->_dbPrefix.
"elements.input_type, ".$this->_dbPrefix.
"elements.restrictions,
278 ".$this->_dbPrefix.
"elements.defaultval, ".$this->_dbPrefix.
"data_types.data_type
279 FROM ".$this->_dbPrefix.
"elements LEFT JOIN ".$this->_dbPrefix.
"data_types ON ".$this->_dbPrefix.
"elements.fk_data_types_id=".$this->_dbPrefix.
"data_types.id
280 WHERE ".$this->_dbPrefix.
"elements.element_name='".$type.
"';";
281 $rs = &$this->_conn->Execute($sqlStr);
282 if (!$rs || $rs->RecordCount() == 0)
285 $nodeData = $rs->FetchRow();
292 $this->_rootElementId = $nodeData[
'id'];
293 $this->_rootId = $nodeData[
'id'];
297 $node =
new Node($type);
298 $node->setMapper($this);
302 $node->setProperty(
'visible', $nodeData[
'visible']);
303 $node->setProperty(
'editable', $nodeData[
'editable']);
304 $node->setProperty(
'alt', $nodeData[
'alt']);
305 $node->setProperty(
'hint', $nodeData[
'hint']);
306 $node->setProperty(
'display_value', $nodeData[
'display_value']);
307 $node->setProperty(
'input_type', $nodeData[
'input_type']);
308 $node->setProperty(
'elementid', $nodeData[
'id']);
310 if ($this->_rootId !=
'')
312 $rootoid = $persistenceFacade->composeOID(array(
'type' => $this->_type,
'id' => $this->_rootId));
313 $node->setProperty(
'rootoid', $rootoid);
318 if (isset($nodeData[
'data_type']))
321 $nodeValue = $this->_dataConverter->convertStorageToApplication($nodeData[
'defaultval'], $nodeData[
'data_type'], $nodeData[
'element_name']);
326 $elementProperties = array(
'visible' => $nodeData[
'visible'],
327 'restrictions' => stripslashes($nodeData[
'restrictions']),
328 'defaultval' => $nodeData[
'defaultval'],
329 'editable' => $nodeData[
'editable'],
330 'alt' => $nodeData[
'alt'],
331 'hint' => $nodeData[
'hint'],
332 'input_type' => $nodeData[
'input_type'],
333 'data_type' => $nodeData[
'data_type'],
334 'id'=> $nodeData[
'id']);
340 $sqlStr =
"SELECT ".$this->_dbPrefix.
"attrib_def.id, ".$this->_dbPrefix.
"attrib_def.attrib_name, ".$this->_dbPrefix.
"attrib_def.optional, ".$this->_dbPrefix.
"attrib_def.restrictions,
341 ".$this->_dbPrefix.
"attrib_def.defaultval, ".$this->_dbPrefix.
"attrib_def.visible, ".$this->_dbPrefix.
"attrib_def.editable, ".$this->_dbPrefix.
"attrib_def.hint,
342 ".$this->_dbPrefix.
"attrib_def.alt, ".$this->_dbPrefix.
"attrib_def.input_type, ".$this->_dbPrefix.
"data_types.data_type
343 FROM ".$this->_dbPrefix.
"attrib_def, ".$this->_dbPrefix.
"data_types
344 WHERE ".$this->_dbPrefix.
"attrib_def.fk_elements_id=".$nodeData[
'id'].
" AND ".$this->_dbPrefix.
"attrib_def.fk_data_types_id=".$this->_dbPrefix.
"data_types.id
345 ORDER BY ".$this->_dbPrefix.
"attrib_def.sort_key;";
346 $rs = &$this->_conn->Execute($sqlStr);
347 while ($rs && $nodeAttributes = $rs->FetchRow())
350 $attributeValue = $this->_dataConverter->convertStorageToApplication($nodeAttributes[
'defaultval'], $nodeAttributes[
'data_type'], $nodeAttributes[
'attrib_name']);
355 $attributeProperties = array(
'visible' => $nodeAttributes[
'visible'],
356 'restrictions' => $nodeAttributes[
'restrictions'],
357 'defaultval' => $nodeAttributes[
'defaultval'],
358 'editable' => $nodeAttributes[
'editable'],
359 'alt' => $nodeAttributes[
'alt'],
360 'optional' => $nodeAttributes[
'optional'],
361 'hint' => $nodeAttributes[
'hint'],
362 'input_type' => $nodeAttributes[
'input_type'],
363 'data_type' => $nodeAttributes[
'data_type'],
364 'id' => $nodeAttributes[
'id']);
365 $node->setValueProperties($nodeAttributes[
'attrib_name'], $attributeProperties,
DATATYPE_ATTRIBUTE);
373 $childoids = array();
374 $sqlStr =
"SELECT ".$this->_dbPrefix.
"elements.element_name, ".$this->_dbPrefix.
"element_relations.fk_elements_child_id, ".$this->_dbPrefix.
"element_relations.repetitive,
375 ".$this->_dbPrefix.
"element_relations.optional
376 FROM ".$this->_dbPrefix.
"element_relations, ".$this->_dbPrefix.
"elements
377 WHERE ".$this->_dbPrefix.
"element_relations.fk_elements_id=".$nodeData[
'id'].
" AND ".$this->_dbPrefix.
"element_relations.fk_elements_child_id=".$this->_dbPrefix.
"elements.id
378 ORDER BY ".$this->_dbPrefix.
"element_relations.sort_key;";
379 $rs = &$this->_conn->Execute($sqlStr);
380 while ($rs && $childData = $rs->FetchRow())
382 $childoid = $persistenceFacade->composeOID(array(
'type' => $childData[
'element_name'],
'id' => $childData[
'fk_elements_child_id']));
383 array_push($childoids, $childoid);
386 $childData[
'minOccurs'] = 1;
387 $childData[
'maxOccurs'] = 1;
388 if ($childData[
'repetitive'] == 1)
389 $childData[
'maxOccurs'] =
'unbounded';
390 if ($childData[
'optional'] == 1)
391 $childData[
'minOccurs'] = 0;
394 ( ($depth < $buildDepth) ||
401 $childNode = &$persistenceFacade->create($childData[
'element_name'], $buildDepth, $buildType, $depth+1);
402 $childNode->setMapper($this);
405 $childNode->setProperty(
'minOccurs', $childData[
'minOccurs']);
406 $childNode->setProperty(
'maxOccurs', $childData[
'maxOccurs']);
408 $node->addChild($childNode);
412 $node->setProperty(
'childoids', $childoids);
424 foreach ($node->getDataTypes() as $type)
425 foreach ($node->getValueNames($type) as $valueName)
427 $properties = $node->getValueProperties($valueName, $type);
431 $value = str_replace(array(
"\'",
"\\\""), array(
"'",
"\""), $node->getValue($valueName, $type));
432 $node->setValue($valueName, $this->_dataConverter->convertApplicationToStorage($value, $properties[
'data_type'], $valueName), $type);
436 $nodeDef = $persistenceFacade->decomposeOID($node->getOID());
441 $parent = &$node->getParent();
442 $parentDef = $persistenceFacade->decomposeOID($parent->getOID());
447 if (!$sortkey) $sortkey = 0;
452 $properties = $node->getValueProperties($node->getType(),
DATATYPE_ELEMENT);
453 if ($properties[
'data_type'] !=
'')
454 $sqlStr =
"INSERT INTO ".$this->_dbPrefix.
"nodes (fk_nodes_id, fk_n_elements_id, ".$properties[
'data_type'].
", sort_key)
455 VALUES (".$parentDef[
'id'].
", ".$node->getProperty(
'elementid').
", ".$this->_conn->qstr($elementValue).
", ".$sortkey.
");";
458 $sqlStr =
"INSERT INTO ".$this->_dbPrefix.
"nodes (fk_nodes_id, fk_n_elements_id, sort_key)
459 VALUES (".$parentDef[
'id'].
", ".$node->getProperty(
'elementid').
", ".$sortkey.
");";
460 if ($this->_conn->Execute($sqlStr) ===
false)
461 WCMFException::throwEx(
"Error inserting node ".$node->getType().
": ".$this->_conn->ErrorMsg(), __FILE__, __LINE__);
464 $node->setOID($persistenceFacade->composeOID(array(
'type' => $nodeDef[
'type'],
'id' => $this->_conn->Insert_ID())));
465 $nodeDef = $persistenceFacade->decomposeOID($node->getOID());
469 foreach($attributeNames as $attributeName)
474 if ($attributeProperties == null)
475 WCMFException::throwEx(
"Can't save ".$node->getType().
".".$attributeName.
": No properties found.", __FILE__, __LINE__);
477 if ($attributeValue !=
'')
480 $sqlStr =
"INSERT INTO ".$this->_dbPrefix.
"attribs (fk_nodes_id, fk_attrib_def_id, ".$attributeProperties[
'data_type'].
")
481 VALUES (".$nodeDef[
'id'].
", ".$attributeProperties[
'id'].
", ".$this->_conn->qstr($attributeValue).
");";
482 if ($this->_conn->Execute($sqlStr) ===
false)
483 WCMFException::throwEx(
"Error inserting node ".$node->getType().
": ".$this->_conn->ErrorMsg(), __FILE__, __LINE__);
503 if (!$sortkey) $sortkey = 0;
508 $properties = $node->getValueProperties($node->getType(),
DATATYPE_ELEMENT);
509 if ($properties[
'data_type'] !=
'')
510 $sqlStr =
"UPDATE ".$this->_dbPrefix.
"nodes SET ".$properties[
'data_type'].
"=".$this->_conn->qstr($elementValue).
", sort_key=".$sortkey.
" WHERE id=".$nodeDef[
'id'].
";";
513 $sqlStr =
"UPDATE ".$this->_dbPrefix.
"nodes SET sort_key=".$sortkey.
" WHERE id=".$nodeDef[
'id'].
";";
514 if ($this->_conn->Execute($sqlStr) ===
false)
515 WCMFException::throwEx(
"Error updating node ".$node->getType().
": ".$this->_conn->ErrorMsg(), __FILE__, __LINE__);
519 foreach($attributeNames as $attributeName)
524 if ($attributeProperties == null)
525 WCMFException::throwEx(
"Can't save ".$node->getType().
".".$attributeName.
": No properties found.", __FILE__, __LINE__);
528 $sqlStr =
"SELECT ".$this->_dbPrefix.
"attribs.id FROM ".$this->_dbPrefix.
"attribs, ".$this->_dbPrefix.
"nodes, ".$this->_dbPrefix.
"attrib_def
529 WHERE ".$this->_dbPrefix.
"attribs.fk_nodes_id=".$nodeDef[
'id'].
" AND ".$this->_dbPrefix.
"attribs.fk_attrib_def_id=".$this->_dbPrefix.
"attrib_def.id
530 AND ".$this->_dbPrefix.
"attrib_def.attrib_name='".$attributeName.
"';";
532 if ($rs = &$this->_conn->Execute($sqlStr))
534 $attribute = $rs->FetchRow();
535 $attribId = $attribute[
'id'];
540 if ($attributeValue !=
'')
543 $sqlStr =
"INSERT INTO ".$this->_dbPrefix.
"attribs (fk_nodes_id, fk_attrib_def_id, ".$attributeProperties[
'data_type'].
")
544 VALUES (".$nodeDef[
'id'].
", ".$attributeProperties[
'id'].
", ".$this->_conn->qstr($attributeValue).
");";
545 if ($this->_conn->Execute($sqlStr) ===
false)
546 WCMFException::throwEx(
"Error updating node ".$node->getType().
": ".$this->_conn->ErrorMsg(), __FILE__, __LINE__);
552 $sqlStr =
"UPDATE ".$this->_dbPrefix.
"attribs SET ".$attributeProperties[
'data_type'].
"=".$this->_conn->qstr($attributeValue).
"
553 WHERE id=".$attribId.
";";
554 if ($this->_conn->Execute($sqlStr) ===
false)
555 WCMFException::throwEx(
"Error updating node ".$node->getType().
": ".$this->_conn->ErrorMsg(), __FILE__, __LINE__);
572 function delete($oid, $recursive=
true)
575 $nodeDef = $persistenceFacade->decomposeOID($oid);
585 $sqlStr =
"DELETE FROM ".$this->_dbPrefix.
"nodes WHERE id=".$nodeDef[
'id'].
";";
586 if ($this->_conn->Execute($sqlStr) ===
false)
588 $sqlStr =
"DELETE FROM ".$this->_dbPrefix.
"attribs WHERE fk_nodes_id=".$nodeDef[
'id'].
";";
589 if ($this->_conn->Execute($sqlStr) ===
false)
595 $sqlStr =
"SELECT ".$this->_dbPrefix.
"nodes.id, element_name FROM ".$this->_dbPrefix.
"nodes, ".$this->_dbPrefix.
"elements
596 WHERE ".$this->_dbPrefix.
"nodes.fk_n_elements_id=".$this->_dbPrefix.
"elements.id AND ".$this->_dbPrefix.
"nodes.fk_nodes_id=".$nodeDef[
'id'].
";";
597 $rs = &$this->_conn->Execute($sqlStr);
598 while ($rs && $childData = $rs->FetchRow())
600 $childoid = $persistenceFacade->composeOID(array(
'type' => $childData[
'element_name'],
'id' => $childData[
'id']));
601 $persistenceFacade->delete($childoid, $recursive);
622 function isGroupChild($childElementId, $parentElementId, $rootElementId)
624 $key = $childElementId.
'_'.$parentElementId.
'_'.$rootElementId;
625 if (isset($this->_groupMap[$key]))
626 return $this->_groupMap[$key];
630 $sqlStr =
"SELECT fk_elements_id, grouproot FROM ".$this->_dbPrefix.
"element_relations WHERE fk_elements_child_id=".$childElementId.
";";
631 $rs = &$this->_conn->Execute($sqlStr);
632 while ($rs && $relation = $rs->FetchRow())
633 if ($relation[
'grouproot'] == $rootElementId && $relation[
'fk_elements_id'] == $parentElementId)
635 $this->_groupMap[$key] = $grouped;
651 $attribTableStr =
'';
653 if ($criteria != null)
656 foreach($criteria as $name => $value)
658 $attribTableStr .=
", ".$this->_dbPrefix.
"attribs as attribs".$i.
", ".$this->_dbPrefix.
"attrib_def as attrib_def".$i.
" ";
659 $attribCondStr .=
"AND attribs".$i.
".fk_nodes_id=".$this->_dbPrefix.
"nodes.id AND attribs".$i.
".fk_attrib_def_id=attrib_def".$i.
".id AND attrib_def".$i.
".attrib_name='".$name.
"' AND
660 (attribs".$i.
".data_txt LIKE '%".$value.
"%' OR attribs".$i.
".data_blob LIKE '%".$value.
"%' OR attribs".$i.
".data_date LIKE '%".$value.
"%' OR attribs".$i.
".data_float LIKE '%".$value.
"%' OR attribs".$i.
".data_int LIKE '%".$value.
"%' OR attribs".$i.
".data_boolean LIKE '%".$value.
"%') ";
665 $sqlStr =
"SELECT ".$this->_dbPrefix.
"nodes.id FROM ".$this->_dbPrefix.
"nodes, ".$this->_dbPrefix.
"elements ".$attribTableStr.
"
666 WHERE ".$this->_dbPrefix.
"nodes.fk_n_elements_id=".$this->_dbPrefix.
"elements.id AND ".$this->_dbPrefix.
"elements.element_name='".$type.
"' ".$attribCondStr;
667 $rs = &$this->_conn->Execute($sqlStr);
672 while ($row = $rs->FetchRow())
673 array_push($oids, $persistenceFacade->composeOID(array(
'type' => $type,
'id' => $row[
'id'])));
696 $nodeDef = $persistenceFacade->decomposeOID($oid);
697 $idCondition = $this->_dbPrefix.
'nodes.id='.$nodeDef[
'id'].
' AND';
701 $attribTableStr =
'';
703 if ($attribute != null)
706 foreach($attribute as $name => $value)
708 $attribTableStr .=
", ".$this->_dbPrefix.
"attribs as attribs".$i.
", ".$this->_dbPrefix.
"attrib_def as attrib_def".$i.
" ";
709 $attribCondStr .=
"AND attribs".$i.
".fk_nodes_id=nodes2.id AND attribs".$i.
".fk_attrib_def_id=attrib_def".$i.
".id AND attrib_def".$i.
".attrib_name='".$name.
"' AND
710 (attribs".$i.
".data_txt LIKE '%".$value.
"%' OR attribs".$i.
".data_blob LIKE '%".$value.
"%' OR attribs".$i.
".data_date LIKE '%".$value.
"%' OR attribs".$i.
".data_float LIKE '%".$value.
"%' OR attribs".$i.
".data_int LIKE '%".$value.
"%' OR attribs".$i.
".data_boolean LIKE '%".$value.
"%') ";
716 if ($property != null)
717 $sqlStr =
"SELECT ".$this->_dbPrefix.
"nodes.id, nodes2.data_txt
718 FROM ".$this->_dbPrefix.
"nodes, ".$this->_dbPrefix.
"nodes as nodes2, ".$this->_dbPrefix.
"elements, ".$this->_dbPrefix.
"elements as elements2 ".$attribTableStr.
"
719 WHERE ".$idCondition.
" ".$this->_dbPrefix.
"nodes.id=nodes2.fk_nodes_id AND ".$this->_dbPrefix.
"nodes.fk_n_elements_id=".$this->_dbPrefix.
"elements.id
720 AND ".$this->_dbPrefix.
"elements.element_name='".$type.
"' AND nodes2.fk_n_elements_id=elements2.id AND elements2.element_name='".$property.
"' ".$attribCondStr.
";";
722 $sqlStr =
"SELECT ".$this->_dbPrefix.
"nodes.id, ".$this->_dbPrefix.
"nodes.data_txt FROM ".$this->_dbPrefix.
"nodes, ".$this->_dbPrefix.
"nodes as nodes2,
723 ".$this->_dbPrefix.
"elements ".$attribTableStr.
"
724 WHERE ".$idCondition.
" ".$this->_dbPrefix.
"nodes.id=nodes2.id AND ".$this->_dbPrefix.
"nodes.fk_n_elements_id=".$this->_dbPrefix.
"elements.id
725 AND ".$this->_dbPrefix.
"elements.element_name='".$type.
"' ".$attribCondStr.
";";
726 $rs = &$this->_conn->Execute($sqlStr);
731 while ($row = $rs->FetchRow())
733 $oid = $persistenceFacade->composeOID(array(
'type' => $type,
'id' => $row[
'id']));
734 $map[$oid] = $this->_dataConverter->convertStorageToApplication($row[
'data_txt'],
'data_txt',
'');
750 $nodeDef = $persistenceFacade->decomposeOID($oid);
756 $sqlStr =
"SELECT ".$this->_dbPrefix.
"elements.element_name FROM ".$this->_dbPrefix.
"nodes, ".$this->_dbPrefix.
"nodes as parentnode, ".$this->_dbPrefix.
"elements,
757 ".$this->_dbPrefix.
"element_relations
758 WHERE ".$this->_dbPrefix.
"nodes.fk_n_elements_id=".$this->_dbPrefix.
"element_relations.fk_elements_child_id
759 AND parentnode.fk_n_elements_id=".$this->_dbPrefix.
"element_relations.fk_elements_id AND ".$this->_dbPrefix.
"nodes.fk_nodes_id=parentnode.id
760 AND ".$this->_dbPrefix.
"element_relations.grouproot=".$this->_dbPrefix.
"elements.id AND ".$this->_dbPrefix.
"nodes.id=".$nodeDef[
'id'];
765 $rs = &$this->_conn->Execute($sqlStr);
770 $row = $rs->FetchRow();
778 $sqlStr =
"SELECT ".$this->_dbPrefix.
"nodes.id, ".$this->_dbPrefix.
"nodes.fk_nodes_id, ".$this->_dbPrefix.
"elements.element_name
779 FROM ".$this->_dbPrefix.
"nodes, ".$this->_dbPrefix.
"elements WHERE ".$this->_dbPrefix.
"nodes.fk_n_elements_id=".$this->_dbPrefix.
"elements.id
780 AND ".$this->_dbPrefix.
"nodes.id=".$nodeDef[
'id'].
";";
781 $rs = &$this->_conn->Execute($sqlStr);
786 $row = $rs->FetchRow();
787 $parentOID = $persistenceFacade->composeOID(array(
'type' => $row[
'element_name'],
'id' => $row[
'fk_nodes_id']));
792 while ($row[
'element_name'] != $type && $row[
'fk_nodes_id'] !=
'')
794 $sqlStr =
"SELECT ".$this->_dbPrefix.
"nodes.id, ".$this->_dbPrefix.
"nodes.fk_nodes_id, ".$this->_dbPrefix.
"elements.element_name
795 FROM ".$this->_dbPrefix.
"nodes, ".$this->_dbPrefix.
"elements WHERE ".$this->_dbPrefix.
"nodes.fk_n_elements_id=".$this->_dbPrefix.
"elements.id
796 AND ".$this->_dbPrefix.
"nodes.id=".$row[
'fk_nodes_id'].
";";
797 $rs = &$this->_conn->Execute($sqlStr);
801 $row = $rs->FetchRow();
802 if ($row[
'element_name'] !=
'' || $row[
'id'] !=
'')
803 $parentOID = $persistenceFacade->composeOID(array(
'type' => $row[
'element_name'],
'id' => $row[
'id']));
NodeToSingleTableMapper maps nodes of different types to the database. It uses a relational database ...
Node is the basic component for building trees (although a Node can have one than more parents)...
& load($oid, $buildDepth, $buildType=BUILDTYPE_COMPLETE, $depth=0)
getParentOID($oid, $type=null, $buildDepth=BUILDDEPTH_SINGLE)
throwEx($message, $file='', $line='')
const BUILDDEPTH_INFINITE
getOIDs($type, $criteria=null)
isGroupChild($childElementId, $parentElementId, $rootElementId)
NodeToSingleTableMapper($params)
const BUILDDEPTH_REQUIRED
DataConverter is the base class for all converter classes. It defines the interface for converting da...
getPropertyMap($type, $property, $attribute=null, $oid=null)
PersistenceMapper is the base class for all mapper classes.
& create($type, $buildDepth, $buildType=BUILDTYPE_COMPLETE, $depth=0)