function udutu_find_common_ancestor($ancestors, $sco) { $pos = udutu_array_search('identifier', $sco->parent, $ancestors); if ($sco->parent != '/') { if ($pos === false) { return udutu_find_common_ancestor($ancestors, udutu_get_parent($sco)); } } return $pos; }
function udutu_seq_temination($seq, $userid) { if (empty($seq->currentactivity)) { $seq->termination = false; $seq->exception = 'TB.2.3-1'; return $seq; } $sco = $seq->currentactivity; if (($seq->termination == 'exit' || $seq->termination == 'abandon') && !$seq->active) { $seq->termination = false; $seq->exception = 'TB.2.3-2'; return $seq; } switch ($seq->termination) { case 'exit': udutu_seq_end_attempt($sco, $userid); $seq = udutu_seq_exit_action_rules($seq, $userid); do { $exit = true; $seq = udutu_seq_post_cond_rules($seq, $userid); if ($seq->termination == 'exitparent') { if ($sco->parent != '/') { $sco = udutu_get_parent($sco); $seq->currentactivity = $sco; $seq->active = udutu_seq_is('active', $sco->id, $userid); udutu_seq_end_attempt($sco, $userid); $exit = false; } else { $seq->termination = false; $seq->exception = 'TB.2.3-4'; return $seq; } } } while ($exit == false && $seq->termination == 'exit'); if ($seq->termination == 'exit') { $seq->termination = true; return $seq; } case 'exitall': if ($seq->active) { udutu_seq_end_attempt($sco, $userid); } /// Terminate Descendent Attempts Process if ($ancestors = udutu_get_ancestors($sco)) { foreach ($ancestors as $ancestor) { udutu_seq_end_attempt($ancestor, $userid); $seq->currentactivity = $ancestor; } } $seq->active = udutu_seq_is('active', $seq->currentactivity->id, $userid); $seq->termination = true; break; case 'suspendall': if ($seq->active || $seq->suspended) { udutu_seq_set('suspended', $sco->id, $userid); } else { if ($sco->parent != '/') { $parentsco = udutu_get_parent($sco); udutu_seq_set('suspended', $parentsco->id, $userid); } else { $seq->termination = false; $seq->exception = 'TB.2.3-3'; // return $seq; } } if ($ancestors = udutu_get_ancestors($sco)) { foreach ($ancestors as $ancestor) { udutu_seq_set('active', $ancestor->id, $userid, 0, false); udutu_seq_set('suspended', $ancestor->id, $userid); $seq->currentactivity = $ancestor; } $seq->termination = true; $seq->sequencing = 'exit'; } else { $seq->termination = false; $seq->exception = 'TB.2.3-5'; } break; case 'abandon': udutu_seq_set('active', $sco->id, $userid, 0, false); $seq->active = null; $seq->termination = true; break; case 'abandonall': if ($ancestors = udutu_get_ancestors($sco)) { foreach ($ancestors as $ancestor) { udutu_seq_set('active', $ancestor->id, $userid, 0, false); $seq->currentactivity = $ancestor; } $seq->termination = true; $seq->sequencing = 'exit'; } else { $seq->termination = false; $seq->exception = 'TB.2.3-6'; } break; default: $seq->termination = false; $seq->exception = 'TB.2.3-7'; break; } return $seq; }