public static function getInstance() { if (!is_object(self::$_instance)) { //or if( is_null(self::$_instance) ) or if( self::$_instance == null ) self::$_instance = new Admin_Model_Countries(); } return self::$_instance; }
public function editUserDetailsAction() { $adminModel = Admin_Model_Users::getInstance(); $result = $adminModel->getAdminDetails(); // showing image if ($result) { $this->view->admindetails = $result; } $userModel = Admin_Model_Users::getInstance(); $userId = $this->getRequest()->getParam("userId"); $objCountry = Admin_Model_Country::getInstance(); $countryCodeDetails = $objCountry->getAllCountryCode(); if ($countryCodeDetails) { $this->view->countryCodeDetails = $countryCodeDetails; } $objCountries = Admin_Model_Countries::getInstance(); $CountriesDetails = $objCountries->getAllCountries(); if ($CountriesDetails) { $this->view->countryDetails = $CountriesDetails; } $objStates = Admin_Model_States::getInstance(); $StatesDetails = $objStates->getAllStates(); if ($StatesDetails) { $this->view->statesDetails = $StatesDetails; } $objCities = Admin_Model_Cities::getInstance(); $CitiesDetails = $objCities->getAllCities(); if ($CitiesDetails) { $this->view->CitiesDetails = $CitiesDetails; } $usermetaModel = Admin_Model_Usermeta::getInstance(); if ($this->_request->isPost()) { $userid = $userId; $userdata['uname'] = $this->getRequest()->getPost('uname'); $userdata['email'] = $this->getRequest()->getPost('email'); $userdata['status'] = $this->getRequest()->getPost('status'); $usermetadata['first_name'] = $this->getRequest()->getPost('first_name'); $usermetadata['last_name'] = $this->getRequest()->getPost('last_name'); $usermetadata['phone'] = $this->getRequest()->getPost('phone'); $usermetadata['city'] = $this->getRequest()->getPost('city'); $usermetadata['state'] = $this->getRequest()->getPost('state'); $usermetadata['country'] = $this->getRequest()->getPost('country'); $usermetadata['contact_country_code'] = $this->getRequest()->getPost('contact_country_code'); $coverphoto = $_FILES["fileToUpload"]["name"]; $dirpath = getcwd() . "/assets/userimages/{$userId}/"; if (!file_exists($dirpath)) { mkdir($dirpath, 0777, true); } if (!empty($coverphoto)) { $imagepath = $dirpath . $coverphoto; $savepath = "/assets/userimages/{$userId}/{$coverphoto}"; $imageTmpLoc = $_FILES["fileToUpload"]["tmp_name"]; $ext = pathinfo($coverphoto, PATHINFO_EXTENSION); if ($ext != "jpg" && $ext != "png" && $ext != "jpeg" && $ext != "gif") { echo json_encode("Something went wrong image upload"); } else { $imagemoveResult = move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $imagepath); if ($imagemoveResult) { $link = $this->_appSetting->hostLink; $usermetadata['profilepic_url'] = $link . $savepath; $result1 = $userModel->updateUserdetails($userid, $userdata); $result2 = $usermetaModel->updateUsermetadetails($userid, $usermetadata); if ($result1 || $result2) { $this->redirect('/admin/userdetails'); } else { $this->view->errormessage = 'user details not updated properly'; } } else { $result1 = $userModel->updateUserdetails($userid, $userdata); $result2 = $usermetaModel->updateUsermetadetails($userid, $usermetadata); } } } else { $result1 = $userModel->updateUserdetails($userid, $userdata); $result2 = $usermetaModel->updateUsermetadetails($userid, $usermetadata); } } $result = $userModel->getAllUserdetails($userId); if ($result) { $this->view->alluserdetails = $result; } else { echo 'controller error occured'; } }