First Commit
This commit is contained in:
Executable
+109
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* SysCMS - Content Management System
|
||||
*
|
||||
* Copyright (c) 2026 Marco Costa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Author: Marco Costa
|
||||
* Email: contato@syspanel.com.br
|
||||
* Project: SysCMS
|
||||
*
|
||||
* This software is licensed, not sold.
|
||||
* Permission is granted to use this software
|
||||
* subject to the terms of the SysCMS Commercial License.
|
||||
*
|
||||
* Redistribution, sublicensing, resale, or
|
||||
* disclosure of this software, in whole or in part,
|
||||
* is strictly prohibited without prior written permission.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.
|
||||
*/
|
||||
|
||||
namespace Modules\Notes\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* Class Note
|
||||
*
|
||||
* Model for notes.
|
||||
*
|
||||
* @package Modules\Notes\Models
|
||||
*/
|
||||
class Note extends Model
|
||||
{
|
||||
/**
|
||||
* @var string The table associated with the model.
|
||||
*/
|
||||
protected $table = 'notes';
|
||||
|
||||
/**
|
||||
* @var string The primary key associated with the table.
|
||||
*/
|
||||
protected $primaryKey = 'notes_id';
|
||||
|
||||
/**
|
||||
* @var array The attributes that are mass assignable.
|
||||
*/
|
||||
protected $fillable = [
|
||||
'notes_idbus',
|
||||
'notes_iduser',
|
||||
'notes_title',
|
||||
'notes_content',
|
||||
'notes_subject_id',
|
||||
'notes_is_pinned',
|
||||
'notes_color',
|
||||
'notes_image',
|
||||
'notes_file'
|
||||
];
|
||||
|
||||
/**
|
||||
* The "booted" method of the model.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected static function booted()
|
||||
{
|
||||
static::creating(function ($note) {
|
||||
if (session_status() === PHP_SESSION_NONE) {
|
||||
session_start();
|
||||
}
|
||||
$note->notes_idbus = $_SESSION['user_idbus'] ?? null;
|
||||
if (empty($note->notes_idbus)) {
|
||||
$note->notes_idbus = 1;
|
||||
}
|
||||
$note->notes_iduser = $_SESSION['user_id'] ?? null;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope a query to only include notes for the current business and user.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeCurrentUser($query)
|
||||
{
|
||||
if (session_status() === PHP_SESSION_NONE) {
|
||||
session_start();
|
||||
}
|
||||
$busId = $_SESSION['user_idbus'] ?? null;
|
||||
if (empty($busId)) {
|
||||
$busId = 1;
|
||||
}
|
||||
$userId = $_SESSION['user_id'] ?? null;
|
||||
|
||||
return $query->where('notes_idbus', $busId)
|
||||
->where('notes_iduser', $userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the subject that owns the note.
|
||||
*/
|
||||
public function subject()
|
||||
{
|
||||
return $this->belongsTo(Subject::class, 'notes_subject_id', 'subjects_id');
|
||||
}
|
||||
}
|
||||
Executable
+109
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* SysCMS - Content Management System
|
||||
*
|
||||
* Copyright (c) 2026 Marco Costa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Author: Marco Costa
|
||||
* Email: contato@syspanel.com.br
|
||||
* Project: SysCMS
|
||||
*
|
||||
* This software is licensed, not sold.
|
||||
* Permission is granted to use this software
|
||||
* subject to the terms of the SysCMS Commercial License.
|
||||
*
|
||||
* Redistribution, sublicensing, resale, or
|
||||
* disclosure of this software, in whole or in part,
|
||||
* is strictly prohibited without prior written permission.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.
|
||||
*/
|
||||
|
||||
namespace Modules\Notes\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* Class Subject
|
||||
*
|
||||
* Model for note subjects/categories.
|
||||
*
|
||||
* @package Modules\Notes\Models
|
||||
*/
|
||||
class Subject extends Model
|
||||
{
|
||||
/**
|
||||
* @var string The table associated with the model.
|
||||
*/
|
||||
protected $table = 'notes_subjects';
|
||||
|
||||
/**
|
||||
* @var string The primary key associated with the table.
|
||||
*/
|
||||
protected $primaryKey = 'subjects_id';
|
||||
|
||||
/**
|
||||
* @var array The attributes that are mass assignable.
|
||||
*/
|
||||
protected $fillable = [
|
||||
'subjects_idbus',
|
||||
'subjects_iduser',
|
||||
'subjects_name',
|
||||
'subjects_color'
|
||||
];
|
||||
|
||||
/**
|
||||
* The "booted" method of the model.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected static function booted()
|
||||
{
|
||||
static::creating(function ($subject) {
|
||||
if (session_status() === PHP_SESSION_NONE) {
|
||||
session_start();
|
||||
}
|
||||
|
||||
if (empty($subject->subjects_idbus)) {
|
||||
$subject->subjects_idbus = $_SESSION['user_idbus'] ?? null;
|
||||
}
|
||||
if (empty($subject->subjects_idbus)) {
|
||||
$subject->subjects_idbus = 1;
|
||||
}
|
||||
if (empty($subject->subjects_iduser)) {
|
||||
$subject->subjects_iduser = $_SESSION['user_id'] ?? null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope a query to only include subjects for the current business and user.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeCurrentUser($query)
|
||||
{
|
||||
if (session_status() === PHP_SESSION_NONE) {
|
||||
session_start();
|
||||
}
|
||||
$busId = $_SESSION['user_idbus'] ?? null;
|
||||
if (empty($busId)) {
|
||||
$busId = 1;
|
||||
}
|
||||
$userId = $_SESSION['user_id'] ?? null;
|
||||
|
||||
return $query->where('subjects_idbus', $busId)
|
||||
->where('subjects_iduser', $userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the notes for the subject.
|
||||
*/
|
||||
public function notes()
|
||||
{
|
||||
return $this->hasMany(Note::class, 'notes_subject_id', 'subjects_id');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user