<commit_before><?php
/**
 * ResolverDelegate.
 *
 * @author juanmsolaro
 */

namespace Minds\Core\Entities\Delegates;

use Minds\Core\Security\ACL;
use Minds\Entities\User;

class FilterEntitiesDelegate
{
    /** @var ACL */
    protected $acl;

    /** @var User */
    protected $user;

    /** @var int */
    protected $time;

    public function __construct($user, $time, $acl = null)
    {
        $this->acl = $acl ?: ACL::_();
        $this->user = $user;
        $this->time = $time;
    }

    /**
     * Filter entities by read rights and write rights for scheduled activities, images, videos or blogs
     * @param array $entities
     * @return array
     */
    public function filter($entities)
    {
        return array_values(array_filter($entities, function ($entity) {
            $filterByScheduled = false;
            if ($this->shouldFilterScheduled($entity->getType())) {
                $filterByScheduled = $entity->getTimeCreated() > $this->time
                    && !ACL::_()->write($entity, $this->user);
            }
            return !$filterByScheduled && $this->acl->read($entity, $this->user);
        }));
    }

    private function shouldFilterScheduled($type)
    {
        return $type == 'activity'
            || $type == 'blog'
            || $type == 'video'
            || $type == 'image';
    }
}<commit_msg>add object type to scheduled subjects<commit_after><?php
/**
 * ResolverDelegate.
 *
 * @author juanmsolaro
 */

namespace Minds\Core\Entities\Delegates;

use Minds\Core\Security\ACL;
use Minds\Entities\User;

class FilterEntitiesDelegate
{
    /** @var ACL */
    protected $acl;

    /** @var User */
    protected $user;

    /** @var int */
    protected $time;

    public function __construct($user, $time, $acl = null)
    {
        $this->acl = $acl ?: ACL::_();
        $this->user = $user;
        $this->time = $time;
    }

    /**
     * Filter entities by read rights and write rights for scheduled activities, images, videos or blogs
     * @param array $entities
     * @return array
     */
    public function filter($entities)
    {
        return array_values(array_filter($entities, function ($entity) {
            $filterByScheduled = false;
            if ($this->shouldFilterScheduled($entity->getType())) {
                $filterByScheduled = $entity->getTimeCreated() > $this->time
                    && !ACL::_()->write($entity, $this->user);
            }
            return !$filterByScheduled && $this->acl->read($entity, $this->user);
        }));
    }

    private function shouldFilterScheduled($type)
    {
        return $type == 'activity'
            || $type == 'object'
            || $type == 'blog'
            || $type == 'video'
            || $type == 'image';
    }
}
{'fraction_non_alphanumeric': 0.15387387387387388, 'fraction_numerical': 0.0, 'mean_word_length': 2.161731207289294, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 29, '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': '5389439', 'n_tokens_mistral': 813, 'n_tokens_neox': 815, 'n_words': 185}