<commit_before><?php

class ItemModel extends CI_Model
{

    public $user_id;

    function __construct() {
        parent::__construct();
        $this->user_id = ($this->session->userdata('user_id')) ? $this->session->userdata('user_id') : 0;
    }

    function doesBelongToUser($id, $itemId) {
        $query = $this->db->select()
                ->where('user_id', $id)
                ->where('item_id', $itemId)
                ->get('item');

        if($query->num_rows() > 0) {
            return true;
        } else {
            return false;
        }
    }

    function getItemInfo($itemId) {
        $query = $this->db->select()
                ->join('artist', 'artist.artist_id = item.artist_id')
                ->join('format', 'format.format_id = item.format_id')
                ->where('item_id', $itemId)
                ->where('item.user_id', $this->user_id)
                ->get('item');

       return $query->result();

    }

    public function getRecentlyAdded() {
        $query = $this->db->select()
                ->join('artist', 'artist.artist_id = item.artist_id')
                ->where('item.user_id', $this->user_id)
                ->order_by('item.created_at DESC')
                ->limit(5)
                ->get('item');

        if($query->num_rows() > 0) {
            return $query->result();
        } else {
            return false;
        }
    }

    function getItemRating($itemId) {
        $rating = $this->db->select('rating')
                ->where('item_id', $itemId)
                ->get('item');

        return $rating->result();
    }

    function updateRating($rating, $itemId) {
        $data = array(
            'rating' => $rating
        );

        $this->db->where('item_id', $itemId);
        $this->db->update('item', $data);
    }

    function updateItem($field, $value, $table, $itemId) {
        $data = array(
            $field => $value
        );

        $this->db->where('item_id', $itemId);
        $query = $this->db->update($table, $data);

        if ($query) {
            return true;
        } else {
            return false;
        }
    }

    function getList($table) {
        $query = $this->db->get($table);

        return $query;
    }

    function addNewCd($title, $artist_id, $summary, $format_id, $reference, $cd_count, $image, $purchasedFrom, $purchaseDate, $price, $user_id) {

        $data = array(
            'artist_id' => $artist_id,
            'format_id' => $format_id,
            'cd_count' => $cd_count,
            'title' => $title,
            'reference' => $reference,<commit_msg>Version 1.1.2, Major DB changes (WIP)<commit_after><?php

class ItemModel extends CI_Model
{

    public $user_id;

    function __construct() {
        parent::__construct();
        $this->user_id = ($this->session->userdata('user_id')) ? $this->session->userdata('user_id') : 0;
    }

    function doesBelongToUser($id, $itemId) {
        $query = $this->db->select()
                ->where('user_id', $id)
                ->where('item_id', $itemId)
                ->get('item');

        if($query->num_rows() > 0) {
            return true;
        } else {
            return false;
        }
    }

    function getItemInfo($itemId) {
        $query = $this->db->select()
                ->join('artist', 'artist.artist_id = item.artist_id')
                ->join('format', 'format.format_id = item.format_id')
                ->where('item_id', $itemId)
                ->where('item.user_id', $this->user_id)
                ->get('item');

       return $query->result();

    }

    public function getRecentlyAdded() {
        $query = $this->db->select()
                ->join('artist', 'artist.artist_id = item.artist_id')
                ->where('item.user_id', $this->user_id)
                ->order_by('item.created_at DESC')
                ->limit(5)
                ->get('item');

        if($query->num_rows() > 0) {
            return $query->result();
        } else {
            return false;
        }
    }

    function getItemRating($itemId) {
        $rating = $this->db->select('rating')
                ->where('item_id', $itemId)
                ->get('item');

        return $rating->result();
    }

    function updateRating($rating, $itemId) {
        $data = array(
            'rating' => $rating
        );

        $this->db->where('item_id', $itemId);
        $this->db->update('item', $data);
    }

    function updateItem($field, $value, $table, $itemId) {
        $data = array(
            $field => $value
        );

        $this->db->where('item_id', $itemId);
        $query = $this->db->update($table, $data);

        if ($query) {
            return true;
        } else {
            return false;
        }
    }

    function getList($table) {
        $query = $this->db->get($table);

        return $query;
    }

    function addNewCd($title, $artist_id, $summary, $format_id, $reference, $cd_count, $image, $purchasedFrom, $purchaseDate, $price, $user_id) {

        $data = array(
            'artist_id' => $artist_id,
            'format_id' => $format_id,
            'disc_count' => $cd_count,
            'title' => $title,
            'reference' => $reference,
{'fraction_non_alphanumeric': 0.17117288651942117, 'fraction_numerical': 0.0020944402132520943, 'mean_word_length': 1.7217616580310882, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 111, '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': '6118935', 'n_tokens_mistral': 1690, 'n_tokens_neox': 1602, 'n_words': 284}