function delete($idallocation)
 {
     global $cfg, $lang;
     $obj = new WorkflowAllocation();
     $obj->loadByPrimaryKey($idallocation);
     $idcatlang = $obj->get("idcatlang");
     $db = new DB_Contenido();
     $sql = "SELECT idcat FROM " . $cfg["tab"]["cat_lang"] . " WHERE idcatlang = '" . Contenido_Security::toInteger($idcatlang) . "'";
     $db->query($sql);
     $db->next_record();
     $idcat = $db->f("idcat");
     $sql = "SELECT idart FROM " . $cfg["tab"]["cat_art"] . " WHERE idcat = '" . Contenido_Security::toInteger($idcat) . "'";
     $db->query($sql);
     while ($db->next_record()) {
         $idarts[] = $db->f("idart");
     }
     $idartlangs = array();
     if (is_array($idarts)) {
         foreach ($idarts as $idart) {
             $sql = "SELECT idartlang FROM " . $cfg["tab"]["art_lang"] . " WHERE idart = '" . Contenido_Security::toInteger($idart) . "' and idlang = '" . Contenido_Security::toInteger($lang) . "'";
             $db->query($sql);
             if ($db->next_record()) {
                 $idartlangs[] = $db->f("idartlang");
             }
         }
     }
     $workflowArtAllocation = new WorkflowArtAllocation();
     $workflowArtAllocations = new WorkflowArtAllocations();
     foreach ($idartlangs as $idartlang) {
         $workflowArtAllocation->loadBy("idartlang", $idartlang);
         $workflowArtAllocations->delete($workflowArtAllocation->get("idartallocation"));
     }
     parent::delete($idallocation);
 }
function getCurrentUserSequence($idartlang, $defaultidworkflow)
{
    $wfaa = new WorkflowArtAllocations();
    $wfaa->select("idartlang = '{$idartlang}'");
    $idusersequence = 0;
    if ($associatedUserSequence = $wfaa->next()) {
        $idusersequence = $associatedUserSequence->get("idusersequence");
    }
    if ($idusersequence == 0) {
        if ($associatedUserSequence != false) {
            $newObj = $associatedUserSequence;
        } else {
            $newObj = $wfaa->create($idartlang);
            if (!$newObj) {
                /* Try to load */
                $newObj = new WorkflowArtAllocation();
                echo $wfaa->lasterror;
                return false;
            }
        }
        /* Get the first idusersequence for the new item */
        $workflowItems = new WorkflowItems();
        $workflowItems->select("idworkflow = '{$defaultidworkflow}' AND position = '1'");
        if ($obj = $workflowItems->next()) {
            $firstitem = $obj->get("idworkflowitem");
        }
        $workflowUserSequences = new WorkflowUserSequences();
        $workflowUserSequences->select("idworkflowitem = '{$firstitem}' AND position = '1'");
        if ($obj = $workflowUserSequences->next()) {
            $firstIDUserSequence = $obj->get("idusersequence");
        }
        $newObj->set("idusersequence", $firstIDUserSequence);
        $newObj->store();
        $idusersequence = $newObj->get("idusersequence");
        $associatedUserSequence = $newObj;
    }
    return $idusersequence;
}