<commit_before><?php

namespace Extia\Bundle\MissionBundle\Model;

use Extia\Bundle\MissionBundle\Model\om\BaseMission;

use Extia\Bundle\UserBundle\Model\Person;
use Extia\Bundle\UserBundle\Model\MissionOrderQuery;
use Extia\Bundle\UserBundle\Model\ConsultantQuery;
use Extia\Bundle\TaskBundle\Workflow\TaskTargetInterface;

class Mission extends BaseMission implements TaskTargetInterface
{
    /**
     * returns mission full label
     * @param  string $sep
     * @return string
     */
    public function getFullLabel($sep = ' - ')
    {
        return sprintf('%s%s%s',
            $this->getClient()->getTitle(),
            $sep,
            $this->getLabel()
        );
    }

    /**
     * tests if mission is in client office
     * @return boolean
     */
    public function isExternal()
    {
        return 'client' == $this->getType();
    }

    /**
     * tests if mission is intercontract (and on profile without mission)
     * @return boolean
     */
    public function isIntercontract()
    {
        return 'ic' == $this->getType()
            || 'waiting' == $this->getType()
        ;
    }

    // --------------------------------------------------
    // Saving override to calculate fields
    // --------------------------------------------------

    private $oldManager;

    /**
     * override setter to memento manager before modification
     */
    public function setManagerId($managerId)
    {
        if ($managerId !== $this->getManagerId()) {
            $this->oldManager = $this->getManager();
        }

        return parent::setManagerId($managerId);
    }

    /**
     * override save to calculate all relative objects
     */
    public function save(\PropelPDO $con = null)
    {
        $return = parent::save($con);

        // fires hooks
        $this->onChangeManager($this->getManager($con), $this->oldManager, $con);

        return $return;
    }

    /**
     * hook fired by save() method, when manager has change
     *
     * @param Person    $newManager
     * @param Person    $oldManager
     * @param PropelPdo $con
     */
    public function onChangeManager(Person $newManager, Person $oldManager = null, \PropelPDO $con = null)
    {
        // change consultants managers

        $consultants = ConsultantQuery::create()
            ->setComment(sprintf('%s l:%s', __METHOD__, __LINE__))
            ->useMissionOrderQuery()
                ->filterByCurrent(true)
                ->filterByMissionId($this->getId())
            ->endUse()
            ->find($con)
        ;

        foreach ($consultants as $consultant) {
            $consultant->setManagerId($newManager->getId());
            $consultant->save($con);
        }
    }

    /**
     * Get consultants ids of current mission
     *
     * @return Array
     */
    public function getConsultantsId()
    {
        $consultantsId = MissionOrderQuery::create()
            ->setComment(sprintf('%s l:%s', __METHOD__, __LINE__))
            ->filterByMissionId($this->id)
            ->select('ConsultantId')
            ->find();

        return $consultantsId;
    }

    /**
     * Get consultants of current mission
     *
     * @return Array
     */
    public function getConsultants()
    {
        $consultantsId = $this->getConsultantsId()->toArray();
        $consultants = ConsultantQuery::create()->findPKs($consultantsId);
<commit_msg>update mission display order in lunch task form<commit_after><?php

namespace Extia\Bundle\MissionBundle\Model;

use Extia\Bundle\MissionBundle\Model\om\BaseMission;

use Extia\Bundle\UserBundle\Model\Person;
use Extia\Bundle\UserBundle\Model\MissionOrderQuery;
use Extia\Bundle\UserBundle\Model\ConsultantQuery;
use Extia\Bundle\TaskBundle\Workflow\TaskTargetInterface;

class Mission extends BaseMission implements TaskTargetInterface
{
    /**
     * returns mission full label
     * @param  string $sep
     * @return string
     */
    public function getFullLabel($sep = ' - ')
    {
        return sprintf('%s%s%s',
            $this->getClient()->getTitle(),
            $sep,
            $this->getLabel()
        );
    }

    /**
     * tests if mission is in client office
     * @return boolean
     */
    public function isExternal()
    {
        return 'client' == $this->getType();
    }

    /**
     * tests if mission is intercontract (and on profile without mission)
     * @return boolean
     */
    public function isIntercontract()
    {
        return 'ic' == $this->getType()
            || 'waiting' == $this->getType()
        ;
    }

    // --------------------------------------------------
    // Saving override to calculate fields
    // --------------------------------------------------

    private $oldManager;

    /**
     * override setter to memento manager before modification
     */
    public function setManagerId($managerId)
    {
        if ($managerId !== $this->getManagerId()) {
            $this->oldManager = $this->getManager();
        }

        return parent::setManagerId($managerId);
    }

    /**
     * override save to calculate all relative objects
     */
    public function save(\PropelPDO $con = null)
    {
        $return = parent::save($con);

        // fires hooks
        $this->onChangeManager($this->getManager($con), $this->oldManager, $con);

        return $return;
    }

    /**
     * hook fired by save() method, when manager has change
     *
     * @param Person    $newManager
     * @param Person    $oldManager
     * @param PropelPdo $con
     */
    public function onChangeManager(Person $newManager, Person $oldManager = null, \PropelPDO $con = null)
    {
        // change consultants managers

        $consultants = ConsultantQuery::create()
            ->setComment(sprintf('%s l:%s', __METHOD__, __LINE__))
            ->useMissionOrderQuery()
                ->filterByCurrent(true)
                ->filterByMissionId($this->getId())
            ->endUse()
            ->find($con)
        ;

        foreach ($consultants as $consultant) {
            $consultant->setManagerId($newManager->getId());
            $consultant->save($con);
        }
    }

    /**
     * Get consultants of current mission
     *
     * @return Array
     */
    public function getConsultants()
    {
        $consultants = ConsultantQuery::create()
            ->setComment(sprintf('%s l:%s', __METHOD__, __LINE__))
            ->useMissionOrderQuery()
                ->filterByMissionId($this->id)
            ->endUse()
            ->find();

{'fraction_non_alphanumeric': 0.15407021309213553, 'fraction_numerical': 0.0, 'mean_word_length': 1.913800803930326, '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': '6195228', 'n_tokens_mistral': 1807, 'n_tokens_neox': 1788, 'n_words': 391}