Advertisement
Guest User

helper.php

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