summaryrefslogtreecommitdiff
authorJosh <jokajak@gmail.com>2011-10-05 20:40:29 (UTC)
committer Josh <jokajak@gmail.com>2011-10-06 01:58:00 (UTC)
commita26b219b6f4f3fee727d9b23d8cd374f6b32a4fa (patch) (side-by-side diff)
tree3ca0b96e843f5820f0bee7dede1847b014bba1e6
parent6ba274c79e60e417132b260bd0117c5a68121387 (diff)
downloadclipperz-a26b219b6f4f3fee727d9b23d8cd374f6b32a4fa.zip
clipperz-a26b219b6f4f3fee727d9b23d8cd374f6b32a4fa.tar.gz
clipperz-a26b219b6f4f3fee727d9b23d8cd374f6b32a4fa.tar.bz2
Fix timestamps on records
- update the access and update date when a record is saved - set the creation date when a record is created
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--backend/php/src/index.php7
-rw-r--r--backend/php/src/objects/class.record.php13
-rw-r--r--backend/php/src/objects/class.recordversion.php4
3 files changed, 19 insertions, 5 deletions
diff --git a/backend/php/src/index.php b/backend/php/src/index.php
index 58c10a9..3d23e7a 100644
--- a/backend/php/src/index.php
+++ b/backend/php/src/index.php
@@ -354,48 +354,55 @@ error_log("oneTimePassword");
} else {
throw new Exception("The requested One Time Password was not active");
}
} else {
throw new Exception("The requested One Time Password has not been found");
}
//=============================================================
}
break;
case "message":
error_log("message");
if ($parameters["srpSharedSecret"] == $_SESSION["K"]) {
$message = $parameters["message"];
//=============================================================
if ($message == "getUserDetails") {
//{"message":"getUserDetails", "srpSharedSecret":"f18e5cf7c3a83b67d4db9444af813ee48c13daf4f8f6635397d593e52ba89a08", "parameters":{}}
$user = new user();
$user = $user->Get($_SESSION["userId"]);
$result["header"] = $user->header;
+ $records = $user->GetRecordList();
+ foreach ($records as $record)
+ {
+ $recordStats["updateDate"] = $record->update_date;
+ $recordsStats[$record->reference] = $recordStats;
+ }
+ $result["recordsStats"] = $recordsStats;
$result["statistics"] = $user->statistics;
$result["version"] = $user->version;
//=============================================================
} else if ($message == "addNewRecords") {
/*
//{
// "message":"addNewRecords",
// "srpSharedSecret":"b58fdf62acebbcb67f63d28c0437f166069f45690c648cd4376a792ae7a325f7",
// "parameters":{
// "records":[
// {
// "record":{
// "reference":"fda703707fee1fff42443124cd0e705f5bea0ac601758d81b2e832705339a610",
// "data":"OBSGtcb6blXq/xaYG.....4EqlQqgAvITN",
// "version":"0.3"
// },
// "currentRecordVersion":{
// "reference":"83ad301525c18f2afd72b6ac82c0a713382e1ef70ac69935ca7e2869dd4ff980",
// "recordReference":"fda703707fee1fff42443124cd0e705f5bea0ac601758d81b2e832705339a610",
// "data":"NXJ5jiZhkd0CMiwwntAq....1TjjF+SGfE=",
// "version":"0.3",
// "previousVersion":"3e174a86afc322271d8af28bc062b0f1bfd7344fad01212cd08b2757c4b199c4",
// "previousVersionKey":"kozaaGCzXWr71LbOKu6Z3nz520V..5U85tSBvb+u44twttv54Kw=="
diff --git a/backend/php/src/objects/class.record.php b/backend/php/src/objects/class.record.php
index a269e75..37a9702 100644
--- a/backend/php/src/objects/class.record.php
+++ b/backend/php/src/objects/class.record.php
@@ -1,36 +1,36 @@
<?php
/*
This SQL query will create the table to store your object.
CREATE TABLE `record` (
`recordid` int(11) NOT NULL auto_increment,
`userid` int(11) NOT NULL,
`reference` VARCHAR(255) NOT NULL,
`data` LONGTEXT NOT NULL,
`version` VARCHAR(255) NOT NULL,
`creation_date` TIMESTAMP NOT NULL,
- `update_date` TIMESTAMP NOT NULL,
+ `update_date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`access_date` TIMESTAMP NOT NULL, INDEX(`userid`), PRIMARY KEY (`recordid`)) ENGINE=MyISAM;
*/
/**
* <b>record</b> class with integrated CRUD methods.
* @author Php Object Generator
* @version POG 3.0e / PHP5.1 MYSQL
* @see http://www.phpobjectgenerator.com/plog/tutorials/45/pdo-mysql
* @copyright Free for personal & commercial use. (Offered under the BSD license)
* @link http://www.phpobjectgenerator.com/?language=php5.1&wrapper=pdo&pdoDriver=mysql&objectName=record&attributeList=array+%28%0A++0+%3D%3E+%27user%27%2C%0A++1+%3D%3E+%27recordversion%27%2C%0A++2+%3D%3E+%27reference%27%2C%0A++3+%3D%3E+%27data%27%2C%0A++4+%3D%3E+%27version%27%2C%0A++5+%3D%3E+%27creation_date%27%2C%0A++6+%3D%3E+%27update_date%27%2C%0A++7+%3D%3E+%27access_date%27%2C%0A%29&typeList=array%2B%2528%250A%2B%2B0%2B%253D%253E%2B%2527BELONGSTO%2527%252C%250A%2B%2B1%2B%253D%253E%2B%2527HASMANY%2527%252C%250A%2B%2B2%2B%253D%253E%2B%2527VARCHAR%2528255%2529%2527%252C%250A%2B%2B3%2B%253D%253E%2B%2527LONGTEXT%2527%252C%250A%2B%2B4%2B%253D%253E%2B%2527VARCHAR%2528255%2529%2527%252C%250A%2B%2B5%2B%253D%253E%2B%2527TIMESTAMP%2527%252C%250A%2B%2B6%2B%253D%253E%2B%2527TIMESTAMP%2527%252C%250A%2B%2B7%2B%253D%253E%2B%2527TIMESTAMP%2527%252C%250A%2529
*/
include_once('class.pog_base.php');
class record extends POG_Base
{
public $recordId = '';
/**
* @var INT(11)
*/
public $userId;
/**
* @var private array of recordversion objects
*/
@@ -105,49 +105,50 @@ class record extends POG_Base
$this->creation_date = $creation_date;
$this->update_date = $update_date;
$this->access_date = $access_date;
}
/**
* Gets object from database
* @param integer $recordId
* @return object $record
*/
function Get($recordId)
{
$connection = Database::Connect();
$this->pog_query = "select * from `record` where `recordid`='".intval($recordId)."' LIMIT 1";
$cursor = Database::Reader($this->pog_query, $connection);
while ($row = Database::Read($cursor))
{
$this->recordId = $row['recordid'];
$this->userId = $row['userid'];
$this->reference = $this->Unescape($row['reference']);
$this->data = $this->Unescape($row['data']);
$this->version = $this->Unescape($row['version']);
$this->creation_date = $row['creation_date'];
- $this->update_date = $row['update_date'];
+ $oDate = strtotime($row['update_date']);
+ $this->update_date = date('r', $oDate);
$this->access_date = $row['access_date'];
}
return $this;
}
/**
* Returns a sorted array of objects that match given conditions
* @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...}
* @param string $sortBy
* @param boolean $ascending
* @param int limit
* @return array $recordList
*/
function GetList($fcv_array = array(), $sortBy='', $ascending=true, $limit='')
{
$connection = Database::Connect();
$sqlLimit = ($limit != '' ? "LIMIT $limit" : '');
$this->pog_query = "select * from `record` ";
$recordList = Array();
if (sizeof($fcv_array) > 0)
{
$this->pog_query .= " where ";
for ($i=0, $c=sizeof($fcv_array); $i<$c; $i++)
@@ -197,111 +198,115 @@ class record extends POG_Base
$sortBy = "$sortBy ";
}
}
else
{
$sortBy = "$sortBy ";
}
}
else
{
$sortBy = "recordid";
}
$this->pog_query .= " order by ".$sortBy." ".($ascending ? "asc" : "desc")." $sqlLimit";
$thisObjectName = get_class($this);
$cursor = Database::Reader($this->pog_query, $connection);
while ($row = Database::Read($cursor))
{
$record = new $thisObjectName();
$record->recordId = $row['recordid'];
$record->userId = $row['userid'];
$record->reference = $this->Unescape($row['reference']);
$record->data = $this->Unescape($row['data']);
$record->version = $this->Unescape($row['version']);
$record->creation_date = $row['creation_date'];
- $record->update_date = $row['update_date'];
+ $oDate = strtotime($row['update_date']);
+ $record->update_date = date('r', $oDate);
$record->access_date = $row['access_date'];
$recordList[] = $record;
}
return $recordList;
}
/**
* Saves the object to the database
* @return integer $recordId
*/
function Save($deep = true)
{
$connection = Database::Connect();
+ $this->update_date = date( 'r');
+ $this->access_date = date( 'r');
$this->pog_query = "select `recordid` from `record` where `recordid`='".$this->recordId."' LIMIT 1";
$rows = Database::Query($this->pog_query, $connection);
if ($rows > 0)
{
$this->pog_query = "update `record` set
`userid`='".$this->userId."',
`reference`='".$this->Escape($this->reference)."',
`data`='".$this->Escape($this->data)."',
`version`='".$this->Escape($this->version)."',
`creation_date`='".$this->creation_date."',
`update_date`='".$this->update_date."',
`access_date`='".$this->access_date."' where `recordid`='".$this->recordId."'";
}
else
{
$this->pog_query = "insert into `record` (`userid`, `reference`, `data`, `version`, `creation_date`, `update_date`, `access_date` ) values (
'".$this->userId."',
'".$this->Escape($this->reference)."',
'".$this->Escape($this->data)."',
'".$this->Escape($this->version)."',
'".$this->creation_date."',
'".$this->update_date."',
'".$this->access_date."' )";
}
$insertId = Database::InsertOrUpdate($this->pog_query, $connection);
if ($this->recordId == "")
{
$this->recordId = $insertId;
}
if ($deep)
{
foreach ($this->_recordversionList as $recordversion)
{
$recordversion->recordId = $this->recordId;
$recordversion->Save($deep);
}
}
return $this->recordId;
}
/**
* Clones the object and saves it to the database
* @return integer $recordId
*/
function SaveNew($deep = false)
{
$this->recordId = '';
+ $this->creation_date = date( 'Y-m-d H:i:s');
return $this->Save($deep);
}
/**
* Deletes the object from the database
* @return boolean
*/
function Delete($deep = false, $across = false)
{
if ($deep)
{
$recordversionList = $this->GetRecordversionList();
foreach ($recordversionList as $recordversion)
{
$recordversion->Delete($deep, $across);
}
}
$connection = Database::Connect();
$this->pog_query = "delete from `record` where `recordid`='".$this->recordId."'";
return Database::NonQuery($this->pog_query, $connection);
}
@@ -412,25 +417,25 @@ class record extends POG_Base
/**
* Associates the recordversion object to this one
* @return
*/
function AddRecordversion(&$recordversion)
{
$recordversion->recordId = $this->recordId;
$found = false;
foreach($this->_recordversionList as $recordversion2)
{
if ($recordversion->recordversionId > 0 && $recordversion->recordversionId == $recordversion2->recordversionId)
{
$found = true;
break;
}
}
if (!$found)
{
$this->_recordversionList[] = $recordversion;
}
}
}
-?> \ No newline at end of file
+?>
diff --git a/backend/php/src/objects/class.recordversion.php b/backend/php/src/objects/class.recordversion.php
index 3fbc436..f2de14a 100644
--- a/backend/php/src/objects/class.recordversion.php
+++ b/backend/php/src/objects/class.recordversion.php
@@ -235,48 +235,50 @@ class recordversion extends POG_Base
$recordversion->recordversionId = $row['recordversionid'];
$recordversion->recordId = $row['recordid'];
$recordversion->reference = $this->Unescape($row['reference']);
$recordversion->header = $this->Unescape($row['header']);
$recordversion->data = $this->Unescape($row['data']);
$recordversion->version = $this->Unescape($row['version']);
$recordversion->previous_version_key = $this->Unescape($row['previous_version_key']);
$recordversion->previous_version_id = $this->Unescape($row['previous_version_id']);
$recordversion->creation_date = $row['creation_date'];
$recordversion->update_date = $row['update_date'];
$recordversion->access_date = $row['access_date'];
$recordversionList[] = $recordversion;
}
return $recordversionList;
}
/**
* Saves the object to the database
* @return integer $recordversionId
*/
function Save()
{
$connection = Database::Connect();
+ $this->update_date = date( 'Y-m-d H:i:s');
+ $this->access_date = date( 'Y-m-d H:i:s');
$this->pog_query = "select `recordversionid` from `recordversion` where `recordversionid`='".$this->recordversionId."' LIMIT 1";
$rows = Database::Query($this->pog_query, $connection);
if ($rows > 0)
{
$this->pog_query = "update `recordversion` set
`recordid`='".$this->recordId."',
`reference`='".$this->Escape($this->reference)."',
`header`='".$this->Escape($this->header)."',
`data`='".$this->Escape($this->data)."',
`version`='".$this->Escape($this->version)."',
`previous_version_key`='".$this->Escape($this->previous_version_key)."',
`previous_version_id`='".$this->Escape($this->previous_version_id)."',
`creation_date`='".$this->creation_date."',
`update_date`='".$this->update_date."',
`access_date`='".$this->access_date."' where `recordversionid`='".$this->recordversionId."'";
}
else
{
$this->pog_query = "insert into `recordversion` (`recordid`, `reference`, `header`, `data`, `version`, `previous_version_key`, `previous_version_id`, `creation_date`, `update_date`, `access_date` ) values (
'".$this->recordId."',
'".$this->Escape($this->reference)."',
'".$this->Escape($this->header)."',
'".$this->Escape($this->data)."',
'".$this->Escape($this->version)."',
@@ -357,25 +359,25 @@ class recordversion extends POG_Base
}
}
/**
* Associates the record object to this one
* @return boolean
*/
function GetRecord()
{
$record = new record();
return $record->Get($this->recordId);
}
/**
* Associates the record object to this one
* @return
*/
function SetRecord(&$record)
{
$this->recordId = $record->recordId;
}
}
-?> \ No newline at end of file
+?>