/**
  * Search Results Loop
  * 
  */
 protected function search_result($path = null)
 {
     //loading resources
     $db =& JFactory::getDBO();
     //initializing variables
     $data = JRequest::get('get');
     $geo = $this->getGeoPostal($data['postal_code']);
     if (!$data['postal_code'] || !$data['distance']) {
         $query = "SELECT * FROM `#__byrdlist_listings` as `listings`" . " WHERE `listings`.`published` = '1'" . " AND (`listings`.`name` LIKE '%" . trim($data['filter']) . "%'" . " OR `listings`.description LIKE '%" . trim($data['filter']) . "%')" . " LIMIT 0,5";
     } else {
         $query = "SELECT id, ( 3959 * acos( cos( radians(" . $geo['lattitude'] . ") ) * cos( radians( `listings`.`lattitude` ) ) * cos( radians( `listings`.`longitude` ) - radians(" . $geo['longitude'] . ") ) + sin( radians(" . $geo['lattitude'] . ") ) * sin( radians( `listings`.`lattitude` ) ) ) ) AS distance " . " FROM `#__byrdlist_listings` as `listings`" . " WHERE `listings`.`published` = '1'" . " AND (`listings`.`name` LIKE '%" . trim($data['filter']) . "%'" . " OR `listings`.description LIKE '%" . trim($data['filter']) . "%')" . " HAVING distance < " . $data['distance'] . " ORDER BY distance" . " LIMIT 0,5";
     }
     $db->setQuery($query);
     $results = $db->loadAssocList();
     //reasons to fail
     if (!$results) {
         return false;
     }
     foreach ($results as $result) {
         $instance = JTable::getInstance($this->_table, 'Table');
         //reasons to continue
         if (!$instance->load($result['id'])) {
             continue;
         }
         $listings[$result['id']] = $instance;
     }
     $listings = ByrdHelper::sort_object($listings, 'created_on');
     foreach ($listings as $id => $record) {
         //loading resources
         $thumb =& $record->thumbnail();
         require $path;
     }
     return true;
 }
 /**
  * Get the Records
  * 
  * @return array
  */
 protected function getList()
 {
     //loading resources
     $results = $this->getQuery();
     //reasons to fail
     if (!$results) {
         return false;
     }
     foreach ($results as $result) {
         $instance = JTable::getInstance($this->_table, 'Table');
         //reasons to continue
         if (!$instance->load($result['id'])) {
             continue;
         }
         $listings[$result['id']] = $instance;
     }
     $listings = ByrdHelper::sort_object($listings, 'created_on');
     return $listings;
 }
 /**
  * Last Bid Object
  * 
  */
 function last_bid()
 {
     //loading resources
     $bids =& $this->getOneToMany('byrdlist_bids');
     $bids = ByrdHelper::sort_object($bids, 'created_on');
     //reasons to fail
     if (empty($bids)) {
         return JTable::getInstance('byrdlist_comments', 'Table');
     }
     return current($bids);
 }
 /**
  * Get the child comments
  * 
  * This method should return the comments in proper order
  * 
  * @return array of objects
  */
 public function getChildComments()
 {
     //loading resources
     $listing =& $this->getOneToOne('byrdlist_listings');
     $comments = $listing->getOneToMany('byrdlist_comments');
     $comments = ByrdHelper::sort_object($comments, 'created_on', false);
     //reasons to return
     if (empty($comments)) {
         return false;
     }
     //initializing variables
     $new = array();
     foreach ($comments as $id => $instance) {
         //skip if its a child of something else
         if ($instance->parent_id() != $this->id()) {
             continue;
         }
         if (!$instance->published()) {
             continue;
         }
         //initializing variables
         $instance->_comments_children = $this->_comments_children + 1;
         $new[$id] = $instance;
         $children = $instance->getChildComments();
         //reasons to continue
         if (!$children) {
             continue;
         }
         foreach ($children as $id => $instance) {
             //initializing variables
             $new[$id] = $instance;
         }
     }
     return $new;
 }