Pommo_User::getList PHP Method

getList() public method

* getList Returns array with users in DB
public getList ( $data )
$data = array( 'limit' => 'Records per page, 'order' => 'ASC or DESC', 'page' => 'Page to return )
    function getList($data)
    {
        try {
            $this->pages = 0;
            if (50 < $data['limit'] && 0 >= $data['limit']) {
                $data['limit'] = 10;
            }
            if (!in_array($data['order'], array('ASC', 'DESC'))) {
                $data['order'] = 'ASC';
            }
            if (!$data['page']) {
                $data['page'] = 1;
            }
            $dbo = Pommo::$_dbo;
            $dbo->_dieOnQuery = false;
            //	Calculate total number of pages
            $query = 'SELECT COUNT(username) AS total
                    FROM ' . $dbo->table['users'];
            $records = (int) $dbo->query($query, 0);
            $this->records = $records;
            $this->pages = ceil($records / $data['limit']);
            if ($data['page'] > $this->pages) {
                $data['page'] = $this->pages;
            }
            $skip = (int) ($data['limit'] * ($data['page'] - 1));
            //	Get the users
            $query = 'SELECT username
                    FROM ' . $dbo->table['users'] . ' ORDER BY username ' . $data['order'] . ' LIMIT ' . $skip . ', %i';
            $query = $dbo->prepare($query, array($data['limit']));
            $users = $dbo->getAll($query);
            return $users;
        } catch (Exception $e) {
            return false;
        }
    }

Usage Example

Exemplo n.º 1
0
 * but WITHOUT ANY WARRANTY; without even the implied warranty
 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
 * the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with program; see the file docs/LICENSE. If not, write to the
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 */
/**********************************
	INITIALIZATION METHODS
*********************************/
require '../bootstrap.php';
require_once Pommo::$_baseDir . 'classes/Pommo_Mailing.php';
require_once Pommo::$_baseDir . 'classes/Pommo_User.php';
Pommo::init();
$logger =& Pommo::$_logger;
$dbo =& Pommo::$_dbo;
//	Get the users
$user = new Pommo_User();
$data = array('limit' => $_GET['rows'], 'page' => $_GET['page']);
$list = $user->getList($data);
//	Format the list for jqgrid
$rows = array();
$i = 0;
foreach ($list as $item) {
    $rows[$i]['id'] = $item['username'];
    $rows[$i]['username'] = $item['username'];
    $i++;
}
$json = array('total' => $user->pages, 'page' => $_GET['page'], 'records' => $user->records, 'rows' => $rows);
echo json_encode($json);