Models
[ class tree: Models ] [ index: Models ] [ all elements ]

Source for file model_students.php

Documentation is available at model_students.php

  1. <?php
  2. /**
  3.  * <b>Class Description</b>: quick and dirty class to provide database access *
  4.  * @since : 29/04/2009
  5.  * @author Jan van der Breggen
  6.  * @package Models
  7.  * 
  8.  ***/
  9.  
  10. class Model_Students extends ORM
  11. {
  12.  
  13.  
  14.     public $table_fields = array();
  15.  
  16.     function __construct()
  17.     {
  18.         $this->database 'rigregversiontwo';
  19.  
  20.         /**
  21.          * Tables name and table alias
  22.          */
  23.         $this->table['students''st';
  24.         $this->table['retreatReg''reg';
  25.         $this->table['retreat''rt';
  26.         $this->table['stud_grp_join']'sgj';
  27.         $this->table['sanghas']'s';
  28.         /**
  29.          * Mapping of table "students"
  30.          */
  31.         $this->map['id']            array('students''id');
  32.         $this->map['local_key']     array('students''local_key');
  33.         $this->map['first_name']    array('students''first');
  34.         $this->map['last_name']     array('students''last');
  35.         $this->map['address_1']     array('students''addr1');
  36.         $this->map['address_2']     array('students''addr2');
  37.         $this->map['town']          array('students''city');
  38.         $this->map['postcode']      array('students''zip');
  39.         $this->map['state']         array('students''province');
  40.         $this->map['country']       array('students''country');
  41.         $this->map['phone']         array('students''dayphone');
  42.         $this->map['email_address'array('students''email');
  43.         $this->map['gender']        array('students''sex');
  44.         $this->map['password']      array('students''password');
  45.         //$this->map['sangha']      = array('students', 'sangha');
  46.         $this->map['sangha_name']     array(
  47.             'sanghas','name','',
  48.             'LEFT JOIN sanghas AS s  ON st.sangha = s.ID'
  49.         );
  50.        /** 
  51.         ID, retreatUID, studentID, regDate, regModifDate, headset, checkIn, checkOut,
  52.  checkedInOut, chairInTemple, disability, translationTo, norota, rotaUID, firstChoice,
  53.  secondChoice, thirdChoice, rotaText, statusQuo, statusQuoText, activity, retreatTotal,
  54.  rigpaDonation, donationPurposeUID, retFundAmount, transactionTrace, paymentStatus,
  55.  cancel, cancelDate, PaymentMode, LogIn, LogOut, amountStillDue, paymentComment,
  56.  comment_payment, comment_accomodation, comment_overview, DayRateFee, IDinOTHER
  57.         **/
  58.         
  59.        /** 
  60.          ID, retName, retOptionName, retStart, retEnd, rankDisplay, headSetFee, retFee1, retFee1closeDate, retFee2, retFee2closeDate, retFee3, retFee3closeDate, status, special, family, child, useRotaFrom, fullPeriodDiscount, displayRetreatOnline, retreatPhoto, displayName, retreatWarning, chooseMeals, maxLunch, bookFullPeriod, minDays, bookPersonalTent, maxPersonalTents, sponsorsBookOnline, rotaChoices, childrenPossible, transportPossible
  61.        **/
  62.         
  63.         $this->map['retId']            array('retreat''ID');
  64.         $this->map['retName']          array('retreat''retName');
  65.         $this->map['retOptionName']    array('retreat''retOptionName');
  66.         $this->map['rtStatus']         array('retreat''status');
  67.         
  68.         
  69.         
  70.         $this->map['regId']            array('retreatReg''ID');
  71.         $this->map['retreatUID']     array('retreatReg''retreatUID');
  72.          $this->map['student_first']     array(
  73.             'students','first','',
  74.             'LEFT JOIN students AS st  ON reg.studentID = st.local_key'
  75.         );
  76.         $this->map['student_last']     array(
  77.             'students','last','',
  78.             'LEFT JOIN students AS st  ON reg.studentID = st.local_key'
  79.         );
  80.         
  81.         
  82.         $this->map['retreat_status']     array(
  83.             'retreat','status','',
  84.             'LEFT JOIN retreat AS rt  ON reg.retreatUID = rt.ID'
  85.         );
  86.         
  87.         $this->map['retreat_name']     array(
  88.             'retreat','retName','concat(retName," ", retOptionName)',
  89.             'LEFT JOIN retreat AS rt  ON reg.retreatUID = rt.ID'
  90.         );
  91.        
  92.         
  93.         
  94.        
  95.         
  96.         
  97.  
  98.     }
  99.  
  100.     function getActiveRetreats()
  101.     {
  102.     
  103.     /*
  104.      * ELECT
  105. reg.ID AS regId,
  106. concat(rt.retName," ", rt.retOptionName) AS retreat_name,
  107. st.first AS student_first,
  108. st.last AS student_last,
  109. rt.status
  110. FROM retreatReg AS reg
  111. LEFT JOIN retreat AS rt ON rt.ID = reg.retreatUID
  112. LEFT JOIN students AS st ON  st.local_key = reg.studentID
  113. order by rt.status desc , retreat_name, student_last
  114.      */
  115.     $this->select('regId''retreat_name''student_first''student_last''retreat_status');
  116.           $this->order_by     ('retreat_status','DESC');
  117.         $this->order_by     ('retreat_name');
  118.         $this->order_by     ('student_last');
  119.     
  120.     return $this->rows_array();
  121.     }
  122.     
  123.  
  124.     function selectLogon($Email$PassWord '')
  125.     {
  126.         $this->select('local_key''first_name''last_name');
  127.         $this->where('email_address'"="$Email);
  128.         if (!empty($PassWord))
  129.         {
  130.             $this->where('password'"="md5($PassWord));
  131.  
  132.         }
  133.  
  134.         return $this->row_array();
  135.  
  136.     }
  137.     
  138.     function getRoles($id)
  139.     {
  140.         $this->query "select sj.group_uid, u.cat_name
  141. from user_group u, stud_grp_join sj
  142. where sj.student_uid = $id
  143. and sj.group_uid = u.cat_id";
  144. return $this->rows_array();
  145.     }
  146.     
  147.     function getUIElements($controller)
  148.     {
  149.         $this->query "select ui_element_id, parent, user_group, access_type
  150. from ui_elements, ui_access
  151. where ui_element_id = ui_element
  152. and controller = '$controller'";
  153. return $this->rows_array();
  154.     }
  155.  
  156.  
  157.     function getStudents()
  158.     {
  159.  
  160.         $this->select(
  161.                        'local_key'
  162.                'first_name'
  163.                'last_name'
  164.                 'email_address'
  165.                'country'
  166.                 
  167.                );
  168.         $this->order_by('last_name');
  169.         //$this->limit(200);
  170.         return $this->rows_array();
  171.         
  172.     }
  173.     
  174.     function getUserRoles()
  175.     {
  176.     $this->query ("select sj.ID, sj.student_uid, s.first, s.last, u.cat_name
  177. from user_group u,students s, stud_grp_join sj
  178. where s.local_key = sj.student_uid
  179. and sj.group_uid = u.cat_id
  180. order by student_uid");
  181.    // $this->limit(1);
  182.     return $this->rows_array();
  183.     }
  184.     
  185.     function getCountries(){
  186.         $this->query ("select code, stdName, iso3 from country ");
  187.         return $this->rows_array();
  188.     }
  189.     
  190.     function resetLinkedTables()
  191.     {
  192.         $this->query('delete from students');
  193.         $sql 'ALTER TABLE students AUTO_INCREMENT = 0';
  194.         $x $this->query($sql);
  195.         
  196.         $this->query('delete from stud_grp_join');
  197.         $sql 'ALTER TABLE stud_grp_join AUTO_INCREMENT = 0';
  198.         $x $this->query($sql);
  199.         
  200.             $this->query('delete from user_group');
  201.         $sql 'ALTER TABLE user_group AUTO_INCREMENT = 0';
  202.         $x $this->query($sql);
  203.           
  204.         $this->query('delete from country');
  205.         $sql 'ALTER TABLE country AUTO_INCREMENT = 0';
  206.         $x $this->query($sql);
  207.         
  208.            $this->query('delete from sanghas');
  209.         $sql 'ALTER TABLE country AUTO_INCREMENT = 0';
  210.         $x $this->query($sql);
  211.         
  212.         return 'done';
  213.     }
  214.  
  215.  
  216. }
  217. ?>

Documentation generated on Mon, 18 May 2009 11:22:12 +0200 by phpDocumentor 1.4.1