You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

108 lines
2.1 KiB

<?php
namespace App\Models;
use CodeIgniter\Model;
class Securite extends Model
{
/**
* table name
* @var string
*/
protected $table = 'securite';
protected $primaryKey = 'id'; // Primary key column
protected $allowedFields = ['product_id', 'status', 'date', 'active'];
/**
* To get store data by ID
* @param int $id
* @return array|object|null
*/
public function getSecuriteData(int $id = null)
{
if ($id) {
return $this->where('id', $id)->first();
}
return $this->findAll();
}
public function getAllSecuriteData(int $id = null)
{
$session = session();
$users = $session->get('user');
if ($users["group_name"] == "Direction") {
return $this->where('active', true)
->findAll();
}
return $this->where('active', true)
->where('store_id', $users['store_id'])->findAll();
}
/**
* create store
* @param array $data
* @return bool|int|string
*/
public function createStore(array $data)
{
if ($data) {
return $this->insert($data);
}
return false;
}
/**
* update stores
* @param array $data
* @param int $id
* @return bool
*/
public function updateSecurite(array $data, int $id)
{
if ($data && $id) {
return $this->update($id, $data);
}
return false;
}
/**
* remove store
* @param int $id
* @return bool|\CodeIgniter\Database\BaseResult
*/
public function removeSecurite(int $id)
{
if ($id) {
return $this->where("product_id", $id)->delete();
}
return false;
}
public function removeStore(int $id)
{
if ($id) {
return $this->delete($id);
}
return false;
}
/**
* count total store
* @return int|string
*/
public function countTotalStores()
{
return $this->where('active', 1)->countAllResults();
}
}