0

OK、特定のコンテンツ タイプ NODE をある参照から別の参照に移動する、PHP と JavaScript の両方のスクリプトを処理しようとしています。これは構造です:

私はプロジェクトを持っています。
各プロジェクトの
中にページがあります。各ページの中にコール
アウトがあり、各コールアウトの中に製品があります。

私がやりたいのは、製品をある CALLOUT から別の CALLOUT に移動することです。これらをマージすることはできますが、ここでやりたいことは最初のインスタンスを削除することです。例:

ページ 6 のコールアウト A にある製品AAG-794200があります。その製品をページ 6 のコールアウト B とマージしています。

製品をマージすることはできますが、コールアウト A から削除する必要があります。コードは次のとおりです。

$merge = explode(',', $merge); //Merge SKUs
$mpages = explode(',', $mpages); //Merge Pages
$mcallouts = explode(',', $mcallouts); //Merge Callouts
$mcallout_nid = explode(',', $mcallout_nid);  //Merge Current callout

$length = count($merge);
$e = 0;
while ($e < $length) {
    //Where is the SKU going to?
    $to_callout_letter = strtoupper($mcallouts[$e]);
    $to_page_num = $mpages[$e];
    $sku = $merge[$e];
    $from_callout = $mcallout_nid[$e];

    //Where is the SKU coming from?     
    $other_callout = node_load($from_callout);

    //Need page ID of current callout for project purposes
    $page_nid = $other_callout->field_page[0]['nid'];
    $page = node_load($page_nid);
    //Need the project NID
    $project_nid = $page->field_project[0]['nid'];

    //We need to get the NID of the page we are going to
    $page_nid = db_query('SELECT * FROM content_type_page WHERE field_page_order_value = "%d" and field_project_nid = "%d" ORDER BY vid DESC LIMIT 1', $to_page_num, $project_nid);

    $page_nid_res = db_fetch_array($page_nid);
    $to_page_nid = $page_nid_res['nid'];

    //We need to get the NID of the callout here
    $co_nid = db_query('SELECT * FROM content_type_callout WHERE field_identifier_value = "%s" and field_page_nid = "%d"', $to_callout_letter, $to_page_nid);
    $co_nid_res = db_fetch_array($co_nid);
    $to_callout_letter_nid = $co_nid_res['nid'];


    //Load the present callout the SKU resides on
    $f_callout = node_load($from_callout);

    $callout = node_load($to_callout_letter_nid);
    $long = count($f_callout->field_skus);
    $deletecallout = array();
    foreach($f_callout->field_skus as $skus) {
        $s = 0;
        while ($s < $long) {
            if($skus['nid'] == $sku) {
                $callout->field_skus[] = $skus;
                $s++;
            }
            else {
                $deletecallout[] = $skus;
                $s++;
            }
        }
    }


    foreach($other_callout->field_images as $old_image) {
        $callout->field_images[] = $old_image;
    }
    foreach($other_callout->field_line_art as $old_image) {
        $callout->field_line_art[] = $old_image;
    }
    foreach($other_callout->field_swatches as $old_image) {
        $callout->field_swatches[] = $old_image;
    }

    $callout->field_copy_text[0]['value'] .= $other_callout->field_copy_text[0]['value'];
    $callout->field_notes[0]['value'] .= $other_callout->field_notes[0]['value'];
    $callout->field_image_notes[0]['value'] .= $other_callout->field_image_notes[0]['value'];
    $callout->field_status[0]['value'] = 'In Process';
    node_save($callout);

これにより、製品がマージされますが、元の製品は削除されません。

助けてくれてありがとう。私はそれが単純なものであることを知っています、そしてそれは手のひらと顔を合わせる瞬間になるでしょう.

4

1 に答える 1

0

私は実際にこれを自分で解決することができました。node_save(callout); @Chris -コピーして貼り付けたときにそれを見逃したに違いないため、ブレースが終了しました。ただし、これが私が最終的に使用したコードです。

$merge = explode(',', $merge); //Merge SKUs
$mpages = explode(',', $mpages); //Merge Pages
$mcallouts = explode(',', $mcallouts); //Merge Callouts
$mcallout_nid = explode(',', $mcallout_nid);  //Merge Current callout
if($merge[0] !== '0') {
    //Store NIDs of Old Callouts to the proper SKU
    $oc_sku = array();
    $oc_sku_e = count($merge);
    $oc_sku_ee = 0;
    while ($oc_sku_ee < $oc_sku_e) {
        $curr_sku = $merge[$oc_sku_ee];
        $curr_oldco = $mcallout_nid[$oc_sku_ee];
        $oc_sku[$curr_sku] = $curr_oldco;
        $oc_sku_ee++;
    }

    //Convert page numbers to page_nids
    $pc = count($mpages); //How many pages are we getting
    $pc_e = 0;
    while($pc_e < $pc) {
        $nid = $mpages[$pc_e];
        $sql = db_query('SELECT * FROM content_type_page WHERE field_page_order_value = "%d" AND field_project_nid = "%d" ORDER BY vid DESC LIMIT 1', $nid, $project_nid);
        $res = db_fetch_array($sql);
        if($res) {
            $npage_arr[] = $res['nid'];
        } else {  //If there is no page, we need to create it here.
            $node = new StdClass();
            $node->type = 'page';
            $node->title = 'Page ' . $nid . ' of ' . $project->title;
            $node->field_project[0]['nid'] = $project_nid;
            $node->field_page_order[0]['value'] = $nid;
            $node = node_submit($node);
            node_save($node);
            $npage_arr[] = $node->nid;
        }
    $pc_e++;
    }


    // Convert callout letters to callout_nids
    $coc = count($mcallouts);
    $coc_e = 0;
    while($coc_e < $coc) {
        $cnid = strtoupper($mcallouts[$coc_e]);
        $pnid = $npage_arr[$coc_e];
        $page_node = node_load($pnid);
        $sql = db_query('SELECT * FROM content_type_callout WHERE field_identifier_value = "%s" AND field_page_nid = "%d" ORDER BY vid DESC LIMIT 1', $cnid, $pnid);
        $res = db_fetch_array($sql);
        if($res) {
            $cpage_arr[] = $res['nid'];
        } else { //If there is no callout that exists, we need to make it here.
            $callout_node = new stdClass();
            $callout_node->type = 'callout';
            $callout_node->field_page[0]['nid'] = $pnid;
            $callout_node->field_identifier[0]['value'] = $cnid;
            $callout_node->field_sequence[0]['value'] = 0;
            $callout_node->title = "Callout ".$callout." on page ".$page_node->field_page_order[0]['value'];
            $callout_node->field_project[0]['nid'] = $project->nid;
            $callout_node->field_wholesaler[0]['value'] = $project->field_wholesaler[0]['value'];
            $callout_node->field_skus = array();

            $callout_node->status = 1;
            $callout_node->uid = 1;             
            $callout_node->revision = true;
            $callout_node = node_submit($callout_node);
            node_save($callout_node);
            $cpage_arr[] = $callout_node->nid;
        }
    $coc_e++;
    }

    //Now we need to assign the skus to the appropriate callout for processing
    $coc2 = count($cpage_arr);
    $coc_e2 = 0;
    while($coc_e2 < $coc2) {
        $co = $cpage_arr[$coc_e2];
        if($co !== '0') {
            $sku = $merge[$coc_e2];
            $m_arr[$co][] = $sku;
        }
    $coc_e2++;
    }

    //we need a way to centrally store all NID's of SKUs to the callouts they belong to
    $oc_arr = array();
    $oc = count($mcallout_nid);
    $oc_e = 0;
    while($oc_e < $oc) {
        $f_callout = $mcallout_nid[$oc_e];
        $former_callout = node_load($f_callout);
        foreach($former_callout->field_skus as $key=>$skus) {
            $oc_arr[] = $skus;
        }
        $oc_e++;
    }

    //Now we are processing the Pages/Callouts/SKUs to save
    $pc_e2 = 0;
    foreach($m_arr as $key=>$values) {
        $callout = node_load($key);
        foreach($values as $value) {
            $oc = count($oc_arr);
            $oc_e = 0;
            while($oc_e < $oc) {
                $skus = $oc_arr[$oc_e];
                if($value == $skus['nid']) {
                    $callout->field_skus[] = $skus;
                    //$nid = $oc_sku[$value];
                    $old_callout_info[] = $oc_sku[$value];
                    $oc_e = $oc;
                }
                else {
                    $oc_e++;
                }
            }
        }

        foreach($old_callout_info as $nid) {
/*          $nid = $oc_sku[$value]; */
            $former_callout = node_load($nid);
            foreach($former_callout->field_images as $old_image) {
            $callout->field_images[] = $old_image;
            }
            foreach($former_callout->field_line_art as $old_image) {
                $callout->field_line_art[] = $old_image;
            }
            foreach($former_callout->field_swatches as $old_image) {
                $callout->field_swatches[] = $old_image;
            }
            $callout->field_copy_text[0]['value'] .= $former_callout->field_copy_text[0]['value'];
        }
        $callout->field_notes[0]['value'] .= $former_callout->field_notes[0]['value'];
        $callout->field_image_notes[0]['value'] .= $former_callout->field_image_notes[0]['value'];
        $callout->field_logos = $former_callout->field_logos;
        $callout->field_affiliations = $former_callout->field_affiliations;
        $callout->field_graphics = $former_callout->field_graphics;
        $callout->revision = 1;



        $callout->field_status[0]['value'] = 'inprocess';
        node_save($callout);
        $pc_e2++;
    }
    }

これはおそらくある意味で単純化できると思いますが、今のところ、これは私がやろうとしていることを考えると完全に機能します。今のところお客様からのクレームはありません。Drupal コミュニティをご覧いただきありがとうございます。

于 2012-10-29T12:41:50.387 に答える