Permalink
Browse files

add APIs for surgeons and operations

Signed-off-by: royganor <roy@zend.com>
  • Loading branch information...
1 parent a9b8a92 commit a8158c76029f30fcf17f7764894c090d71463166 @royatzend royatzend committed Apr 10, 2012
View
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<buildpath>
<buildpathentry kind="con" path="org.eclipse.php.core.LANGUAGE"/>
- <buildpathentry excluding="build/|.settings/" kind="src" path=""/>
+ <buildpathentry excluding=".settings/" kind="src" path=""/>
+ <buildpathentry kind="con" path="com.zend.php.phpunit.CONTAINER"/>
</buildpath>
@@ -1,5 +1,5 @@
eclipse.preferences.version=1
-include_path=0;/doc-reports\u00050;/doc-reports/library\u00050;/doc-reports/src
+include_path=5;com.zend.php.phpunit.CONTAINER\u00050;/doc-reports\u00050;/doc-reports/library\u00050;/doc-reports/src
phpVersion=php5.4
useShortTags=true
use_asp_tags_as_php=false
View
@@ -28,16 +28,42 @@ function getDbPassword() {
}
function runQuery($query) {
- $link = mysqli_connect(getDbHost(), getDbUser(), getDbPassword(), getDbName());
+ global $appLocation;
+ file_put_contents($appLocation . '/public/install.html', "before connect");
+
+ $mysqli = mysqli_connect(getDbHost(), getDbUser(), getDbPassword(), getDbName());
+
+ file_put_contents($appLocation . '/public/install.html', "after connect");
/* check connection */
if (mysqli_connect_errno()) {
throw new Exception("error connecting db " . mysqli_connect_error());
}
+ file_put_contents($appLocation . '/public/install.html', "before query");
+
/* execute multi query */
- mysqli_multi_query($link, $query);
+ $r = mysqli_multi_query($mysqli, $query);
+ if (!$r) {
+ throw new Exception('Failed running query ' . mysqli_error_list($mysqli));
+ }
+ do {
+ /* store first result set */
+ if ($result = $mysqli->store_result()) {
+ while ($row = $result->fetch_row()) {
+ printf("%s\n", $row[0]);
+ }
+ $result->free();
+ }
+ /* print divider */
+ if ($mysqli->more_results()) {
+ printf("-----------------\n");
+ }
+ } while ($mysqli->next_result());
+
+ file_put_contents($appLocation . '/public/install.html', "after query > " . $query . ' < ');
/* close connection */
- mysqli_close($link);
+ mysqli_close($mysqli);
}
+
@@ -0,0 +1,15 @@
+<?php
+set_error_handler ( 'my_error_handler' );
+set_exception_handler ( 'my_exception_handler' );
+function my_exception_handler($e) {
+ global $appLocation;
+ file_put_contents ( $appLocation . '/public/installing.html', 'Huston! We have a problem: ' . $e );
+}
+function my_error_handler($no, $str, $file, $line) {
+ $e = new ErrorException ( $str, $no, 0, $file, $line );
+ my_exception_handler ( $e );
+ /*
+ * Do not throw, simply call error handler with exception object
+ */
+}
+
@@ -27,13 +27,16 @@
* - ZS_<PARAMNAME> - will contain value of parameter defined in deployment.xml, as specified by
* user during deployment.
*/
+$appLocation = getenv('ZS_APPLICATION_BASE_DIR');
+$previousVersion = getenv('ZS_PREVIOUS_APP_VERSION');
+
+require_once 'exceptions.php';
require_once 'db.php';
require_once 'rewrite.php';
-
-// get application location
-$appLocation = getenv('ZS_APPLICATION_BASE_DIR');
+
+// get application location
handleRewrite($appLocation);
-$query = file_get_contents ( 'create-schema.sql' );
+$query = file_get_contents ( dirname(__FILE__) . '/schema-1.0.sql' );
runQuery($query);
@@ -1,22 +1,22 @@
-DROP TABLE IF EXISTS users;
+DROP TABLE IF EXISTS `users`;
CREATE TABLE `users` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT 'id primary',
`name` VARCHAR( 255 ) NOT NULL COMMENT 'user name',
`fb_session` TEXT NULL COMMENT 'facebook session id',
`last_login` DATE NOT NULL COMMENT 'last time log in'
) ENGINE = INNODB;
-DROP TABLE IF EXISTS doctors;
-CREATE TABLE `doctors` (
- `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT 'id',
+DROP TABLE IF EXISTS `surgeons`;
+CREATE TABLE `surgeons` (
+ `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT 'id primary',
`name` VARCHAR( 50 ) NOT NULL COMMENT 'doc name ',
- `title` SET( 'Dr.', 'Prof.' ) NOT NULL COMMENT 'title'
+ `title` SET( 'Dr.', 'Prof.' ) NOT NULL COMMENT 'title'
) ENGINE = INNODB;
-DROP TABLE IF EXISTS operations;
+DROP TABLE IF EXISTS `operations`;
CREATE TABLE `operations` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT 'id',
- `name` VARCHAR( 50 ) NOT NULL COMMENT 'doc name ',
+ `name` VARCHAR( 50 ) NOT NULL COMMENT 'doc name '
) ENGINE = INNODB;
DROP TABLE IF EXISTS sessions;
@@ -33,8 +33,8 @@ CREATE TABLE `shifts` (
`comments` VARCHAR( 300 ) NULL COMMENT 'comments'
) ENGINE = INNODB;
-DROP TABLE IF EXISTS sessions;
-CREATE TABLE `sessions` (
+DROP TABLE IF EXISTS surgeries;
+CREATE TABLE `surgeries` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT 'id',
`date` DATE NOT NULL COMMENT 'date',
`op_type` INT NOT NULL COMMENT 'operation type ',
View
@@ -2,6 +2,7 @@ appdir.includes = library,\
public,\
src
scriptsdir.includes = build/scripts/post_activate.php,\
- build/scripts/create-schema.sql,\
+ build/scripts/schema-1.0.sql,\
build/scripts/db.php,\
- build/scripts/rewrite.php
+ build/scripts/rewrite.php,\
+ build/scripts/exceptions.php
View
@@ -1,97 +1,36 @@
<?php
+set_include_path ( get_include_path () . PATH_SEPARATOR . '../library' . PATH_SEPARATOR . '../src' );
require_once 'Gateful/Main.php';
+require_once 'Services/all.php';
$gateful->router ( array (
// users
- array (
- '/users/login',
- 'users_login'
- ),
+ '/doc-reports/users/login' => 'users_login',
// sessions
- array (
- '/sessions/create',
- 'sessions_create'
- ),
- array (
- '/sessions/edit',
- 'sessions_edit'
- ),
- array (
- '/sessions/remove',
- 'sessions_remove'
- ),
- array (
- '/sessions/list',
- 'sessions_list'
- ),
+ '/doc-reports/sessions/create' => 'sessions_create',
+ '/doc-reports/sessions/edit' => 'sessions_edit',
+ '/doc-reports/sessions/remove' => 'sessions_remove',
+ '/doc-reports/sessions/list' => 'sessions_list',
// shifts
- array (
- '/shifts/create',
- 'shifts_create'
- ),
- array (
- '/shifts/edit',
- 'shifts_edit'
- ),
- array (
- '/shifts/remove',
- 'shifts_remove'
- ),
- array (
- '/shifts/list',
- 'shifts_list'
- ),
+ '/doc-reports/shifts/create' => 'shifts_create',
+ '/doc-reports/shifts/edit' => 'shifts_edit',
+ '/doc-reports/shifts/remove' => 'shifts_remove',
+ '/doc-reports/shifts/list' => 'shifts_list',
// surgeries
- array (
- '/surgeries/create',
- 'surgeries_create'
- ),
- array (
- '/surgeries/edit',
- 'surgeries_edit'
- ),
- array (
- '/surgeries/remove',
- 'surgeries_remove'
- ),
- array (
- '/surgeries/list',
- 'surgeries_list'
- ),
+ '/doc-reports/surgeries/create' => 'surgeries_create',
+ '/doc-reports/surgeries/edit' => 'surgeries_edit',
+ '/doc-reports/surgeries/remove' => 'surgeries_remove',
+ '/doc-reports/surgeries/list' => 'surgeries_list',
// doctors
- array (
- '/doctors/create',
- 'doctors_create'
- ),
- array (
- '/doctors/edit',
- 'doctors_edit'
- ),
- array (
- '/doctors/remove',
- 'doctors_remove'
- ),
- array (
- '/doctors/list',
- 'doctors_list'
- ),
+ '/doc-reports/surgeons/create' => 'surgeons_create',
+ '/doc-reports/surgeons/edit' => 'surgeons_edit',
+ '/doc-reports/surgeons/remove' => 'surgeons_remove',
+ '/doc-reports/surgeons/list' => 'surgeons_list',
// operations
- array (
- '/operations/create',
- 'operations_create'
- ),
- array (
- '/operations/edit',
- 'operations_edit'
- ),
- array (
- '/operations/remove',
- 'operations_remove'
- ),
- array (
- '/operations/list',
- 'operations_list'
- )
+ '/doc-reports/operations/create' => 'operations_create',
+ '/doc-reports/operations/edit' => 'operations_edit',
+ '/doc-reports/operations/remove' => 'operations_remove',
+ '/doc-reports/operations/list' => 'operations_list'
) );
$gateful->send ();
View
@@ -0,0 +1,8 @@
+<?php
+require_once 'Services/db.php';
+require_once 'Services/surgeons.php';
+require_once 'Services/operations.php';
+require_once 'Services/sessions.php';
+require_once 'Services/shifts.php';
+require_once 'Services/surgeries.php';
+require_once 'Services/users.php';
View
@@ -0,0 +1,69 @@
+<?php
+/**
+ * @return string the container db host
+ */
+function getDbHost() {
+ return get_cfg_var ( 'zend_developer_cloud.db.host' );
+}
+
+/**
+ *
+ * @return string the container db name
+ */
+function getDbName() {
+ return get_cfg_var ( 'zend_developer_cloud.db.name' );
+}
+
+/**
+ *
+ * @return string the container db user
+ */
+function getDbUser() {
+ return get_cfg_var ( 'zend_developer_cloud.db.username' );
+}
+
+/**
+ *
+ * @return string the container db password
+ */
+function getDbPassword() {
+ return get_cfg_var ( 'zend_developer_cloud.db.password' );
+}
+
+/**
+ * @param string $query
+ * @throws Exception
+ * @return array
+ */
+function runQuery($query) {
+ global $appLocation;
+ $mysqli = mysqli_connect ( getDbHost (), getDbUser (), getDbPassword (), getDbName () );
+
+ /* check connection */
+ if (mysqli_connect_errno ()) {
+ throw new Exception ( "error connecting db " . mysqli_connect_error () );
+ }
+
+ $result = mysqli_query ( $mysqli, $query );
+ if (! $result) {
+ throw new Exception ( 'Failed running query ' . mysqli_error_list ( $mysqli ) );
+ }
+
+ if (substr($query, 0, 6) == 'INSERT') {
+ $r = mysqli_insert_id($mysqli);
+ } else {
+ while ($out = mysqli_fetch_array ( $result, MYSQLI_ASSOC )) {
+ $r[] = $out;
+ }
+ }
+
+ /* Select queries return a resultset */
+
+ /* free result set */
+ mysqli_free_result ( $result );
+
+ /* close connection */
+ mysqli_close ( $mysqli );
+
+ return $r;
+}
Oops, something went wrong.

0 comments on commit a8158c7

Please sign in to comment.