<?php
/**
 * Netgo_News extension
 * 
 * NOTICE OF LICENSE
 * 
 * This source file is subject to the MIT License
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/mit-license.php
 * 
 * @category       Netgo
 * @package        Netgo_News
 * @copyright      Copyright (c) 2015
 * @license        http://opensource.org/licenses/mit-license.php MIT License
 */
/**
 * Admin search model
 *
 * @category    Netgo
 * @package     Netgo_News
 * @author      Ultimate Module Creator
 */
class Netgo_News_Model_Adminhtml_Search_News
    extends Varien_Object {
    /**
     * Load search results
     * @access public
     * @return Netgo_News_Model_Adminhtml_Search_News
     * @author Ultimate Module Creator
     */
    public function load(){
        $arr = array();
        if (!$this->hasStart() || !$this->hasLimit() || !$this->hasQuery()) {
            $this->setResults($arr);
            return $this;
        }
        $collection = Mage::getResourceModel('netgo_news/news_collection')
            ->addFieldToFilter('title', array('like' => $this->getQuery().'%'))
            ->setCurPage($this->getStart())
            ->setPageSize($this->getLimit())
            ->load();
        foreach ($collection->getItems() as $news) {
            $arr[] = array(
                'id'=> 'news/1/'.$news->getId(),
                'type'  => Mage::helper('netgo_news')->__('News'),
                'name'  => $news->getTitle(),
                'description'   => $news->getTitle(),
                'url' => Mage::helper('adminhtml')->getUrl('*/news_news/edit', array('id'=>$news->getId())),
            );
        }
        $this->setResults($arr);
        return $this;
    }
}
