• Hello again,

    Sorry to keep asking lots of questions, but once I have the main setup done, I will be good to go…so thank you for your patience.

    Is there a way with the current version, or possibly with your upgraded version to count entries in a “Multiselect Checkbox” – so for example, if the multiselect was as follows:

    Car Design:

    – Leather seats: Checked
    – Alloy wheels: Checked
    – Metallic paint: Unchecked
    – Satnav: Unchecked
    – Diesel: Checked

    So in this case all the “Checked” items would equate to 1 and all the “Unchecked” items would equate to 0, which means the total would equal 3 in the above example.

    Thank you

Viewing 15 replies - 76 through 90 (of 94 total)
  • Plugin Author xnau webdesign

    (@xnau)

    The filter you’re using replaces the normal calculation that takes place just before the record data is updated to the database. If you look in the debugging log, you’ll see that the newly calculated values are included in the query that updates the whole record.

    If you have plugin debugging enabled, an error_log statement will be printed to the log so you can see how your code is doing.

    Simplifying the code can mean a lot of things, but most importantly, it should be possible to check on things at different stages of the function so you can check to see if things are calculating as expected.

    crowwoods1

    (@crowwoods1)

    I simplified the code so that it’s clear which calculated fields is doing what but the result is the same.

    Now the only thing in the debugging log between each of the updates is:
    PDb_Participant_Cache::refresh_cache: Refreshing Participants Database cache for cache group 0

    Could this have something to do with it?

    crowwoods1

    (@crowwoods1)

    I put in an error_log right before the role_points return but it didn’t show up in the log.

    error_log(“result for role_points: $result and replacement data: $replacement_data”);

    Also, are the $result and $replacement_data supposed to be the same? Where is $replacement data set?

    crowwoods1

    (@crowwoods1)

    Roland,

    I used echo and I found the culprit, yay! But I don’t know how to fix it.

    It looks like the $record_data[‘role’] is pulling in the role before the update. So how do I get it to pick up the one that’s after the update?

    Ivy

    Plugin Author xnau webdesign

    (@xnau)

    Make sure you have the “role” field in your calculation template (even though you’re not actually using the template because of your custom code) so that that value is available in the data set provided to the filter. The data set ($replacement_data) provided to the filter only includes the fields named in the template.

    crowwoods1

    (@crowwoods1)

    I see, so I would have to have all 43 fields in the calculation template for regular_points. That seems doable.

    Is it a problem since role is not a numeric field?

    Plugin Author xnau webdesign

    (@xnau)

    The only ones you need to include are ones that might have changed because this is how you get the values that are getting submitted in the record update.

    “role” not being numeric won’t matter because the filter happens before the calculation is attempted.

    crowwoods1

    (@crowwoods1)

    Nope! I put all the related fields in the templates but it’s still the same.

    crowwoods1

    (@crowwoods1)

    It doesn’t work and this is what I put into one of the templates.

    [change_led] + [test_drive] + [plant_tree] + [local_csa] + [volunteer] + [paperless] + [rain_barrels] + [aerators] + [microplastics] + [shower_heads] + [running_toilets] =[?unformatted]

    Now I put =[?integer] in at the end but every time I save, it adds [?unformatted] to the end. So I removed =[?integer]
    Does that cause it not to work?

    Plugin Author xnau webdesign

    (@xnau)

    OK, well, I’m sorry, I’m a bit lost, I’m advising you based on what I know, but I’m not looking at your data, and I’m not debugging your code, so really, I can’t solve your problems for you. If the plugin is working as it should ( I see no evidence it isn’t at this point) then you should be able to do what you want to do.

    I’m not having any trouble accessing the fresh values from the submission using the same filter you’re using, so as far as I can see, it’s all working. Why it’s not working in your particular case, I can’t say.

    I don’t know why [?integer] isn’t working, I just tested it and it works. The good news is it won’t matter if you’re doing the calculations in your custom code.

    crowwoods1

    (@crowwoods1)

    ok, I deactivated my Google analytics, and the [?integer] is now working. Not sure if that’s related. The only other 2 plugins are Elementor and Calculated Fields Form.

    I know that when I first used the Echo (probably 2 upgrades ago), it was picking up the right data. It’s just that I couldn’t see the Echo unless I went back a screen. Now 2 upgrades later, I can’t even read in the right data.

    Does it have to do with this? I’m reading the record, not something just submitted and not gone into the record.
    $record_data = Participants_Db::get_participant( $field->record_id );

    Also, the Calculated Fields Form plugin allows for dynamic updating of the points field. As one updates the actions, the points update right away. No button to press. Unfortunately I can’t get it to write to the database. Can something like that be done with Participant Database?

    crowwoods1

    (@crowwoods1)

    If I want to debug it, what file(s) should I be looking at?

    crowwoods1

    (@crowwoods1)

    I think if I can debug the file for numeric calculation, the one that calls this filter, I can see if it’s at least reading the template. What is the name of the file, and where can I find it?

    Thanks!

    Plugin Author xnau webdesign

    (@xnau)

    The filter you are using is in the plugin file classes/PDb_fields/calculations.php on line 53.

    The other plugin you’re talking about uses javascript to update the display immediately, this is something I am considering for Participants Database, but it is unrelated to the problem you’re having: you would just see the incorrect result immediately instead of after refreshing the page.

    crowwoods1

    (@crowwoods1)

    Thanks! Looking at calculation.php, line 84 seems to indicate that replacement data is based on $post.
    abstract protected function replacement_data( $post );

    Then line 192 seems to be setting the submission data as something that requires the field to be checked for signup.

    public function set_submission_value( $post )
      {
        foreach( $this->field_list() as $field )
        {
          if ( $field->is_signup() && isset( $post[$field->name()] ) ) {
            $this->set_field( $field->name() );
            $post[$field->name()] = $this->dynamic_value($post);
          }
        }
        
        return $post;
      }

    Most of my fields are not checked for signup. Ironically ‘role’ is the only field that’s indicated for signup. Is that a problem?

Viewing 15 replies - 76 through 90 (of 94 total)
  • The topic ‘Numeric Calculation’ is closed to new replies.