Source for file ipointbank_object.php

Documentation is available at ipointbank_object.php

  1. <?php
  2.     /**
  3.     * The iPointBank class provides basic transaction functions for the Sloodle iBank module.
  4.     *
  5.     * @package sloodle
  6.     * @copyright Copyright (c) 2008 Sloodle (various contributors)
  7.     * @license http://www.gnu.org/licenses/gpl-3.0.html GNU GPL v3
  8.     * @see iBank
  9.     * @contributor Paul G. Preibisch - aka Fire Centaur
  10.     */
  11.   class iPointBank{
  12.    
  13.       var $name='';
  14.       
  15.       var $sloodleid = null;
  16.       
  17.       var $transactionRecords = null;
  18.       
  19.       function iPointBank($id){
  20.           $this->sloodleid = $id;                    
  21.           $this->transactionRecords = $this->getTransactionRecords();          
  22.       
  23.       }
  24.        /**
  25.      * @method makeTransaction 
  26.      * @author Paul Preibisch
  27.      * 
  28.      *  makeTransaction inserts a record into the sloodle_ipoint_trans table
  29.      * 
  30.      *  
  31.      * @package sloodle
  32.      * @returns returns true if insert was successful
  33.      * @returns returns false if insert was unsuccessful
  34.      * 
  35.      * @$iTransaction is a dataObject (stdClass object)  with appropriate fields matching the table structure
  36.      */
  37.       
  38.       function makeTransaction($iTransaction){      
  39.         if (insert_record('sloodle_ipoint_trans',$iTransaction)) return true;
  40.         else return false;
  41.       }
  42.       
  43.       function update(){
  44.          $this->transactionRecords = $this->getTransactionRecords()
  45.           
  46.           
  47.       }
  48.     /**
  49.      * @method getTransactionRecords 
  50.      * @author Paul Preibisch
  51.      * 
  52.      *  getTransactionRecords returns the recordset of sloodle_ipoint_trans record
  53.      *  for the $userId specified.  if $userId is null, returns all the transaction records for this stipend
  54.      *  
  55.      * @package sloodle
  56.      * @return returns transaction records for this user / or for all users
  57.      * @return If $userId is null, then all transactions are returned
  58.      * 
  59.      * @staticvar $userId moodle id of the user
  60.      */
  61.       function getTransactionRecords($userId=null)
  62.       {
  63.           global $CFG;
  64.          if (!$userId){
  65.             return get_records('sloodle_ipoint_trans','sloodleid',$this->getSloodleId());          
  66.          }
  67.          else {
  68.             $sql 'SELECT * FROM '.$CFG->prefix.'sloodle_ipoint_trans'.
  69.             ' WHERE userid='.$userId.' AND sloodleid='.$this->getSloodleId().
  70.             ' ORDER BY timemodified DESC';
  71.             $transRecs get_records_sql($sql);
  72.             return $transRecs;            
  73.             
  74.          }
  75.       }
  76.            /**
  77.      * @method removeTransaction 
  78.      * @author Paul Preibisch
  79.      * 
  80.      *  removeTransaction removes the transaction for this stipend
  81.      *  
  82.      * @package sloodle
  83.      * @return true if successful
  84.      * @return false if unsuccessful
  85.      * 
  86.      * @staticvar $userId moodle id of the user
  87.      * @staticvar $iType type of the transaction "stipend","credit","debit"
  88.      */
  89.      
  90.      function removeTransaction($userId,$iType){
  91.          if (delete_records("sloodle_ipoint_trans",'sloodleid',$this->sloodleid,'itype',$iType,'userid',$userId))
  92.             return true;
  93.             else return false;
  94.      }
  95.       function updateTransaction($transactionUpdate){
  96.         if (!update_record("sloodle_ipoint_trans",$transactionUpdate))
  97.             error(get_string("stipendgiver:cantupdate","sloodle"));
  98.         
  99.       }
  100.       
  101.       function getSloodleId(){
  102.         return $this->sloodleid;
  103.       }
  104.      /**
  105.      * getAvatarDebits function
  106.      * @desc This function will search through all the transactions
  107.      *  for this stipend based on avatar uuid and return the TOTAL debits amount
  108.      * @staticvar integer $debitAmount will be zero if no debits exist for this user and stipend
  109.      * @param string $avuuid the avatar UUID to search for
  110.      * @link http://sloodle.googlecode.com
  111.      * @return integer 
  112.      */ 
  113.      function getAvatarDebits($avuuid){
  114.           //transactionRecords fields are: 
  115.           //avuuid,userid,avname,amount,type,timemodified
  116.           $debits 0;   
  117.          foreach ($this->getTransactionRecords(as $t){
  118.             if ($t->avuuid == $avuuid)
  119.                if ($t->itype=='debit')
  120.                     $debits +=$t->amount;
  121.          }
  122.          return $debits
  123.      
  124.      /**
  125.  * getUserDebits function
  126.  * @desc This function will search through all the transactions
  127.  *  and return TOTAL debits for this course user
  128.  * @staticvar integer $debitAmount will be zero if no debits exist for this user and stipend
  129.  * @param string $avuuid the avatar UUID to search for
  130.  * @link http://sloodle.googlecode.com
  131.  * @return integer 
  132.  */ 
  133.  function getUserDebits($userid=null){
  134.       //transactionRecords fields are: 
  135.       //avuuid,userid,avname,amount,type,timemodified
  136.       $debits 0;
  137.       if ($userid==null)
  138.           $transRecs $this->getTransactionRecords();
  139.       else      
  140.           $transRecs $this->getTransactionRecords($userid);
  141.           if ($transRecs)
  142.             foreach ($transRecs as $t)
  143.                    if ($t->itype=='debit')
  144.                        $debits +=$t->amount;
  145.      return $debits
  146.  }
  147.  
  148.       
  149.       
  150.   
  151.   }
  152. ?>

Documentation generated on Fri, 17 Jul 2009 11:01:28 +0100 by phpDocumentor 1.4.0