Skip to content

Instantly share code, notes, and snippets.

@igoralves1
Created December 5, 2016 15:41
Show Gist options
  • Save igoralves1/e1bd9a37fd4c75977caed30ed2463263 to your computer and use it in GitHub Desktop.
Save igoralves1/e1bd9a37fd4c75977caed30ed2463263 to your computer and use it in GitHub Desktop.
API/v1 ... update_manageResources($jsonInfo)
//This is an method of an API that will create new resources in the database.
//Insert new users (STAFF).
public static function update_manageResources($jsonInfo) {
try {
$arrData=json_decode($jsonInfo, true);
$arrMapProfession=[
"1"=>"assistant",
"2"=>"agentadmin",
"3"=>"agentsalubrite",
"4"=>"chefeequipe",
"5"=>"chefeunite",
"6"=>"fellow",
"7"=>"nursing",
"8"=>"inhalotherapeute",
"9"=>"patron",
"10"=>"resident",
"11"=>"prepose",
"12"=>"pharmacist",
];
//xdebug_break();
$nbProfession=$arrData["profession"];
$tblProfession=$arrMapProfession[$nbProfession];
$firstName = $arrData["first_name"];
$last_name = $arrData["last_name"];
$residentType=$arrData["residentType"];
$db=new db();
$conn=$db->conn;
$conn->beginTransaction();
if($nbProfession=="10"){//Insert Resident. Will need $residentType
$sql = "INSERT INTO {$tblProfession} (first_name, last_name, fk_type, status, dt_sys, tel)
VALUES
('{$firstName}','{$last_name}','{$residentType}','1',NOW(),' ')";
}
//elseif ($nbProfession<>"10"){//Delete later
else{
$sql = "INSERT INTO {$tblProfession} (first_name, last_name, status, dt_sys)
VALUES
('{$firstName}','{$last_name}','1',NOW())";
}
$conn->exec($sql);
$id = $conn->lastInsertId();
$conn->commit();
$arrToJSON = array(
"id"=>$id,
"URL"=>"http://hsj_dev/api/v1/get/get_list.php?tbl=".$tblProfession.".arr"
);
return json_encode($arrToJSON);
}// End of try
catch(PDOException $e){
echo $e->getMessage();
$this->conn = null;
die();
}// End of catch
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment