58 lines
1.2 KiB
PHP
58 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use CodeIgniter\Model;
|
|
|
|
class SectionModel extends Model
|
|
{
|
|
protected $table = 'sections';
|
|
protected $primaryKey = 'id';
|
|
|
|
protected $allowedFields = [
|
|
'section_name',
|
|
'description',
|
|
'created_at',
|
|
'updated_at',
|
|
'updated_by'
|
|
];
|
|
|
|
protected $useTimestamps = true;
|
|
protected $createdField = 'created_at';
|
|
protected $updatedField = 'updated_at';
|
|
|
|
/**
|
|
* Get section by name.
|
|
*
|
|
* @param string $sectionName
|
|
* @return array|null
|
|
*/
|
|
public function getSectionByName($sectionName)
|
|
{
|
|
return $this->where('section_name', $sectionName)->first();
|
|
}
|
|
|
|
/**
|
|
* Update section details by ID.
|
|
*
|
|
* @param int $sectionId
|
|
* @param array $data
|
|
* @return bool
|
|
*/
|
|
public function updateSection($sectionId, $data)
|
|
{
|
|
$data['updated_at'] = utc_now(); // Set the updated_at timestamp
|
|
return $this->update($sectionId, $data);
|
|
}
|
|
|
|
/**
|
|
* Delete section by ID.
|
|
*
|
|
* @param int $sectionId
|
|
* @return bool
|
|
*/
|
|
public function deleteSection($sectionId)
|
|
{
|
|
return $this->delete($sectionId);
|
|
}
|
|
} |