Getting field values from LISE and use in an UDT Topic is solved

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
User avatar
webform
Power Poster
Power Poster
Posts: 503
Joined: Sat Nov 25, 2006 3:39 pm
Location: Copenhagen, Denmark

Getting field values from LISE and use in an UDT

Post 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}
base640
New Member
New Member
Posts: 3
Joined: Sat Dec 04, 2021 11:15 am
Location: Finland

Re: Getting field values from LISE and use in an UDT

Post 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 :)
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: Getting field values from LISE and use in an UDT

Post 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;
User avatar
webform
Power Poster
Power Poster
Posts: 503
Joined: Sat Nov 25, 2006 3:39 pm
Location: Copenhagen, Denmark

Re: Getting field values from LISE and use in an UDT

Post 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.
Post Reply

Return to “Modules/Add-Ons”