Files
admin-php-module/models/Subscriber.php
miroman-afk cf1e228f26 v.2.4
Restore shifts
2022-01-10 14:42:35 +03:00

30 lines
905 B
PHP

<?php
namespace App\Component\Models;
use Illuminate\Database\Eloquent\Model;
class Subscriber extends Model {
protected $table = 'subscribers';
public $timestamps = false;
public static function add($event, $callback, $weight = 0) {
list($destination_module, $destination_method) = explode(':', $callback);
list($source_module, $source_method) = explode(':', $event);
$code = strtolower($destination_module . '_' . $destination_method . '_after_' . $source_module . '_' . $source_method);
if (Subscriber::where('code', $code)->count() == 0) {
$subscriber = new Subscriber([
'code' => $code,
'destination_module' => strtolower($destination_module),
'destination_method' => strtolower($destination_method),
'source_module' => strtolower($source_module),
'source_method' => strtolower($source_method),
'weight' => $weight,
]);
$subscriber->save();
}
}
}