Fix models database calls and structural updates
This commit is contained in:
@@ -10,28 +10,28 @@ use App\Core\Security;
|
||||
*/
|
||||
class Template extends BaseModel
|
||||
{
|
||||
protected string $table = 'templates';
|
||||
protected static string $table = 'templates';
|
||||
|
||||
/**
|
||||
* Create template with encrypted media URL if exists
|
||||
*/
|
||||
public function createSecure(array $data)
|
||||
public static function createSecure(array $data)
|
||||
{
|
||||
if (!empty($data['media_url'])) {
|
||||
$data['media_url'] = Security::encrypt($data['media_url']);
|
||||
}
|
||||
return $this->create($data);
|
||||
return self::create($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve and decrypt templates
|
||||
*/
|
||||
public function findAllByCompany(int $companyId)
|
||||
public static function findAllByCompany(int $companyId)
|
||||
{
|
||||
$templates = $this->db->query(
|
||||
"SELECT * FROM {$this->table} WHERE company_id = ? ORDER BY id DESC",
|
||||
$templates = \App\Core\Database::select(
|
||||
"SELECT * FROM " . static::$table . " WHERE company_id = ? ORDER BY id DESC",
|
||||
[$companyId]
|
||||
)->fetchAll();
|
||||
);
|
||||
|
||||
foreach ($templates as &$template) {
|
||||
if (!empty($template['media_url'])) {
|
||||
@@ -45,12 +45,12 @@ class Template extends BaseModel
|
||||
/**
|
||||
* Get single template and decrypt
|
||||
*/
|
||||
public function findByIdAndCompany(int $id, int $companyId)
|
||||
public static function findByIdAndCompany(int $id, int $companyId)
|
||||
{
|
||||
$template = $this->db->query(
|
||||
"SELECT * FROM {$this->table} WHERE id = ? AND company_id = ? LIMIT 1",
|
||||
$template = \App\Core\Database::selectOne(
|
||||
"SELECT * FROM " . static::$table . " WHERE id = ? AND company_id = ? LIMIT 1",
|
||||
[$id, $companyId]
|
||||
)->fetch();
|
||||
);
|
||||
|
||||
if ($template && !empty($template['media_url'])) {
|
||||
$template['media_url'] = Security::decrypt($template['media_url']);
|
||||
|
||||
Reference in New Issue
Block a user