adding read page and side calendar

This commit is contained in:
2018-11-18 15:52:22 +01:00
parent d3c3f8141b
commit bcdcf0d2f0
20 changed files with 386 additions and 247 deletions

View File

@@ -34,6 +34,7 @@ class MyThoughts extends Main
const SIZE_16 = '16';
const SIZE_18 = '18';
const SIZE_20 = '20';
const LAST_THOUGHT_LIMIT = 60*60*24;
//Format
const OBJ = 'object';
@@ -140,7 +141,7 @@ class MyThoughts extends Main
);
//Pages
$asPages = array('logon', 'logoff', 'write', 'settings', 'template');
$asPages = array('logon', 'logoff', 'write', 'read', 'settings', 'template');
foreach($asPages as $sPage) $asGlobalVars['consts']['pages'][$sPage] = $this->getPageContent($sPage);
//Main Page
@@ -163,7 +164,7 @@ class MyThoughts extends Main
return array(
'tables' => array(
self::USER_TABLE => array(Db::getText(self::USER_TABLE), 'nickname', 'pass', 'cookie'),
Thought::THOUGHT_TABLE => array(Db::getId(self::USER_TABLE), Db::getText(Thought::THOUGHT_TABLE)),
Thought::THOUGHT_TABLE => array(Db::getId(self::USER_TABLE), Db::getText(Thought::THOUGHT_TABLE), 'created'),
self::SETTINGS_TABLE => array(Db::getId(self::USER_TABLE), Db::getText(self::SETTINGS_TABLE), 'value')
),
'types' => array(
@@ -172,6 +173,7 @@ class MyThoughts extends Main
'pass' => "varchar(256) NOT NULL",
'cookie' => "varchar(255)",
Db::getText(Thought::THOUGHT_TABLE) => "longtext",
'created' => "timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP",
Db::getText(self::SETTINGS_TABLE) => "varchar(20) NOT NULL",
'value' => "varchar(20) NOT NULL"
),
@@ -188,13 +190,9 @@ class MyThoughts extends Main
public function getThought($iThoughtId, $sFormat=self::OBJ)
{
$oThought = new Thought($this->oDb);
$oThought = new Thought($this->oDb, $this->oAuth->getUserId());
if($iThoughtId=='last')
{
$oThought->setUserId($this->oAuth->getUserId());
$oThought->openLast();
}
if($iThoughtId=='last') $oThought->openLast(self::LAST_THOUGHT_LIMIT);
else $oThought->open($iThoughtId);
switch($sFormat)
@@ -208,15 +206,9 @@ class MyThoughts extends Main
}
}
public function updateThought($asOps, $iThoughtId=0, $iUserId=-1)
public function updateThought($asOps, $iThoughtId=0)
{
$oThought = new Thought($this->oDb, $iThoughtId);
if($oThought->getId() == 0) {
if($iUserId==-1) $iUserId = $this->oAuth->getUserId();
if($iUserId!=0) $oThought->setUserId($iUserId);
else $this->addError('Adding a thought with no user id');
}
$oThought = new Thought($this->oDb, $this->oAuth->getUserId(), $iThoughtId);
$oThought->setOps($asOps);
$iThoughtId = $oThought->save();
@@ -226,12 +218,26 @@ class MyThoughts extends Main
return self::getJsonResult($bSuccess, $sDesc, $this->getThought($iThoughtId, self::ARRAY));
}
public function getThoughtDates()
{
$asThoughts = Thought::getThoughtDates($this->oDb, $this->oAuth->getUserId());
foreach($asThoughts as &$asThought) $asThought['created_f'] = self::formatDate($asThought['created'], 'j M');
return self::getJsonResult(true, '', $asThoughts);
}
/* Static toolbox functions */
public static function getSafeNickName($sNickName)
{
return $sNickName;
}
private static function formatDate($iTime, $sFormat, $sField='')
{
$iTime = ($sField == '')?$iTime:$iTime[$sField];
$iTime = is_numeric($iTime)?$iTime:strtotime($iTime);
return date($sFormat, $iTime);
}
}
?>