vb_book/app/Models/EventModel.php
2024-10-29 15:37:48 +05:30

55 lines
1.7 KiB
PHP
Executable File

<?php
namespace App\Models;
use CodeIgniter\Model;
class EventModel extends Model
{
protected $table = 'events';
protected $primaryKey = 'event_id';
protected $allowedFields = ['event_id','event_name','created_by','created_on','updated_on' ,'updated_by','business_id','is_the_default'];
public function getEventnamesByBusiness($business_id)
{
$this->builder()->where('business_id ', $business_id); // Filter by business_id
$query = $this->builder()->get(); // Use findAll() instead of get()
return ($query->getResult());
}
public function setTable($tableName)
{
$this->table = $tableName;
return $this;
}
public function insertData($table, $data)
{
try {
$this->db->table($table)->insert($data);
$last_insert_id = $this->db->insertID();
return ["info"=>$last_insert_id,"err"=>""];
} catch (\CodeIgniter\Database\Exceptions\DatabaseException $e) {
return ["info"=>"","err"=>'Database operation failed: ' . $e->getMessage()];
} catch (\Exception $e) {
return ["info"=>"","err"=>'An error occurred: ' . $e->getMessage()];
}
}
public function updateData($table, $data, $where)
{
try {
$this->db->table($table)->update($data, $where);
$affected_rows = $this->db->affectedRows();
return ["info"=>$affected_rows." Affected","err"=>""];
} catch (\CodeIgniter\Database\Exceptions\DatabaseException $e) {
return ["info"=>"","err"=>'Database operation failed: ' . $e->getMessage()];
} catch (\Exception $e) {
return ["info"=>"","err"=>'Database operation failed: ' . $e->getMessage()];
}
}
}
?>