1. Fabrik 3.9 has been released. If you have updated Joomla to 3.9, this is a required update.
    Dismiss Notice

Set a status field depending on an value of an other table

Discussion in 'Community' started by wuschel_lux, Jul 12, 2019.

  1. wuschel_lux

    wuschel_lux Member

    Level: Community
    Hi all,
    I am trying again to do something new for me.

    E.g. a person wants to subscribe to a course, I have a field (dropdown element) only visible for Admins with the status. In the table courses, there is a field with the max. participants in.
    So when someone subscribes and the already registered amount is <= the mac amount of participants then set the status value to "accepted", if over the limit set to "waiting list".

    I suppose it is possible, as nearly everything ist possible with this fantastic tool, just need some help to achieve this.

    Many thanks for your support.
    BR
     
  2. lousyfool

    lousyfool Active Member

    Level: Community
  3. wuschel_lux

    wuschel_lux Member

    Level: Community
    Hey sound good. Just started to read the wiki of the php form plugin. I think this is a very flexible and powerful tool.
    Thanks!
     
  4. wuschel_lux

    wuschel_lux Member

    Level: Community
    So finally I managed the job with 2 sql queries and then update the dropdown element field as described in the wiki.
    PHP:
    // SQL Querries
    // ...

    if($regPlaces >= $maxPlaces){
      $formModel->updateFormData('fkm_register_course___status', 'waiting list', true);
    } else {
      $formModel->updateFormData('fkm_register_course___status', 'confirmed', true);
    }
    I have just one concern. I have a so called Admin Area (Fabrik Group), hidden from public/registered users. Only Event Validators (Joomla Group) have access to this Group to validate/update the status, the status field is no more populated but is NULL.

    How ca I populate it while saving the record but hide it from groups having non Admin access.
    Thanks for your help, I'm a bit stuck on this.

    BR
     
  5. lousyfool

    lousyfool Active Member

    Level: Community
    If I understand you correctly, the PHP form plugin with your code doesn't work for public/registered users because only Event Validators (EV) have access to the status element, and so it is still NULL once an EV looks it up?
    This would mean the status field is not part of the form data, and then you'll need to replace the $formModel->updateFormData lines with PHP SQL queries to update the field.

    Hint: to avoid it also "auto-happening" for EVs, you may want to restrict the execution only to public/registered users by wrapping your code into a condition equivalent to "if my user group is not EV"...
     
    wuschel_lux likes this.
  6. wuschel_lux

    wuschel_lux Member

    Level: Community
    Thanks lousyfool,
    I will update the DB then with a SQL query and php form plugin code is just executed on a new submitted record, so later when EV are entering the record to modify fields the status field is not re-evaluated.
    BR
     
  7. wuschel_lux

    wuschel_lux Member

    Level: Community
    Hi again, I am facing problems with the SQL Update query:
    PHP:
      $db = JFactory::getDbo();
      $query = $db->getQuery(true);
        $query->clear();
        $query->update('table');
        $query->set('status = "waiting list"');
        $query->where('course = ' . $courseID);
        $db->setQuery($query);
        $db->execute();
     
    The value stored in DB is NULL.

    Is the query wrong or maybe the time when the php code is triggered. I tried with:
    - End of form submission
    - After Data stored, ...

    Is there a possibility to echo the query when populated to see possible errors?

    Thanks
     
  8. lousyfool

    lousyfool Active Member

    Level: Community
    Try
    Code (Text):
    $db = JFactory::getDbo();
    $query = $db->getQuery(true);
    $query->update($db->quoteName('table'));
    $query->set($db->quoteName('status') . ' = ' . $db->quote('waiting list'));
    $query->where($db->quoteName('course') . ' = ' . $courseID);
    $db->setQuery($query);
    $db->execute();
    Search the forum for "fabrikdebug".
     
    wuschel_lux likes this.
  9. troester

    troester Well-Known Member Staff Member

    Level: Community
    You can do
    echo $query;exit;

    Where is $courseID coming from?

    BTW: don't use $db etc (this may conflict with Fabrik variables), use something like $mydb
     
    wuschel_lux likes this.
  10. wuschel_lux

    wuschel_lux Member

    Level: Community
    Thanks again, there is an update done, but I have to fine tune a bit.

    The ?fabrikdebug=1 was enabled but I did not find the "php form plugin" query in the debug accordion.

    PHP:
    // get course ID
    $courseID = $formModel->getElementData('fkm_register_course___course', true);
    $courseID = is_array($courseID) ? $courseID[0] : $courseID;
     
  11. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    Nope, you won't see your queries there. As Troester said, you'll have to dump it by hand and exit.

    var_dump((string)$query);exit;

    ... which should just echo your query to the browser then quit.

    -- hugh
     

Share This Page