<commit_before><?php

namespace PlaygroundDesign\Service;

use PlaygroundDesign\Entity\Company as CompanyEntity;

use Zend\Form\Form;
use Zend\ServiceManager\ServiceManagerAwareInterface;
use Zend\ServiceManager\ServiceManager;
use Zend\Validator\NotEmpty;
use ZfcBase\EventManager\EventProvider;
use PlaygroundDesign\Options\ModuleOptions;
use DoctrineModule\Validator\NoObjectExists as NoObjectExistsValidator;
use Zend\Stdlib\ErrorHandler;

class Company extends EventProvider implements ServiceManagerAwareInterface
{

    /**
     * @var companyMapperInterface
     */
    protected $companyMapper;

    /**
     * @var ServiceManager
     */
    protected $serviceManager;

    /**
     * @var UserServiceOptionsInterface
     */
    protected $options;

    /**
     *
     * This service is ready for create a company
     *
     * @param  array  $data
     * @param  string $formClass
     *
     * @return \PlaygroundDesign\Entity\Company
     */
    public function create(array $data)
    {
        $company = new CompanyEntity;
        $entityManager = $this->getServiceManager()->get('playgrounddesign_doctrine_em');

        $form = $this->getServiceManager()->get('playgrounddesign_company_form');

        $form->bind($company);
        $form->setData($data);

        if (!$form->isValid()) {
            return false;
        }

        $companyMapper = $this->getCompanyMapper();
        $company = $companyMapper->insert($company);

        $this->uploadImage($company, $data);

        $company = $companyMapper->update($company);

        return $company;
    }

    /**
     *
     * This service is ready for edit a company
     *
     * @param  array  $data
     * @param  string $company
     * @param  string $formClass
     *
     * @return \PlaygroundDesign\Entity\Company
     */
    public function edit(array $data, $company)
    {
        $entityManager = $this->getServiceManager()->get('playgrounddesign_doctrine_em');

        $form  = $this->getServiceManager()->get('playgrounddesign_company_form');

        $form->bind($company);

        $form->setData($data);

        if (!$form->isValid()) {
            return false;
        }

        $company = $this->uploadImage($company, $data);
        $company = $this->getCompanyMapper()->update($company);

        return $company;
    }

    public function uploadImage($company, $data)
    {
         if (!empty($data['uploadMainImage']['tmp_name'])) {
            $path = $this->getOptions()->getMediaPath();
            if (!is_dir($path)) {
                mkdir($path,0777, true);
            }
            $media_url = $this->getOptions()->getMediaUrl() . '/';
            move_uploaded_file($data['uploadMainImage']['tmp_name'], $path . $company->getId() . "-" . $data['uploadMainImage']['name']);<commit_msg>Fix the path for the logo<commit_after><?php

namespace PlaygroundDesign\Service;

use PlaygroundDesign\Entity\Company as CompanyEntity;

use Zend\Form\Form;
use Zend\ServiceManager\ServiceManagerAwareInterface;
use Zend\ServiceManager\ServiceManager;
use Zend\Validator\NotEmpty;
use ZfcBase\EventManager\EventProvider;
use PlaygroundDesign\Options\ModuleOptions;
use DoctrineModule\Validator\NoObjectExists as NoObjectExistsValidator;
use Zend\Stdlib\ErrorHandler;

class Company extends EventProvider implements ServiceManagerAwareInterface
{

    /**
     * @var companyMapperInterface
     */
    protected $companyMapper;

    /**
     * @var ServiceManager
     */
    protected $serviceManager;

    /**
     * @var UserServiceOptionsInterface
     */
    protected $options;

    /**
     *
     * This service is ready for create a company
     *
     * @param  array  $data
     * @param  string $formClass
     *
     * @return \PlaygroundDesign\Entity\Company
     */
    public function create(array $data)
    {
        $company = new CompanyEntity;
        $entityManager = $this->getServiceManager()->get('playgrounddesign_doctrine_em');

        $form = $this->getServiceManager()->get('playgrounddesign_company_form');

        $form->bind($company);
        $form->setData($data);

        if (!$form->isValid()) {
            return false;
        }

        $companyMapper = $this->getCompanyMapper();
        $company = $companyMapper->insert($company);

        $this->uploadImage($company, $data);

        $company = $companyMapper->update($company);

        return $company;
    }

    /**
     *
     * This service is ready for edit a company
     *
     * @param  array  $data
     * @param  string $company
     * @param  string $formClass
     *
     * @return \PlaygroundDesign\Entity\Company
     */
    public function edit(array $data, $company)
    {
        $entityManager = $this->getServiceManager()->get('playgrounddesign_doctrine_em');

        $form  = $this->getServiceManager()->get('playgrounddesign_company_form');

        $form->bind($company);

        $form->setData($data);

        if (!$form->isValid()) {
            return false;
        }

        $company = $this->uploadImage($company, $data);
        $company = $this->getCompanyMapper()->update($company);

        return $company;
    }

    public function uploadImage($company, $data)
    {
         if (!empty($data['uploadMainImage']['tmp_name'])) {
            $path = $this->getOptions()->getMediaPath() . DIRECTORY_SEPARATOR;
            if (!is_dir($path)) {
                mkdir($path,0777, true);
            }
            $media_url = $this->getOptions()->getMediaUrl() . '/';
            move_uploaded_file($data['uploadMainImage']['tmp_name'], $path . $company->getId() . "-" . $data['uploadMainImage']['name']);
{'fraction_non_alphanumeric': 0.13695960311835578, 'fraction_numerical': 0.001417434443656981, 'mean_word_length': 2.706500328299409, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 55, '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': '7378636', 'n_tokens_mistral': 1599, 'n_tokens_neox': 1553, 'n_words': 295}