當前位置: 首頁>>代碼示例>>PHP>>正文


PHP item::resequence_child_weights方法代碼示例

本文整理匯總了PHP中item::resequence_child_weights方法的典型用法代碼示例。如果您正苦於以下問題:PHP item::resequence_child_weights方法的具體用法?PHP item::resequence_child_weights怎麽用?PHP item::resequence_child_weights使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在item的用法示例。


在下文中一共展示了item::resequence_child_weights方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: rearrange

 function rearrange()
 {
     access::verify_csrf();
     $input = Input::instance();
     $target = ORM::factory("item", $input->post("target_id"));
     if (!$target->loaded()) {
         json::reply(null);
         return;
     }
     $album = $target->parent();
     access::required("edit", $album);
     if ($album->sort_column != "weight") {
         // Force all the weights into the current order before changing the order to manual
         // @todo: consider making this a trigger in the Item_Model.
         item::resequence_child_weights($album);
         $album->sort_column = "weight";
         $album->sort_order = "ASC";
         $album->save();
     }
     $source_ids = explode(",", $input->post("source_ids"));
     $base_weight = $target->weight;
     if ($input->post("relative") == "after") {
         $base_weight++;
     }
     if ($source_ids) {
         // Make a hole the right size
         db::build()->update("items")->set("weight", db::expr("`weight` + " . count($source_ids)))->where("parent_id", "=", $album->id)->where("weight", ">=", $base_weight)->execute();
         // Move all the source items to the right spots.
         for ($i = 0; $i < count($source_ids); $i++) {
             $source = ORM::factory("item", $source_ids[$i]);
             if ($source->parent_id == $album->id) {
                 $source->weight = $base_weight + $i;
                 $source->save();
             }
         }
     }
     json::reply(null);
 }
開發者ID:HarriLu,項目名稱:gallery3,代碼行數:38,代碼來源:organize.php

示例2: resequence_child_weights_test

 public function resequence_child_weights_test()
 {
     $album = test::random_album_unsaved();
     $album->sort_column = "id";
     $album->save();
     $photo1 = test::random_photo($album);
     $photo2 = test::random_photo($album);
     $this->assert_true($photo2->weight > $photo1->weight);
     $album->reload();
     $album->sort_order = "DESC";
     $album->save();
     item::resequence_child_weights($album);
     $this->assert_equal(2, $photo1->reload()->weight);
     $this->assert_equal(1, $photo2->reload()->weight);
 }
開發者ID:HarriLu,項目名稱:gallery3,代碼行數:15,代碼來源:Item_Helper_Test.php


注:本文中的item::resequence_child_weights方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。