| 1 |  |  | <?php | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  You may not change or alter any portion of this comment or credits | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  of supporting developers from this source code or any supporting source code | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  which is considered copyrighted (c) material of the original comment or credit authors. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  This program is distributed in the hope that it will be useful, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  but WITHOUT ANY WARRANTY; without even the implied warranty of | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * Alumni module for Xoops | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * @copyright       XOOPS Project https://xoops.org/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * @license         GPL 2.0 or later | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * @package         alumni | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * @since           2.6.x | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * @author          John Mordo (jlm69) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | use Xoops\Core\Database\Connection; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | use Xoops\Core\Kernel\XoopsObject; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | use Xoops\Core\Kernel\XoopsPersistableObjectHandler; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | //defined('XOOPS_ROOT_PATH') or exit('XOOPS root path not defined'); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | $xoops = Xoops::getInstance(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  * Class AlumniListing | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | class AlumniListing extends XoopsObject | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |      * @var Alumni | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      * @access public | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     public $alumni = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |      * Constructor | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     public function __construct() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         global $xoops; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         $this->db = $xoops->db(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         $this->initVar('lid', XOBJ_DTYPE_INT, null, false, 11); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         $this->initVar('cid', XOBJ_DTYPE_INT, null, false, 11); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         $this->initVar('name', XOBJ_DTYPE_TXTBOX, null, false); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         $this->initVar('mname', XOBJ_DTYPE_TXTBOX, null, false); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         $this->initVar('lname', XOBJ_DTYPE_TXTBOX, null, false); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         $this->initVar('school', XOBJ_DTYPE_TXTBOX, null, false); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         $this->initVar('year', XOBJ_DTYPE_TXTBOX, null, false); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         $this->initVar('studies', XOBJ_DTYPE_TXTBOX, null, false); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         $this->initVar('activities', XOBJ_DTYPE_TXTAREA, null, false); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         $this->initVar('extrainfo', XOBJ_DTYPE_TXTAREA, null, false); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         $this->initVar('occ', XOBJ_DTYPE_TXTBOX, null, false); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         $this->initVar('date', XOBJ_DTYPE_INT, null, false, 10); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         $this->initVar('email', XOBJ_DTYPE_TXTBOX, null, false); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         $this->initVar('submitter', XOBJ_DTYPE_TXTBOX, null, false); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         $this->initVar('usid', XOBJ_DTYPE_TXTBOX, null, false); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         $this->initVar('town', XOBJ_DTYPE_TXTBOX, null, false); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         $this->initVar('valid', XOBJ_DTYPE_INT, null, false, 3); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         $this->initVar('photo', XOBJ_DTYPE_TXTBOX, null, false); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         $this->initVar('photo2', XOBJ_DTYPE_TXTBOX, null, false); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         $this->initVar('view', XOBJ_DTYPE_TXTBOX, null, false); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |      * @return mixed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |     public function get_new_id() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         $xoops  = Xoops::getInstance(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         $new_id = $xoops->db()->getInsertId(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |         return $new_id; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |      * @return mixed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |     public function updateCounter() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  | //        return $this->updateCounter($this->getVar('lid')); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |         return $this->alumni->getHandler('listing')->updateCounter($this->getVar('lid')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |  * Class AlumniListingHandler | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 93 |  |  |  */ | 
            
                                                                        
                            
            
                                    
            
            
                | 94 |  |  | class AlumniListingHandler extends XoopsPersistableObjectHandler | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 95 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 96 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 97 |  |  |      * @param null|Connection|XoopsDatabase $db | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 98 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |     public function __construct(Connection $db = null) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |         parent::__construct($db, 'alumni_listing', 'alumnilisting', 'lid', 'title'); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 102 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 103 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 104 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 105 |  |  |      * @param int    $start | 
            
                                                                        
                            
            
                                    
            
            
                | 106 |  |  |      * @param int    $limit | 
            
                                                                        
                            
            
                                    
            
            
                | 107 |  |  |      * @param string $sort | 
            
                                                                        
                            
            
                                    
            
            
                | 108 |  |  |      * @param string $order | 
            
                                                                        
                            
            
                                    
            
            
                | 109 |  |  |      * @return array | 
            
                                                                        
                            
            
                                    
            
            
                | 110 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |     public function getListingPublished($start = 0, $limit = 0, $sort = 'date', $order = 'ASC') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |         $helper    = Alumni::getInstance(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |         $xoops     = $helper->xoops(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |         $moduleId = $helper->getModule()->getVar('mid'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |         // get permitted id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |         $groups     = $xoops->isUser() ? $xoops->user->getGroups() : '3'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |         $alumniIds = $helper->getGrouppermHandler()->getItemIds('alumni_view', $groups, $moduleId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |         // criteria | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |         $criteria = new CriteriaCompo(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |         $criteria->add(new Criteria('valid', 1, '=')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |         $criteria->add(new Criteria('cid', '(' . implode(', ', $alumniIds) . ')', 'IN')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |         $criteria->setSort($sort); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |         $criteria->setOrder($order); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |         $criteria->setStart($start); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |         $criteria->setLimit($limit); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |         return parent::getAll($criteria); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 129 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 130 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 131 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 132 |  |  |      * @param null $keys | 
            
                                                                        
                            
            
                                    
            
            
                | 133 |  |  |      * @param null $format | 
            
                                                                        
                            
            
                                    
            
            
                | 134 |  |  |      * @param null $maxDepth | 
            
                                                                        
                            
            
                                    
            
            
                | 135 |  |  |      * @return mixed | 
            
                                                                        
                            
            
                                    
            
            
                | 136 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |     public function getValues($keys = null, $format = null, $maxDepth = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |         $page             = Page::getInstance(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |         $ret              = parent::getValues($keys, $format, $maxDepth); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |         $ret['rating']    = number_format($this->getVar('rating'), 1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |         $ret['lid']       = $this->getVar('lid'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |         $ret['name']      = $this->getVar('name'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |         $ret['mname']     = $this->getVar('mname'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |         $ret['lname']     = $this->getVar('lname'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |         $ret['school']    = $this->getVar('school'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |         $ret['year']      = $this->getVar('year'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |         $ret['submitter'] = $this->getVar('submitter'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |         $ret['date']      = $this->getVar('date'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |         return $ret; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 152 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 153 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 154 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 155 |  |  |      * @param int    $start | 
            
                                                                        
                            
            
                                    
            
            
                | 156 |  |  |      * @param int    $limit | 
            
                                                                        
                            
            
                                    
            
            
                | 157 |  |  |      * @param string $sort | 
            
                                                                        
                            
            
                                    
            
            
                | 158 |  |  |      * @param string $order | 
            
                                                                        
                            
            
                                    
            
            
                | 159 |  |  |      * @return int | 
            
                                                                        
                            
            
                                    
            
            
                | 160 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |     public function countAlumni($start = 0, $limit = 0, $sort = 'date', $order = 'ASC') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |         $criteria = new CriteriaCompo(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |         $criteria->setSort($sort); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |         $criteria->setOrder($order); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |         $criteria->setStart($start); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |         $criteria->setLimit($limit); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |         return parent::getCount($criteria); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 170 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 171 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 172 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 173 |  |  |      * @param $lid | 
            
                                                                        
                            
            
                                    
            
            
                | 174 |  |  |      * @return bool | 
            
                                                                        
                            
            
                                    
            
            
                | 175 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |     public function updateCounter($lid) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |         $xoops      = Xoops::getInstance(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  |         $listingObj = $this->get($lid); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |         if (!is_object($listingObj)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  |             return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  |         $listingObj->setVar('view', $listingObj->getVar('view', 'n') + 1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |         $this->insert($listingObj, true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  |         return true; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 187 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 188 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 189 |  |  |  | 
            
                        
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.