<commit_before><?php

namespace CollegeFB\Repositories\MongoDB;

use CollegeFB\Repositories\NewsInterface;
use CollegeFB\Entities\News as NewsEntity;
use CollegeFB\Iterators\News as NewsIterator;
use MongoDB;
use MongoId;
use MongoDate;

class News implements NewsInterface
{
    const COLLECTION_NAME = 'news';

    private $collection;
    private $query_params = array();

    public function __construct(MongoDB $connection)
    {
        $this->collection = $connection->selectCollection(self::COLLECTION_NAME);
    }

    public function setQueryParams($param, $value)
    {
        if (!empty($value)) {
            $this->query_params[$param] = (string) $value;
        }
    }

    public function save(NewsEntity $news)
    {
        $news_info = $news->getData();

        if ((false !== $news->hasId()) && (null !== ($id = $news->getId()))) {
            $news_info['_id'] = new MongoId($id);
        } else {
            $news_info['_id'] = new MongoId();
            $news->setId($news_info['_id']);
        }

        $news_info['pub_date'] = new MongoDate($news_info['pub_date']);

        $this->collection->save($news_info);

        return $news;
    }

    public function remove(NewsEntity $news)
    {
        $id = $news->getId();<commit_msg>Fixes #7: Add possibility to filter by array<commit_after><?php

namespace CollegeFB\Repositories\MongoDB;

use CollegeFB\Repositories\NewsInterface;
use CollegeFB\Entities\News as NewsEntity;
use CollegeFB\Iterators\News as NewsIterator;
use MongoDB;
use MongoId;
use MongoDate;

class News implements NewsInterface
{
    const COLLECTION_NAME = 'news';

    private $collection;
    private $query_params = array();

    public function __construct(MongoDB $connection)
    {
        $this->collection = $connection->selectCollection(self::COLLECTION_NAME);
    }

    public function setQueryParams($param, $value)
    {
        if (!empty($value)) {
            if (is_array($value)) {
                $this->query_params[$param] = array('$in' => $value);
            } else {
                $this->query_params[$param] = (string) $value;
            }
        }
    }

    public function save(NewsEntity $news)
    {
        $news_info = $news->getData();

        if ((false !== $news->hasId()) && (null !== ($id = $news->getId()))) {
            $news_info['_id'] = new MongoId($id);
        } else {
            $news_info['_id'] = new MongoId();
            $news->setId($news_info['_id']);
        }

        $news_info['pub_date'] = new MongoDate($news_info['pub_date']);

        $this->collection->save($news_info);

        return $news;
    }

    public function remove(NewsEntity $news)
    {
        $id = $news->getId();
{'fraction_non_alphanumeric': 0.14818920916481892, 'fraction_numerical': 0.0003695491500369549, 'mean_word_length': 2.713305898491084, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, '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': '3202599', 'n_tokens_mistral': 841, 'n_tokens_neox': 818, 'n_words': 168}