<commit_before><?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class Organization extends Model
{

    /**
     * The attributes that hold geometrical data.
     *
     * @var array
     */
    protected $geometry = array('polygon');

    /**
     * Select geometrical attributes as text from database.
     *
     * @var bool
     */
    protected $geometryAsText = true;

    //protected $appends = ['geometry'];

    public function committees()
    {
        return $this->hasMany('App\Models\Committee');
    }

    public function socialMedia()
    {
        return $this->hasMany('App\Models\SocialMedia');
    }

    public function getMedia($type)
    {
        foreach ($this->socialMedia as $media) {
            if (strtolower($media->type) === strtolower($type)) {
                return $media;
            }
        }
        return null;
    }

    public function setMedia($type, $value)
    {
        $media = $this->getMedia($type);
        if (!$media) {
            $media = new SocialMedia();
            $media->organization_id = $this->id;
        }
        $media->type = $type;
        $media->handle = $value;
        $media->save();
        return $media;
    }

    public function getDisplayGeometry()
    {
        $result = $this->polygon;
        $result = str_replace(',', '],[', $result);
        $result = str_replace('((', '[[', $result);
        $result = str_replace('))', ']]', $result);
        $result = str_replace(' ', ',', $result);
        $result = str_replace('POLYGON', '', $result);
        return $result;
    }

    public static function convertGeoPolygon($polygon)
    {
        $polygon = preg_replace('/,(\d)/', ' $1', $polygon);
        $polygon = str_replace('],[', ',', $polygon);
        $polygon = str_replace('[[', '((', $polygon);
        $polygon = str_replace(']]', '))', $polygon);
        $polygon = "POLYGON" . $polygon;
        return $polygon;
    }
    /**
     * Get a new query builder for the model's table.
     * Manipulate in case we need to convert geometrical fields to text.
     *
     * @param  bool  $excludeDeleted
     * @return \Illuminate\Database\Eloquent\Builder
     */
    public function newQuery($excludeDeleted = true)<commit_msg>Toying around with this<commit_after><?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class Organization extends Model
{

    /**
     * The attributes that hold geometrical data.
     *
     * @var array
     */
    protected $geometry = array('polygon');

    /**
     * Select geometrical attributes as text from database.
     *
     * @var bool
     */
    protected $geometryAsText = true;

    //protected $appends = ['geometry'];

    public function committees()
    {
        return $this->hasMany('App\Models\Committee');
    }

    public function socialMedia()
    {
        return $this->hasMany('App\Models\SocialMedia');
    }

    public function getMedia($type)
    {
        foreach ($this->socialMedia as $media) {
            if (strtolower($media->type) === strtolower($type)) {
                return $media;
            }
        }
        return null;
    }

    public function setMedia($type, $value)
    {
        $media = $this->getMedia($type);
        if (!$media) {
            $media = new SocialMedia();
            $media->organization_id = $this->id;
        }
        $media->type = $type;
        $media->handle = $value;
        $media->save();
        return $media;
    }

    public function getDisplayGeometry()
    {
        $result = $this->polygon;
        $result = str_replace(',', '],[', $result);
        $result = str_replace('((', '[[', $result);
        $result = str_replace('))', ']]', $result);
        $result = str_replace(' ', ',', $result);
        $result = str_replace('POLYGON', '', $result);
        return $result;
    }

    public static function convertGeoPolygon($polygon)
    {
        $polygon = preg_replace('/,(\d)/', ' $1', $polygon);
        $polygon = str_replace('],[', ',', $polygon);
        $polygon = str_replace('[[', '(', $polygon);
        $polygon = str_replace(']]', ')', $polygon);
        //$polygon = "POLYGON" . $polygon;
        return $polygon;
    }

    public function setPolygonAttribute($value) {
        $this->attributes['polygon'] = DB::raw("POLYGON($value)");
    }
 

    /**
     * Get a new query builder for the model's table.
     * Manipulate in case we need to convert geometrical fields to text.
     *
     * @param  bool  $excludeDeleted
     * @return \Illuminate\Database\Eloquent\Builder
     */
    public function newQuery($excludeDeleted = true)
{'fraction_non_alphanumeric': 0.1577602725143709, 'fraction_numerical': 0.0004258037044922291, 'mean_word_length': 2.23331039229181, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 26, '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': '221350', 'n_tokens_mistral': 1429, 'n_tokens_neox': 1395, 'n_words': 315}