<commit_before><?php
/**
 * Tatoeba Project, free collaborative creation of languages corpuses project
 * Copyright (C) 2010  <NAME> <<EMAIL>>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * PHP version 5
 *
 * @category PHP
 * @package  Tatoeba
 * @author   <NAME> <<EMAIL>>
 * @license  Affero General Public License
 * @link     http://tatoeba.org
 */

/**
 * Model for association table between sentences and lists.
 *
 * @category SentencesSentencesLists
 * @package  Models
 * @author   <NAME> <<EMAIL>>
 * @license  Affero General Public License
 * @link     http://tatoeba.org
 */

class SentencesSentencesLists extends AppModel
{
    public $name = 'SentencesSentencesLists';
    public $useTable = 'sentences_sentences_lists';
    public $actsAs = array('Containable');

    public $belongsTo = array(
        'Sentence' => array('foreignKey' => 'sentence_id')
    );

    /**
     * Add sentence to list.
     *
     * @param int $sentenceId Id of the sentence.
     * @param int $listId     Id of the list.
     *
     * @return array
     */
    public function addSentenceToList($sentenceId, $listId)
    {
        $data = array(
            'sentence_id' => $sentenceId,
            'sentences_list_id' => $listId
        );

        $isSaved = $this->save($data);

        return $isSaved;
    }


    /**
     * Remove sentence from list.
     *
     * @param int $sentenceId Id of the sentence.
     * @param int $listId     Id of the list.
     *
     * @return array
     */
    public function removeSentenceFromList($sentenceId, $listId)
    {
        $conditions = array(
            'sentence_id' => $sentenceId,
            'sentences_list_id' => $listId
        );

        $isDeleted = $this->deleteAll($conditions, false);

        return $isDeleted;
    }


    /**
     * Returns value of $this->paginate, for paginating sentences of a list.
     *
     * @param int    $listId           Id of the list.
     * @param string $translationsLang Language of the translations.
     * @param int    $limit            Number of sentences per page.
     *
     * @return array
     */
    public function getPaginatedSentencesInList($listId, $translationsLang, $limit)
    {
        $sentenceParams = array(
            'fields' => array('id', 'text', 'lang', 'hasaudio', 'correctness'),
            'User' => array('fields' => array('id', 'username'))
        );

        if ($translationsLang != null) {
            // All
            $sentenceParams['Translation'] = array(
                "fields" => array("id", "lang", "text", "correctness"),
            );
            // Specific language
            if ($translationsLang != 'und') {
                $sentenceParams['Translation']['conditions'] = array(
                    "lang" => $translationsLang
                );
            }
        }

        return array(
            'limit' => $limit,
            'conditions' => array('sentences_list_id' => $listId),
            'contain' => array(
                'Sentence' => $sentenceParams
            )
        );
    }
}<commit_msg>Order sentences in list by descending added date.<commit_after><?php
/**
 * Tatoeba Project, free collaborative creation of languages corpuses project
 * Copyright (C) 2010  <NAME> <<EMAIL>>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * PHP version 5
 *
 * @category PHP
 * @package  Tatoeba
 * @author   <NAME> <<EMAIL>>
 * @license  Affero General Public License
 * @link     http://tatoeba.org
 */

/**
 * Model for association table between sentences and lists.
 *
 * @category SentencesSentencesLists
 * @package  Models
 * @author   <NAME> <<EMAIL>>
 * @license  Affero General Public License
 * @link     http://tatoeba.org
 */

class SentencesSentencesLists extends AppModel
{
    public $name = 'SentencesSentencesLists';
    public $useTable = 'sentences_sentences_lists';
    public $actsAs = array('Containable');

    public $belongsTo = array(
        'Sentence' => array('foreignKey' => 'sentence_id')
    );

    /**
     * Add sentence to list.
     *
     * @param int $sentenceId Id of the sentence.
     * @param int $listId     Id of the list.
     *
     * @return array
     */
    public function addSentenceToList($sentenceId, $listId)
    {
        $data = array(
            'sentence_id' => $sentenceId,
            'sentences_list_id' => $listId
        );

        $isSaved = $this->save($data);

        return $isSaved;
    }


    /**
     * Remove sentence from list.
     *
     * @param int $sentenceId Id of the sentence.
     * @param int $listId     Id of the list.
     *
     * @return array
     */
    public function removeSentenceFromList($sentenceId, $listId)
    {
        $conditions = array(
            'sentence_id' => $sentenceId,
            'sentences_list_id' => $listId
        );

        $isDeleted = $this->deleteAll($conditions, false);

        return $isDeleted;
    }


    /**
     * Returns value of $this->paginate, for paginating sentences of a list.
     *
     * @param int    $listId           Id of the list.
     * @param string $translationsLang Language of the translations.
     * @param int    $limit            Number of sentences per page.
     *
     * @return array
     */
    public function getPaginatedSentencesInList($listId, $translationsLang, $limit)
    {
        $sentenceParams = array(
            'fields' => array('id', 'text', 'lang', 'hasaudio', 'correctness'),
            'User' => array('fields' => array('id', 'username'))
        );

        if ($translationsLang != null) {
            // All
            $sentenceParams['Translation'] = array(
                "fields" => array("id", "lang", "text", "correctness"),
            );
            // Specific language
            if ($translationsLang != 'und') {
                $sentenceParams['Translation']['conditions'] = array(
                    "lang" => $translationsLang
                );
            }
        }

        return array(
            'limit' => $limit,
            'conditions' => array('sentences_list_id' => $listId),
            'contain' => array(
                'Sentence' => $sentenceParams
            ),
            'order' => 'created DESC'
        );
    }
}
{'fraction_non_alphanumeric': 0.11537946727345737, 'fraction_numerical': 0.0016062106813010306, 'mean_word_length': 2.2, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 62, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6874753', 'n_tokens_mistral': 2138, 'n_tokens_neox': 2045, 'n_words': 662}