CategoryRepository
in package
カテゴリーのリポジトリ
Table of Contents
Methods
- changeParent() : bool
- カテゴリーの親を付け替え、ツリーの left/right/sort を再配置する
- delete() : void
- カテゴリーを物理削除し、関連リソース(fulltext / geo / entry_sub_category / カスタムフィールド / ワークフロー)も一括削除する
- exists() : bool
- カテゴリーが存在するかチェック
- existsByCode() : bool
- 同じブログ内、(strict mode の場合のみ)同じ親内に同一 code のカテゴリーが存在するか
- existsCategoryInDescendantBlogs() : bool
- 自ブログの子孫ブログに同一コードのカテゴリーが存在するか (自身を global に設定したい場合のチェックに利用)
- existsGlobalCategoryInAncestorBlogs() : bool
- 自ブログの祖先ブログにグローバルカテゴリー(同一コード)が存在するか
- findBoundary() : array{left: int, right: int}|null
- 指定カテゴリーの左右値(nested set)境界を取得
- findDescendantIdsInclusive() : array<string|int, int>
- 自身と子孫の category_id 一覧を返す(nested set の左右値 inclusive 範囲)
- findMaxRightCategoryInBlog() : array<string, mixed>|null
- 指定ブログ内で category_right が最大の行を返す(新規追加時の位置計算に利用)
- hasChildren() : bool
- 指定カテゴリーが子カテゴリーを持つか
- hasClosedAncestor() : bool
- 指定カテゴリーの祖先(自身は含まない)に category_status='close' のものがあるか
- hasEntryInOtherBlog() : bool
- 指定カテゴリーを参照するエントリーが、指定ブログ以外のブログに存在するか
- insert() : void
- カテゴリーを新規 INSERT
- isDescendantOf() : bool
- $descendantId が $ancestorId の真の子孫(自分自身を除く)かどうか
- nextCategoryId() : int
- category_id のシーケンスから次の値を採番
- reorderSibling() : bool
- 同一親内での並び順を $toSort に変更し、関連する left/right/sort を再配置
- update() : void
- 指定カラムで対象カテゴリーを UPDATE
- updateConfigSetBulk() : void
- 指定カテゴリー ID 群の config_set_id を一括更新
- updateDescendants() : void
- 指定ブログ内、祖先境界 (ancestorLeft, ancestorRight) 内の子孫カテゴリーを 一括 UPDATE(祖先自身は更新しない)
- updateStatusBulk() : void
- 指定 ID 群の category_status を一括更新
- findCategoryRow() : array<string, mixed>|null
- 指定 ID のカテゴリー行を取得(存在しなければ null)
- inheritStatusFromCurrentParent() : void
- 指定カテゴリーが現在所属する親の status を継承し、自身と子孫の category_status を 親に揃える。親が open / 存在しない / parent=0 の場合は何もしない。
- realignTreeAfterRemoval() : void
- カテゴリー削除に伴う nested set ツリーの詰め直し
- unsetEntryCategoryRef() : void
- 対象カテゴリーを参照するエントリーの entry_category_id を NULL にリセット
Methods
changeParent()
カテゴリーの親を付け替え、ツリーの left/right/sort を再配置する
public
changeParent(int $categoryId, int $toParentId, int $blogId) : bool
以下の場合は false を返す:
- 自分自身を親に指定
- 指定カテゴリーが対象ブログに存在しない
- すでに同じ親(no-op)
- 新しい親が自分の子孫
Parameters
- $categoryId : int
- $toParentId : int
- $blogId : int
Return values
booldelete()
カテゴリーを物理削除し、関連リソース(fulltext / geo / entry_sub_category / カスタムフィールド / ワークフロー)も一括削除する
public
delete(int $categoryId) : void
削除前に対象カテゴリーの行を取得し、参照エントリーの category_id リセットと nested set ツリーの詰め直しを内部で実施する。
Parameters
- $categoryId : int
exists()
カテゴリーが存在するかチェック
public
exists(int $categoryId[, int|null $blogId = null ]) : bool
Parameters
- $categoryId : int
-
カテゴリーID
- $blogId : int|null = null
-
ブログID(指定された場合、そのブログに属するかもチェック)
Return values
bool —存在する場合true
existsByCode()
同じブログ内、(strict mode の場合のみ)同じ親内に同一 code のカテゴリーが存在するか
public
existsByCode(string $code, int $blogId, bool $strictParent, int $parentId, int|null $excludeCategoryId) : bool
Parameters
- $code : string
- $blogId : int
- $strictParent : bool
-
true の場合、$parentId 内で重複チェック
- $parentId : int
- $excludeCategoryId : int|null
-
除外したいカテゴリーID(編集時に自分自身を除く)
Return values
boolexistsCategoryInDescendantBlogs()
自ブログの子孫ブログに同一コードのカテゴリーが存在するか (自身を global に設定したい場合のチェックに利用)
public
existsCategoryInDescendantBlogs(string $code, int $blogId) : bool
Parameters
- $code : string
- $blogId : int
Return values
boolexistsGlobalCategoryInAncestorBlogs()
自ブログの祖先ブログにグローバルカテゴリー(同一コード)が存在するか
public
existsGlobalCategoryInAncestorBlogs(string $code, int $blogId) : bool
Parameters
- $code : string
- $blogId : int
Return values
boolfindBoundary()
指定カテゴリーの左右値(nested set)境界を取得
public
findBoundary(int $categoryId) : array{left: int, right: int}|null
Parameters
- $categoryId : int
Return values
array{left: int, right: int}|nullfindDescendantIdsInclusive()
自身と子孫の category_id 一覧を返す(nested set の左右値 inclusive 範囲)
public
findDescendantIdsInclusive(int $categoryId, int $blogId) : array<string|int, int>
Parameters
- $categoryId : int
- $blogId : int
Return values
array<string|int, int>findMaxRightCategoryInBlog()
指定ブログ内で category_right が最大の行を返す(新規追加時の位置計算に利用)
public
findMaxRightCategoryInBlog(int $blogId) : array<string, mixed>|null
Parameters
- $blogId : int
Return values
array<string, mixed>|nullhasChildren()
指定カテゴリーが子カテゴリーを持つか
public
hasChildren(int $categoryId) : bool
Parameters
- $categoryId : int
Return values
boolhasClosedAncestor()
指定カテゴリーの祖先(自身は含まない)に category_status='close' のものがあるか
public
hasClosedAncestor(int $categoryId, int $blogId) : bool
Parameters
- $categoryId : int
- $blogId : int
Return values
boolhasEntryInOtherBlog()
指定カテゴリーを参照するエントリーが、指定ブログ以外のブログに存在するか
public
hasEntryInOtherBlog(int $categoryId, int $blogId) : bool
Parameters
- $categoryId : int
- $blogId : int
Return values
boolinsert()
カテゴリーを新規 INSERT
public
insert(array<string, mixed> $columns) : void
Parameters
- $columns : array<string, mixed>
-
カラム名 => 値
isDescendantOf()
$descendantId が $ancestorId の真の子孫(自分自身を除く)かどうか
public
isDescendantOf(int $descendantId, int $ancestorId, int $blogId) : bool
Parameters
- $descendantId : int
- $ancestorId : int
- $blogId : int
Return values
boolnextCategoryId()
category_id のシーケンスから次の値を採番
public
nextCategoryId() : int
Return values
intreorderSibling()
同一親内での並び順を $toSort に変更し、関連する left/right/sort を再配置
public
reorderSibling(int $categoryId, int $toSort, int $blogId) : bool
Parameters
- $categoryId : int
- $toSort : int
- $blogId : int
Return values
bool —成功時 true、無効な対象 / 同位置 / 範囲外などは false
update()
指定カラムで対象カテゴリーを UPDATE
public
update(int $categoryId, array<string, mixed> $columns) : void
Parameters
- $categoryId : int
- $columns : array<string, mixed>
-
カラム名 => 値
updateConfigSetBulk()
指定カテゴリー ID 群の config_set_id を一括更新
public
updateConfigSetBulk(array<string|int, int|string> $categoryIds, int|null $configSetId) : void
Parameters
- $categoryIds : array<string|int, int|string>
-
更新対象 ID 群
- $configSetId : int|null
-
設定する config_set_id。null で解除
updateDescendants()
指定ブログ内、祖先境界 (ancestorLeft, ancestorRight) 内の子孫カテゴリーを 一括 UPDATE(祖先自身は更新しない)
public
updateDescendants(int $blogId, int $ancestorLeft, int $ancestorRight, array<string, mixed> $columns) : void
Parameters
- $blogId : int
- $ancestorLeft : int
- $ancestorRight : int
- $columns : array<string, mixed>
-
カラム名 => 値
updateStatusBulk()
指定 ID 群の category_status を一括更新
public
updateStatusBulk(array<string|int, int|string> $categoryIds, string $status) : void
Parameters
- $categoryIds : array<string|int, int|string>
- $status : string
findCategoryRow()
指定 ID のカテゴリー行を取得(存在しなければ null)
private
findCategoryRow(int $categoryId) : array<string, mixed>|null
Parameters
- $categoryId : int
Return values
array<string, mixed>|nullinheritStatusFromCurrentParent()
指定カテゴリーが現在所属する親の status を継承し、自身と子孫の category_status を 親に揃える。親が open / 存在しない / parent=0 の場合は何もしない。
private
inheritStatusFromCurrentParent(int $categoryId, int $blogId) : void
changeParent 内部から呼ばれ、親変更後の status 不整合を防ぐ。
Parameters
- $categoryId : int
- $blogId : int
realignTreeAfterRemoval()
カテゴリー削除に伴う nested set ツリーの詰め直し
private
realignTreeAfterRemoval(array<string, mixed> $category) : void
- left/right が削除位置より後の行はギャップ 2 ぶん -2
- 削除カテゴリーの内側(祖先 - 子孫境界内)は -1(削除カテゴリーは通常リーフのため通常該当しない)
- 同一親内の sort が削除位置より大きい兄弟は -1
Parameters
- $category : array<string, mixed>
-
削除直前のカテゴリーレコード(category テーブル1行)
unsetEntryCategoryRef()
対象カテゴリーを参照するエントリーの entry_category_id を NULL にリセット
private
unsetEntryCategoryRef(int $categoryId) : void
Parameters
- $categoryId : int