<commit_before><?php

defined('BASEPATH') OR exit('No direct script access allowed');

class Welcome extends Application {

    public function __construct()
    {
        parent::__construct();

        // loading models
        $this->load->model('ads');
        $this->load->model('categories');

        // loading helpers
        $this->load->helper('card');
        $this->load->helper('grid');
        $this->load->helper('array');
        $this->load->helper('html');
    }

    public function index()
    {
        // inject template parameters
        $this->data['navbar_activelink'] = base_url('/');
        $this->data['page_title']        = 'Welcome';
        $this->data['page_body']         = 'welcome';
        $this->data['search']            = $this->parser->parse('_search',$this->data,true);

        // generating categories for the sidebar
        $this->data['categories'] = $this->_generate_categories();

        // show all ads in the database
        $ads = $this->ads->all();
        $this->data['cards'] = generateCards($this, $ads);

        // render...
        $this->render();
    }

    public function category($categoryid)
    {
        // inject template parameters
        $this->data['navbar_activelink']    = base_url('/');
        $this->data['page_title']           = 'Welcome';
        $this->data['page_body']            = 'welcome';
        $this->data['search'] = $this->parser->parse('_search',$this->data,true);

        // generating categories for the sidebar
        $this->data['categories'] = $this->_generate_categories();

        // show all ads from a category
        $ads = $this->ads->some('categoryID',$categoryid);
        $this->data['cards'] = generateCards($this, $ads);

        // render...
        $this->render();
    }

    public function search()
    {
        // get post parameters
        $adname    = $_POST['adname'];

        // inject template parameters
        $this->data['navbar_activelink']    = base_url('/');
        $this->data['page_title']           = 'Welcome';
        $this->data['page_body']            = 'welcome';
        $this->data['search'] = $this->parser->parse('_search',$this->data,true);

        // generating categories for the sidebar
        $this->data['categories'] = $this->_generate_categories();

        // show all ads with matching titles
        $ads = $this->ads->search($adname);
        $this->data['cards'] = generateCards($this, $ads);

        // render...
        $this->render();
    }

    private function _generate_categories()
    {
      $categories = $this->categories->all();

      $list = array();
      foreach ($categories as $category)
      {
          $list[] = anchor(base_url('/welcome/category/'.$category->ID), $category->name, 'title="'.$category->name.'"');
      }

      $attributes = array();
      $attributes['class'] = 'nav menu-item nav-stacked list-group';
      $attributes['id']    = 'mylist';

      return ul($list, $attributes);
    }
}

/* End of file welcome.php */
/* Location: ./application/controllers/Welcome.php */<commit_msg>added comments to the welcome controller<commit_after><?php

defined('BASEPATH') OR exit('No direct script access allowed');

class Welcome extends Application {

    /**
     * load the necessary models and helpers required by this model.
     */
    public function __construct()
    {
        parent::__construct();

        // loading models
        $this->load->model('ads');
        $this->load->model('categories');

        // loading helpers
        $this->load->helper('card');
        $this->load->helper('grid');
        $this->load->helper('array');
        $this->load->helper('html');
    }

    /**
     * displays all ads from the database.
     */
    public function index()
    {
        // inject template parameters
        $this->data['navbar_activelink'] = base_url('/');
        $this->data['page_title']        = 'Welcome';
        $this->data['page_body']         = 'welcome';
        $this->data['search']            = $this->parser->parse('_search',$this->data,true);

        // generating categories for the sidebar
        $this->data['categories'] = $this->_generate_categories();

        // show all ads in the database
        $ads = $this->ads->all();
        $this->data['cards'] = generateCards($this, $ads);

        // render...
        $this->render();
    }

    /**
     * displays all the ads that belong to the indicated category.
     *
     * @param  $categoryid id of the category to display.
     */
    public function category($categoryid)
    {
        // inject template parameters
        $this->data['navbar_activelink']    = base_url('/');
        $this->data['page_title']           = 'Welcome';
        $this->data['page_body']            = 'welcome';
        $this->data['search'] = $this->parser->parse('_search',$this->data,true);

        // generating categories for the sidebar
        $this->data['categories'] = $this->_generate_categories();

        // show all ads from a category
        $ads = $this->ads->some('categoryID',$categoryid);
        $this->data['cards'] = generateCards($this, $ads);

        // render...
        $this->render();
    }

    /**
     * search for ads that contain the posted search parameters, and display
     *   them.
     */
    public function search()
    {
        // get post parameters
        $adname    = $_POST['adname'];

        // inject template parameters
        $this->data['navbar_activelink']    = base_url('/');
        $this->data['page_title']           = 'Welcome';
        $this->data['page_body']            = 'welcome';
        $this->data['search'] = $this->parser->parse('_search',$this->data,true);

        // generating categories for the sidebar
        $this->data['categories'] = $this->_generate_categories();

        // show all ads with matching titles
        $ads = $this->ads->search($adname);
        $this->data['cards'] = generateCards($this, $ads);

        // render...
        $this->render();
    }

    /**
     * generate an unordered list of categories.
     *
     * @return returns a list of categories in an unordered list.
     */
    private function _generate_categories()
    {
        // get all the categories
        $categories = $this->categories->all();

        // build the links
        $list = array();
        foreach ($categories as $category)
        {
            $list[] = anchor(base_url('/welcome/category/'.$category->ID),
                $category->name,
                'title="'.$category->name.'"');
        }

        // add attributes to categories
        $attributes = array();
        $attributes['class'] = 'nav menu-item nav-stacked list-group';
        $attributes['id']    = 'mylist';

        // return an unordered list
        return ul($list, $attributes);
    }
}

/* End of file Welcome.php */
/* Location: ./application/controllers/Welcome.php */
{'fraction_non_alphanumeric': 0.17094263476506197, 'fraction_numerical': 0.0, 'mean_word_length': 2.145512239347235, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 115, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4992937', 'n_tokens_mistral': 1935, 'n_tokens_neox': 1880, 'n_words': 414}