Skip to content

Commit

Permalink
Phonebook API - New Datatype
Browse files Browse the repository at this point in the history
Phonebook can now handle datetime.
  • Loading branch information
krisdb2009 committed Jul 18, 2019
1 parent 295e694 commit cb63033
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 30 deletions.
4 changes: 4 additions & 0 deletions api/reqs/database.run.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
$row = $row.' NUMERIC';
$typeSet = true;
}
if($v == 'timestamp') {
$row = $row.' DATETIME NOT NULL';
$typeSet = true;
}
if($v == 'text') {
$row = $row.' TEXT';
$typeSet = true;
Expand Down
13 changes: 12 additions & 1 deletion api/reqs/library.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,20 @@ function createModifyOrFindObject($row = array()) {
if(empty($rowWithoutUnique)) {
removeObject($objectID);
} else {
if(!isset($row['modified'])) {
$row['modified'] = time();
}
$db->update('objects', $row, array('objectid' => $objectID));
}
} else { //Insert the data
if(!empty($rowWithoutUnique)) {
$row['objectid'] = $objectID = bin2hex(random_bytes(5));
if(!isset($row['created'])) {
$row['created'] = time();
}
if(!isset($row['modified'])) {
$row['modified'] = time();
}
$db->insert('objects', $row);
} else {
$objectID = false;
Expand Down Expand Up @@ -163,9 +172,11 @@ function importDatabaseObjects($objects) {
foreach($object as $attribute => $value) { //For every attribute in an import object, check that the attribute exists, otherwise do not add it to the row.
if(isset(SCHEMA[$attribute]) && $attribute !== 'tags' && !empty($value)) { //If an attribute in the schema and not a tag list or empty.
if(isset(SCHEMA[$attribute]['type'])) { //Check type constraints
if(SCHEMA[$attribute]['type'] == 'number') { //Check number constraint
if(SCHEMA[$attribute]['type'] == 'number' || SCHEMA[$attribute]['type'] == 'timestamp') { //Check number constraint
if(ctype_digit($value)) {
$value = intval($value); //Convert string to number if it is a string.
} elseif(SCHEMA[$attribute]['type'] == 'timestamp') {
$value = strtotime($value);
} else {
break;
}
Expand Down
82 changes: 53 additions & 29 deletions api/schema.cfg.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,59 @@
{
"created": {
"export": false,
"name": "Created",
"print": false,
"tagged": false,
"visible": false,
"type": "timestamp",
"sortable": true
},
"modified": {
"export": false,
"length": 10,
"name": "Modified",
"print": false,
"tagged": false,
"visible": false,
"type": "timestamp",
"sortable": true
},
"description": {
"export": true,
"length": 1000,
"name": "Description",
"print": true,
"tagged": true,
"visible": true
"visible": true,
"sortable": true
},
"type": {
"choices": [
"Business",
"Fax",
"Location",
"Person"
],
"export": true,
"length": 10,
"name": "Type",
"print": true,
"tagged": true,
"type": "choice",
"visible": true,
"sortable": true
},
"number": {
"export": true,
"indexed": true,
"length": 50,
"name": "Phone Number",
"print": true,
"tagged": false,
"type": "number",
"unique": true,
"visible": true,
"sortable": true
},
"email": {
"export": true,
Expand Down Expand Up @@ -41,7 +89,8 @@
"type": [
"Person"
]
}
},
"sortable": true
},
"lastname": {
"export": true,
Expand All @@ -53,33 +102,8 @@
"type": [
"Person"
]
}
},
"number": {
"export": true,
"indexed": true,
"length": 50,
"name": "Phone Number",
"print": true,
"tagged": false,
"type": "number",
"unique": true,
"visible": true
},
"type": {
"choices": [
"Business",
"Fax",
"Location",
"Person"
],
"export": true,
"length": 10,
"name": "Type",
"print": true,
"tagged": true,
"type": "choice",
"visible": true
},
"sortable": true
},
"username": {
"length": 50,
Expand Down

0 comments on commit cb63033

Please sign in to comment.