| 
									
										
										
										
											2022-03-06 02:02:12 +11:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace App\Models; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | use Illuminate\Database\Eloquent\Factories\HasFactory; | 
					
						
							|  |  |  | use Illuminate\Database\Eloquent\Model; | 
					
						
							| 
									
										
										
										
											2022-05-15 00:15:20 +10:00
										 |  |  | use Illuminate\Support\Facades\Cache; | 
					
						
							| 
									
										
										
										
											2023-09-25 23:40:13 +10:00
										 |  |  | use Mockery\Exception; | 
					
						
							| 
									
										
										
										
											2022-03-06 02:02:12 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | class Labels extends Model | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     use HasFactory; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public $incrementing = false; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-19 15:21:35 +10:00
										 |  |  |     protected $table = 'labels'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-22 23:49:18 +10:00
										 |  |  |     protected $keyType = 'string'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-06 02:02:12 +11:00
										 |  |  |     protected $fillable = ['id', 'label', 'server_id', 'server_id_2', 'domain_id', 'domain_id_2', 'shared_id', 'shared_id_2']; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-19 23:46:18 +10:00
										 |  |  |     public static function deleteLabelsAssignedTo($service_id): void | 
					
						
							| 
									
										
										
										
											2022-03-06 02:02:12 +11:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2023-08-19 23:52:59 +10:00
										 |  |  |         LabelsAssigned::where('service_id', $service_id)->delete(); | 
					
						
							| 
									
										
										
										
											2022-03-06 02:02:12 +11:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-19 23:46:18 +10:00
										 |  |  |     public static function deleteLabelAssignedAs($label_id): void | 
					
						
							| 
									
										
										
										
											2022-03-06 02:02:12 +11:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2023-08-19 23:52:59 +10:00
										 |  |  |         LabelsAssigned::where('label_id', $label_id)->delete(); | 
					
						
							| 
									
										
										
										
											2022-03-06 02:02:12 +11:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-05-09 14:35:07 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-19 23:46:18 +10:00
										 |  |  |     public static function insertLabelsAssigned(array $labels_array, string $service_id): void | 
					
						
							| 
									
										
										
										
											2022-05-09 14:35:07 +10:00
										 |  |  |     { | 
					
						
							|  |  |  |         for ($i = 1; $i <= 4; $i++) { | 
					
						
							|  |  |  |             if (!is_null($labels_array[($i - 1)])) { | 
					
						
							| 
									
										
										
										
											2023-09-25 23:40:13 +10:00
										 |  |  |                 try { | 
					
						
							|  |  |  |                     LabelsAssigned::create([ | 
					
						
							|  |  |  |                         'label_id' => $labels_array[($i - 1)], | 
					
						
							|  |  |  |                         'service_id' => $service_id | 
					
						
							|  |  |  |                     ]); | 
					
						
							|  |  |  |                 } catch (Exception $exception) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2022-05-09 14:35:07 +10:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-19 23:46:18 +10:00
										 |  |  |     public static function labelsCount(): int | 
					
						
							| 
									
										
										
										
											2022-05-15 00:15:20 +10:00
										 |  |  |     { | 
					
						
							|  |  |  |         return Cache::remember('labels_count', now()->addMonth(1), function () { | 
					
						
							| 
									
										
										
										
											2023-08-18 19:28:53 +10:00
										 |  |  |             return Labels::count(); | 
					
						
							| 
									
										
										
										
											2022-05-15 00:15:20 +10:00
										 |  |  |         }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-19 23:46:18 +10:00
										 |  |  |     public function assigned(): \Illuminate\Database\Eloquent\Relations\HasMany | 
					
						
							| 
									
										
										
										
											2022-05-15 01:21:51 +10:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-07-20 14:36:19 +10:00
										 |  |  |         return $this->hasMany(LabelsAssigned::class, 'label_id', 'id'); | 
					
						
							| 
									
										
										
										
											2022-05-15 01:21:51 +10:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-06 02:02:12 +11:00
										 |  |  | } |