| Server IP : 188.114.96.2 / Your IP : 104.23.243.200 Web Server : Apache/2.4.59 (Debian) System : Linux EDL-STRETCH 4.19.0-27-amd64 #1 SMP Debian 4.19.316-1 (2024-06-25) x86_64 User : edlftp ( 1002) PHP Version : 7.4.33 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /home/git/sms.edl.codes.solutions/application/models/ |
Upload File : |
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Address_model extends CI_Model {
protected $locationType='id';
function __construct($config=array()) {
parent::__construct();
}
function locationType($type){
$this->locationType=$type;
return $this;
}
function get($addressID){
$addressID*=1;
switch ($this->locationType){
case 'text':
$data=$this->db->get_where('address',array('address_id'=>$addressID),1)->row_array();
break;
default:
$data=$this->db->select('a.*,l.location_id,s.state_id,c.country_id')
->join('location AS l','l.location_id=a.location_id','inner')
->join('state AS s','s.state_id=l.state_id','inner')
->join('country AS c','c.country_id=s.country_id','inner')
->get_where('address AS a',array('a.address_id'=>$addressID),1)->row_array();
if ($data){
$data['countries']=$this->db->get('country')->result_array();
$data['states']=$this->db->get_where('state',array('country_id'=>$data['country_id']))->result_array();
$data['locations']=$this->db->get_where('location',array('state_id'=>$data['state_id']))->result_array();
}
break;
}
return $data;
}
function save($data,$required=false){
$CI=& get_instance();
$addressData=$CI->input->_fetch_from_array($data,NULL,TRUE);
$addressID=$addressData['address_id']*1;
$dataSet=array();
$errors=array();
switch ($this->locationType){
case 'text':
$fields=array('line_1','country','location','postcode');
break;
default:
$fields=array('line_1','location_id','postcode');
break;
}
foreach($fields AS $f){
if (empty($addressData[$f])){
$errors[]=$CI->translate($addressData['type'].'_'.$f.'_should_be_set');
}
else {
$dataSet[$f]=$addressData[$f];
}
}
if (!empty($addressData['line_2'])){
$dataSet['line_2']=$addressData['line_2'];
}
if (!empty($addressData['state'])){
$dataSet['state']=$addressData['state'];
}
if ($required || $dataSet!==array()){
if ($errors!==array()){
foreach($errors AS $e){
$CI->error($e);
}
}
}
if (!$CI->hasErrors() && $dataSet!==array()){
if ($addressID==0){
$this->db->insert('address',$dataSet);
return $this->db->insert_id();
}
else {
$this->db->where('address_id',$addressID)->update('address',$dataSet);
return $addressID;
}
}
return false;
}
}
?>