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


namespace AppBundle\Entity\AcquisitionAttribute;


use AppBundle\Entity\Participant;
use AppBundle\Form\ParticipantDetectingType;

class ParticipantFilloutValue extends FilloutValue
{

    const KEY_PROPOSED_IDS = 'proposed_aids';

    /**
     * True if @see $rawValue is processed
     *
     * @var bool
     */
    private $processed = false;

    /**
     * Textual original first name value of participant
     *
     * @var string|null
     */
    private $relatedFirstName;

    /**
     * Textual original last name value of participant
     *
     * @var string|null
     */
    private $relatedLastName;

    /**
     * Aid of @see Participant if one was selected for this user
     *
     * @var int|null
     */
    private $participantAid = null;

    /**
     * First name of @see Participant
     *
     * @var null|string
     */
    private $participantFirstName = null;

    /**
     * Last name of @see Participant
     *
     * @var null|string
     */
    private $participantLastName = null;

    /**
     * List of @see Participant ids which are proposed to be related to this user
     *
     * List of @see Participant ids which are proposed to be related to this user. @see null if not initialized
     *
     * @var array|int[]|null
     */
    private $proposedParticipants = null;

    /**
     * Create duplicate, having transmitted participant selected
     *
     * @param Participant $participant Participant to select
     * @return ParticipantFilloutValue New instance
     */
    public function createWithParticipantSelected(Participant $participant)
    {
        $value = json_decode($this->getRawValue(), true);
        if (!is_array($value)) {
            $value = [];
        }
        $value['participant_selected']            = $participant->getAid();
        $value['participant_selected_first_name'] = $participant->getNameFirst();
        $value['participant_selected_last_name']  = $participant->getNameLast();
        return new self($this->getAttribute(), json_encode($value));
    }

    /**
     * Transform fillout to string; Useful for textual display in ui
     *
     * Transform fillout to string; Useful for textual display in ui. Will return label of selected item if
     * this fillout belongs to a choice field
     *
     * @return string
     */
    public function getTextualValue()
    {
        $this->ensureProcessed();
        return (string)$this->relatedFirstName . ' ' . $this->relatedLastName;
    }

    /**
     * Get related @see Participant first name
     *
     * @return string|null<commit_msg>Now supporting deselection of related participant<commit_after><?php
/**
 * This file is part of the Juvem package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */


namespace AppBundle\Entity\AcquisitionAttribute;


use AppBundle\Entity\Participant;
use AppBundle\Form\ParticipantDetectingType;

class ParticipantFilloutValue extends FilloutValue
{

    const KEY_PROPOSED_IDS = 'proposed_aids';

    /**
     * True if @see $rawValue is processed
     *
     * @var bool
     */
    private $processed = false;

    /**
     * Textual original first name value of participant
     *
     * @var string|null
     */
    private $relatedFirstName;

    /**
     * Textual original last name value of participant
     *
     * @var string|null
     */
    private $relatedLastName;

    /**
     * Aid of @see Participant if one was selected for this user
     *
     * @var int|null
     */
    private $participantAid = null;

    /**
     * First name of @see Participant
     *
     * @var null|string
     */
    private $participantFirstName = null;

    /**
     * Last name of @see Participant
     *
     * @var null|string
     */
    private $participantLastName = null;

    /**
     * List of @see Participant ids which are proposed to be related to this user
     *
     * List of @see Participant ids which are proposed to be related to this user. @see null if not initialized
     *
     * @var array|int[]|null
     */
    private $proposedParticipants = null;

    /**
     * Create duplicate, having transmitted participant selected
     *
     * @param Participant|null $participant Participant to select
     * @return ParticipantFilloutValue New instance
     */
    public function createWithParticipantSelected(Participant $participant = null)
    {
        $value = json_decode($this->getRawValue(), true);
        if (!is_array($value)) {
            $value = [];
        }
        
        $participantId = $participant ? $participant->getAid() : null;
        $participantFirstName = $participant ? $participant->getNameFirst() : null;
        $participantLastName = $participant ? $participant->getNameLast() : null;
        
        $value['participant_selected']            = $participantId;
        $value['participant_selected_first_name'] = $participantFirstName;
        $value['participant_selected_last_name']  = $participantLastName;
        return new self($this->getAttribute(), json_encode($value));
    }

    /**
     * Transform fillout to string; Useful for textual display in ui
     *
     * Transform fillout to string; Useful for textual display in ui. Will return label of selected item if
     * this fillout belongs to a choice field
     *
     * @return string
     */
    public function getTextualValue()
    {
        $this->ensureProcessed();
        return (string)$this->relatedFirstName . ' ' . $this->relatedLastName;
    }

    /**
     * Get related @see Participant first name
     *
     * @return string|null
{'fraction_non_alphanumeric': 0.09893093500763618, 'fraction_numerical': 0.0, 'mean_word_length': 2.5104228707564027, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 25, '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': '7661196', 'n_tokens_mistral': 1693, 'n_tokens_neox': 1609, 'n_words': 493}