<commit_before><?php

namespace App\Models\Membership;

use App\Models\MembershipModel;
use App\Models\ElasticSearchable;
use App\Models\Documentable;

use Illuminate\Support\Facades\Log;

use Carbon\Carbon;

/**
 * An occurrence of a program at the museum.
 */
class LegacyEvent extends MembershipModel
{

    use ElasticSearchable;
    use Documentable;

    protected $dates = [
        'start_at',
        'end_at',
        'source_created_at',
        'source_modified_at',
    ];

    public function exhibitions()
    {

        return $this->belongsToMany('App\Models\Collections\Exhibition', 'legacy_event_exhibition', 'legacy_event_membership_id', 'exhibition_citi_id');

    }

    protected function getExtraFillFieldsFrom($source)
    {

        //// Available fields we haven't done anything with yet:
        // +"url": "http://www.artic.edu/event/gallery-talk-modern-wing-highlights"

        $ret = [
            'description' => $source->body,
            'short_description' => $source->summary,
            'image_url' => $source->image,
            'start_at' => new Carbon($source->dates ." " .$source->start_time),
            'end_at' => new Carbon($source->dates ." " .$source->end_time),
            'resource_title' => $source->location,
            'web_url' => $source->url,
        ];

        // Set flag is_admission_required
        $ret['is_admission_required'] = FALSE;
        if ($source->fee == "Free with museum admission"
            || $source->fee == "Free with museum admission*"
            || $source->fee == "Free with museum admission, no registration required"
            || $source->fee == "Free with museum admission; registration required"
            || $source->fee == "Free with museum admission, registration required"
            || $source->fee == "Free with museum admission; registration required*"
            || $source->fee == "Free to Illinois residents or with museum admission; registration required*") {

            $ret['is_admission_required'] = TRUE;

        }

        if ($source->button_link)
        {
            $dom = new \DOMDocument();
            @$dom->loadHTML($source->button_link);
            foreach ($dom->getElementsByTagName('a') as $a)
            {

                $ret['button_text'] = $a->textContent;
                $ret['button_url'] = $a->getAttribute('href');

            }
        }
        return $ret;

    }

    public function attachFrom($source)
    {

        if ($source->exhibition_id)
        {

            $ids = explode(', ', $source->exhibition_id);
            $syncIds = [];
            foreach ($ids as $id)
            {
                if ($this->exhibitionIdFromDrupal($id)) {
                    $syncIds[] = $this->exhibitionIdFromDrupal($id);
                }
            }
            $this->exhibitions()->sync($syncIds, false);

        }

        return $this;

    }

    /**
     * Specific field definitions for a given class. See `transformMapping()` for more info.
     */
    protected function transformMappingInternal()
    {

        return [

            [
                "name" => 'description',
                "doc" => "Long description of the event",
                "type" => "string",
                "elasticsearch" => [
                    "default" => true,
                    "type" => 'text',
                ],
                "value" => function() { return $this->description; },
            ],
            [
                "name" => 'short_description',
                "doc" => "Short description of the event",
                "type" => "string",
                'elasticsearch_type' => 'text',
                "value" => function() { return trim($this->short_description); },
            ],
            [
                "name" => 'image',
                "doc" => "URL to an image representing this event",
                "type" => "url",
                'elasticsearch_type' => 'keyword',
                "value" => function() { return $this->image_url; },
            ],
            [
                "name" => 'type',
                "doc" => "The name of the type of event",
                "type" => "string",
                'elasticsearch_type' => 'keyword',
                "value" => function() { return $this->type; },
            ],
            [
                "name" => 'start_at',
                "doc" => "Date and time the event begins",
                "type" => "ISO 8601 date and time",
                'elasticsearch_type' => 'date',
                "value" => function() { return $this->start_at ? $this->start_at->toIso8601String() : NULL; },
            ],
            [
                "name" => 'end_at',
                "doc" => "Date and time the event ends",
                "type" => "ISO 8601 date and time",
                'elasticsearch_type' => 'date',
                "value" => function() { return $this->end_at ? $this->end_at->toIso8601String() : NULL; },
            ],
            [
                "name" => 'resource_title',
                "doc" => "The name of the resource associated with this event, often the venue in which it takes place",
                "type" => "string",
                'elasticsearch_type' => 'keyword',
                "value" => function() { return $this->resource_title; },
            ],
            [
                "name" => 'exhibition_ids',
                "doc" => "Unique identifiers of the exhibitions associated with this work",
                "type" => "array",
                'elasticsearch_type' => 'integer',
                "value" => function() { return $this->exhibitions->pluck('citi_id')->all(); },
            ],
            [
                "name" => 'button_text',
                "doc" => "Name of text on the CTA to buy tickets/register",
                "type" => "string",
                'elasticsearch_type' => 'keyword',
                "value" => function() { return $this->button_text; },
            ],
            [<commit_msg>Rename `resource_title` to `location` in `/legacy-events`<commit_after><?php

namespace App\Models\Membership;

use App\Models\MembershipModel;
use App\Models\ElasticSearchable;
use App\Models\Documentable;

use Illuminate\Support\Facades\Log;

use Carbon\Carbon;

/**
 * An occurrence of a program at the museum.
 */
class LegacyEvent extends MembershipModel
{

    use ElasticSearchable;
    use Documentable;

    protected $dates = [
        'start_at',
        'end_at',
        'source_created_at',
        'source_modified_at',
    ];

    public function exhibitions()
    {

        return $this->belongsToMany('App\Models\Collections\Exhibition', 'legacy_event_exhibition', 'legacy_event_membership_id', 'exhibition_citi_id');

    }

    protected function getExtraFillFieldsFrom($source)
    {

        //// Available fields we haven't done anything with yet:
        // +"url": "http://www.artic.edu/event/gallery-talk-modern-wing-highlights"

        $ret = [
            'description' => $source->body,
            'short_description' => $source->summary,
            'image_url' => $source->image,
            'start_at' => new Carbon($source->dates ." " .$source->start_time),
            'end_at' => new Carbon($source->dates ." " .$source->end_time),
            'resource_title' => $source->location,
            'web_url' => $source->url,
        ];

        // Set flag is_admission_required
        $ret['is_admission_required'] = FALSE;
        if ($source->fee == "Free with museum admission"
            || $source->fee == "Free with museum admission*"
            || $source->fee == "Free with museum admission, no registration required"
            || $source->fee == "Free with museum admission; registration required"
            || $source->fee == "Free with museum admission, registration required"
            || $source->fee == "Free with museum admission; registration required*"
            || $source->fee == "Free to Illinois residents or with museum admission; registration required*") {

            $ret['is_admission_required'] = TRUE;

        }

        if ($source->button_link)
        {
            $dom = new \DOMDocument();
            @$dom->loadHTML($source->button_link);
            foreach ($dom->getElementsByTagName('a') as $a)
            {

                $ret['button_text'] = $a->textContent;
                $ret['button_url'] = $a->getAttribute('href');

            }
        }
        return $ret;

    }

    public function attachFrom($source)
    {

        if ($source->exhibition_id)
        {

            $ids = explode(', ', $source->exhibition_id);
            $syncIds = [];
            foreach ($ids as $id)
            {
                if ($this->exhibitionIdFromDrupal($id)) {
                    $syncIds[] = $this->exhibitionIdFromDrupal($id);
                }
            }
            $this->exhibitions()->sync($syncIds, false);

        }

        return $this;

    }

    /**
     * Specific field definitions for a given class. See `transformMapping()` for more info.
     */
    protected function transformMappingInternal()
    {

        return [

            [
                "name" => 'description',
                "doc" => "Long description of the event",
                "type" => "string",
                "elasticsearch" => [
                    "default" => true,
                    "type" => 'text',
                ],
                "value" => function() { return $this->description; },
            ],
            [
                "name" => 'short_description',
                "doc" => "Short description of the event",
                "type" => "string",
                'elasticsearch_type' => 'text',
                "value" => function() { return trim($this->short_description); },
            ],
            [
                "name" => 'image',
                "doc" => "URL to an image representing this event",
                "type" => "url",
                'elasticsearch_type' => 'keyword',
                "value" => function() { return $this->image_url; },
            ],
            [
                "name" => 'type',
                "doc" => "The name of the type of event",
                "type" => "string",
                'elasticsearch_type' => 'keyword',
                "value" => function() { return $this->type; },
            ],
            [
                "name" => 'start_at',
                "doc" => "Date and time the event begins",
                "type" => "ISO 8601 date and time",
                'elasticsearch_type' => 'date',
                "value" => function() { return $this->start_at ? $this->start_at->toIso8601String() : NULL; },
            ],
            [
                "name" => 'end_at',
                "doc" => "Date and time the event ends",
                "type" => "ISO 8601 date and time",
                'elasticsearch_type' => 'date',
                "value" => function() { return $this->end_at ? $this->end_at->toIso8601String() : NULL; },
            ],
            [
                "name" => 'location',
                "doc" => "Location of the event (freetext)",
                "type" => "string",
                "value" => function() { return $this->resource_title; },
            ],
            [
                "name" => 'exhibition_ids',
                "doc" => "Unique identifiers of the exhibitions associated with this work",
                "type" => "array",
                'elasticsearch_type' => 'integer',
                "value" => function() { return $this->exhibitions->pluck('citi_id')->all(); },
            ],
            [
                "name" => 'button_text',
                "doc" => "Name of text on the CTA to buy tickets/register",
                "type" => "string",
                'elasticsearch_type' => 'keyword',
                "value" => function() { return $this->button_text; },
            ],
            [
{'fraction_non_alphanumeric': 0.14435409506245284, 'fraction_numerical': 0.0026825383519155, 'mean_word_length': 1.6190998902305158, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 198, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3088643', 'n_tokens_mistral': 3293, 'n_tokens_neox': 3108, 'n_words': 733}