bb_sign/app/Models/StaffModel.php
2024-07-09 09:31:54 +05:30

62 lines
1.7 KiB
PHP

<?php namespace App\Models;
use CodeIgniter\Model;
class StaffModel extends Model
{
protected $table = 'staff';
protected $primaryKey = 'staff_id';
protected $allowedFields = [ 'business_id','role' , 'name', 'mobile_no' , 'email', 'password' , 'address' , 'city' , 'state' , 'country' , 'pin_code' , 'is_active' ,'created_by','updated_by'];
protected $beforeInsert = ['beforeInsert'];
protected $beforeUpdate = ['beforeUpdate'];
protected function beforeInsert(array $data){
$data= $this->passwordHash($data);
return $data;
}
protected function beforeUpdate(array $data){
$data= $this->passwordHash($data);
return $data;
}
protected function passwordHash(array $data)
{
if(isset($data['data']['password']))
$data['data']['password'] = password_hash($data['data']['password'],PASSWORD_DEFAULT);
return $data;
}
public function verifyEmail($email)
{
$builder = $this->db->table('staff');
// $builder -> select("staff_id,name,email,password,is_active,role,branch_id,business_id");
$builder -> select("staff_id,name,email,password,is_active,role,business_id");
$builder -> where('email',$email);
$result = $builder->get();
if(count($result->getResultArray()) ==1)
{
return $result->getRowArray();
}else{
return false;
}
}
public function getStaffWithBusinessAndBranch($is_staff_logged_in, $logged_in_staff_branch_id) {
$query = $this->db->table('staff')
->select('staff.*')
// ->join('business', 'business.business_id = staff.business_id')
->where('staff.staff_id != ', $is_staff_logged_in);
// Execute the query and fetch results as an array
$result = $query->get()->getResultArray();
return $result;
}
}