<commit_before><?php

namespace PFCD\TourismBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

use Symfony\Component\HttpFoundation\File\UploadedFile;

use PFCD\TourismBundle\Entity\Activity;

/**
 * @ORM\Entity
 * @ORM\Table(name="image")
 * @ORM\HasLifecycleCallbacks()
 */
class Image
{
    /**
     * @ORM\Id
     * @ORM\Column(name="id", type="integer")
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $id;

    /**
     * @ORM\ManyToOne(targetEntity="Activity", inversedBy="gallery")
     * @ORM\JoinColumn(name="activity_id", referencedColumnName="id")
     */
    private $activity;
    
    /**
     * @ORM\Column(name="description", type="string", nullable=true)
     */
    private $description;

    /**
     * @ORM\Column(name="path", type="string", nullable=true)
     */
    private $path;
    
    /** 
     * Property used temporarily while deleting
     * 
     * @var type  
     */
    private $filenameForRemove;
    
    /** 
     * @var FileUploaded 
     */
    private $file;

    /**
     * Get rid of the __DIR__ so it doesn't screw when displaying uploaded doc/image in the view
     * 
     * @return string 
     */
    private function getUploadDir()
    {
        if (null !== $this->activity)
        {
            return 'uploads/org' . $this->activity->getOrganization()->getId() . '/act' . $this->activity->getId();
        }
        else
        {
            return 'uploads/img';
        }
    }
   
    /**
     * @ORM\PrePersist()
     * @ORM\PreUpdate()
     */
    public function preUpload()
    {
        if (null !== $this->file)
        {
            $this->path = $this->getUploadDir() . '/img' . uniqid() . '.' . $this->file->guessExtension();
        }
    }

    /**
     * @ORM\PostPersist()
     * @ORM\PostUpdate()
     */
    public function upload()
    {
        if (null !== $this->file)
        {
            // you must throw an exception here if the file cannot be moved so that the entity
            // is not persisted to the database which the UploadedFile move() method does
            $this->file->move(__DIR__ . '/../../../../web/' . $this->getUploadDir(), $this->path);

            unset($this->file);
        }
    }

    /**
     * @ORM\PreRemove()
     */
    public function storeFilenameForRemove()
    {
        $this->filenameForRemove = __DIR__ . '/../../../../web/' . $this->path;
    }

    /**
     * @ORM\PostRemove()
     */
    public function removeUpload()
    {
        if ($this->filenameForRemove)
        {
            unlink($this->filenameForRemove);
        }
    }

    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }
    
    /**
     * Set activity
     *
     * @param Activity $activity
     */
    public function setActivity(Activity $activity)
    {
        $this->activity = $activity;
    }

    /**
     * Get activity
     *
     * @return Activity 
     */
    public function getActivity()
    {
        return $this->activity;
    }

    /**
     * Set description
     *
     * @param string $description
     */
    public function setDescription($description)
    {
        $this->description = $description;
    }

    /**
     * Get description
     *
     * @return string 
     */
    public function getDescription()
    {<commit_msg>updated to allow associate Images with News<commit_after><?php

namespace PFCD\TourismBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

use Symfony\Component\HttpFoundation\File\UploadedFile;

use PFCD\TourismBundle\Entity\Activity;
use PFCD\TourismBundle\Entity\News;

/**
 * @ORM\Entity
 * @ORM\Table(name="image")
 * @ORM\HasLifecycleCallbacks()
 */
class Image
{
    /**
     * @ORM\Id
     * @ORM\Column(name="id", type="integer")
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $id;

    /**
     * @ORM\ManyToOne(targetEntity="Activity", inversedBy="gallery")
     * @ORM\JoinColumn(name="activity_id", referencedColumnName="id")
     */
    private $activity;

    /**
     * @ORM\ManyToOne(targetEntity="News", inversedBy="gallery")
     * @ORM\JoinColumn(name="news_id", referencedColumnName="id")
     */
    private $news;
    
    /**
     * @ORM\Column(name="description", type="string", nullable=true)
     */
    private $description;

    /**
     * @ORM\Column(name="path", type="string", nullable=true)
     */
    private $path;
    
    /** 
     * Property used temporarily while deleting
     * 
     * @var type  
     */
    private $filenameForRemove;
    
    /** 
     * @var FileUploaded 
     */
    private $file;

    /**
     * Get rid of the __DIR__ so it doesn't screw when displaying uploaded doc/image in the view
     * 
     * @return string 
     */
    private function getUploadDir()
    {
        if (null !== $this->activity)
        {
            return 'uploads/org' . $this->activity->getOrganization()->getId() . '/act' . $this->activity->getId();
        }
        elseif (null !== $this->news)
        {
            return 'uploads/org' . $this->news->getOrganization()->getId() . '/news' . $this->news->getId();
        }
        else
        {
            return 'uploads/img';
        }
    }
   
    /**
     * @ORM\PrePersist()
     * @ORM\PreUpdate()
     */
    public function preUpload()
    {
        if (null !== $this->file)
        {
            $this->path = $this->getUploadDir() . '/img' . uniqid() . '.' . $this->file->guessExtension();
        }
    }

    /**
     * @ORM\PostPersist()
     * @ORM\PostUpdate()
     */
    public function upload()
    {
        if (null !== $this->file)
        {
            // you must throw an exception here if the file cannot be moved so that the entity
            // is not persisted to the database which the UploadedFile move() method does
            $this->file->move(__DIR__ . '/../../../../web/' . $this->getUploadDir(), $this->path);

            unset($this->file);
        }
    }

    /**
     * @ORM\PreRemove()
     */
    public function storeFilenameForRemove()
    {
        $this->filenameForRemove = __DIR__ . '/../../../../web/' . $this->path;
    }

    /**
     * @ORM\PostRemove()
     */
    public function removeUpload()
    {
        if ($this->filenameForRemove)
        {
            unlink($this->filenameForRemove);
        }
    }

    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }
    
    /**
     * Set activity
     *
     * @param Activity $activity
     */
    public function setActivity(Activity $activity)
    {
        $this->activity = $activity;
    }

    /**
     * Get activity
     *
     * @return Activity 
     */
    public function getActivity()
    {
        return $this->activity;
    }
    
    /**
     * Set news
     *
     * @param News $news
     */
    public function setNews(News $news)
    {
        $this->news = $news;
    }

    /**
     * Get news
     *
     * @return News 
     */
    public function getNews()
    {
        return $this->news;
    }

    /**
     * Set description
     *
     * @param string $description
     */
    public function setDescription($description)
    {
        $this->description = $description;
    }

    /**
     * Get description
     *
     * @return string 
     */
    public function getDescription()
    {
{'fraction_non_alphanumeric': 0.15425315425315425, 'fraction_numerical': 0.0, 'mean_word_length': 1.7334074898034852, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 61, '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': '3419126', 'n_tokens_mistral': 2276, 'n_tokens_neox': 2209, 'n_words': 440}