54 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			54 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
 | 
						|
namespace kernel\app_modules\gestalt_profile_relationship\services;
 | 
						|
 | 
						|
use kernel\app_modules\gestalt_profile\models\Gestalt_profile;
 | 
						|
use kernel\helpers\Debug;
 | 
						|
use kernel\app_modules\gestalt_profile_relationship\models\GestaltProfileRelationship;
 | 
						|
use kernel\FormModel;
 | 
						|
 | 
						|
class GestaltProfileRelationshipService
 | 
						|
{
 | 
						|
    public function create(FormModel $form_model): false|GestaltProfileRelationship
 | 
						|
    {
 | 
						|
        $model = new GestaltProfileRelationship();
 | 
						|
         $model->gestalt_profile_id = $form_model->getItem('gestalt_profile_id');
 | 
						|
         $model->entity = $form_model->getItem('entity');
 | 
						|
         $model->entity_id = $form_model->getItem('entity_id');
 | 
						|
 | 
						|
        if ($model->save()){
 | 
						|
            return $model;
 | 
						|
        }
 | 
						|
 | 
						|
        return false;
 | 
						|
    }
 | 
						|
 | 
						|
    public function update(FormModel $form_model, GestaltProfileRelationship $gestalt_profile_relationship): false|GestaltProfileRelationship
 | 
						|
    {
 | 
						|
        $gestalt_profile_relationship->gestalt_profile_id = $form_model->getItem('gestalt_profile_id');
 | 
						|
        $gestalt_profile_relationship->entity = $form_model->getItem('entity');
 | 
						|
        $gestalt_profile_relationship->entity_id = $form_model->getItem('entity_id');
 | 
						|
 | 
						|
        if ($gestalt_profile_relationship->save()){
 | 
						|
            return $gestalt_profile_relationship;
 | 
						|
        }
 | 
						|
 | 
						|
        return false;
 | 
						|
    }
 | 
						|
 | 
						|
    public static function getProfileByEntity(string $entity, int $entity_id): array
 | 
						|
    {
 | 
						|
        $profiles = GestaltProfileRelationship::with('profile')->where("entity_id", $entity_id)->where("entity", $entity)->get();
 | 
						|
        $value = [];
 | 
						|
        foreach ($profiles as $profile) {
 | 
						|
            $value[$profile->gestalt_profile_id] = $profile->profile->fio;
 | 
						|
        }
 | 
						|
 | 
						|
        return $value;
 | 
						|
    }
 | 
						|
 | 
						|
    public static function getProfilesList(): array
 | 
						|
    {
 | 
						|
        return Gestalt_profile::pluck('fio', 'id')->all();
 | 
						|
    }
 | 
						|
} |