Patch multiday thoughts

This commit is contained in:
2020-03-22 17:29:50 +01:00
parent 80b9a54607
commit 1c88ce7dfa
17 changed files with 2372 additions and 2285 deletions

View File

@@ -5,6 +5,8 @@ class Thought extends PhpObject
const THOUGHT_TABLE = 'thoughts';
private $iId;
private $iPrevId;
private $iNextId;
private $iUserId;
private $asOps;
private $iCreateTimestamp;
@@ -32,6 +34,7 @@ class Thought extends PhpObject
public function setId($iId, $bOpen=true)
{
$this->iId = $iId;
$this->iNextId = 0;
if($this->iId > 0 && $bOpen) $this->open($this->iId);
}
@@ -66,6 +69,8 @@ class Thought extends PhpObject
$asWhere = array(Db::getId(self::THOUGHT_TABLE)=>$iId, Db::getId(MyThoughts::USER_TABLE) => $this->iUserId);
$asInfo = $this->oDb->selectRow(self::THOUGHT_TABLE, $asWhere);
$this->iPrevId = $this->getRelativeThoughtId($iId, -1);
$this->iNextId = $this->getRelativeThoughtId($iId, 1);
$this->iId = $asInfo[Db::getId(self::THOUGHT_TABLE)];
$this->iUserId = $asInfo[Db::getId(MyThoughts::USER_TABLE)];
$this->asOps = self::decodeThought($asInfo[Db::getText(self::THOUGHT_TABLE)]);
@@ -77,6 +82,23 @@ class Thought extends PhpObject
else $this->addError('getting thought info with no thought id');
}
private function getRelativeThoughtId($iId, $iOffset) {
$iThoughtId = 0;
$asThoughtIds = $this->oDb->selectRows(array(
'select' => Db::getId(self::THOUGHT_TABLE),
'from' => self::THOUGHT_TABLE,
'constraint'=> array('id_thought'=> $iId, Db::getId(MyThoughts::USER_TABLE) => $this->iUserId),
'constOpe' => array('id_thought'=> $iOffset>0?'>':'<', Db::getId(MyThoughts::USER_TABLE) => '='),
'orderBy' => array(Db::getId(self::THOUGHT_TABLE) => $iOffset>0?'ASC':'DESC'),
'limit' => abs($iOffset)
));
$iIndex = abs($iOffset) - 1;
if(array_key_exists($iIndex, $asThoughtIds)) $iThoughtId = $asThoughtIds[$iIndex];
return $iThoughtId;
}
public function save()
{
$asThought = array(
@@ -94,10 +116,13 @@ class Thought extends PhpObject
{
return array(
'id' => $this->iId,
'prev_id' => $this->iPrevId,
'next_id' => $this->iNextId,
'id_user' => $this->iUserId,
'ops' => $this->asOps,
'created' => $this->iCreateTimestamp,
'created_f' => date('l, j F', $this->iCreateTimestamp),
'created_d' => date('l, j F', $this->iCreateTimestamp),
'created_h' => date('H:i', $this->iCreateTimestamp),
'led' => $this->sLed
);
}