57 lines
1.8 KiB
PHP
57 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use CodeIgniter\Model;
|
|
|
|
|
|
class EventModel extends Model
|
|
{
|
|
protected $table = 'campaign';
|
|
protected $primaryKey = 'campaign_id';
|
|
protected $allowedFields = ['campaign_id','name', 'description','start_date', 'end_date','created_by','created_on','updated_on' ,'updated_by','business_id'];
|
|
|
|
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()];
|
|
}
|
|
}
|
|
|
|
}
|
|
?>
|