@@ -26,23 +26,38 @@ class Numbers extends User_Controller
2626 private $ error_message = FALSE ;
2727 private $ new_number = null ;
2828
29+ private $ numbers_per_page = 50 ;
30+
2931 function __construct ()
3032 {
3133 parent ::__construct ();
3234 $ this ->section = 'numbers ' ;
3335 $ this ->template ->write ('title ' , 'Numbers ' );
3436 $ this ->load ->model ('vbx_incoming_numbers ' );
37+ $ this ->load ->library ('pagination ' );
3538 }
3639
3740 function index ()
3841 {
3942 $ this ->admin_only ($ this ->section );
4043 $ this ->template ->add_js ('assets/j/numbers.js ' );
41-
44+
45+ $ max = $ this ->input ->get_post ('max ' );
46+ $ offset = $ this ->input ->get_post ('offset ' );
47+
48+ if (empty ($ offset )) {
49+ $ offset = 0 ;
50+ }
51+
52+ if (empty ($ max )) {
53+ $ max = $ this ->numbers_per_page ;
54+ }
55+
4256 $ data = $ this ->init_view_data ();
4357 $ data ['selected_country ' ] = $ this ->vbx_settings ->get ('numbers_country ' , $ this ->tenant ->id );
4458
4559 $ numbers = array ();
60+ $ total_numbers = 0 ;
4661 $ data ['countries ' ] = array ();
4762 $ data ['openvbx_js ' ]['countries ' ] = array ();
4863 try
@@ -85,10 +100,6 @@ function index()
85100 }
86101
87102 $ item ->phone_formatted = format_phone ($ item ->phone );
88- if (!empty ($ item ->pin ))
89- {
90- $ item ->pin = implode ('- ' , str_split ($ item ->pin , 4 ));
91- }
92103
93104 $ capabilities = array ();
94105 if (!empty ($ item ->capabilities ))
@@ -103,7 +114,7 @@ function index()
103114 }
104115 $ item ->capabilities = $ capabilities ;
105116
106- $ item ->status = null ;
117+ $ item ->status = null ;
107118
108119 if ($ item ->installed )
109120 {
@@ -113,12 +124,12 @@ function index()
113124
114125 array_push ($ data ['incoming_numbers ' ], $ item );
115126 }
116- elseif (!empty ($ item ->url ) || !empty ($ item ->smsUrl ))
127+ elseif (( !empty ($ item ->url ) || !empty ($ item ->smsUrl )) && $ offset == 0 )
117128 {
118129 // Number is in use elsewhere
119130 array_push ($ data ['other_numbers ' ], $ item );
120131 }
121- else
132+ elseif ( $ offset == 0 )
122133 {
123134 // Number is open for use
124135 array_push ($ data ['available_numbers ' ], $ item );
@@ -149,6 +160,22 @@ function index()
149160
150161 $ data ['counts ' ] = $ this ->message_counts ();
151162
163+ /**
164+ * $numbers is a list of phone numbers straight from the Twilio API,
165+ * there's no fancy query logic here, just slicing up the array.
166+ */
167+ $ total_numbers = count ($ data ['incoming_numbers ' ]);
168+ $ data ['incoming_numbers ' ] = array_slice ($ data ['incoming_numbers ' ], $ offset , $ max , true );
169+
170+ // pagination
171+ $ page_config = array (
172+ 'base_url ' => site_url ('numbers ' ),
173+ 'total_rows ' => $ total_numbers ,
174+ 'per_page ' => $ max
175+ );
176+ $ this ->pagination ->initialize ($ page_config );
177+ $ data ['pagination ' ] = CI_Template::literal ($ this ->pagination ->create_links ());
178+
152179 $ this ->respond ('' , 'numbers/numbers ' , $ data );
153180 }
154181
0 commit comments