Пример #1
0
 /**
  * Lists all instances of the model, (databasetable) except for noListing.
  *
  * @param $noListing params not to be listed
  * @param $model model object to list (create an html table from) 
  *
  * @return void
  */
 public function listAction($noListing = NULL, $model)
 {
     $this->model = $model;
     $this->model->setDI($this->di);
     $all = $this->model->findAll();
     $aContent = array();
     //gör om arrayen av objekt till en array av arrayer
     foreach ($all as $key1 => $value) {
         foreach ($value as $key2 => $v) {
             if (!in_array($key2, $noListing)) {
                 //$noListing, parametrar som inte ska vara med
                 $aContent[$key1][$key2] = $v;
             }
         }
     }
     $aHeading = [];
     //hittar objektens parametrar/tabellens kolumnnamn och skapar
     //en ny array av rubriker
     foreach ($all as $key1 => $value) {
         foreach ($value as $key2 => $v) {
             if (!in_array($key2, $noListing)) {
                 //$noListing, parametrar som inte ska vara med
                 $aHeading[] = $key2;
             }
         }
         break;
     }
     $chtml = new \Jovis\HTMLTable\CHTMLTable($aHeading, $aContent);
     $htmltable = $chtml->getTable();
     $source = $this->model->getSource();
     $this->theme->setTitle("Visa alla användare");
     $this->views->add('table/list-all', ['title' => $source, 'htmltable' => $htmltable]);
 }
Пример #2
0
 /**
  * Test
  *
  * @return void
  *
  */
 public function testgetTable()
 {
     $headline = array("Title", "Description", "Date");
     $data = array(['Title' => 'Me', 'Description' => 'The story about me', 'Date' => '2015-01-16'], ['Title' => 'You', 'Description' => 'The Wonderful You', 'Date' => '2015-12-15']);
     $table = new \Jovis\HTMLTable\CHTMLTable($headline, $data);
     $res = $table->getTable();
     $res = preg_replace('/\\s+/', '', $res);
     $exp = "<div class='dbtable'>\n     \t  <table class>\n            <tr class='rows'>\n\t\t<th>Title</th><th>Description</th><th>Date</th>\n\t  </tr>\n\t<tr>\n\t<td>Me</td><td>The story about me</td><td>2015-01-16</td>\n\t</tr>\n\t<tr>\n\t<td>You</td><td>The Wonderful You</td><td>2015-12-15</td>\n\t</tr></table></div>";
     $exp = preg_replace('/\\s+/', '', $exp);
     $this->assertEquals($res, $exp, "Something went wrong in creating the table");
 }