Example #1
0
 public function Save(User $user)
 {
     try {
         $SQL = self::$INSERT;
         $isUpdate = false;
         if ($user->getSeq() != null && $user->getSeq() != "" && $user->getSeq() > 0) {
             $SQL = self::$UPDATE;
             $isUpdate = true;
         }
         $conn = self::$db_New->getConnection();
         $stmt = $conn->prepare($SQL);
         $stmt->bindValue(':fullname', $user->getFullName());
         $stmt->bindValue(':username', $user->getUserName());
         $stmt->bindValue(':password', $user->getPassword());
         $stmt->bindValue(':emailid', $user->getEmailId());
         $stmt->bindValue(':dateofregistration', $user->getDateOfRegistration());
         $isActive = 0;
         if ($user->getIsActive() == "true" || $user->getIsActive() == 1) {
             $isActive = 1;
         }
         $stmt->bindValue(':isactive', $isActive);
         $isManager = 0;
         if ($user->getIsManager() == "true" || $user->getIsManager() == 1) {
             $isManager = 1;
         }
         $stmt->bindValue(':ismanager', $isManager);
         $stmt->bindValue(':locationseq', $user->getLocationSeq());
         $stmt->bindValue(':folderseq', $user->getFolderSeq());
         if ($isUpdate) {
             $stmt->bindValue(':seq', $user->getSeq());
             $stmt->execute();
         } else {
             $stmt->execute();
             $id = $conn->lastInsertId();
             $user->setSeq($id);
         }
         //i will put the code here for return the error and show on the screen
         $error = $stmt->errorInfo();
         if ($error[2] != "") {
             $logger = Logger::getLogger("logger");
             $logger->error("Error occured :" . $error[2]);
             throw new Exception($error[2]);
         }
         $otherLocations = $user->getOtherLocationSeqs();
         if (empty($otherLocations)) {
             $otherLocations = array();
         }
         if (!in_array($user->getLocationSeq(), $otherLocations)) {
             array_push($otherLocations, $user->getLocationSeq());
         }
         $this->saveOtherLocationUser($otherLocations, $user->getSeq());
     } catch (Exception $e) {
         $logger = Logger::getLogger($ConstantsArray["logger"]);
         $logger->error($e->getMessage());
     }
 }