Beispiel #1
0
 public function action_referrals()
 {
     if (strtolower(\Sentry::user()->groups()[0]['name']) != 'club members') {
         \Messages::error('Only club members can access this page.');
         \Response::redirect('/');
     }
     \View::set_global('title', 'Referrals');
     $id = \Sentry::user()['id'];
     $items = Model_Referal::find(function ($query) use($id) {
         $query->where('user_added', $id);
         $query->order_by('id', 'desc');
     });
     // Reset to empty array if there are no result found by query
     if (is_null($items)) {
         $items = array();
     }
     // Initiate pagination
     $pagination = \Hybrid\Pagination::make(array('total_items' => count($items), 'per_page' => \Input::get('per_page', 10), 'uri_segment' => null));
     // Remove unwanted items, and show only required ones
     $items = array_slice($items, $pagination->offset, $pagination->per_page);
     \Theme::instance()->set_partial('content', $this->view_dir . 'referrals')->set('pagination', $pagination, false)->set('items', $items);
 }
Beispiel #2
0
 public function action_delete_referral($id = false)
 {
     if (is_numeric($id)) {
         // Get user delete
         if ($item = Model_Referal::find_one_by_id((int) $id)) {
             // Delete item
             try {
                 // Delete group
                 $item->delete();
                 \Messages::success('User successfully deleted.');
             } catch (\Sentry\SentryUserException $e) {
                 // show validation errors
                 \Messages::error('<strong>There was an error while trying to delete item</strong>');
                 // Uncomment lines below to show database errors
                 $errors = $e->getMessage();
                 \Messages::error($errors);
             }
         }
     }
     \Response::redirect(\Input::referrer());
 }