ordem alfabetica
Como colocar esse código em ordem alfabética?
<?php
class PlacesController extends ItemController
{
public $tablename = "places";
public $filter_valid_columns = array( 'id','accepted','name','text','submission_date','author_id');
//make Available for everyone, not just admin
function beforeroute()
{
}
function getById($f3)
{
$item = $this->getByIdFromParameters();
$item['category'] = json_encode($this->getRelationTableFromDb("places_categories", "place_id", "category_id", $item['id']));
if ($item['author_id']>0) {
$user = new User($this->db);
$user->getById( $item['author_id']);
$item['author'] = $user->username;
} else {
$item['author'] ="";
}
$sql = "SELECT COALESCE(COUNT(id), 0) AS totalratings ,COALESCE(AVG(rating), 0) AS avgrating FROM ratings WHERE placeid=".$item['id'].";";
$output = $this->db->exec($sql, $args);
$item['avgrating']=$output[0]['avgrating'];
$item['totalratings']=$output[0]['totalratings'];
if ($item['pin']!=null) {
$itemModel = new ItemModel($this->db, "pins");
$pin = $itemModel->getById($f3, $item['pin']);
$item['pinimage']=$pin['image'];
}
echo json_encode($item);
}
function getMultiplePlaces($f3, $top, $local_filter = array(), $featured_first = true)
{
//get pagination parameters
$limit = $f3->get('PARAMS.limit');
$pos = $f3->get('PARAMS.pos');
$category_id = $f3->get('GET.category');
$accepted = $f3->get('GET.accepted');
$currentlat = $f3->get('GET.currentlat');
$currentlng = $f3->get('GET.currentlng');
$hasAuth=$this->hasAuth(User::AUTHOR);
//accepted or not accepted
if ($accepted=="") {
$accepted="1";
}
if ($accepted==null) {
$accepted="1";
}
$local_filter['accepted'] = $accepted;
//categories
if (isset( $_GET[ 'category' ] )) {
$ids = $this->getRelationTableFromDb("places_categories", "category_id", "place_id", $category_id);
$local_filter['id'] = $ids;
}
//filter
$filter = $this->getFilterFromParameters("name", $local_filter, "places.");
//print_r( $filter);
$sql = "SELECT places.*, COALESCE(COUNT(r.id), 0) AS totalratings ,COALESCE((SELECT AVG(rating) FROM ratings WHERE placeid = places.id), 0) AS avgrating, pin.image as pinimage ";
if ($currentlat!=null & $currentlng!=null) {
$sql.=" , (ACOS(SIN(RADIANS(?))*SIN(RADIANS( gpslat ))+COS(RADIANS(?))*COS(RADIANS( gpslat ))*COS(RADIANS(gpslng-?)))*6371) as distance";
}
$sql.=" FROM places LEFT JOIN ratings AS r ON places.id = r.placeid LEFT JOIN pins AS pin ON places.pin = pin.id ";
$args=array();
if ($filter) {
if (is_array($filter)) {
$args=isset($filter[1]) && is_array($filter[1])?
$filter[1]:
array_slice($filter, 1, null, true);
$args=is_array($args)?$args:array(1=>$args);
list($filter)=$filter;
}
$sql.=' WHERE '.$filter;
}
if ($currentlat!=null & $currentlng!=null) {
array_unshift($args, $currentlat, $currentlat, $currentlng);
}
$sql .=" GROUP BY places.id";
if ($currentlat!=null & $currentlng!=null) {
$sql .=" ORDER BY distance ASC LIMIT ".$pos.", ".$limit.";";
} else {
if ($featured_first) {
$sql .=" ORDER BY featured DESC, ".$top." DESC LIMIT ".$pos.", ".$limit.";";
} else {
$sql .=" ORDER BY ".$top." DESC LIMIT ".$pos.", ".$limit.";";
}
}
$output = $this->db->exec($sql, $args);
echo json_encode($output);
//return list
//print_r( "\r\n\r\n\r\n\r\n");
// print_r( $sql);
//echo json_encode($list);
}
function getMultiple($f3)
{
$top = $f3->get('GET.sort');
if ($top==null) {
$this->getMultiplePlaces($f3, "submission_date");
} else {
$this->getMultiplePlaces($f3, $top);
}
}
function getTop($f3)
{
$top = $f3->get('PARAMS.top');
//$preferences = new Preferences($this->db);
//$topduration = $preferences->getValue("topduration", "7");
//$now = new DateTime();
// $lastweek = $now->sub(new DateInterval('P'.$topduration.'D'));
//$local_filter = array('minimum_submission_date' => $lastweek->format('Y-m-d H:i:s'));
$this->getMultiplePlaces($f3, $top, array(), false);
}
function add($f3)
{
//authenticate
$this->auth(User::AUTHOR);
if ($f3->get('DEMO')) {
exit;
}
//check if accepted
$accepted=$this->hasAuth(User::AUTHOR);
if ($f3->get('POST.accepted')=="0") {
$accepted=0;
exit;
}
//get author id
$user = new User($this->db);
$user->getByEmail($_SESSION['email']);
//add item
$item = new ItemModel($this->db, $this->tablename);
$item->loadIfIdAvailable($f3, "id");
$item->accepted = $accepted;
$item->read($f3, 'name', 'text', 'submission_date', 'author_id', 'featured', 'address', 'gpslat', 'gpslng', 'price', 'deal_link', 'price_suffix', 'telephone', 'email', 'pin');
$item->readImage($f3, "image", true, 600, 300);
$item->author_id = $user->id;
$item->save();
$this->getRelationTableFromPost("category", "places_categories", "place_id", "category_id", $item->id);
//send push notification if enabled
if (!(empty($f3->get('POST.pushnotification')))) {
$apiController = new ApiController();
$apiController->sendPushNotification($f3, "News", $f3->get('POST.name'));
}
}
function delete($f3)
{
//authenticate
$this->auth(User::AUTHOR);
if ($f3->get('DEMO')) {
exit;
}
//delete item by id
$item = new ItemModel($this->db, $this->tablename);
$item->deleteById($this->db, $f3->get('PARAMS.id'));
}
function viewed($f3)
{
//increment viewed
$item = new ItemModel($this->db, $this->tablename);
$item->incrementById($f3, 'viewed');
echo "1";
}
function shared($f3)
{
//increment shared
$item = new ItemModel($this->db, $this->tablename);
$item->incrementById($f3, 'shared');
echo "1";
}
function favorited($f3)
{
//increment favorited
$item = new ItemModel($this->db, $this->tablename);
$item->incrementById($f3, 'favorited');
echo "1";
}
}
quero colocar o resultado que é places em ordem alfabética mas não consigo.Discussão (2)
Carregando comentários...