This topic is locked

Guide 33 – Context menu. data selection

1/17/2022 7:42:04 PM
PHPRunner Tips and Tricks
fhumanes author

img alt
In how many applications do we want to select a set of information and perform actions on that set? It can be a company and center the data on an address or section. It can be a school and center the action in a class. There are thousands of examples where this same situation occurs.

As we will see, with PHPRunner it is solved quite simply. What is necessary is to know some characteristics of the product that its use is not habitual.

In this example that I am going to use to explain the solution, what is desired is, from the data of a school, select a class and on this class, a contextual menu appears that allows us to manage the data of said class. It will give the sensation of a dynamic menu, but it is not so much. We will see how easy it is to solve this requirement.

Objetive

From the set of all the data (school) we are going to select a set (class) and on the data of the selected class, we update its information.

DEMO: https://fhumanes.com/menu

If you are interested in this tea, continue reading the article at this link .

fhumanes author 1/17/2022

I am going to explain functionally what I have done, so that the solution is understood.

img alt
When we access the consultation of the schools or classes, we see all of them that are in the system. We have 2 buttons to set or clear, the selection of the class we want to work with.

(1) Button to set the class with which we want to work. (3) the record with which we want to do the action is selected.

(2) button to clear the selection that has previously been made.

img alt
When the class has been selected, the menu (1) is enabled indicating the class with which you are working (context).

(2) all the information that is provided is subject to the selection of the previously fixed context.

img alt
In the screens that are "under" the control of the context, their dropdowns are adjusted to the data of said context. Only the subjects and students of the “fixed” class appear.

The “Fix College” button has this code:

$result["txt"] = "No college has been selected";
$count = 0;
while ( $data = $button->getNextSelectedRecord() ) {
$id = $data['id_menu_college'];
$code = $data['code'];
$name = $data['name'];
$count += 1;
}
if ($count == 0 ){
$result["txt"] = "No college has been selected";
}
if ($count > 1 ) {
$result["txt"] = "Only one college can be selected";
}
if ($count == 1 ) {
$result["txt"] = "OK";
$_SESSION['id'] = $id;
$_SESSION['code'] = $code;
$_SESSION['name'] = $name;
}

Mainly what it does, if all goes well, is create 3 session variables with the college data. These variables will be used for the selection of information and adaptation of the menu.

In the menu event “Menu item:Modify”, I have coded:

$title = $menuItem->getTitle();
$prefix = substr($title,0, 3);
if ($prefix == 'm1_' and !isset($_SESSION['code'])) { // Yes No College selected or displays the menu
return false;
}
if ( $prefix == 'm1_' ) {
$title = substr($title,3); // Clean prefix of title
$menuItem->setTitle($title);
}
if ($title == 'college' ) {
$menuItem->setTitle('<span style="color:Tomato;"><b>'.$_SESSION['code'].' - '.$_SESSION['name'].'</b></span>');
}

return true;

img alt

All options beginning with "m1" are treated to display if “college” has previously been selected or are “removed” if not already done.

The selection of the data of the selected "college" is done through the "After table initialized" event:

$query->addWhere("menu_college_id=".$_SESSION["id"]);

PHPRunner has a lot of facilities to adapt the interface and the data and it makes things like this very, very easy to program.

For any questions or what you need, contact me through my email fernandohumanes@gmal.com

I leave you the example so that you can install it on your Windows and do all the tests and adjustments that you consider appropriate.