Jump to content

Custom PIREP field to appear in Pilot Center or Custom Profile Field to appear in PIREP!


opsman

Recommended Posts

Hi,

I've added a custom PIREP field so my pilots can record the number of points they get following each flight however I'm not sure how to display this in the Pilot Center as part of their profiles...any ideas?
I've tried the Custom Profile Field option however this doesnt appear on the PIREP so not quite what I'm looking for :-)

Any help is appreciated!

Link to comment
Share on other sites

  • Moderators

Hmmm, what you request is not that easy because it may require a few work to be done. Open the core/common/PIREPData.class.php file and find this:

public static function deleteField($id) {
        
        $sql = 'DELETE FROM ' . TABLE_PREFIX . 'pirepfields WHERE fieldid=' . $id;

        $res = DB::query($sql);

        if (DB::errno() != 0) return false;

        return true;

        //TODO: delete all of the field values!
        //$sql = 'DELETE FROM '.TABLE_PREFIX.'
    }

after this, add the following part of code:

public static function getSumByField($pilotid, $field) {
    $sql = "SELECT SUM(v.value) AS total FROM ".TABLE_PREFIX."pirepvalues AS v LEFT JOIN ".TABLE_PREFIX."pireps AS p ON p.pirepid=v.pirepid WHERE v.fieldid='$field' AND p.pilotid='$pilotid' AND v.value REGEXP '^[0-9]+$'";
    $total = DB::get_row($sql);
    if(!$total) return 0;
    return $total->total;
}

Then within the pilot's center or any other part of your website, you can use the following code to show the total points. Just ensure that the pilot really submits numbers within the points section although I added an extra check within the where statement.

<?php echo PIREPData::getSumByField(SET_HERE_THE_PILOT_ID, SET_HERE_THE_FIELD_ID); ?>

Do not forget to update the SET_HERE_THE_PILOT_ID and SET_HERE_THE_FIELD_ID values accordingly. I did not test it but it should work. Let me know if it does.

___________________________________________

logo.png
phpVMS Modules | Web Hosting | Pilot Awards (w/Auto Awards) | Pilot Shop | Real Booking System | Forum System

Link to comment
Share on other sites

  • 4 weeks later...

Hi @servetas

I've added your code to the core/common/PIREPData.class.php however when I add the following line to profile_main.php, I can see the name of the field but no values within?

  • Grade: 4
  • Violations: 68
  • Latest XP: 

Here is what I added in profile_main.php

<li><strong>Latest XP: </strong><?php echo PIREPData::getSumByField($pilotid, $field); ?></li>

Any help would be appreciated!

Thanks

Nick

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...