Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Updating Extra Columns
#1
Suppose you would like to save the total score in a column.  There will shortly be two ways to do this.  

1. You can let me know and the app can do it.  The issue with this is that you can never change this column.

2. You can use the hook system to have the data updated.  This way is a little better as it gives you control over where the data goes and lets you change it.  


First you will need a module - core/modules/FinalScore/FinalScore.php
PHP Code:
<?php

class FinalScore extends CodonModule 
      
    public 
function __construct() 
 
          
        CodonEvent
::addListener('FinalScore', array('kACARSII_pirep_filed'));        
    
  
    
    public 
function EventListener($eventinfo
 
       
        $xml 
$eventinfo[2];
 
       
        if
($eventinfo[0] == 'kACARSII_pirep_filed'
 
       {
 
           /*
             * kACARSII has filed a pirep
             * xml will have all data for 
             * the pirep
             * 
             * Do stuff below and return out of here
             */ 
         
                        
            $column 
'final_score'// This would be the name of the column in the pirep table
 
           $data $xml->pirep->finalScore// Other standard data items that are included can be located in the kACARSII module
 
           PIREPData::updatePIREPFields($xml->pirepid, array($column => (string)$data));
 
           
            return
;
 
              
        
        
    
   

[Image: fsproducts_xsmall.png]
Reply
#2
Hello Jeffry

I did as you say but it did not work.

with this code work or not?

Laurent
Reply
#3
It works on my server. It also works on a customers server that I set up this week.
[Image: fsproducts_xsmall.png]
Reply
#4
I'll try it again tomorrow

thanks
Reply
#5
Let me know if you have any issues.
[Image: fsproducts_xsmall.png]
Reply
#6
Hello Jeffry,
it works, it was my mistake.

I need a little help
I have it in PilotData.class.php

public static function getPilotScore($pilotid) {

$totalscore = DB::get_row(
'SELECT SUM(`final_score`) AS `total`
FROM `'.TABLE_PREFIX.'pireps`
WHERE `accepted`=' . PIREP_ACCEPTED.' AND `pilotid`='.$pilotid);

return $totalscore;
}

this is it in Profile_main.php

<?php echo $userinfo->totalscore; ?>

the problem is I do not know what to put in Modules / Profile.php

$this->set(' HERE ', $totalSCORE);


thanks

Laurent
Reply
#7
Does this even work?  It looks like you would need to reference like $totalscore->total;

Code:
public static function getPilotScore($pilotid)
{

    $totalscore = DB::get_row(
      'SELECT SUM(`final_score`) AS `total`
      FROM `'.TABLE_PREFIX.'pireps`
      WHERE `accepted`=' . PIREP_ACCEPTED.' AND `pilotid`='.$pilotid);

    return $totalscore;
}


I would do it like this.
Code:
public static function getPilotScore($pilotid)
{
    $sql = 'SELECT SUM(`final_score`) AS `total`
        FROM `'.TABLE_PREFIX.'pireps`
        WHERE `accepted`=' . PIREP_ACCEPTED.' AND `pilotid`='.$pilotid
    );

    $ret = DB::get_row($sql);

    return $ret->total;
}


In the module
Code:
$totalscore = PilotData::getPilotScore($pilotid);

$userinfo->totalscore = $totalscore;


If you are already setting the userinfo this will add a new property to the object that can then be accessed without having to set something else.


*** None of the above has been tested ***
[Image: fsproducts_xsmall.png]
Reply
#8
did not work

I did so directly on the profile_main

function getTotalScore()
{
$query = "SELECT SUM(`final_score`) AS score FROM ".TABLE_PREFIX."pireps WHERE pilotid = ".Auth::$userinfo->pilotid." AND accepted = 1";
$result = DB::get_row($query);
if (!$result) return 0;
return ($result->score == '') ? 0 : $result->score;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)