method update documentation in bbn\Appui\Task
function($idTask, $prop, $value)
{
$ok = false;
$states = $this->states();
switch ($prop) {
case 'deadline':
$prev = $this->db->selectOne('bbn_tasks', 'deadline', ['id' => $idTask]);
if ( !$prev && $value ){
$this->addLog($idTask, 'deadline_insert', [$value]);
$ok = 1;
}
else if ( $prev && !$value ){
$this->addLog($idTask, 'deadline_delete', [$value]);
$ok = 1;
}
if ( $prev && $value && ($prev !== $value) ){
$this->addLog($idTask, 'deadline_update', [$prev, $value]);
$ok = 1;
}
break;
case 'price':
$prev = $this->db->selectOne('bbn_tasks', 'price', ['id' => $idTask]);
if ( !$prev && $value ){
$this->addLog($idTask, 'price_insert', [$value]);
$ok = 1;
}
else if ( $prev && !$value ){
$this->addLog($idTask, 'price_delete', [$prev]);
$ok = 1;
}
if ( $prev && $value && ($prev !== $value) ){
$this->addLog($idTask, 'price_update', [$prev, $value]);
$ok = 1;
}
if ($ok) {
$oldState = $this->getState($idTask);
}
break;
case 'state':
switch ( $value ){
case $states['closed']:
$ok = 1;
$this->addLog($idTask, 'task_close');
$this->stopAllTracks($idTask);
break;
case $states['holding']:
$ok = 1;
$this->addLog($idTask, 'task_hold');
$this->stopAllTracks($idTask);
break;
case $states['ongoing']:
$ok = 1;
$this->addLog($idTask, 'task_start');
break;
case $states['opened']:
$ok = 1;
$this->addLog($idTask, 'task_reopen');
break;
case $states['unapproved']:
$this->addLog($idTask, 'task_unapproved');
$this->stopAllTracks($idTask);
$ok = 1;
break;
}
break;
case 'title':
case 'content':
if (($idNote = $this->getIdNote($idTask))
&& ($n = $this->noteCls->get($idNote))
) {
$title = $n['title'];
$content = $n['content'];
$log = '_update';
$vals = [];
if (($prop === 'title')
&& ($title !== $value)
) {
$vals = [$title, $value];
$title = $value;
}
else if (($prop === 'content')
&& ($content !== $value)
) {
$prev = $content;
if (empty($prev)) {
$log = '_insert';
$vals = [$value];
}
else if (empty($value)) {
$log = '_delete';
}
else {
$vals = [$content, $value];
}
$content = $value;
}
if ($this->noteCls->insertVersion($idNote, $title, $content, $this->noteCls->getExcerpt($title, $content))) {
$this->addLog($idTask, $prop.$log, $vals);
return true;
}
}
break;
default:
if ( $prev = $this->db->selectOne('bbn_tasks', $prop, ['id' => $idTask]) ){
$ok = 1;
$this->addLog($idTask, $prop.'_update', [$prev, $value]);
}
break;
}
if ($ok && $this->db->update('bbn_tasks', [$prop => $value], ['id' => $idTask])) {
if ($prop === 'price') {
if (($idParent = $this->getIdParent($idTask))) {
if (!empty($value)
&& ($this->getState($idParent) !== $states['unapproved'])
) {
$this->update($idParent, 'state', $states['unapproved']);
}
else if (empty($value)
&& ($this->getState($idParent) === $states['unapproved'])
&& !$this->getUnapprovedChildrenIds($idParent)
) {
$this->update($idParent, 'state', $states['opened']);
}
}
$this->update($idTask, 'state', empty($value) ? $states['opened'] : $states['unapproved']);
}
if ($prop === 'state') {
if ($value === $states['unapproved']) {
if (!!$this->getPrice($idTask) && ($children = $this->getChildrenIds($idTask))) {
foreach ($children as $child) {
$s = $this->getState($child);
if (($s !== $states['unapproved'])
&& ($s !== $states['closed'])
) {
$this->update($child, 'state', $states['unapproved']);
}
}
}
if (($idParent = $this->getIdParent($idTask))
&& ($this->getState($idParent) !== $states['unapproved'])
) {
$this->update($idParent, 'state', $states['unapproved']);
}
}
else if ($value === $states['opened']) {
if ($children = $this->getUnapprovedChildrenIds($idTask)) {
foreach ($children as $child) {
$this->update($child, 'state', $states['opened']);
}
}
if (($idParent = $this->getIdParent($idTask))
&& ($this->getState($idParent) === $states['unapproved'])
&& !$this->getUnapprovedChildrenIds($idParent)
) {
$this->update($idParent, 'state', $states['opened']);
}
}
}
return true;
}
}
return false;
}
BBN is a suite of PHP and JS libraries and VueJS components - all open-source! bbn.io, build applications, the quick way
This website uses cookies to ensure you get the best experience on our website.
© 2011-2023
BBN Solutions