diff --git a/mocha-php/src/mocha-php/include/mochacommon.inc.php b/mocha-php/src/mocha-php/include/mochacommon.inc.php
index 19019f9..0798d8d 100644
--- a/mocha-php/src/mocha-php/include/mochacommon.inc.php
+++ b/mocha-php/src/mocha-php/include/mochacommon.inc.php
@@ -101,12 +101,15 @@ function mocha_get_current_user() : ?InstanceReference
if ($currentTenant !== null)
{
- if (isset($_SESSION["user_token_" . $currentTenant->ID]))
+ if (isset($_SESSION["user_token_" . System::GetTenantName()]))
{
// SELECT FROM `Users` WHERE `Token` = $_SESSION["user_token"]
+
+ //! FIXME: this still results in loads of (tiny) HTTP calls to the OMS
+ // replace with: /tenants/super/instances?4$223=...&4$215=...
$insts = $oms->getInstancesOfByAttributes(KnownClassGuids::UserLogin, array
(
- KnownAttributeGuids::Token => $_SESSION["user_token_" . $currentTenant->ID]
+ KnownAttributeGuids::Token => $_SESSION["user_token_" . System::GetTenantName()]
));
$currentUser = null;
diff --git a/mocha-php/src/mocha-php/lib/mocha/core/InstanceKey.inc.php b/mocha-php/src/mocha-php/lib/mocha/core/InstanceKey.inc.php
index f589d98..c5e0360 100644
--- a/mocha-php/src/mocha-php/lib/mocha/core/InstanceKey.inc.php
+++ b/mocha-php/src/mocha-php/lib/mocha/core/InstanceKey.inc.php
@@ -5,23 +5,39 @@
{
public $ClassIndex;
public $InstanceIndex;
+ public $IsDerived;
- public function __construct(int $class_id, int $inst_id)
+ public function __construct(int $class_id, int $inst_id, bool $isDerived = false)
{
$this->ClassIndex = $class_id;
$this->InstanceIndex = $inst_id;
+ $this->IsDerived = $isDerived;
}
public static function Parse(?string $instanceKeyStr) : ?InstanceKey
{
if ($instanceKeyStr !== null)
{
- $split = explode("$", $instanceKeyStr);
- if (count($split) == 2)
+ $sep = null;
+ $isDerived = false;
+ if (str_contains($instanceKeyStr, '$'))
{
- if (is_numeric($split[0]) && is_numeric($split[1]))
+ $sep = '$';
+ }
+ else if (str_contains($instanceKeyStr, '!'))
+ {
+ $sep = '!';
+ $isDerived = true;
+ }
+ if ($sep != null)
+ {
+ $split = explode($sep, $instanceKeyStr);
+ if (count($split) == 2)
{
- return new InstanceKey(intval($split[0]), intval($split[1]));
+ if (is_numeric($split[0]) && is_numeric($split[1]))
+ {
+ return new InstanceKey(intval($split[0]), intval($split[1]), $isDerived);
+ }
}
}
}
diff --git a/mocha-php/src/mocha-php/lib/mocha/core/InstanceReference.inc.php b/mocha-php/src/mocha-php/lib/mocha/core/InstanceReference.inc.php
index faaffbc..6a9a98e 100644
--- a/mocha-php/src/mocha-php/lib/mocha/core/InstanceReference.inc.php
+++ b/mocha-php/src/mocha-php/lib/mocha/core/InstanceReference.inc.php
@@ -14,6 +14,18 @@
public ?int $DatabaseId;
public InstanceKey|null $InstanceKey;
public UUID|null $GlobalIdentifier;
+ public string|null $Text;
+ public InstanceReference|null $DefaultTask;
+ public string|null $DefaultTaskUrl;
+ public InstanceReference|null $ParentClass;
+
+ public static function parse(array|null $obj) : InstanceReference|null
+ {
+ if ($obj == null)
+ return null;
+
+ return new InstanceReference(null, InstanceKey::parse($obj["iid"]), UUID::parse($obj["globalIdentifier"]), $obj["text"], InstanceReference::parse($obj["parentClass"]["defaultTask"]), InstanceReference::parse($obj["parentClass"]));
+ }
public static function toInstanceKeys(array $instanceReferences) : array
{
@@ -25,7 +37,7 @@
return $keys;
}
- public function __construct(?int $databaseId, InstanceKey|null $instanceKey, UUID|string|null $globalIdentifier)
+ public function __construct(?int $databaseId, InstanceKey|null $instanceKey, UUID|string|null $globalIdentifier, string|null $text = null, InstanceReference|string|null $defaultTaskOrUrl = null, InstanceReference|null $parentClass = null)
{
//$this->OMS = $oms;
$this->DatabaseId = $databaseId;
@@ -36,6 +48,19 @@
$globalIdentifier = UUID::parse($globalIdentifier);
}
$this->GlobalIdentifier = $globalIdentifier;
+ $this->Text = $text;
+
+ if (is_string($defaultTaskOrUrl))
+ {
+ $this->DefaultTaskUrl = $defaultTaskOrUrl;
+ $this->DefaultTask = null;
+ }
+ else
+ {
+ $this->DefaultTask = $defaultTaskOrUrl;
+ $this->DefaultTaskUrl = null;
+ }
+ $this->ParentClass = $parentClass;
}
/*
diff --git a/mocha-php/src/mocha-php/lib/mocha/core/KnownRelationshipGuids.inc.php b/mocha-php/src/mocha-php/lib/mocha/core/KnownRelationshipGuids.inc.php
index 4dc1136..a441803 100644
--- a/mocha-php/src/mocha-php/lib/mocha/core/KnownRelationshipGuids.inc.php
+++ b/mocha-php/src/mocha-php/lib/mocha/core/KnownRelationshipGuids.inc.php
@@ -255,6 +255,7 @@ class KnownRelationshipGuids
const Instance__for__Element_Content = "c3959f84248d4edea3f2f262917c7b56";
const Element_Content__has__Layout = "1ab7412005ea4acab6d3c7e0133e0c4f";
+
const Element_Content__has__EC_Dynamic_Display_Option = "{4a41391a-c325-4182-920a-a94ad28c15fa}";
const EC_Dynamic_Display_Option__modifies__Element_Content = "{4d091643-2bfc-4b83-b3e4-8a3b22c665a9}";
diff --git a/mocha-php/src/mocha-php/lib/mocha/core/Oms.inc.php b/mocha-php/src/mocha-php/lib/mocha/core/Oms.inc.php
index 358bff1..b5ed6c0 100644
--- a/mocha-php/src/mocha-php/lib/mocha/core/Oms.inc.php
+++ b/mocha-php/src/mocha-php/lib/mocha/core/Oms.inc.php
@@ -192,7 +192,6 @@
*/
public function getParentClass(InstanceReference $inst) : ?InstanceReference
{
- $gid = $inst->GlobalIdentifier->__toString();
$forClass = $this->getRelatedInstance($inst, $this->getInstanceByGlobalIdentifier(KnownRelationshipGuids::Instance__for__Class));
return $forClass;
}
@@ -964,9 +963,14 @@
return new OmsContext();
}
- public function isConnected()
+ public function isConnected() : bool
{
return true;
}
+
+ public function processElement(InstanceReference $element, array $values) : array | bool
+ {
+ return false;
+ }
}
?>
\ No newline at end of file
diff --git a/mocha-php/src/mocha-php/lib/mocha/oms/HttpOmsClient.inc.php b/mocha-php/src/mocha-php/lib/mocha/oms/HttpOmsClient.inc.php
index d031458..c8fb9f5 100644
--- a/mocha-php/src/mocha-php/lib/mocha/oms/HttpOmsClient.inc.php
+++ b/mocha-php/src/mocha-php/lib/mocha/oms/HttpOmsClient.inc.php
@@ -56,9 +56,10 @@
{
//trigger_error("curl_request for url " . $relativeUrl);
$curl = $this->curl_new($relativeUrl);
+ \curl_setopt($curl, CURLOPT_HTTPHEADER, array("X-Forwarded-For:" . $_SERVER["REMOTE_ADDR"]));
if ($method == HttpRequestMethod::POST)
{
- trigger_error("POST " . $relativeUrl);
+ //trigger_error("POST " . $relativeUrl);
\curl_setopt($curl, CURLOPT_POST, true);
if ($data !== null)
{
@@ -70,7 +71,7 @@
{
if ($dataFormat == HttpPostDataFormat::URLENCODED)
{
- trigger_error("POST(" . count($data) . ") " . http_build_query2($data));
+ //trigger_error("POST(" . count($data) . ") " . http_build_query2($data));
\curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query2($data));
}
else
@@ -196,9 +197,54 @@
return $insts2;
}
+ public function search(string $query, array | InstanceReference | null $parentClasses = null, string | null $m = null) : array | bool
+ {
+ $uri = "/tenants/super/instances?";
+
+ if ($m != null)
+ {
+ $uri .= "m=" . urlencode($m) . "&";
+ }
+ $uri .= "q=" . urlencode($query);
+ if (is_array($parentClasses))
+ {
+ for ($i = 0; $i < count($parentClasses); $i++)
+ {
+ $uri .= "&parentClassIid=" . $parentClasses[$i]->InstanceKey->__toString();
+ }
+ }
+ else if ($parentClasses instanceof InstanceReference)
+ {
+ $uri .= "&parentClassIid=" . $parentClasses->InstanceKey->__toString();
+ }
+
+ $json = $this->curl_request_json($uri, HttpRequestMethod::GET);
+ return $json;
+ }
public function getInstancesOfByAttributes(array|InstanceKey|InstanceReference|string|null $parentClass, array $parms)
{
$parentClass = $this->normalizeInstanceReference($parentClass);
+ $data = array();
+ foreach ($parms as $k => $v)
+ {
+ $data[$this->normalizeInstanceReference($k)->GlobalIdentifier->__toString()] = $v;
+ }
+
+ $insts2 = array();
+ $url = "/tenants/" . $this->getTenantName() . "/instances";
+ if ($parentClass !== null)
+ {
+ $url .= "?parentClassIid=" . $parentClass->GlobalIdentifier;
+ }
+ $json = $this->curl_request_json($url, HttpRequestMethod::POST, $data);
+ foreach ($json["instances"] as $inst)
+ {
+ $insts2[] = new InstanceReference(null, InstanceKey::parse($inst["iid"]), UUID::parse($inst["globalIdentifier"]));
+ }
+ return $insts2;
+
+ /*
+
// FIXME: NOT IMPLEMENTED
//usage:
// getInstanceByAttributes (array ( getInstanceByGlobalIdentifier(NAME_ATTRIBUTE) => "zq-developer" ))
@@ -227,6 +273,7 @@
}
return $insts2;
+ */
}
public function getInstanceData(array|InstanceKey|InstanceReference|string|null $inst)
@@ -312,7 +359,7 @@
public function getInstanceByKey(InstanceKey|string $key) : ?InstanceReference
{
$result = $this->curl_request_json("/tenants/" . $this->getTenantName() . "/instances/" . $key);
- return new InstanceReference(null, InstanceKey::parse($result["instanceKey"]), UUID::parse($result["globalIdentifier"]));
+ return new InstanceReference(null, InstanceKey::parse($result["iid"]), UUID::parse($result["globalIdentifier"]));
}
/**
@@ -321,7 +368,7 @@
public function getInstanceByGlobalIdentifier(UUID|string $inst) : ?InstanceReference
{
$result = $this->curl_request_json("/tenants/" . $this->getTenantName() . "/instances/" . $inst);
- return new InstanceReference(null, InstanceKey::parse($result["instanceKey"]), UUID::parse($result["globalIdentifier"]));
+ return new InstanceReference(null, InstanceKey::parse($result["iid"]), UUID::parse($result["globalIdentifier"]));
}
public function createInstanceOf(InstanceReference $classInstance) : ?InstanceReference
@@ -337,6 +384,26 @@
return null;
}
+ public function processElement(InstanceReference $element, array $values) : array | bool
+ {
+ $result = $this->curl_request_json("/tenants/" . $this->getTenantName() . "/instances/" . $element->GlobalIdentifier . "/element", HttpRequestMethod::POST, $values);
+ if ($result["result"] == "success")
+ {
+ return $result;
+ }
+ return false;
+ }
+
+ public function getRelatedTasks(InstanceReference $inst)
+ {
+ $result = $this->curl_request_json("/tenants/" . $this->getTenantName() . "/instances/" . $inst->GlobalIdentifier . "/relatedTasks", HttpRequestMethod::GET);
+ if ($result["result"] == "success")
+ {
+ return $result;
+ }
+ return [ ];
+ }
+
}
?>
\ No newline at end of file
diff --git a/mocha-php/src/mocha-php/lib/mocha/search/SearchHelper.inc.php b/mocha-php/src/mocha-php/lib/mocha/search/SearchHelper.inc.php
index a82a153..b1a5c1a 100644
--- a/mocha-php/src/mocha-php/lib/mocha/search/SearchHelper.inc.php
+++ b/mocha-php/src/mocha-php/lib/mocha/search/SearchHelper.inc.php
@@ -1,11 +1,14 @@
searchSlow($q);
return $this->searchIndexed($q);
+ */
+
+ $json = $this->_OMS->search($q, $this->ValidClasses, $m);
+ $results = array();
+
+ foreach ($json["instances"] as $obj)
+ {
+ $results[] = InstanceReference::parse($obj);
+ }
+ return $results;
}
public function searchIndexed(string $q)
diff --git a/mocha-php/src/mocha-php/lib/mocha/ui/controls/InstanceBrowser.inc.php b/mocha-php/src/mocha-php/lib/mocha/ui/controls/InstanceBrowser.inc.php
index b2bf81f..a352922 100644
--- a/mocha-php/src/mocha-php/lib/mocha/ui/controls/InstanceBrowser.inc.php
+++ b/mocha-php/src/mocha-php/lib/mocha/ui/controls/InstanceBrowser.inc.php
@@ -194,12 +194,12 @@
$li = new WebControl();
$li->TagName = "li";
- $instParent = $oms->getParentClass($inst);
- $parentClassName = $oms->getInstanceText($instParent);
+ //$instParent = $oms->getParentClass($inst);
+ //$parentClassName = $oms->getInstanceText($instParent);
$adw = new AdditionalDetailWidget("");
$adw->RelatedActionButtonUrl = "~/d/inst/" . $inst->InstanceKey . "/rel-tasks.htmld";
-
+
if (mocha_asset_exists("uic-assets", "1.1.5", "zq/icons/1$" . $inst->InstanceKey->ClassIndex . ".png")
|| mocha_asset_exists("uic-assets", "1.1.5", "zq/icons/1$" . $inst->InstanceKey->ClassIndex . ".svg"))
{
@@ -207,9 +207,9 @@
}
$adw->Attributes[] = new WebControlAttribute("data-instance-id", $inst->InstanceKey);
$adw->ClassList[] = "mcx-moniker";
- $adw->ClassTitle = $parentClassName;
+ //$adw->ClassTitle = $parentClassName;
- $defaultTaskUrl = $oms->getDefaultTaskUrl($inst);
+ $defaultTaskUrl = $inst->DefaultTaskUrl; // $oms->getDefaultTaskUrl($inst);
if ($defaultTaskUrl !== null)
{
$adw->TargetURL = $defaultTaskUrl;
@@ -226,8 +226,13 @@
}
else
{
- $adw->Text = $oms->getInstanceText($inst);
+ if ($inst->Text !== null)
+ {
+ $adw->Text = $inst->Text;
+ }
+ //$adw->Text = $oms->getInstanceText($inst);
}
+
/*
$this->MenuItems = array(
diff --git a/mocha-php/src/mocha-php/lib/mocha/ui/renderers/html/HTMLRenderer2.inc.php b/mocha-php/src/mocha-php/lib/mocha/ui/renderers/html/HTMLRenderer2.inc.php
index 19fce0c..8392043 100644
--- a/mocha-php/src/mocha-php/lib/mocha/ui/renderers/html/HTMLRenderer2.inc.php
+++ b/mocha-php/src/mocha-php/lib/mocha/ui/renderers/html/HTMLRenderer2.inc.php
@@ -2,8 +2,13 @@
namespace Mocha\UI\Renderers\HTML;
+ use Mocha\Core\InstanceKey;
+ use Mocha\Core\InstanceReference;
use Mocha\Core\OmsContext;
+ use Mocha\UI\Controls\InstanceBrowser;
use Phast\System;
+ use Phast\WebControlAttribute;
+ use Phast\WebControls\AdditionalDetailWidget;
class HTMLRenderer2 extends HTMLRenderer
{
@@ -12,6 +17,60 @@
parent::__construct($context, $withoutOms);
}
+ public function processPostback(InstanceReference $element) : array | bool
+ {
+ /**
+ * @var \Mocha\Core\Oms
+ */
+ $oms = mocha_get_oms();
+
+ $values = array();
+ foreach ($_POST as $key => $value)
+ {
+ if (str_starts_with($key, "ec_"))
+ {
+ $fqecid = substr($key, 3);
+ $values[$fqecid] = $value;
+ }
+ }
+
+ $array = $this->OMS->processElement($element, $values);
+ if ($array === false)
+ {
+ return false;
+ }
+
+ if (is_callable($this->ProcessPostbackFunction))
+ {
+ // call user-defined ProcessPostbackFunction
+ return call_user_func($this->ProcessPostbackFunction, $this, $element, $array);
+ }
+ else
+ {
+ $dummy = [ ];
+ if (!$this->processRelatedPostback($dummy, $element))
+ {
+ return false;
+ }
+ }
+
+ if (count($this->FailedValidations) > 0)
+ return false;
+
+ if ($this->DebugMode)
+ {
+ echo ("debug mode done");
+ die();
+ }
+
+ if (isset($_POST["ReturnToURL"]))
+ {
+ System::Redirect($_POST["ReturnToURL"]);
+ return true;
+ }
+ return $array;
+ }
+
public function renderInitialElement($element)
{
$json = $this->OMS->getResponse($element);
@@ -32,7 +91,11 @@
public function renderFragment(array $json, $fqecidPrefix = "")
{
+ // echo ("renderFragment:
"); print_r($json);
+ //print_r($json); die();
$fqecid = $fqecidPrefix . $json["ecid"];
+ // we do not yet know how to deal with fully-qualified ECIDs
+ $fqecid = $json["ecid"];
if ($json["visible"] === false)
{
return;
@@ -42,6 +105,45 @@
{
$this->renderFragment($json["body"]);
}
+ else if ($json["widget"] == "grid")
+ {
+ echo ("
| "); + echo (""); + echo (" | "); + } + echo ("
|---|
| "); + //print_r($col); + $this->renderFragment($col); + echo (" | "); + } + echo ("