Esempio n. 1
0
function copy_group($source_group_id, $dest_user, $revset_id = 0)
{
    check_permission(PERM_SYNTAX);
    if (!$source_group_id || !$dest_user) {
        throw new UnexpectedValueException();
    }
    sql_begin();
    if (!$revset_id) {
        $revset_id = create_revset();
    }
    sql_query("\n        INSERT INTO anaphora_syntax_groups\n        (\n            SELECT NULL, group_type, {$revset_id}, head_id, {$dest_user}, marks\n            FROM anaphora_syntax_groups\n            WHERE group_id = {$source_group_id}\n            LIMIT 1\n        )\n    ");
    $copy_id = sql_insert_id();
    // save head
    $r = sql_fetch_array(sql_query("SELECT head_id FROM anaphora_syntax_groups WHERE group_id = {$copy_id} LIMIT 1"));
    $head_id = $r['head_id'];
    // simple group
    copy_simple_group($source_group_id, $copy_id);
    // complex group (recursive)
    $res = sql_query("\n        SELECT child_gid\n        FROM anaphora_syntax_groups_complex\n        WHERE parent_gid = {$source_group_id}\n    ");
    while ($r = sql_fetch_array($res)) {
        $gid = copy_group($r['child_gid'], $dest_user, $revset_id);
        sql_query("INSERT INTO anaphora_syntax_groups_complex VALUES ({$copy_id}, {$gid})");
        if ($r['child_gid'] == $head_id) {
            $head_id = $gid;
        }
    }
    // update head
    sql_query("UPDATE anaphora_syntax_groups SET head_id={$head_id} WHERE group_id={$copy_id} LIMIT 1");
    sql_commit();
    return $copy_id;
}
Esempio n. 2
0
<?php

require_once '../lib/header_ajax.php';
require_once '../lib/lib_anaphora_syntax.php';
/*
    Сюда приходит POST'ом следующее:
    act - что нужно делать
*/
try {
    switch ($_POST['act']) {
        case 'newGroup':
            $result['gid'] = add_group($_POST['tokens'], (int) $_POST['type']);
            break;
        case 'copyGroup':
            $old_groups = get_groups_by_sentence((int) $_POST['sentence_id'], (int) $_SESSION['user_id']);
            $new_group_id = copy_group((int) $_POST['gid'], (int) $_SESSION['user_id']);
            $new_groups = get_groups_by_sentence((int) $_POST['sentence_id'], (int) $_SESSION['user_id']);
            $result['new_groups'] = array();
            $result['new_groups']['simple'] = arr_diff($new_groups['simple'], $old_groups['simple']);
            $result['new_groups']['complex'] = arr_diff($new_groups['complex'], $old_groups['complex']);
            break;
        case 'deleteGroup':
            delete_group($_POST['gid']);
            break;
        case 'setGroupHead':
            set_group_head($_POST['gid'], $_POST['head_id']);
            break;
        case 'setGroupType':
            set_group_type($_POST['gid'], $_POST['type']);
            break;
        case 'getGroupsTable':