19 require_once(BASE.
"wcmf/lib/core/class.WCMFException.php");
20 require_once(BASE.
"wcmf/lib/util/class.Log.php");
21 require_once(BASE.
"wcmf/lib/util/class.StringUtil.php");
22 require_once(BASE.
"wcmf/lib/util/class.FormUtil.php");
23 require_once(BASE.
"wcmf/lib/model/class.Node.php");
24 require_once(BASE.
"wcmf/lib/model/class.NodeIterator.php");
25 require_once(BASE.
"wcmf/lib/model/class.NodeProcessor.php");
26 require_once(BASE.
"wcmf/lib/persistence/class.PersistenceFacade.php");
62 $parentOIDs = $node->getProperty(
'parentoids');
63 $parentOID = $parentOIDs[0];
69 array_push($path, $nodeInPath);
70 $parentOIDs = $nodeInPath->getProperty(
'parentoids');
71 $parentOID = $parentOIDs[0];
91 $parentOIDs = $tplNode->getProperty(
'parentoids');
92 if (
sizeof($parentOIDs) > 0)
97 foreach ($parentOIDs as $oid)
100 if ($parent->getType() == $ancestorType)
102 $nodes[
sizeof($nodes)] = &$parent;
105 $parents[
sizeof($parents)] = &$parent;
108 foreach ($parents as $parent)
110 $parentOIDs = $parent->getProperty(
'parentoids');
111 if (
sizeof($parentOIDs) > 0)
113 $nodes[
sizeof($nodes)] = &$parent;
130 if ($nodes == null) {
133 $childOIDs = $tplNode->getProperty(
'childoids');
134 if (
sizeof($childOIDs) > 0)
139 foreach ($childOIDs as $oid)
142 if ($child->getType() == $descendantType)
144 $nodes[
sizeof($nodes)] = &$child;
147 $children[
sizeof($children)] = &$child;
150 foreach ($children as $child)
152 $childOIDs = $child->getProperty(
'childoids');
153 if (
sizeof($childOIDs) > 0)
155 $nodes[
sizeof($nodes)] = &$child;
170 return $query->toString();
182 $tpl = &$query->getObjectTemplate($nodeType);
183 $mapper = &$tpl->getMapper();
186 foreach ($mapper->getPkNames() as $pkName => $pkValueType) {
187 $tpl->setValue($pkName,
'= '.$oidParts[
'id'][$i++], $pkValueType);
189 return $query->toString();
201 $tpl = &$query->getObjectTemplate($parentType);
203 $cTpl = &$query->getObjectTemplate($childNode->getType());
204 $mapper = &$childNode->getMapper();
205 foreach ($mapper->getPkNames() as $pkName => $pkValueType) {
206 $cTpl->setValue($pkName,
'= '.$childNode->getValue($pkName, $pkValueType), $pkValueType);
208 $tpl->addChild($cTpl);
209 return $query->toString();
220 $tpl = &$query->getObjectTemplate($childType);
223 $pTpl = &$query->getObjectTemplate($parentNode->getBaseType());
224 $mapper = &$parentNode->getMapper();
225 foreach ($mapper->getPkNames() as $pkName => $pkValueType) {
226 $pTpl->setValue($pkName,
'= '.$parentNode->getValue($pkName, $pkValueType), $pkValueType);
228 $pTpl->addChild($tpl);
229 return $query->toString();
244 $allowedParentTypes = array();
245 if ($tplNode != null && $realNode != null)
248 $possibleParentOIDs = $tplNode->getProperty(
'parentoids');
249 for ($i=0; $i<
sizeof($possibleParentOIDs); $i++)
252 $possibleParent = &$persistenceFacade->create($type, 1);
255 $children = $possibleParent->getChildrenEx(null, $realNode->getType(), null, null);
256 if (
sizeof($children) > 0)
258 $possibleParent->setProperty(
'canAssociate',
true);
259 $possibleParent->setProperty(
'composition', $children[0]->getProperty(
'composition'));
263 $possibleParent->setProperty(
'canAssociate',
false);
264 $possibleParent->setProperty(
'composition',
true);
268 foreach ($realNode->getProperty(
'parentoids') as $parentOID)
272 $possibleParent->setProperty(
'parentOID', $parentOID);
277 $allowedParentTypes[$type] = &$possibleParent;
280 return $allowedParentTypes;
294 $allowedChildTypes = array();
295 if ($tplNode != null && $realNode != null && $tplNode->getNumChildren() > 0)
298 $possibleChildren = $tplNode->getChildren();
299 for ($i=0; $i<
sizeof($possibleChildren); $i++)
301 $possibleChild = &$possibleChildren[$i];
305 $childOIDs = $realNode->getProperty(
'childoids');
306 foreach($childOIDs as $childOID)
312 if ($possibleChild->getProperty(
'maxOccurs') ==
'unbounded' || ($occurs < $possibleChild->getProperty(
'maxOccurs'))) {
313 $possibleChild->setProperty(
'canCreate',
true);
316 $possibleChild->setProperty(
'canCreate',
false);
321 $type = $possibleChild->getType();
323 if ($realSubjectType != null)
325 $associatedNode = &$persistenceFacade->create($realSubjectType, BUILDTYPE_SINGLE);
326 $possibleChild->setProperty(
'composition',
false);
327 $possibleChild->setProperty(
'realSubject', $associatedNode);
330 if ($realSubjectType != null && $resolveManyToMany) {
331 $type = $realSubjectType;
334 $type = $possibleChild->getType();
336 $allowedChildTypes[$type] = &$possibleChild;
339 return $allowedChildTypes;
351 $manyToMany = $proxy->getProperty(
'manyToMany');
352 if (is_array($manyToMany))
354 if (
sizeof($manyToMany) == 2)
357 foreach($proxy->getProperty(
'manyToMany') as $curParentType)
359 if ($curParentType != $parentType) {
360 return $curParentType;
367 $mapper = $proxy->getMapper();
368 if (method_exists($mapper,
'getRealSubjectType')) {
369 return $mapper->getRealSubjectType($proxy, $parentType);
382 $displayValueStr = $node->getProperty(
'display_value');
383 if (!strPos($displayValueStr,
'|')) {
384 $displayValues = array($displayValueStr);
387 $displayValues = split(
'\|', $displayValueStr);
389 return $displayValues;
425 if ($language != null) {
426 $localization->loadTranslation($node, $language);
429 $displayArray = array();
431 $formUtil =
new FormUtil($language);
432 $pathToShow = $node->getProperty(
'display_value');
433 if (!strPos($pathToShow,
'|')) {
434 $pathToShowPieces = array($pathToShow);
437 $pathToShowPieces = split(
'\|', $pathToShow);
439 foreach($pathToShowPieces as $pathToShowPiece)
443 if ($pathToShowPiece !=
'')
446 $pieces = split(
'/', $pathToShowPiece);
447 foreach ($pieces as $curPiece)
449 if (in_array($curPiece, $curNode->getValueNames()))
452 $tmpDisplay = $curNode->getValue($curPiece);
453 $properties = $curNode->getValueProperties($curPiece);
454 $inputType = $properties[
'input_type'];
455 $displayType = $properties[
'display_type'];
467 $possibleValues = $template->getValueNames();
468 foreach ($values as $key => $value) {
469 if (!in_array($key, $possibleValues)) {
470 unset($values[$key]);
473 if (sizeOf($values) == 0) {
480 $curNodeArray = $curNode->getChildrenEx(null, $curPiece, $values, null);
481 if (sizeOf($curNodeArray) > 0) {
482 $curNode = $curNodeArray[0];
490 $nodesOfTypePiece = $persistenceFacade->getOIDs($curPiece);
491 foreach($curNode->getProperty(
'childoids') as $childOID)
493 if (in_array($childOID, $nodesOfTypePiece))
497 if ($language != null) {
498 $localization->loadTranslation($curNode, $language);
504 foreach($values as $key => $value)
506 if ($curNode->getValue($key) != $value)
528 $tmpDisplay = $formUtil->translateValue($tmpDisplay, $inputType);
529 if (strlen($tmpDisplay) == 0) {
530 $tmpDisplay = $node->getOID();
535 if (!is_object(
$GLOBALS[
'gValueRenderer']))
538 $GLOBALS[
'gValueRenderer'] = &$objectFactory->createInstanceFromConfig(
'implementation',
'ValueRenderer');
539 if (
$GLOBALS[
'gValueRenderer'] == null) {
545 preg_match_all(
"/[\w][^\[\]]+/", $displayType, $matches);
546 if (sizeOf($matches[0]) > 0) {
547 list($type, $attributes) = $matches[0];
549 if (!$type || $type ==
'') {
552 $tmpDisplay =
$GLOBALS[
'gValueRenderer']->renderValue($type, $tmpDisplay, $attributes);
555 $displayArray[$pathToShowPiece] = $tmpDisplay;
557 return $displayArray;
568 return $typeNode->getObjectDisplayName();
579 return $typeNode->getObjectDescription();
595 function getInputControl(&$node, $name, $dataType=null, $templateNode=null, $addEmptyValue=
false)
598 if ($dataType == null)
600 $dataTypes = $node->getValueTypes($name);
601 if (
sizeof($dataTypes) > 0) {
602 $dataType = $dataTypes[0];
606 if ($templateNode != null) {
607 $properties = $templateNode->getValueProperties($name, $dataType);
610 $properties = $node->getValueProperties($name, $dataType);
615 $properties = $templateNode->getValueProperties($name, $dataType);
618 $value = $node->getValue($name, $dataType);
620 return $this->_formUtil->getInputControl($controlName, $properties[
'input_type'], $value, $properties[
'is_editable'], $addEmptyValue);
633 return 'value'.$fieldDelimiter.$dataType.$fieldDelimiter.$name.$fieldDelimiter.$node->getOID();
643 if (!(strpos($name,
'value') === 0)) {
648 $pieces = split($fieldDelimiter, $name);
649 if (!
sizeof($pieces) == 4) {
652 $forget = array_shift($pieces);
653 $dataType = array_shift($pieces);
654 if (strlen($dataType) > 0) {
655 $def[
'dataType'] = intval($dataType);
660 $def[
'name'] = array_shift($pieces);
661 $def[
'oid'] = array_shift($pieces);
672 $oldState = $node->getState();
683 $node->setState($oldState,
false);
695 if(
sizeof($nodeList) > 0 && $nodeList[0]->hasValue(
'sortkey',
DATATYPE_IGNORE)) {
698 for ($i=0; $i<
sizeof($nodeList); $i++)
709 $nodeList[$i]->setValue(
'prevoid', $nodeList[$i-1]->getOID(),
DATATYPE_IGNORE);
711 if ($i ==
sizeof($nodeList)-1) {
715 $nodeList[$i]->setValue(
'nextoid', $nodeList[$i+1]->getOID(),
DATATYPE_IGNORE);
731 $processor->run($node, $recursive);
742 $value = $node->getValue($valueName, $dataType);
747 if (strpos($value,
'http://') === 0 || strpos($value,
'https://') === 0) {
748 array_push($urls, $value);
751 foreach ($urls as $url)
755 if (strpos($url, $baseUrl) === 0) {
756 $urlConv = str_replace($baseUrl,
'', $url);
759 $value = str_replace($url, $urlConv, $value);
761 $node->setValue($valueName, $value, $dataType);
774 $formUtil =
new FormUtil($language);
775 $processor =
new NodeProcessor(
'renderValue', array($formUtil), $nodeUtil);
776 for($i=0; $i<
sizeof($nodes); $i++)
779 $processor->run($nodes[$i],
false);
791 $value = $node->getValue($valueName, $dataType);
793 $value = $formUtil->translateValue($value, $node->getValueProperty($valueName,
'input_type', $dataType),
true);
795 $displayType = $node->getValueProperty($valueName,
'display_type', $dataType);
796 if (strlen($displayType) == 0) {
797 $displayType =
'text';
800 $value = $renderer->renderValue($displayType, $value, $renderAttribs);
802 $node->setValue($valueName, $value, $dataType,
true);
818 $formUtil =
new FormUtil($language);
819 $processor =
new NodeProcessor(
'translateValue', array($formUtil), $nodeUtil);
820 for($i=0; $i<
sizeof($nodes); $i++)
823 $processor->run($nodes[$i],
false);
835 $value = $node->getValue($valueName, $dataType);
838 $value = $formUtil->translateValue($value, $node->getValueProperty($valueName,
'input_type', $dataType),
true, $node->getBaseOid());
840 $node->setValue($valueName, $value, $dataType,
true);
850 $valueNames = $node->getValueNames();
851 foreach($valueNames as $name) {
852 if (!in_array($name, $displayValues)) {
853 $node->removeValue($name);
getSelfQuery($nodeType, $oid)
getDescriptionFromType($type)
getInputControlName(&$node, $name, $dataType=null)
getChildQuery(&$parentNode, $childType)
setSortProperties(&$nodeList)
getParentQuery($parentType, &$childNode)
getDisplayValueNames(&$node)
makeValueUrlsRelative(&$node, $valueName, $dataType, $baseUrl)
sort(&$nodeList, $criteria, $recursive=false, $changeSortkey=false, $sortFunction='')
getDisplayValues(&$node, $useDisplayType=false, $language=null, $values=null)
getPossibleChildren(&$realNode, &$tplNode, $resolveManyToMany=true)
getDisplayNameFromType($type)
NodeProcessor is used to iterate over all values of a Node and apply a given callback function...
NodeUtil provides services for the Node class. All methods are static.
renderValues(&$nodes, $language=null)
throwEx($message, $file='', $line='')
makeNodeUrlsRelative(&$node, $baseUrl, $recursive=true)
getConnectionToAncestor(&$tplNode, $ancestorType, $nodes=null)
translateValues(&$nodes, $language=null)
decomposeOID($oid, $validate=true)
renderValue(&$node, $valueName, $dataType, $formUtil)
removeNonDisplayValues(&$node)
translateValue(&$node, $valueName, $dataType, $formUtil)
getOIDParameter($oid, $param, $validate=true)
getInputControl(&$node, $name, $dataType=null, $templateNode=null, $addEmptyValue=false)
getPossibleParents(&$realNode, &$tplNode)
getDisplayValue(&$node, $useDisplayType=false, $language=null, $values=null)
DefaultValueRenderer is responsible for rendering (Node) values of a given display type...
getConnectionToDescendant(&$tplNode, $descendantType, $nodes=null)
getValueDefFromInputControlName($name)
getRealSubjectType(&$proxy, $parentType)