<commit_before><?php
/*
 * This file is part of the CampaignChain package.
 *
 * (c) CampaignChain, Inc. <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace CampaignChain\Hook\ImageBundle\EntityService;

use CampaignChain\CoreBundle\Entity\Activity;
use CampaignChain\CoreBundle\EntityService\HookServiceDefaultInterface;
use CampaignChain\Hook\AssigneeBundle\Model\Assignee;
use CampaignChain\Hook\ImageBundle\Entity\Image;
use Doctrine\ORM\EntityManager;
use Doctrine\Common\Inflector\Inflector;

class ImageService implements HookServiceDefaultInterface
{
    protected $em;

    public function __construct(EntityManager $em)
    {
        $this->em = $em;
    }

    public function getHook($entity){
        return $entity->getImages();
    }

    /**
     * @param $entity
     * @param Image[] $hook
     * @return mixed
     */
    public function processHook($entity, $hook){
        if (!$entity instanceof Activity) {
            return $entity;
        }

        foreach ($hook as $image) {
            if (!$image->getPath()) {
                continue;
            }

            $image->setActivity($entity);
            // TODO: https://github.com/CampaignChain/campaignchain-ce/issues/82
            $entity->addImage($image);
            $this->em->persist($image);
        }

        return $entity;
    }

    public function arrayToObject($hookData){
        if(is_array($hookData) && count($hookData)){
            foreach($hookData as $imageData){
                $image = new Image();
                $image->setPath($imageData['path']);

                $hook[] = $image;
            }
        }

        return $hook;
    }

    public function tplInline($entity){
    }
}<commit_msg>CampaignChain/campaignchain-ce#83 Image in Activity not being removed in Modal<commit_after><?php
/*
 * This file is part of the CampaignChain package.
 *
 * (c) CampaignChain, Inc. <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace CampaignChain\Hook\ImageBundle\EntityService;

use CampaignChain\CoreBundle\Entity\Activity;
use CampaignChain\CoreBundle\EntityService\HookServiceDefaultInterface;
use CampaignChain\Hook\AssigneeBundle\Model\Assignee;
use CampaignChain\Hook\ImageBundle\Entity\Image;
use Doctrine\ORM\EntityManager;
use Doctrine\Common\Inflector\Inflector;

class ImageService implements HookServiceDefaultInterface
{
    protected $em;

    public function __construct(EntityManager $em)
    {
        $this->em = $em;
    }

    public function getHook($entity){
        return $entity->getImages();
    }

    /**
     * @param $entity
     * @param Image[] $hook
     * @return mixed
     */
    public function processHook($entity, $hook){
        if (!$entity instanceof Activity) {
            return $entity;
        }

        foreach ($hook as $image) {
            if (!$image->getPath()) {
                continue;
            }

            $image->setActivity($entity);
            // TODO: https://github.com/CampaignChain/campaignchain-ce/issues/82
            $entity->addImage($image);
            $this->em->persist($image);
        }

        return $entity;
    }

    public function arrayToObject($hookData){
        if(is_array($hookData) && count($hookData)){
            foreach($hookData as $imageData){
                $image = new Image();
                $image->setPath($imageData['path']);

                $hook[] = $image;
            }
        }

        return $hook;
    }

    public function processOrphaneHook($entity)
    {
        $qb = $this->em->createQueryBuilder();
        $qb->delete('CampaignChain\Hook\ImageBundle\Entity\Image', 'i');
        // TODO: https://github.com/CampaignChain/campaignchain-ce/issues/82
        $qb->where('i.activity = :activity');
        $qb->setParameter('activity', $entity);
        $qb->getQuery()->execute();
    }

    public function tplInline($entity){
    }
}
{'fraction_non_alphanumeric': 0.12490815576781777, 'fraction_numerical': 0.0019593436198873378, 'mean_word_length': 2.4406065711878684, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 30, 'https://': 3, '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': '945313', 'n_tokens_mistral': 1144, 'n_tokens_neox': 1113, 'n_words': 248}