Commit 43b2fb29 authored by Stephane Bouvry's avatar Stephane Bouvry
Browse files

Champ libre (type Text) ajouté à la fiche activité (Enregistrement/MAJ ok)

parent 5d5766d6
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -885,7 +885,7 @@ class ProjectGrantController extends AbstractOscarController implements UseNotif
        if ($request->isPost()) {
            $form->setData($request->getPost());
            if ($form->isValid()) {
                $this->getEntityManager()->flush($projectGrant);
                $this->getEntityManager()->flush();

                if ($projectGrant->getStatus() !== $beforeStatus) {
                    $this->getEventManager()->trigger(
@@ -917,6 +917,7 @@ class ProjectGrantController extends AbstractOscarController implements UseNotif
                'numerotationKeys'   => $numerotationKeys,
                'hidden'             => $hidden,
                'form'               => $form,
                'freeFields'        => $form->getFreeFieldsInfos(),
                'activity'           => $projectGrant,
                'numbers_keys'       => $numerotationKeys,
                'allowNodeSelection' => $this->getOscarConfigurationService()->isAllowNodeSelection(),
+158 −98
Original line number Diff line number Diff line
@@ -29,7 +29,8 @@ class Activity implements ResourceInterface
{
    use TraitTrackable;

    public static function getStatusInactive() :array {
    public static function getStatusInactive(): array
    {
        return [
            self::STATUS_ABORDED,
            self::STATUS_CLOSED,
@@ -451,6 +452,14 @@ class Activity implements ResourceInterface
     */
    protected $avenants;

    /**
     * Liste des champs libres
     *
     * @var ActivityFreeFieldValue[]
     * @ORM\OneToMany(targetEntity="ActivityFreeFieldValue", mappedBy="activity", cascade={"remove", "persist"})
     */
    protected $freeFields;

    /**
     * @var ArrayCollection
     * @ORM\ManyToMany(targetEntity="Person", inversedBy="validatorActivitiesPrj")
@@ -791,7 +800,8 @@ class Activity implements ResourceInterface
        \DateTime $cache_at = new \DateTime(),
        bool      $cache_lock = false,
        string    $cache_lock_reason = self::CACHE_REASON_DEFAULT
    ): self {
    ): self
    {
        $this->cache = $cache_content;
        $this->dateCached = $cache_at;
        if ($cache_lock === true) {
@@ -837,7 +847,8 @@ class Activity implements ResourceInterface
        bool    $diplayCurrency = true,
        bool    $displayPercentInfo = true,
        bool    $fraisDeGestionInclusDansMontant = false,
    ): string {
    ): string
    {
        $percent = '';
        $currency = '';
        $data = '';
@@ -894,7 +905,8 @@ class Activity implements ResourceInterface
        bool $diplayCurrency = true,
        bool $displayPercentInfo = true,
        bool $fraisDeGestionInclusDansMontant = false
    ) {
    )
    {
        return $this->getFraisDisplay($this->getFraisDeGestionPartGestionnaire(), true, true, $fraisDeGestionInclusDansMontant);
    }

@@ -1205,7 +1217,8 @@ class Activity implements ResourceInterface

    public function getActivityTypeChain(
        ActivityTypeService $activityTypeService
    ) {
    )
    {
        return $activityTypeService->getActivityTypeChain($this->getActivityType());
    }

@@ -1381,8 +1394,7 @@ class Activity implements ResourceInterface
    {
        if ($this->getDateNegociation()) {
            return $this->getDateNegociation()->format($format);
        }
        else {
        } else {
            return "";
        }
    }
@@ -1406,8 +1418,7 @@ class Activity implements ResourceInterface
    {
        if ($this->getDateDepotProjet()) {
            return $this->getDateDepotProjet()->format($format);
        }
        else {
        } else {
            return "";
        }
    }
@@ -1603,6 +1614,7 @@ class Activity implements ResourceInterface
        $this->organizations = new ArrayCollection();
        $this->milestones = new ArrayCollection();
        $this->avenants = new ArrayCollection();
        $this->freeFields = new ArrayCollection();
        $this->payments = new ArrayCollection();
        $this->disciplines = new ArrayCollection();
        $this->motscles = new ArrayCollection();
@@ -1671,6 +1683,24 @@ class Activity implements ResourceInterface
        return count($this->getValidatorsAdm()) > 0;
    }

    /**
     * @return ArrayCollection
     */
    public function getFreeFields(): Collection
    {
        return $this->freeFields;
    }

    public function getFreeFieldsValues(ActivityFreeField $type): mixed
    {
        foreach ($this->getFreeFields() as $freeField) {
            if ($freeField->getType() == $type) {
                return $freeField->getValue();
            }
        }
        return null;
    }

    /**
     * @param ArrayCollection $validatorsAdm
     */
@@ -1899,7 +1929,8 @@ class Activity implements ResourceInterface
                     $role,
                     $start = null,
                     $to = null
    ) {
    )
    {
        if (!$this->hasOrganization($organization, $role)) {
            $partner = new ActivityOrganization();
            $partner->setOrganization($organization)
@@ -2094,6 +2125,34 @@ class Activity implements ResourceInterface
        return $partners;
    }

    public function setFreeField(ActivityFreeField $type, array $value)
    {
        /** @var ActivityFreeFieldValue $freeField */
        $freeField = null;
        /** @var ActivityFreeFieldValue $field */
        foreach ($this->getFreeFields() as $field) {
            if ($field->getType() === $type) {
                $freeField = $field;
                $this->getFreeFields()->removeElement($freeField);
            }
        }
        $freeField = new ActivityFreeFieldValue();
        $freeField->setType($type);
        $freeField->setActivity($this);
        $this->getFreeFields()->add($freeField);
        $freeField->setData($value);
    }

    public function getFreeFieldOfType(?object $typeObj) : ActivityFreeFieldValue|null
    {
        /** @var ActivityFreeFieldValue $field */
        foreach ($this->getFreeFields() as $field) {
            if ($field->getType() === $typeObj) {
                return $field;
            }
        }
        return null;
    }


    protected function deepParent(Organization $organization, &$out = []): array
@@ -2160,7 +2219,8 @@ class Activity implements ResourceInterface
        ?\DateTime $dateStart = null,
        ?\DateTime $dateEnd = null,
        bool       $deep = true
    ) {
    )
    {
        $found = false;
        /** @var ActivityPerson $activityPerson */
        foreach ($this->persons as $activityPerson) {
@@ -2482,8 +2542,7 @@ class Activity implements ResourceInterface
        /** @var ActivityPayment $payment */
        foreach ($this->getPayments() as $payment) {
            if (
                $payment->getDatePayment() == $datePayment && $payment->getAmount(
                ) == $amount && $payment->getDatePredicted() == $datePredicted
                $payment->getDatePayment() == $datePayment && $payment->getAmount() == $amount && $payment->getDatePredicted() == $datePredicted
            ) {
                return true;
            }
@@ -2502,7 +2561,8 @@ class Activity implements ResourceInterface
        Organization $organization,
                     $role = null,
                     $deep = true
    ) {
    )
    {
        $found = false;
        /** @var ActivityOrganization $relation */
        foreach ($this->organizations as $relation) {
+12 −0
Original line number Diff line number Diff line
@@ -149,4 +149,16 @@ class ActivityFreeField
    {
        $this->required = $required;
    }

    public function getParams(): array
    {
        return $this->params;
    }

    public function setParams(array $params): void
    {
        $this->params = $params;
    }


}
 No newline at end of file
+96 −0
Original line number Diff line number Diff line
<?php

namespace Oscar\Entity;

use DateTime;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 */
class ActivityFreeFieldValue
{
    /**
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @var
     * @ORM\ManyToOne(targetEntity="ActivityFreeField")
     */
    private $type;

    /**
     * @var
     * @ORM\ManyToOne(targetEntity="Activity", inversedBy="freefields")
     */
    private $activity;


    /**
     * Indique si le champ est obligatoire.
     *
     * @var array
     * @ORM\Column(type="json", nullable=false)
     */
    private $data = [];

    public function getId(): ?int
    {
        return $this->id;
    }

    /**
     * @return mixed
     */
    public function getType()
    {
        return $this->type;
    }

    /**
     * @param mixed $type
     */
    public function setType($type): void
    {
        $this->type = $type;
    }

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

    /**
     * @param mixed $activity
     */
    public function setActivity($activity): void
    {
        $this->activity = $activity;
    }

    public function getData(): array
    {
        return $this->data;
    }

    public function setData(array $data): void
    {
        $this->data = $data;
    }

    public function getValue(): mixed {
        switch ($this->getType()->getType()) {
            case ActivityFreeField::FREE_FIELD_TYPE_TEXT :
                $data  = $this->getData();
                return array_key_exists('value', $data) ? $data['value'] : null;
        }
        return null;
    }
}
 No newline at end of file
+1 −1
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@ class ActivityFreeFieldRepository extends EntityRepository
        $query->select('f')->where('f.editable = true');
        $out = [];
        foreach ($query->getQuery()->getArrayResult() as $row) {
            $out[sprintf(self::PATTERN_NAME, $row['id'], $row['name'])] = $row['label'];
            $out[sprintf(self::PATTERN_NAME, $row['id'], $row['name'])] = $row;
        }
        return $out;
    }
Loading