Page 1 of 1
Getting field values from LISE and use in an UDT
Posted: Fri Sep 27, 2024 2:10 pm
by webform
I wonder how I can retrieve values from a LISE Instance and use in a UDT (to be used in a mail script and looping through recipients)?
I have no problems with getting a single value where I have a template like:
Code: Select all
{* Module: LISEInstance Layout: MyLayout *}
{foreach from=$items item=item name=assets}
{$item->name}{if not $smarty.foreach.assets.last},{/if}
{/foreach}
And a UDT like:
Code: Select all
$smarty_data = "{cms_module module='LISEInstance' template_summary='MyLayout'}";
$name = $smarty->fetch('eval:'.$smarty_data);
$result = explode(",", $name);
foreach ($result as $row) {
echo $row ."<br>";
}
But what do I do if I want to retrieve more field values from LISE and use in my UDT? For example
Code: Select all
{foreach from=$items item=item name=assets}
Name => {$item->name}
Email => {$item->name}
Category => {$item->category}
{/foreach}
Re: Getting field values from LISE and use in an UDT
Posted: Sat Sep 28, 2024 6:58 am
by base640
I don't really know Smarty, but if the first code snippet could somehow output JSON:
Code: Select all
{* Module: LISEInstance Layout: MyLayout *}
echo json_encode(array_map(fn($item) =>
["name" => $item->name, "email" => $item->email, "category" => $item->category]
, $items))
or
$out = [];
{foreach from=$items item=item name=assets}
$out[] = ["name" => $item->name, "email" => $item->email, "category" => $item->category];
{/foreach}
echo json_encode($out);
then in the UDT, you could read them like this:
Code: Select all
$smarty_data = "{cms_module module='LISEInstance' template_summary='MyLayout'}";
$json = $smarty->fetch('eval:'.$smarty_data);
$parsed = json_decode($json, false);
foreach ($parsed as $item) {
echo "Name: ", $item->name, "\n",
"Email: ", $item->email, "\n",
"Cat: ", $item->category;
}
Maybe someone from the development team can take it from here

Re: Getting field values from LISE and use in an UDT
Posted: Sat Sep 28, 2024 10:04 am
by velden
LISE has a very useful api by its own. So you don't need to fiddle around with Smarty templates and calls
The sample code below will return all items but of course you change it to do what you need.
Code: Select all
$mod = cmsms()->GetModuleInstance('LISEyourinstancename');
$parms['pagelimit'] = 1000;
$parms['showall'] = true; // <- To disable time control queries
$item_query = new LISEItemQuery($mod, $parms);
$item_query->AppendTo(LISEQuery::VARTYPE_WHERE, 'A.active = 1');
$result = $item_query->Execute(true);
$items = array();
while ($result && $row = $result->FetchRow())
{
$obj = $mod->InitiateItem(array("item_id","title"));
LISEItemOperations::Load($mod, $obj, $row);
$items[$obj->item_id] = $obj->title;
}
return $items;
Re: Getting field values from LISE and use in an UDT
Posted: Sat Sep 28, 2024 2:47 pm
by webform
Thanks a lot velden!
Totally forgot about LISE's api
After fiddling around a bit, I came up with the following (test) UDT, where I retrieve different field values and filter/search on params values, that seems to work:
Code: Select all
$mod = cmsms()->GetModuleInstance('LISEyourinstancename');
$parms['pagelimit'] = 1000;
$parms['showall'] = true; // <- To disable time control queries
$parms['xs_issued'] = 1; // <- Filter/Search a field value
$item_query = new LISEItemQuery($mod, $parms);
$item_query->AppendTo(LISEQuery::VARTYPE_WHERE, 'A.active = 1');
$result = $item_query->Execute(true);
$items = array(); // Holds structured data
while ($result && $row = $result->FetchRow())
{
// Initialize an object
$obj = $mod->InitiateItem(array("item_id", "title", "email", "type", "return_date"));
LISEItemOperations::Load($mod, $obj, $row);
// Append to $items as an associative array
$items[] = array(
'title' => $obj->title,
'email' => $obj->email,
'type' => $obj->type,
'return_date' => $obj->return_date
);
}
// Access each row and its fields
foreach ($items as $item) {
echo "Title: " . $item['title'] . "<br>";
echo "Email: " . $item['email'] . "<br>";
echo "Type: " . $item['type'] . "<br>";
echo "Return Date: " . $item['return_date'] . "<br><br>";
}
Now I just need to have the code implemented in my mail script, where a user gets an email if they have not returned a borrowed item on the specified return date.