Beispiel #1
0
 /**
  * @inheritdoc
  */
 public function getInheritedChildModels($parentObject)
 {
     $p = [];
     if (isset($this->owner->objectTypeItem) && !empty($this->owner->objectTypeItem->children)) {
         foreach ($this->owner->objectTypeItem->children as $relationship) {
             $relationshipId = $parentObject->objectType->systemId . '.' . $relationship->child->systemId;
             if (!Relationship::getById($relationshipId)) {
                 continue;
             }
             if ($relationship->parentInherit) {
                 $p[] = $relationship->child->primaryModel;
             }
         }
     }
     return $p;
 }
Beispiel #2
0
 /**
  * @inheritdoc
  */
 public function getItems()
 {
     $instructions = $this->instructions;
     $items = [];
     if (!isset($instructions['typeFilters'])) {
         $instructions['typeFilters'] = [];
     } elseif (!is_array($instructions['typeFilters'])) {
         $instructions['typeFilters'] = [$instructions['typeFilters']];
     }
     if (!isset($instructions['modules'])) {
         $instructions['modules'] = false;
     }
     if (isset($instructions['relationshipRole'])) {
         if (!isset($instructions['relationship'])) {
             throw new InvalidConfigException("Relationship type tasks require a relationship ID");
         }
         $relationship = Relationship::getById($instructions['relationship']);
         if (empty($relationship)) {
             throw new InvalidConfigException("Relationship type tasks require a relationship");
         }
         if ($instructions['relationshipRole'] === 'parent') {
             $relationships = $relationship->parent->collectorItem->parents;
             $baseType = $relationship->parent;
         } else {
             $relationships = $relationship->child->collectorItem->parents;
             $baseType = $relationship->child;
         }
         $types = ArrayHelper::map($relationships, 'parent.systemId', 'parent');
         $types[$baseType->systemId] = $baseType;
     } else {
         $typesRaw = Yii::$app->collectors['types']->getAll();
         $types = ArrayHelper::map($typesRaw, 'object.systemId', 'object');
     }
     unset($types['']);
     foreach ($types as $typeKey => $type) {
         if (isset($instructions['limitTypes'])) {
             if (!in_array($typeKey, $instructions['limitTypes'])) {
                 continue;
             }
         }
         if (in_array('hasDashboard', $instructions['typeFilters']) && !$type->hasDashboard) {
             continue;
         }
         if (in_array('authority', $instructions['typeFilters']) && $type->getBehavior('Authority') === null) {
             continue;
         }
         $item = ['type' => 'type', 'id' => $type->systemId, 'descriptor' => $type->title->upperPlural, 'hasChildren' => !empty($type->collectorItem->children) || $instructions['modules'] !== false && in_array($type->systemId, $instructions['modules'])];
         if ($item['hasChildren'] && (!$this->filterQuery || preg_match('/' . preg_quote($this->filterQuery) . '/i', $item['descriptor']) === 1)) {
             $items[] = $item;
         }
     }
     if (!$this->filterQuery) {
         ArrayHelper::multisort($items, 'descriptor', SORT_ASC);
     } else {
         $filterQuery = $this->filterQuery;
         usort($items, function ($a, $b) use($filterQuery) {
             $a = levenshtein($a['descriptor'], $filterQuery);
             $b = levenshtein($b['descriptor'], $filterQuery);
             return $a < $b ? -1 : 1;
         });
     }
     return $items;
 }