Sort list

Permalink
Hi

I want to amend my system so that a list of tickets that is retrieved from a custom object is sorted alphabetically rather than in the order they were entered into the system. Any help appreciated.

Justyn

<form action="<?=$this->action('add_attendee')?>" id="new_attendee" method="post">
               <h3><?=t('Add New Attendee')?></h3>
               <br/>
               <?php
               foreach($tickets as $ticket){
                  $ticket_name = $ticket->getAttribute('tickets_title');
                  $ticket_event = $ticket->getAttribute('ticket_event');
                  $ticket_price = Loader::helper('ticket_adjust','attendees')->CompareTicketChange($ticket);
                  if($ticket_name != 'General Admission'                                                         && $ticket_name!= 'Serve Part Time - Under 19')
                                                {
                  ?>
                  <div class="clearfix">
                     <div class="row">
                        <div class="span3">
                           <b><?=$ticket_name?></b>

 
hutman replied on at Permalink Reply
hutman
Can you provide us the code which creates the $tickets array rather than the code that displays it? I'm guessing you need something like $pl->sortByName()
justynpride replied on at Permalink Reply
Sorry my error:

<?php 
defined('C5_EXECUTE') or die(_("Access Denied."));
class BookingSelectAttendeesController extends Controller {
   public function on_start(){
      Loader::model('attribute/categories/proforms_item','proforms');
      Loader::model('proforms_item_list','proforms');
      Loader::model('proforms_item','proforms');
      Loader::model('attendees','attendees');
      Loader::model('attendees_list','attendees');
      Loader::model('attribute/categories/attendees','attendees');
      Loader::model('tickets_list','tickets');
      Loader::model('attribute/categories/tickets','tickets');
      $this->set('fm',Loader::helper('form'));
      $html = Loader::helper('html');
      $this->addHeaderItem($html->css('catalyst_special.css', 'catalyst'));
hutman replied on at Permalink Reply
hutman
It looks like tickets is just a TicketList->get(), what's in the tickets_list model?
justynpride replied on at Permalink Reply
It's a custom object with a list of tickets and relevant attributes such as the handle I want sort by which is tickets_title. is that enough info?
hutman replied on at Permalink Reply
hutman
Try using this

$al = new TicketsList();
$al->sortByName();
$tickets = $al->get();

I'm making some assumptions but I think that will work
justynpride replied on at Permalink Reply
Thanks for this. Unfortunately there was no change when I used but. It was enough for me to the do a free google and come up with:

$al = new TicketsList();
                   $al->sortBy(ak_tickets_title);
         $tickets = $al->get();
         $this->set('tickets',$tickets);


This works perfectly. Thank you SO much.