- Timestamp:
- 2007/08/16 19:39:59 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/feature-module-update/data/class/util/SC_Utils.php
r15290 r15293 426 426 } 427 427 exit; 428 }429 430 // ランキングを上げる。431 function sfRankUp($table, $colname, $id, $andwhere = "") {432 $objQuery = new SC_Query();433 $objQuery->begin();434 $where = "$colname = ?";435 if($andwhere != "") {436 $where.= " AND $andwhere";437 }438 // 対象項目のランクを取得439 $rank = $objQuery->get($table, "rank", $where, array($id));440 // ランクの最大値を取得441 $maxrank = $objQuery->max($table, "rank", $andwhere);442 // ランクが最大値よりも小さい場合に実行する。443 if($rank < $maxrank) {444 // ランクが一つ上のIDを取得する。445 $where = "rank = ?";446 if($andwhere != "") {447 $where.= " AND $andwhere";448 }449 $uprank = $rank + 1;450 $up_id = $objQuery->get($table, $colname, $where, array($uprank));451 // ランク入れ替えの実行452 $sqlup = "UPDATE $table SET rank = ?, update_date = Now() WHERE $colname = ?";453 $objQuery->exec($sqlup, array($rank + 1, $id));454 $objQuery->exec($sqlup, array($rank, $up_id));455 }456 $objQuery->commit();457 }458 459 // ランキングを下げる。460 function sfRankDown($table, $colname, $id, $andwhere = "") {461 $objQuery = new SC_Query();462 $objQuery->begin();463 $where = "$colname = ?";464 if($andwhere != "") {465 $where.= " AND $andwhere";466 }467 // 対象項目のランクを取得468 $rank = $objQuery->get($table, "rank", $where, array($id));469 470 // ランクが1(最小値)よりも大きい場合に実行する。471 if($rank > 1) {472 // ランクが一つ下のIDを取得する。473 $where = "rank = ?";474 if($andwhere != "") {475 $where.= " AND $andwhere";476 }477 $downrank = $rank - 1;478 $down_id = $objQuery->get($table, $colname, $where, array($downrank));479 // ランク入れ替えの実行480 $sqlup = "UPDATE $table SET rank = ?, update_date = Now() WHERE $colname = ?";481 $objQuery->exec($sqlup, array($rank - 1, $id));482 $objQuery->exec($sqlup, array($rank, $down_id));483 }484 $objQuery->commit();485 }486 487 //---- 指定順位へ移動488 function sfMoveRank($tableName, $keyIdColumn, $keyId, $pos, $where = "") {489 $objQuery = new SC_Query();490 $objQuery->begin();491 492 // 自身のランクを取得する493 $rank = $objQuery->get($tableName, "rank", "$keyIdColumn = ?", array($keyId));494 $max = $objQuery->max($tableName, "rank", $where);495 496 // 値の調整(逆順)497 if($pos > $max) {498 $position = 1;499 } else if($pos < 1) {500 $position = $max;501 } else {502 $position = $max - $pos + 1;503 }504 505 if( $position > $rank ) $term = "rank - 1"; //入れ替え先の順位が入れ換え元の順位より大きい場合506 if( $position < $rank ) $term = "rank + 1"; //入れ替え先の順位が入れ換え元の順位より小さい場合507 508 //-- 指定した順位の商品から移動させる商品までのrankを1つずらす509 $sql = "UPDATE $tableName SET rank = $term, update_date = NOW() WHERE rank BETWEEN ? AND ? AND del_flg = 0";510 if($where != "") {511 $sql.= " AND $where";512 }513 514 if( $position > $rank ) $objQuery->exec( $sql, array( $rank + 1, $position ));515 if( $position < $rank ) $objQuery->exec( $sql, array( $position, $rank - 1 ));516 517 //-- 指定した順位へrankを書き換える。518 $sql = "UPDATE $tableName SET rank = ?, update_date = NOW() WHERE $keyIdColumn = ? AND del_flg = 0 ";519 if($where != "") {520 $sql.= " AND $where";521 }522 523 $objQuery->exec( $sql, array( $position, $keyId ) );524 $objQuery->commit();525 }526 527 // ランクを含むレコードの削除528 // レコードごと削除する場合は、$deleteをtrueにする。529 function sfDeleteRankRecord($table, $colname, $id, $andwhere = "", $delete = false) {530 $objQuery = new SC_Query();531 $objQuery->begin();532 // 削除レコードのランクを取得する。533 $where = "$colname = ?";534 if($andwhere != "") {535 $where.= " AND $andwhere";536 }537 $rank = $objQuery->get($table, "rank", $where, array($id));538 539 if(!$delete) {540 // ランクを最下位にする、DELフラグON541 $sqlup = "UPDATE $table SET rank = 0, del_flg = 1, update_date = Now() ";542 $sqlup.= "WHERE $colname = ?";543 // UPDATEの実行544 $objQuery->exec($sqlup, array($id));545 } else {546 $objQuery->delete($table, "$colname = ?", array($id));547 }548 549 // 追加レコードのランクより上のレコードを一つずらす。550 $where = "rank > ?";551 if($andwhere != "") {552 $where.= " AND $andwhere";553 }554 $sqlup = "UPDATE $table SET rank = (rank - 1) WHERE $where";555 $objQuery->exec($sqlup, array($rank));556 $objQuery->commit();557 }558 559 // レコードの存在チェック560 function sfIsRecord($table, $col, $arrval, $addwhere = "") {561 $objQuery = new SC_Query();562 $arrCol = split("[, ]", $col);563 564 $where = "del_flg = 0";565 566 if($addwhere != "") {567 $where.= " AND $addwhere";568 }569 570 foreach($arrCol as $val) {571 if($val != "") {572 if($where == "") {573 $where = "$val = ?";574 } else {575 $where.= " AND $val = ?";576 }577 }578 }579 $ret = $objQuery->get($table, $col, $where, $arrval);580 581 if($ret != "") {582 return true;583 }584 return false;585 428 } 586 429
Note: See TracChangeset
for help on using the changeset viewer.