<commit_before><?php

namespace Symfony\Cmf\Bundle\CoreBundle\Twig;

use Symfony\Cmf\Bundle\CoreBundle\PublishWorkflow\PublishWorkflowCheckerInterface;
use Doctrine\ODM\PHPCR\DocumentManager;

class TwigExtension extends \Twig_Extension
{
    /**
     * @var DocumentManager
     */
    protected $dm;

    /**
     * @var PublishWorkflowCheckerInterface
     */
    protected $publishWorkflowChecker;

    /**
     * Instantiate the content controller.
     *
     * @param PublishWorkflowCheckerInterface $publishWorkflowChecker
     */
    public function __construct(DocumentManager $dm, PublishWorkflowCheckerInterface $publishWorkflowChecker)
    {
        $this->dm = $dm;
        $this->publishWorkflowChecker = $publishWorkflowChecker;
    }

    public function getFunctions()
    {
        return array(
            'cmf_children' => new \Twig_Function_Method($this, 'children'),
            'cmf_prev' => new \Twig_Function_Method($this, 'prev'),
            'cmf_next' => new \Twig_Function_Method($this, 'next'),
            'cmf_is_published' => new \Twig_Function_Method($this, 'isPublished'),
        );
    }

    public function children($current, $limit = false)
    {
        $children = $this->dm->getChildren($current);
        foreach ($children as $key => $child) {
            if (!$this->publishWorkflowChecker->checkIsPublished($child)) {
                $children->remove($key);
            }

            if (false !== $limit) {
                $limit--;
                if (!$limit) {
                    break;
                }
            }
        }

        return $children;
    }

    private function search($current, $reverse = false)
    {
        // TODO optimize
        $path = $this->dm->getUnitOfWork()->getDocumentId($current);
        $node = $this->dm->getPhpcrSession()->getNode($path);
        $parent = $node->getParent();
        $children = $parent->getNodes();

        $childNames = array_keys($children->getArrayCopy());
        if ($reverse) {
            $childNames = array_reverse($childNames);
        }

        $check = false;
        foreach ($childNames as $name) {<commit_msg>added support for role ignore in children()<commit_after><?php

namespace Symfony\Cmf\Bundle\CoreBundle\Twig;

use Symfony\Cmf\Bundle\CoreBundle\PublishWorkflow\PublishWorkflowCheckerInterface;
use Doctrine\ODM\PHPCR\DocumentManager;

class TwigExtension extends \Twig_Extension
{
    /**
     * @var DocumentManager
     */
    protected $dm;

    /**
     * @var PublishWorkflowCheckerInterface
     */
    protected $publishWorkflowChecker;

    /**
     * Instantiate the content controller.
     *
     * @param PublishWorkflowCheckerInterface $publishWorkflowChecker
     */
    public function __construct(DocumentManager $dm, PublishWorkflowCheckerInterface $publishWorkflowChecker)
    {
        $this->dm = $dm;
        $this->publishWorkflowChecker = $publishWorkflowChecker;
    }

    public function getFunctions()
    {
        return array(
            'cmf_children' => new \Twig_Function_Method($this, 'children'),
            'cmf_prev' => new \Twig_Function_Method($this, 'prev'),
            'cmf_next' => new \Twig_Function_Method($this, 'next'),
            'cmf_is_published' => new \Twig_Function_Method($this, 'isPublished'),
        );
    }

    public function children($current, $limit = false, $ignoreRole = false)
    {
        $children = $this->dm->getChildren($current);
        foreach ($children as $key => $child) {
            if (!$this->publishWorkflowChecker->checkIsPublished($child, $ignoreRole)) {
                $children->remove($key);
            }

            if (false !== $limit) {
                $limit--;
                if (!$limit) {
                    break;
                }
            }
        }

        return $children;
    }

    private function search($current, $reverse = false)
    {
        // TODO optimize
        $path = $this->dm->getUnitOfWork()->getDocumentId($current);
        $node = $this->dm->getPhpcrSession()->getNode($path);
        $parent = $node->getParent();
        $children = $parent->getNodes();

        $childNames = array_keys($children->getArrayCopy());
        if ($reverse) {
            $childNames = array_reverse($childNames);
        }

        $check = false;
        foreach ($childNames as $name) {
{'fraction_non_alphanumeric': 0.12942528735632183, 'fraction_numerical': 0.0, 'mean_word_length': 2.3037205770690963, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 45, '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': '622297', 'n_tokens_mistral': 1230, 'n_tokens_neox': 1225, 'n_words': 225}