Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
4 / 4 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
| CompanyRolePlayScorecard | |
100.00% |
4 / 4 |
|
100.00% |
4 / 4 |
4 | |
100.00% |
1 / 1 |
| scopeForCompany | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| scopeForCallType | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| company | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| creator | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Models; |
| 4 | |
| 5 | use App\Http\Models\Admin\Company; |
| 6 | use App\Http\Models\Auth\User; |
| 7 | |
| 8 | /** |
| 9 | * CompanyRolePlayScorecard Model |
| 10 | * |
| 11 | * Stores company-level scorecard configurations for roleplay sessions. |
| 12 | * Companies can define custom scorecards per call type that override system |
| 13 | * defaults for all users within the company. When `is_forced` is true, users |
| 14 | * cannot modify the scorecard — they can only view it. |
| 15 | * |
| 16 | * @property string $company_id The company that owns this scorecard configuration |
| 17 | * @property string $call_type The call type identifier (e.g., 'cold-call', 'discovery-call') |
| 18 | * @property array $scorecard Array of ScorecardConfig objects: [{name, is_default, weight, criteria: [{name, description, weight}]}] |
| 19 | * @property bool $is_forced Whether users are prevented from editing (true = read-only for users) |
| 20 | * @property string $created_by The admin user ID who created this configuration |
| 21 | * @property \Carbon\Carbon|null $created_at |
| 22 | * @property \Carbon\Carbon|null $updated_at |
| 23 | */ |
| 24 | class CompanyRolePlayScorecard extends Moloquent |
| 25 | { |
| 26 | /** |
| 27 | * The database table used by the model. |
| 28 | * |
| 29 | * @var string |
| 30 | */ |
| 31 | protected $table = 'company_roleplay_scorecards'; |
| 32 | |
| 33 | /** |
| 34 | * The attributes that are mass assignable. |
| 35 | * |
| 36 | * @var array<int, string> |
| 37 | */ |
| 38 | protected $fillable = [ |
| 39 | 'company_id', |
| 40 | 'call_type', |
| 41 | 'scorecard', |
| 42 | 'is_forced', |
| 43 | 'created_by', |
| 44 | ]; |
| 45 | |
| 46 | /** |
| 47 | * The attributes that should be cast. |
| 48 | * |
| 49 | * @var array<string, string> |
| 50 | */ |
| 51 | protected $casts = [ |
| 52 | 'scorecard' => 'array', |
| 53 | 'is_forced' => 'boolean', |
| 54 | 'created_at' => 'datetime', |
| 55 | 'updated_at' => 'datetime', |
| 56 | ]; |
| 57 | |
| 58 | /** |
| 59 | * The model's default attribute values. |
| 60 | * |
| 61 | * @var array<string, mixed> |
| 62 | */ |
| 63 | protected $attributes = [ |
| 64 | 'is_forced' => false, |
| 65 | ]; |
| 66 | |
| 67 | /** |
| 68 | * Scope query to a specific company. |
| 69 | * |
| 70 | * @param \Illuminate\Database\Eloquent\Builder $query |
| 71 | * @param string $companyId The company ID to filter by |
| 72 | * @return \Illuminate\Database\Eloquent\Builder |
| 73 | */ |
| 74 | public function scopeForCompany($query, string $companyId) |
| 75 | { |
| 76 | return $query->where('company_id', $companyId); |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Scope query to a specific call type. |
| 81 | * |
| 82 | * @param \Illuminate\Database\Eloquent\Builder $query |
| 83 | * @param string $callType The call type to filter by (e.g., 'cold-call') |
| 84 | * @return \Illuminate\Database\Eloquent\Builder |
| 85 | */ |
| 86 | public function scopeForCallType($query, string $callType) |
| 87 | { |
| 88 | return $query->where('call_type', $callType); |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Get the company that owns this scorecard configuration. |
| 93 | * |
| 94 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
| 95 | */ |
| 96 | public function company() |
| 97 | { |
| 98 | return $this->belongsTo(Company::class, 'company_id'); |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Get the admin user who created this scorecard configuration. |
| 103 | * |
| 104 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
| 105 | */ |
| 106 | public function creator() |
| 107 | { |
| 108 | return $this->belongsTo(User::class, 'created_by'); |
| 109 | } |
| 110 | } |