Source for file stipendgiver_object.php
Documentation is available at stipendgiver_object.php
* Defines a class to manipilate a stipendGiver
* @copyright Copyright (c) 2008 Sloodle (various contributors)
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU GPL v3
* @see http://slisweb.sjsu.edu/sl/index.php/Sloodle_Stipend_Giver
* @author Paul Preibisch - aka Fire Centaur
require_once(SLOODLE_LIBROOT.
'/ipointbank_object.php');
* @var $startingBalance - the default value of the stipend
* @var $stipendGiverRec - the actual record of the stipendgiver from sloodle_stipengiver
* @var $icurrency - can be either iPoints or Lindens - specified by initial config page
* @var $sloodleId - sloodleId of this stipendgiver
* @var $id - the sloodle id of this stipendgiver
//parent::iPointBank($id);
$instanceid =
get_field('course_modules', 'instance', 'id', $id);
$this->stipendGiverRec =
get_record('sloodle_stipendgiver','sloodleid',$instanceid);
* updateUserList searches through the list of users in the course,
* and adds new stipends for new users to transactions table, and or removes students stipends
* who have been removed from the class list
* @return false if not found
* @staticvar $userList users in this course
* @staticvar $userId - moodle id of user sought
//for each user who doesnt have a stipend allocated, allocate them 0 - because they have just been added
foreach ($userList as $u){
$newStipend =
new stdClass();
$newStipend->userid =
$u->id;
$newStipend->itype=
"stipend";
$newStipend->amount=
0; //set amount to zero so teacher must manually add stipends for new students
$newStipend->timemodified =
time();
$newStipends[]=
$newStipend;
//now add to iPoint_trans records for the new students who have not been alocated the default stipend.
foreach ($newStipends as $nS){
//also, check to see if any students have been removed from the class, then we should
//build list of students who have been allocated stipends
//get existing transactions
//compare userlist with all the stipend transactions. If there is a transactopm
//for a user who is not in the course, remove that stipend allocation
if ($t->itype==
"stipend"){
//check if this user is in this class
//if user of this stipend is not in the userList, remove this stipend
* searchUserList searches through the list of users
* @return false if not found
* @staticvar $userList users in this course
* @staticvar $userId - moodle id of user sought
foreach ($userList as $u){
if ($u->id ==
$userid) $found=
true;
* getStartingBalance gets the default stipend property for this stipendgiver object
* setStartingBalance - sets this class property starting balance which is actually the default stipend. DOES NOT write to the db
* @var $newStartingBalace - x
* geticurrency gets the currency property of this object
* get gets the currency property of this object
* @method getStipendBudget
* getStipendBudget gets the stipend amount allocated to this user
* @return returns bugeted amount for this user,
* @return If $userId is null, the default stipend of the stipend is returned
* @returns false if no stipend was allocated for the userId specified
* @staticvar $userId moodle id of the user
//transactionRecords fields are:
//avuuid,userid,avname,amount,type,timemodified
//first update the transaction list in case new students have been added
foreach ($transRecs as $t)
if ($t->itype==
'stipend')
$budgetAmount +=
$t->amount;
* @method setStipendBudget
* setStipendBudget can be used to set the default stipend,
* or a stipend of an individual user
* @return true if record can be updates
* @return false if there was an error updating ipoint_trans table
* @staticvar $amount is amount of the stipend - defaults to zero
* @staticvar $userId moodle id of the user
$update =
new stdClass();
if ($userId==
null){ //modify default stipend
$updatedStipendGiver =
new stdClass();
$updatedStipendGiver->amount =
$amount;
if (!update_record("sloodle_stipendgiver",$updatedStipendGiver)){
$sloodle->response->quick_output(-
701, 'STIPENDGIVER', 'Failed to update stipendGiver for default stipend in setStipendBudget function', FALSE);
}else{ //modify stipend budget of individual user
$update =
new stdClass();
$update->id =
$stipendRec->id;
$update->amount =
$amount;
if (!update_record('sloodle_ipoint_trans', $update)){
$sloodle->response->quick_output(-
701, 'STIPENDGIVER', 'Failed to update stipendGiver in setStipendBudget function', FALSE);
* getStipendRec returns the stipend record for this user.
* itype in the sloodle_ipoint_trans table must be 'stipend',
* @returns a record from the sloodle_ipoint_trans table
* @returns false if no stipend has been allocated
* @staticvar $userId moodle id of the user
$sql =
'SELECT * FROM '.
$CFG->prefix.
'sloodle_ipoint_trans'.
' WHERE itype=\'stipend\' AND sloodleid='.
$this->getSloodleId() .
$userStipendId =
get_record_sql($sql);
Documentation generated on Fri, 17 Jul 2009 11:02:33 +0100 by phpDocumentor 1.4.0