I have below 3 tables created with data as shown in the image.
"Lanlords" table is parent to "Properties" table.
"Properties" table is parent to "Applicant" table.
When "Applicant1" status is updated as "Completed", then the user should not be able to update its parents records.
It means user should not be able to edit "Property1" and "Landlord1" records in the parent tables.
How can I achieve this?
When child record updated as Completed, then corresponding parent records should not be Editable
Re: When child record updated as Completed, then corresponding parent records should not be Editable
Hi,
in hooks/child-tablename.php you can check in the _before_update function if field X from some table contains Y and the react on that.
In your case: If status=completed then return false -> False will cancel the update process, thus making it impossible to change anything in the child record.
You might want to inform the user about this (see my footer: Custom (error) message
You can also check out the $options->AllowUpdate and set this in the _init function of hooks/child-tablename.php. This will make it possible to disallow any changes. Same procedure: check (in the init) if the user can (still) edit the record. If no, set the value to 0 which should disable editing that record.
AllowUpdate is (unfortunately as some others) not listed on https://bigprof.com/appgini/help/advanc ... ist-object
@ahmed: Please update the options on that page as every single /hooks/tablename file references this URL.
Olaf
in hooks/child-tablename.php you can check in the _before_update function if field X from some table contains Y and the react on that.
In your case: If status=completed then return false -> False will cancel the update process, thus making it impossible to change anything in the child record.
You might want to inform the user about this (see my footer: Custom (error) message
You can also check out the $options->AllowUpdate and set this in the _init function of hooks/child-tablename.php. This will make it possible to disallow any changes. Same procedure: check (in the init) if the user can (still) edit the record. If no, set the value to 0 which should disable editing that record.
AllowUpdate is (unfortunately as some others) not listed on https://bigprof.com/appgini/help/advanc ... ist-object
@ahmed: Please update the options on that page as every single /hooks/tablename file references this URL.
Olaf
Some postings I was involved, you might find useful:
SingleEdit - Prevent concurrent edits on records; Field Permissions; Column-Value-Based-Permissions; Custom (error) message; Audit Log; Backup your database; Two Factor Authentication; Block brute force (failed) logins; Add 2nd SAVE CHANGES button; Place a search on details view
SingleEdit - Prevent concurrent edits on records; Field Permissions; Column-Value-Based-Permissions; Custom (error) message; Audit Log; Backup your database; Two Factor Authentication; Block brute force (failed) logins; Add 2nd SAVE CHANGES button; Place a search on details view
Re: When child record updated as Completed, then corresponding parent records should not be Editable
Well, the reason AllowUpdate is not listed is that it won't workAllowUpdate is (unfortunately as some others) not listed on https://bigprof.com/appgini/help/advanc ... ist-object
@ahmed: Please update the options on that page as every single /hooks/tablename file references this URL.
To actually prevent editing a record based on some value in another table, one way is to set up the users permissions so that users can view all but edit only their group records. And in the childtable_after_update/childtable_after_insert hooks, change the owner of the related parent record to another group 'locked' for example or so. This way, the parent record will no longer be editable for users.
AppGini plugins to add more power to your apps:
- DataTalk is an innovative AppGini plugin based on ChatGPT that allows you to interact with your AppGini database using natural language questions, without writing any SQL. Check the demo video
- Mass Update plugin: Update multiple records at once and improve your workflow efficiency.
- Check our other plugins and get a generous discount of up to 30% when buying 2 or more plugins.
Re: When child record updated as Completed, then corresponding parent records should not be Editable
@onoehring, @a.gneady - Thank you for your response and guidance. I have followed your suggestions and updated code to meet my requirements and got the solution working.
I am sharing the solution below for other friends, who might be looking for actual code.
I am sharing the solution below for other friends, who might be looking for actual code.
Code: Select all
// ====== Show Error for Parent Edit, if child status is 'Completed'
/* ====== STEP-1:
==================
create a view with below query in mySQL (phpMyAdmin) in your DB.
This query assuming I have 5 tables as below.
DB schema (Tables): Parent > Child relation:
landlords > properties > applicants > schedule > status
*/
//view_name: "parentlock_forchildcompleted"
SELECT a.id as Tstatus_id, a.status as Tstatus,
b.id as Tschedule_id, b.date as Tschedule_date,
c.id as Tapplicant_id, c.first_name as Tapplicant_first_name,
d.id as Tproperties_id, d.property_name as Tproperties_property_name,
e.id as Tlandlords_id, e.first_name as Tlandlords_first_name
FROM `status` a, `schedule` b, `applicants` c, `properties` d, `landlords` e
WHERE a.status = 'completed'
AND a.Schedule_id = b.id
AND b.applicant_name = c.id
AND c.property = d.id
AND d.landlord_name = e.id
/* ====== STEP-2:
==================
Put below code in hooks/<ParentTable>.php file under Landlords_before_update().
In this example my parent table name as "Landlords".
So I need to add below code in "hooks/Landlords.php" file.
*/
function Landlords_before_update(&$data, $memberInfo, &$args) {
$sqlQuery = "
SELECT DISTINCT `Tlandlords_id`
FROM `parentlock_forchildcompleted` va
WHERE va.Tlandlords_id = '{$data['selectedID']}' ";
$id = sqlValue($sqlQuery);
$msg = "This parent record can not be updated, as its child record(s) status is 'Completed'";
if($id==null){
return TRUE;
}
else{
$_SESSION['custom_err_msg']= $msg; //json_encode($data);
return FALSE;
}
}
/* ====== STEP-3:
==================
Put below code in hooks/header-extras.php file
*/
<?php
if (isset($_SESSION['custom_err_msg'])) {
$customError ='<div style="margin-top:2em !important; padding:0.5em !important;" class="custmErrMsg alert alert-dismissable alert-danger">'.$_SESSION['custom_err_msg'].'</div>';
echo $customError;
if ($_SESSION['custom_err_shown'] == 1){
unset($_SESSION['custom_err_msg']);
$_SESSION['custom_err_shown'] = 0;
}
else {
$_SESSION['custom_err_shown'] = 1;
}
}
Re: When child record updated as Completed, then corresponding parent records should not be Editable
Hi ndoddi,
thank you for sharing your solution.
Olaf
thank you for sharing your solution.
Olaf
Some postings I was involved, you might find useful:
SingleEdit - Prevent concurrent edits on records; Field Permissions; Column-Value-Based-Permissions; Custom (error) message; Audit Log; Backup your database; Two Factor Authentication; Block brute force (failed) logins; Add 2nd SAVE CHANGES button; Place a search on details view
SingleEdit - Prevent concurrent edits on records; Field Permissions; Column-Value-Based-Permissions; Custom (error) message; Audit Log; Backup your database; Two Factor Authentication; Block brute force (failed) logins; Add 2nd SAVE CHANGES button; Place a search on details view