Example #1
0
 private function getPageData($total_rows, $entity, $page, $opt_conditions = NULL)
 {
     //If $page is not a number, getMultiplier will return 0.
     $start = Controller_Admin::getMultiplier($page) * Controller_Admin::ROWS_PER_PAGE;
     $rows = ORM::factory($entity)->limit(Controller_Admin::ROWS_PER_PAGE)->offset($start);
     if ($opt_conditions) {
         foreach ($opt_conditions as $field => $value) {
             $rows->where($field, '=', $value);
         }
     }
     $rows = $rows->find_all();
     //Error conditions.
     if (count($rows) == 0 && $total_rows > 0) {
         $this->addError(__('Invalid page number'));
     } else {
         if (!count($rows)) {
             $this->addError(__("You should probably create an {$entity} to start with."));
         }
     }
     return $rows;
 }