Ejemplo n.º 1
0
 static function pagination($limit = 10, $page = 1, array $options = [])
 {
     $p = $page;
     if (!$options['num']) {
         $aw = new AdminWidgets();
         $num = $aw->getNum($options['table']);
     } else {
         $num = $options['num'];
     }
     $pages = round($num / $limit);
     if ($page == 0) {
         $page = 1;
     }
     if ($page == 1) {
         $disabledP = 'disabled';
     } else {
         if ($page == $pages) {
             $disabledN = 'disabled';
         } else {
             $disabled = '';
         }
     }
     $fc = FrontController::getInstance();
     $controller = $fc->getClearController();
     $action = $fc->getClearAction();
     $link = "/{$controller}/{$action}";
     if (!empty($options)) {
         foreach ($options as $key => $value) {
             if (!empty($value)) {
                 $link .= "/{$key}/{$value}";
             }
         }
     }
     $output = '';
     $output .= '<ul class="pagination">' . "\n";
     $output .= '<li class="' . $disabledP . '" id="previous">' . "\n";
     $output .= '<a href="' . $link . '/page/' . --$p . '" aria-controls="pgn" data-dt-idx="0" tabindex="0">&laquo;</a>' . "\n";
     $output .= '</li>' . "\n";
     for ($i = 1; $i <= $pages; $i++) {
         if ($page == $i) {
             $active = 'active';
         } else {
             $active = '';
         }
         $output .= '<li class="paginate_button ' . $active . '">' . "\n";
         $output .= '<a href="' . $link . '/page/' . $i . '" aria-controls="pgn" data-dt-idx="' . $i . '" tabindex="0">' . $i . '</a>' . "\n";
         $output .= '</li>' . "\n";
     }
     $output .= '<li class="paginate_button next ' . $disabledN . '" id="next">' . "\n";
     $output .= '<a href="' . $link . '/page/' . ++$page . '" aria-controls="pgn" data-dt-idx="' . ++$page . '" tabindex="0">&raquo;</a>' . "\n";
     $output .= '</li>' . "\n";
     $output .= '</ul>' . "\n";
     return $output;
 }
Ejemplo n.º 2
0
 public function editOrderAction()
 {
     $fc = FrontController::getInstance();
     $model = new AdminModel('Редактирование заказа', 'управление заказами');
     $orderModel = new AdminWidgets();
     if ($_SERVER['REQUEST_METHOD'] === 'POST') {
         Session::setMsg('Заказ успешно обновлен', 'success');
         header('Location: /admin/orders');
         exit;
     } else {
         $id = filter_var($fc->getParams()['id'], FILTER_SANITIZE_NUMBER_INT);
         if (!$id) {
             header('Location: /admin/notFound');
             exit;
         }
         $model->setData(['order' => $orderModel->getAllOrders('*', "WHERE id = {$id}")]);
         $output = $model->render('../views/admin/order/editorder.php', 'admin');
         $fc->setPage($output);
     }
 }