<commit_before><?php
namespace KapAlbum;

use KapAlbum\V1\Rest\Album\AlbumCollection;
use KapAlbum\V1\Rest\Album\AlbumEntity;
use KapAlbum\V1\Rest\AlbumItem\AlbumItemCollection;
use KapAlbum\V1\Rest\AlbumItem\AlbumItemEntity;
use KapAlbum\V1\Rest\AlbumItemRel\AlbumItemRelEntity;
use KapAlbum\V1\Rest\AlbumItemTag\AlbumItemTagCollection;
use KapAlbum\V1\Rest\AlbumItemTag\AlbumItemTagEntity;
use KapApigility\DbEntityRepository;
use KapApigility\EntityRepositoryResource;
use KapTaxonomy\V1\Rest\Tag\TagCollection;
use KapTaxonomy\V1\Rest\Tag\TagEntity;
use Zend\Mvc\MvcEvent;
use Zend\Paginator\Adapter\ArrayAdapter;
use ZF\Apigility\Provider\ApigilityProviderInterface;
use ZF\Hal\Link\Link;

class Module implements ApigilityProviderInterface
{
    public function onBootstrap($e)
    {
        $app = $e->getTarget();
        $this->sm = $app->getServiceManager();

        $events   = $app->getEventManager();
        $events->attach(MvcEvent::EVENT_RENDER, array($this, 'onRender'), 110);
    }

    public function onRender($e)
    {
        $helpers = $this->sm->get('ViewHelperManager');
        $hal = $helpers->get('hal');

        $hal->getEventManager()->attach(['renderEntity', 'renderCollection.entity'], array($this, 'onRenderCollectionEntity'));
    }

    public function onRenderCollectionEntity($e)
    {
        if($e->getName() === 'renderEntity') {
            $entity = $e->getParam('entity')->entity;
        }
        else {
            $entity = $e->getParam('entity');
        }
        
        $embeddingHal = $e->getParam('embeddingHalEntity');

        if($entity instanceof AlbumEntity && !($embeddingHal && $embeddingHal->entity instanceof AlbumItemEntity)) {
            
            if(!empty($entity['primary_item_id'])) {
                $albumItemRepo = $this->sm->get('KapAlbum\\AlbumItemRepository');
                $entity['primary_item'] = $albumItemRepo->find($entity['primary_item_id']);
            }
        }

        if($entity instanceof AlbumItemEntity) {
            //tags
            $tagRepository = $this->sm->get('KapTaxonomy\\TagRepository');

            $adapter = $this->sm->get('KapAlbum\AlbumItemTagRepository')->getPaginatorAdapter([
                'album_item_id' => $entity['id']
            ]);
            
            $tags = [];
            foreach($adapter->getItems(0, 9999)->toArray() as $itemTag) {
                $tags[] = $tagRepository->find($itemTag['tag_id']);
            }
            
            $entity['tag_collection'] = new TagCollection(new ArrayAdapter($tags));
            //END
            
            //albums
            $albumRepo = $this->sm->get('KapAlbum\\AlbumRepository');
            $adapter = $this->sm->get('KapAlbum\AlbumItemRelRepository')->getPaginatorAdapter([
                'album_item_id' => $entity['id']
            ]);

            $tags = [];
            foreach($adapter->getItems(0, 9999)->toArray() as $itemTag) {
                $tags[] = $albumRepo->find($itemTag['album_id']);
            }
            
            $entity['album_collection'] = new AlbumCollection(new ArrayAdapter($tags));
            //END
            
            if($entity['type'] == 'FILE') {
                $fileRepo = $this->sm->get('KapFileManager\\FileRepository');
                $entity['file'] = $fileRepo->find($entity['file_id']);
            }

            if(!empty($entity['thumbnail_file_id'])) {
                $fileRepo = $this->sm->get('KapFileManager\\FileRepository');
                $entity['thumbnail_file'] = $fileRepo->find($entity['thumbnail_file_id']);
            }
        }


        if($entity instanceof AlbumItemRelEntity) {
            $itemRepo = $this->sm->get('KapAlbum\\AlbumItemRepository');
            $item = $itemRepo->find($entity['album_item_id']);
            
            $entity['album_item'] = $item;
        }

        if($entity instanceof AlbumItemTagEntity) {
            $repo = $this->sm->get('KapTaxonomy\\TagRepository');
            $item = $repo->find($entity['tag_id']);
            $entity['tag'] = $item;
        }

        if($entity instanceof TagEntity) {
            <commit_msg>file ignored<commit_after><?php
namespace KapAlbum;

use KapAlbum\V1\Rest\Album\AlbumCollection;
use KapAlbum\V1\Rest\Album\AlbumEntity;
use KapAlbum\V1\Rest\AlbumItem\AlbumItemCollection;
use KapAlbum\V1\Rest\AlbumItem\AlbumItemEntity;
use KapAlbum\V1\Rest\AlbumItemRel\AlbumItemRelEntity;
use KapAlbum\V1\Rest\AlbumItemTag\AlbumItemTagCollection;
use KapAlbum\V1\Rest\AlbumItemTag\AlbumItemTagEntity;
use KapApigility\DbEntityRepository;
use KapApigility\EntityRepositoryResource;
use KapTaxonomy\V1\Rest\Tag\TagCollection;
use KapTaxonomy\V1\Rest\Tag\TagEntity;
use Zend\Mvc\MvcEvent;
use Zend\Paginator\Adapter\ArrayAdapter;
use ZF\Apigility\Provider\ApigilityProviderInterface;
use ZF\Hal\Link\Link;

class Module implements ApigilityProviderInterface
{
    public function onBootstrap($e)
    {
        $app = $e->getTarget();
        $this->sm = $app->getServiceManager();

        $events   = $app->getEventManager();
        $events->attach(MvcEvent::EVENT_RENDER, array($this, 'onRender'), 110);
    }

    public function onRender($e)
    {
        $helpers = $this->sm->get('ViewHelperManager');
        $hal = $helpers->get('hal');

        $hal->getEventManager()->attach(['renderEntity', 'renderCollection.entity'], array($this, 'onRenderCollectionEntity'));
    }

    public function onRenderCollectionEntity($e)
    {
        if($e->getName() === 'renderEntity') {
            $entity = $e->getParam('entity')->entity;
        }
        else {
            $entity = $e->getParam('entity');
        }
        
        $embeddingHal = $e->getParam('embeddingHalEntity');

        if($entity instanceof AlbumEntity && !($embeddingHal && $embeddingHal->entity instanceof AlbumItemEntity)) {
            
            if(!empty($entity['primary_item_id'])) {
                $albumItemRepo = $this->sm->get('KapAlbum\\AlbumItemRepository');
                $entity['primary_item'] = $albumItemRepo->find($entity['primary_item_id']);
            }
        }

        if($entity instanceof AlbumItemEntity) {
            //tags
            $tagRepository = $this->sm->get('KapTaxonomy\\TagRepository');

            $adapter = $this->sm->get('KapAlbum\AlbumItemTagRepository')->getPaginatorAdapter([
                'album_item_id' => $entity['id']
            ]);
            
            $tags = [];
            foreach($adapter->getItems(0, 9999)->toArray() as $itemTag) {
                $tags[] = $tagRepository->find($itemTag['tag_id']);
            }
            
            $entity['tag_collection'] = new TagCollection(new ArrayAdapter($tags));
            //END
            
            //albums
            $albumRepo = $this->sm->get('KapAlbum\\AlbumRepository');
            $adapter = $this->sm->get('KapAlbum\AlbumItemRelRepository')->getPaginatorAdapter([
                'album_item_id' => $entity['id']
            ]);

            $tags = [];
            foreach($adapter->getItems(0, 9999)->toArray() as $itemTag) {
                $tags[] = $albumRepo->find($itemTag['album_id']);
            }
            
            $entity['album_collection'] = new AlbumCollection(new ArrayAdapter($tags));
            //END
            
            if(!empty($entity['file_id'])) {
                $fileRepo = $this->sm->get('KapFileManager\\FileRepository');
                $entity['file'] = $fileRepo->find($entity['file_id']);
            }

            if(!empty($entity['thumbnail_file_id'])) {
                $fileRepo = $this->sm->get('KapFileManager\\FileRepository');
                $entity['thumbnail_file'] = $fileRepo->find($entity['thumbnail_file_id']);
            }
        }


        if($entity instanceof AlbumItemRelEntity) {
            $itemRepo = $this->sm->get('KapAlbum\\AlbumItemRepository');
            $item = $itemRepo->find($entity['album_item_id']);
            
            $entity['album_item'] = $item;
        }

        if($entity instanceof AlbumItemTagEntity) {
            $repo = $this->sm->get('KapTaxonomy\\TagRepository');
            $item = $repo->find($entity['tag_id']);
            $entity['tag'] = $item;
        }

        if($entity instanceof TagEntity) {
            
{'fraction_non_alphanumeric': 0.15500603136308805, 'fraction_numerical': 0.005307599517490953, 'mean_word_length': 2.395167895167895, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 101, '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': '3418871', 'n_tokens_mistral': 2466, 'n_tokens_neox': 2371, 'n_words': 316}