<commit_before><?php

class TalkMapper extends ApiMapper
{
    /**
     * Iterate through results from the database to ensure data consistency and
     * add sub-resource data
     *
     * @param  array|false $results
     * @return array
     */
    public function processResults($results)
    {
        if (!is_array($results)) {
            // $results isn't an array. This shouldn't happen as an exception
            // should have been raised by PDO. However if it does, return an
            // empty array.
            return [];
        }

        if (count($results)) {
            $base    = $this->_request->base;
            $version = $this->_request->version;
            foreach ($results as $key => $row) {
                // generate and store an inflected talk title if there isn't one
                if (empty($row['url_friendly_talk_title'])) {
                    $results[$key]['url_friendly_talk_title'] = $this->generateInflectedTitle(
                        $row['talk_title'],
                        $row['ID']
                    );
                }

                // if the stub is empty, we need to generate one and store it
                if (empty($row['stub'])) {
                    $results[$key]['stub'] = $this->generateStub($row['ID']);
                }

                // did the logged in user star this talk?
                if (isset($this->_request->user_id)) {
                    $results[$key]['starred'] = $this->hasUserStarredTalk($row['ID'], $this->_request->user_id);
                } else {
                    $results[$key]['starred'] = false;
                }

                // add speakers & tracks
                $results[$key]['speakers'] = $this->getSpeakers($row['ID']);
                $results[$key]['tracks']   = $this->getTracks($row['ID']);
            }
        }
        return $results;
    }

    /**
     * Get all the talks for this event
     *
     * @param int $event_id         The event to fetch talks for
     * @param int $resultsperpage   How many results to return on each page
     * @param int $start            Which result to start with
     */
    public function getTalksByEventId($event_id, $resultsperpage, $start)
    {
        $sql = $this->getBasicSQL();
        $sql .= ' and t.event_id = :event_id';
        $sql .= ' order by t.date_given';
        $sql .= $this->buildLimit($resultsperpage, $start);

        $stmt     = $this->_db->prepare($sql);
        $response = $stmt->execute(array(
            ':event_id' => $event_id
        ));
        if ($response) {
            $results = $stmt->fetchAll(PDO::FETCH_ASSOC);
            $total = $this->getTotalCount($sql, array(':event_id' => $event_id));
            $results = $this->processResults($results);

            return new TalkModelCollection($results, $total);
        }

        return false;
    }

    /**
     * Retrieve a single talk
     *
     * @param  integer $talk_id
     * @param  bool $verbose<commit_msg>Ensure media links are loaded on the talk list#<commit_after><?php

class TalkMapper extends ApiMapper
{
    /**
     * Iterate through results from the database to ensure data consistency and
     * add sub-resource data
     *
     * @param  array|false $results
     * @return array
     */
    public function processResults($results)
    {
        if (!is_array($results)) {
            // $results isn't an array. This shouldn't happen as an exception
            // should have been raised by PDO. However if it does, return an
            // empty array.
            return [];
        }

        if (count($results)) {
            $base    = $this->_request->base;
            $version = $this->_request->version;
            foreach ($results as $key => $row) {
                // generate and store an inflected talk title if there isn't one
                if (empty($row['url_friendly_talk_title'])) {
                    $results[$key]['url_friendly_talk_title'] = $this->generateInflectedTitle(
                        $row['talk_title'],
                        $row['ID']
                    );
                }

                // if the stub is empty, we need to generate one and store it
                if (empty($row['stub'])) {
                    $results[$key]['stub'] = $this->generateStub($row['ID']);
                }

                // did the logged in user star this talk?
                if (isset($this->_request->user_id)) {
                    $results[$key]['starred'] = $this->hasUserStarredTalk($row['ID'], $this->_request->user_id);
                } else {
                    $results[$key]['starred'] = false;
                }

                // add speakers & tracks
                $results[$key]['speakers'] = $this->getSpeakers($row['ID']);
                $results[$key]['tracks']   = $this->getTracks($row['ID']);
            }
        }
        return $results;
    }

    /**
     * Get all the talks for this event
     *
     * @param int $event_id         The event to fetch talks for
     * @param int $resultsperpage   How many results to return on each page
     * @param int $start            Which result to start with
     */
    public function getTalksByEventId($event_id, $resultsperpage, $start)
    {
        $sql = $this->getBasicSQL();
        $sql .= ' and t.event_id = :event_id';
        $sql .= ' order by t.date_given';
        $sql .= $this->buildLimit($resultsperpage, $start);

        $stmt     = $this->_db->prepare($sql);
        $response = $stmt->execute(array(
            ':event_id' => $event_id
        ));
        if ($response) {
            $results = $stmt->fetchAll(PDO::FETCH_ASSOC);
            $total = $this->getTotalCount($sql, array(':event_id' => $event_id));
            $results = $this->processResults($results);
            $results = $this->addTalkMediaTypes($results);

            return new TalkModelCollection($results, $total);
        }

        return false;
    }

    /**
     * Retrieve a single talk
     *
     * @param  integer $talk_id
     * @param  bool $verbose
{'fraction_non_alphanumeric': 0.13370657006421868, 'fraction_numerical': 0.0, 'mean_word_length': 1.6769501983252535, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 52, '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': '6580927', 'n_tokens_mistral': 1677, 'n_tokens_neox': 1610, 'n_words': 427}