<commit_before><?php

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

class User_detail extends Application {

    public function __construct()
    {
        parent::__construct();
        $this->load->library('parser');
        $this->load->helper('formfields');
        $this->load->model('users');
        $this->load->model('ads');
        $this->load->model('categories');
        $this->load->model('reviews');

        $this->load->helper('card');
        $this->load->helper('grid');
        $this->load->helper('array');
    }

    private function getUserDetails($username)
    {
        $record = $this->users->some('username', $username);

        // use the first record (username should be unique)
        $this->data['username'] = $record[0]->username;
        $this->data['displayname'] = $record[0]->displayname;
        $this->data['email'] = $record[0]->email;

        $this->data['username'] = $record->username;
        $this->data['displayname'] = $record->displayname;
        $this->data['email'] = $record->email;
        $this->data['imagesrc'] = $this->users->getUserImageSrc($id);
    }

    public function confirm()
    {
        // create a record to add to the database
        $addRecord = $this->reviews->create();

        $addRecord->from = 'from user'; // need to update this once log-in is implemented
        $addRecord->to = 'to user'; // need to update this once log-in is implemented
        $addRecord->review = $this->input->post('review');
        $addRecord->rating = $this->input->post('rating');

        // Add validation here once log in is implemented
        // there shouldn't be an anonymous review

        $this->reviews->add($addRecord);<commit_msg>Fixed user detail after merge from upstream<commit_after><?php

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

class User_detail extends Application {

    public function __construct()
    {
        parent::__construct();
        $this->load->library('parser');
        $this->load->helper('formfields');
        $this->load->model('users');
        $this->load->model('ads');
        $this->load->model('categories');
        $this->load->model('reviews');

        $this->load->helper('card');
        $this->load->helper('grid');
        $this->load->helper('array');
    }

    private function getUserDetails($username)
    {
        $record = $this->users->some('username', $username);

        // use the first record (username should be unique)
        $this->data['username'] = $record[0]->username;
        $this->data['displayname'] = $record[0]->displayname;
        $this->data['email'] = $record[0]->email;

        return $record[0]->ID;
    }

    private function generateStars($setStars, $numStars)
    {
        $stars = array();
        for ($i = 1; $i <= $numStars; $i++)
        {
            $star = array( 'rate' => 'rated',
                           'status' => ($i <= $setStars ? 'class=set' : 'class=not-set'));
            $stars[] = $star;
        }

        return $stars;
    }

    // create the stars
    private function getReviewStars($username)
    {
        // get total number of stars
        $records = $this->reviews->some('to', $username);
        $total = 0;

        // get the average and round up to nearest whole number
        foreach($records as $record)
        {
            $total += $record->rating;
        }

        $ratingCount = sizeof($records);
        $rating = ceil($total/($ratingCount == 0 ? 1 : $ratingCount));


        $reviewStars = array();
        $reviewStars['stars'] = $this->generateStars($rating, NUMRATING);

        return $this->parser->parse('_stars', $reviewStars, true);
    }

    // get reviews
    private function getReviews($username)
    {
        // get reviews
        $records = $this->reviews->some('to', $username);

        // generate reviews
        $reviews = array();
        foreach($records as $record)
        {
            $review = array();
            $review['from'] = $record->from;

            // get user rating and display stars
            $userrating = array();
            $userrating['stars'] = $this->generateStars($record->rating, NUMRATING);
            $review['stars'] = $this->parser->parse('_stars', $userrating, true);

            $review['review'] = $record->review;
            $reviews[] = $review;
        }

        $allReviews['rows'] = $reviews;
        return $this->parser->parse('_reviews', $allReviews, true);
    }

    public function confirm()
    {
        // create a record to add to the database
        $addRecord = $this->reviews->create();

        $addRecord->from = 'from user'; // need to update this once log-in is implemented
        $addRecord->to = 'to user'; // need to update this once log-in is implemented
        $addRecord->review = $this->input->post('review');
        $addRecord->rating = $this->input->post('rating');

        // Add validation here once log in is implemented
        // there shouldn't be an anonymous review

        $this->reviews->add($addRecord);
{'fraction_non_alphanumeric': 0.16972205795387343, 'fraction_numerical': 0.0021683422038241674, 'mean_word_length': 2.3691899070385127, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 107, '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': '6873820', 'n_tokens_mistral': 1449, 'n_tokens_neox': 1400, 'n_words': 331}