• New Commercial Services Section

    We have now opened a commercial services section here on the forum. If you have a Fabrik project that you wish to have someone work on for you, post it under Help Wanted. If you are an application developer and wish to earn some money helping others, post your details under Fabrik Application Developers.

    Both of these are unmoderated. It will be up to both parties to work out the details and come to an agreement.

Can Edit Row list plugin

  • Views Views: 17,612
  • Last updated Last updated:

Navigation

  • This plug-in provides a fine grained control over which records can be edited.

    The list's Access->edit records option takes precedence over this plugin. That is to say that if you are logged in as a registered user, and the list's delete records option is set to Special, then no records can be edited, regardless of any match that might be made with this plugin. In other words, this plugin can only be used to deny access to a row which the built in list ACL's would usually allow. It cannot permit edit access, if the normal list ACL's do not allow permission.

    If more than one can edit plugin is used, and any one of the plugins returns false, then the row will not be editable.


    NOTE the above precedence was change on 12/1/2017. The plugin now takes precedence over the list's normal group/user ACLs. If the plugin returns true or false, this overrides the list's ACLs. If the plugin returns null, then the list ACL's are used. If more than one plugin returns a result, 'false' takes precedence.

    caneditrow-options.png


    • Access - Which Joomla User 'Access level' will this plug-in be applied to
    • Element - The element whose data needs to make the value specified in the 'value' field.
    • Use Raw - Should we compare the element's raw data or the visible data (e.g. if using a User element, do we compare against the raw value '62' or the display value of 'Admin')
    • Value - The value to compare against. If the element's value matches this then the row IS editable
    caneditrow-example.png


    caneditrow-advanced.png

    • PHP (eval) - A PHP statement which needs to return the value to match against the element's data. Anything entered here takes precedence over the 'value' field. usual Placeholders can be used, like {tablename___elementname}, {$my->id}, etc.
    Code:

    /**
    * If status is 1, allow edit. If status is 2, don't allow edit. If status is 3, punt and let normal ACLs decide
    */
    switch ('{tablename___status_raw}') {
    case '1':
    return true;
    case '2':
    return false;
    case '3':
    return null;
    }

    Here is another php plugin example based on date.
    In this example, there is a Date element (field) called "flight_date" - the date of an aircraft flight.
    If the flight date is prior to last year, the record is read only.
    So - the user with the specified permission can edit a flight this year and last year, but not before.

    Note: the php DateTime() function could be used - perhaps to good effect.

    Code:

    /* This plugin compares the flight date to the jan 1 of the previous year and makes this record read only if the flight is that old.
    * So - if it is 2021, and you try to edit a flight, if that flight happened in 2020 or 2021, you can edit it. If it happened in 2019, you cannot.
    */

    $flight_date = strtotime('{daily_log___flight_date}'); // date of the flight as entered in the log.
    $compare_date = strtotime(date('Y')-1 . '-01-01'); //Take this year - 1 and jan 1 to it and convert to unix time

    if ( $flight_date < $compare_date) {
    return false; // flight too old - cannot edit
    }
    return true; // Go ahead and edit.
Back
Top