<commit_before><?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class ScreenGroup extends Model
{
    /**
     * Database table
     * @var string
     */
    protected $table = 'screengroups';
    /**
     * The attributes that are mass assignable.
     * @var [type]
     */
    protected $fillable = [
        'name',
        'desc',
    ];

    /**
     * Boot method used to update associations depending on actions.
     *
     */
    public static function boot() {
        parent::boot();

        ScreenGroup::deleting(function ($screengroup) {
            foreach( $screengroup->clients as $client) {
                $client->update(['screen_group_id' => 1]);
                $client->save();
            }

            foreach ( $screengroup->screens as $screen ){
                $screengroup->screens()->detach($screen->id);
            }

            foreach ( $screengroup->tickers as $ticker ){
                $screengroup->tickers()->detach($ticker->id);
            }

        });
    }

    /**
     * Screen association
     *
     * @return [type] [description]
     */

    public function screens() {
        return $this->belongsToMany(Screen::class, 'screengroup_screen')->withTimestamps();
    }


    public function tickers() {
        return $this->belongsToMany(Ticker::class, 'screengroup_ticker')->withTimestamps();
    }

    /**
     * Client association
     * @return [type] [description]
     */
    public function clients() {
        return $this->hasMany(Client::class);
    }

    /**
     * Returns an array of all active photos.
     *
     * @return array
     */
    public function getActivePhotos() {
        $array = [];
        foreach($this->screens as $screen) {
            
            $shadow_event = $screen->getActiveEvents();
                if(!$shadow_event->isEmpty()) {
                    $array[] = $screen->photo->path;
                }
        }
        return $array;
    }

    /**
     * Returns an array of all active tickers.
     *
     * @return array
     */
    public function getActiveTickers() {

        $array = [];
        foreach($this->tickers as $ticker) {
            
            $shadow_event = $ticker->getActiveEvents();
                if(!$shadow_event->isEmpty()) {
                    $array[] = $ticker->text;
                }
        }
        
        return $array;
    }
}<commit_msg>ScreenGroup: Check if photo is available before returning a screen to show<commit_after><?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class ScreenGroup extends Model
{
    /**
     * Database table
     * @var string
     */
    protected $table = 'screengroups';
    /**
     * The attributes that are mass assignable.
     * @var [type]
     */
    protected $fillable = [
        'name',
        'desc',
    ];

    /**
     * Boot method used to update associations depending on actions.
     *
     */
    public static function boot() {
        parent::boot();

        ScreenGroup::deleting(function ($screengroup) {
            foreach( $screengroup->clients as $client) {
                $client->update(['screen_group_id' => 1]);
                $client->save();
            }

            foreach ( $screengroup->screens as $screen ){
                $screengroup->screens()->detach($screen->id);
            }

            foreach ( $screengroup->tickers as $ticker ){
                $screengroup->tickers()->detach($ticker->id);
            }

        });
    }

    /**
     * Screen association
     *
     * @return [type] [description]
     */

    public function screens() {
        return $this->belongsToMany(Screen::class, 'screengroup_screen')->withTimestamps();
    }


    public function tickers() {
        return $this->belongsToMany(Ticker::class, 'screengroup_ticker')->withTimestamps();
    }

    /**
     * Client association
     * @return [type] [description]
     */
    public function clients() {
        return $this->hasMany(Client::class);
    }

    /**
     * Returns an array of all active photos.
     *
     * @return array
     */
    public function getActivePhotos() {

        $array = [];

        foreach($this->screens as $screen) {

            if($screen->photo){

                $shadow_event = $screen->getActiveEvents();
                
                if(!$shadow_event->isEmpty())
                    $array[] = $screen->photo->path;
                
            }

        }

        return $array;
    }

    /**
     * Returns an array of all active tickers.
     *
     * @return array
     */
    public function getActiveTickers() {

        $array = [];

        foreach($this->tickers as $ticker) {
            
            $shadow_event = $ticker->getActiveEvents();
            
            if(!$shadow_event->isEmpty())
                $array[] = $ticker->text;

        }
        
        return $array;
    }
}
{'fraction_non_alphanumeric': 0.13504169208867195, 'fraction_numerical': 0.0004067520846044336, 'mean_word_length': 1.6512129380053908, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 56, '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': '5185717', 'n_tokens_mistral': 1413, 'n_tokens_neox': 1325, 'n_words': 280}