DataInterface = $DataInterface; } /** * */ public function homeGet($User) { // user type $statement = $this->DataInterface->DatabaseConnection->prepare( "SELECT type FROM user WHERE ID = :fk_user" ); $statement->bindParam(':fk_user', $User->ID); // Error check if(!$statement->execute()) { return ['result' => 'ERROR', 'reason' => 'internal_error', 'message' => 'Database error', 'data' => $statement->errorInfo()]; } $userType = $statement->fetchAll(\PDO::FETCH_ASSOC)[0]['type']; $targetID = $User->ID; if($userType=='reader') { // customer CRO $statement = $this->DataInterface->DatabaseConnection->prepare( "SELECT * FROM user WHERE type = 'cro' ORDER BY ID LIMIT 0,1" ); // Error check if(!$statement->execute()) { return ['result' => 'ERROR', 'reason' => 'internal_error', 'message' => 'Database error', 'data' => $statement->errorInfo()]; } $customer = $statement->fetchAll(\PDO::FETCH_ASSOC); $targetID = $customer[0]['ID']; } // total purchased credits $statement = $this->DataInterface->DatabaseConnection->prepare( "SELECT SUM(count) AS purchased FROM credit WHERE ID_user = :fk_user" ); $statement->bindParam(':fk_user', $targetID); // Error check if(!$statement->execute()) { return ['result' => 'ERROR', 'reason' => 'internal_error', 'message' => 'Database error', 'data' => $statement->errorInfo()]; } $purchased = intval($statement->fetchAll(\PDO::FETCH_ASSOC)[0]['purchased']); // total used credits $statement = $this->DataInterface->DatabaseConnection->prepare( "SELECT COUNT(ID) AS used FROM credit_usage WHERE fk_user = :fk_user" ); $statement->bindParam(':fk_user', $targetID); // Error check if(!$statement->execute()) { return ['result' => 'ERROR', 'reason' => 'internal_error', 'message' => 'Database error', 'data' => $statement->errorInfo()]; } $used = intval($statement->fetchAll(\PDO::FETCH_ASSOC)[0]['used']); // settings $statement = $this->DataInterface->DatabaseConnection->prepare( "SELECT data FROM settings" ); if(!$statement->execute()) { return ['result' => 'ERROR', 'reason' => 'internal_error', 'message' => 'Database error', 'data' => $statement->errorInfo()]; } $settings = $statement->fetchAll(\PDO::FETCH_ASSOC)[0]['data']; // CT $statement = $this->DataInterface->DatabaseConnection->prepare( "SELECT * FROM clinical_trial" ); if(!$statement->execute()) { return ['result' => 'ERROR', 'reason' => 'internal_error', 'message' => 'Database error', 'data' => $statement->errorInfo()]; } $clinical_trial = $statement->fetchAll(\PDO::FETCH_ASSOC)[0]; // OK return [ 'result' => 'OK', 'ID' => $User->ID, 'type' => $userType, 'firstname' => $User->firstname, 'lastname' => $User->lastname, 'email' => $User->email, 'settings' => json_decode($settings), 'clinical_trial' => $clinical_trial, 'credit_left' => $userType=='investigator'?1:($purchased - $used) ]; } } }