Advertisement
Vol3n

Helper class

Oct 11th, 2017
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.69 KB | None | 0 0
  1. <?php
  2.  
  3. class ModDisplayVacanciesHelper
  4. {
  5.  
  6.     function __construct()
  7.     {
  8.         $app = JFactory::getApplication();
  9.     }
  10.  
  11.     public function setVacancyIdAjax()
  12.     {
  13.         //Get request data
  14.         $jinput = JFactory::getApplication()->input;
  15.         $vacancy_id = $jinput->get("vacancy_id");
  16.  
  17.         $session = JFactory::getSession();
  18.         $session->set('vacancy_id', $vacancy_id);
  19.  
  20.         return $vacancy_id;
  21.     }
  22.  
  23.     public function createTable($params)
  24.     {
  25.         include_once JPATH_ROOT . '/components/com_content/helpers/route.php';
  26.        
  27.         $session = JFactory::getSession();
  28.         $session->set('current_page', '0');
  29.  
  30.         $count = $params->get("count");
  31.         $tableClass = $params->get("table_classes");
  32.  
  33.         //Connect to the database
  34.         $db = JFactory::getDbo();
  35.         $query = $db->getQuery(true);
  36.  
  37.  
  38.         //Set table headers
  39.         $htmlResult =   "<table id='vacanciesTable' class='".$tableClass."'>
  40.                        <th>Functie</th>
  41.                        <th>Specialiteit</th>
  42.                        <th>Regio</th>
  43.                        <th>Expertise</th>";
  44.  
  45.         //Build the query
  46.         $query
  47.             ->select($db->quoteName(array('Function', 'SpecialityName', 'RegioName', 'Expertise-1', 'ID')))
  48.             ->from($db->quoteName('vacancies'))
  49.             ->order('Registered DESC');
  50.  
  51.         $db->setQuery($query);
  52.         $this->vacanciesRows = $db->loadRowList();
  53.  
  54.         //Add rows to the table
  55.         foreach ($this->vacanciesRows as $index=>$row)
  56.         {  
  57.             if( $index == $count)
  58.                 break;
  59.  
  60.             $newRow = $this->createTableRow($row);
  61.             $htmlResult .= $newRow;
  62.         }
  63.  
  64.         $htmlResult .= "</table>";
  65.  
  66.         return $htmlResult;
  67.     }
  68.  
  69.     public function addPagination($params)
  70.     {
  71.         $count = $params->get("count");
  72.         $multiPage =  $params->get("multiple_pages");
  73.        
  74.         //Add controls for changing pages
  75.  
  76.         if($multiPage)
  77.         {
  78.             jimport('joomla.html.pagination');
  79.             $pagination = new JPagination(count($this->vacanciesRows) , 0, $count);
  80.    
  81.             echo $pagination->getListFooter();
  82.         }
  83.     }
  84.  
  85.     private function createTableRow($row)
  86.     {
  87.         $count =  count($row);
  88.  
  89.         $htmlRow = "<tr id=".$row[$count-1]."'>";
  90.  
  91.         foreach($row as $index=>$element)
  92.         {
  93.             if($index == $count - 1)
  94.             {
  95.                 //Dont show the ID in the table
  96.                 break;
  97.             }
  98.             $htmlRow .= "<td>".$element."</td>";
  99.         }
  100.  
  101.         $htmlRow .= "</tr>";
  102.  
  103.         return $htmlRow;
  104.     }
  105.  
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement