| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\librarys\shareTree\behaviors;
- use yii\base\Behavior;
- use yii\db\ActiveQuery;
- /**
- *
- * @property ActiveQuery $owner
- */
- class ClosureTableTreePathQueryBehavior extends Behavior
- {
- /**
- * 获取指定父节点下的元素
- *
- * @param int $childId
- * @return $this
- */
- public function byParentId(int $parentId): ActiveQuery
- {
- return $this->owner->andWhere(['parent_id' => $parentId]);
- }
- /**
- * 获取指定子节点上边的父元素
- *
- * @param int $childId
- * @return $this
- */
- public function byChildId(int $childId): ActiveQuery
- {
- return $this->owner->andWhere(['child_id' => $childId]);
- }
- /**
- * 通过非child_id过滤
- *
- * @param int $childId
- * @return $this
- */
- public function byNotChildId(int $childId): ActiveQuery
- {
- return $this->owner->andWhere(['!=', 'child_id', $childId]);
- }
- /**
- * 按父级别筛选
- *
- * @param int $parentLevel
- * @return ActiveQuery
- */
- public function byParentLevel(int $parentLevel): ActiveQuery
- {
- return $this->owner->andWhere(['parent_level' => $parentLevel]);
- }
- /**
- * 按子级别筛选
- *
- * @param int $childLevel
- * @return ActiveQuery
- */
- public function byChildLevel(int $childLevel): ActiveQuery
- {
- return $this->owner->andWhere(['child_level' => $childLevel]);
- }
- /**
- * 确定该节点是否为父节点的子节点
- *
- * @param int $parentId
- * @param int $childId
- * @return ActiveQuery
- */
- public function isChildOf(int $parentId, int $childId): ActiveQuery
- {
- return $this->owner
- ->byParentId($parentId)
- ->byChildId($childId)
- ->byNotChildId($parentId);
- }
- }
|