/** * Get unmapped foreign keys. * * @return array the foreign keys that haven't been mapped */ public function getUnmappedForeignKeys() { $mappedForeign = ArrayHelper::getColumn($this->_map, 'foreignKey'); $u = array_diff(array_keys($this->foreignModel->meta->schema->columns), $mappedForeign); unset($u[$this->foreignPrimaryKeyName]); return $u; }
/** * Get interface. * * @return Item The data interface */ public function getDataInterface() { if (!$this->started) { return $this->_interface; } if (is_null($this->_interface)) { $interfaces = ArrayHelper::map(Yii::$app->collectors['dataInterfaces']->getAll(), 'systemId', 'object.name'); $this->dataInterface = $this->select("Choose interface", $interfaces); } return $this->_interface; }
/** * Get module. * * @return [[@doctodo return_type:getModule]] [[@doctodo return_description:getModule]] */ public function getModule() { $method = ArrayHelper::getValue($this->parentWidget->settings, 'queryRole', 'all'); $relationship = ArrayHelper::getValue($this->parentWidget->settings, 'relationship', false); if ($method === 'children') { return $relationship->child; } elseif ($method === 'parents') { return $relationship->parent; } return false; }
/** * {@inheritdocs}. */ public function generate() { $this->type = 'dropDownList'; $baseOptions = []; if (!$this->modelField->taxonomy->required) { $baseOptions[''] = ''; } $this->options = array_merge($baseOptions, ArrayHelper::map($this->modelField->taxonomy->taxonomies, 'id', 'name')); if ($this->modelField->taxonomy->multiple) { $this->htmlOptions['multiple'] = true; } return parent::generate(); }
/** * [[@doctodo method_description:handleInstructions]]. * * @param [[@doctodo param_type:params]] $params [[@doctodo param_description:params]] */ public function handleInstructions($params) { $this->clearParams($params); //\d($params); $this->scope = ArrayHelper::getValue($params, 'scope', 'watching'); $direction = $this->direction = ArrayHelper::getValue($params, 'direction', '_older'); $limit = ArrayHelper::getValue($params, 'limit', 25); $object = $this->context = ArrayHelper::getValue($params, 'object', false); if ($direction === '_newer') { $mostRecentItem = ArrayHelper::getValue($params, 'mostRecentItem', false); $this->query->andWhere($this->query->primaryAlias . '.[[created]] > FROM_UNIXTIME(' . (double) $mostRecentItem . ')'); $this->query->orderBy([$this->query->primaryAlias . '.[[created]]' => SORT_DESC]); $this->pagination->pageSize = false; //\d(["newer", $this->query->createCommand()->rawSql]);exit; } else { // _older $this->pagination->pageSize = $limit; $lastTime = ArrayHelper::getValue($params, 'lastItemTimestamp', false); $lastItem = ArrayHelper::getValue($params, 'lastItem', false); if ($lastItem) { $this->query->andWhere($this->query->primaryAlias . '.[[created]] < FROM_UNIXTIME(' . (double) $lastItem . ')'); } $this->query->orderBy([$this->query->primaryAlias . '.[[created]]' => SORT_DESC]); //SORT_ASC //\d($lastTime); //echo $this->query->createCommand()->rawSql;exit; } if ($this->scope === 'object' && $object) { $this->query->andWhere(['or', [$this->query->primaryAlias . '.direct_object_id' => $object], [$this->query->primaryAlias . '.indirect_object_id' => $object]]); } elseif ($this->scope !== 'all' && !empty(Yii::$app->user->id)) { $subquery = ObjectFamiliarity::find(); $subquery->andWhere([$subquery->primaryAlias . '.user_id' => Yii::$app->user->id]); if ($this->scope === 'watching') { $subquery->andWhere([$subquery->primaryAlias . '.watching' => 1]); } $subquery->select(['object_id']); $this->query->join('INNER JOIN', ['sof' => $subquery], ['or', '{{sof}}.[[object_id]] = {{' . $this->query->primaryAlias . '}}.[[direct_object_id]]', '{{sof}}.[[object_id]] = {{' . $this->query->primaryAlias . '}}.[[indirect_object_id]]']); $this->query->distinct = true; } else { $this->scope = 'all'; } }
/** * Get sections. * * @return unknown */ public function getSections() { if (!is_null($this->_sections)) { return $this->_sections; } $this->_sections = []; foreach ($this->_children as $rel) { if (!$rel->active) { continue; } // if ($rel->isHasOne()) { continue; } $child = $rel->child; $instanceSettings = ['relationship' => $rel, 'queryRole' => 'children']; $items = Yii::$app->collectors['widgets']->getLocation('parent_objects', $child); foreach ($items as $item) { $widgetObject = $item->object; $item->settings = $instanceSettings; $section = $item->getSection($widgetObject, $instanceSettings); if (empty($section)) { continue; } if (!isset($this->_sections[$item->section->systemId])) { $this->_sections[$section->systemId] = $section; } $this->_sections[$section->systemId]->register($this, $item); } } foreach ($this->_parents as $rel) { if (!$rel->active) { continue; } if ($rel->isHasOne()) { continue; } $parent = $rel->parent; $instanceSettings = ['relationship' => $rel, 'queryRole' => 'parents']; $items = Yii::$app->collectors['widgets']->getLocation('child_objects', $parent); foreach ($items as $item) { $item->settings = $instanceSettings; $section = $item->getSection($this->object); if (empty($section)) { continue; } if (!isset($this->_sections[$item->section->systemId])) { $this->_sections[$section->systemId] = $section; } $this->_sections[$section->systemId]->register($this, $item); } } $items = Yii::$app->collectors['widgets']->getLocation('self', $this->object); foreach ($items as $item) { $item->settings = $instanceSettings; $section = $item->getSection($this->object); if (empty($section)) { continue; } if (!isset($this->_sections[$item->section->systemId])) { $this->_sections[$section->systemId] = $section; } $this->_sections[$section->systemId]->register($this, $item); } ArrayHelper::multisort($this->_sections, ['priority', 'sectionTitle'], [SORT_ASC, SORT_ASC]); return $this->_sections; }
<?php use canis\helpers\ArrayHelper; use canis\helpers\Html; use canis\web\grid\Cell; use canis\web\grid\Grid; use yii\helpers\Url; $js = []; $this->title = 'Dashboard'; $refreshable = ['url' => Url::to(['/app/stream']), 'stream' => true, 'data' => ['baseInstructions' => []]]; $this->bodyHtmlOptions['data-refreshable'] = json_encode($refreshable); echo Html::beginTag('div', ['class' => 'ic-dashboard row']); Yii::beginProfile("Build Grid"); $widgets = Yii::$app->collectors['widgets']->getLocation('front'); ArrayHelper::multisort($widgets, ['priority', 'name'], [SORT_ASC, SORT_ASC]); $topGrid = new Grid(); $watchingWidget = Yii::$app->collectors['widgets']->getOne('WatchingContent'); $watchingCell = Yii::$app->collectors['widgets']->build(null, $watchingWidget, [], ['columns' => 6]); $topGrid->currentRow->addCell($watchingCell); $itemsCell = $topGrid->currentRow->addCell(new Cell(['columns' => 6])); $widgetGrid = new Grid(); Html::addCssClass($widgetGrid->htmlOptions, 'ic-front-side'); $js[] = '$("#' . $widgetGrid->id . '").canisAffix();'; $widgetGrid->baseRow = ['trueWidth' => 6]; $cells = []; Yii::beginProfile("Collect Widgets"); foreach ($widgets as $item => $widget) { $cells[] = Yii::$app->collectors['widgets']->build(null, $widget, [], []); } Yii::endProfile("Collect Widgets"); $widgetGrid->cells = $cells;
<?php /** * @var yii\base\View */ use canis\helpers\ArrayHelper; use canis\helpers\Html; use canis\daemon\widgets\ExtendedStatus as DaemonStatus; \canis\web\assetBundles\CanisLogViewerAsset::register($this); ArrayHelper::multisort($tasks, 'title'); $this->title = 'Administration'; // $this->params['breadcrumbs'][] = ['label' => 'Administration', 'url' => ['/admin/index']]; $this->params['breadcrumbs'][] = ['label' => $this->title]; echo Html::beginTag('div', ['class' => 'panel panel-default']); echo Html::beginTag('div', ['class' => 'panel-heading']); echo Html::beginTag('h3', ['class' => 'panel-title']); echo Html::beginTag('div', ['class' => 'btn-group btn-group-sm pull-right']); echo Html::endTag('div'); echo 'Administration Tasks'; echo Html::endTag('h3'); echo Html::endTag('div'); echo Html::beginTag('div', ['class' => 'panel-body']); echo Html::beginTag('div', ['class' => 'list-group']); foreach ($tasks as $taskId => $task) { $dataHandler = ''; if (!isset($task['url'])) { $dataHandler = 'background'; $task['url'] = ['/admin/index', 'task' => $taskId]; } echo Html::a(Html::tag('h4', $task['title'], ['class' => 'list-group-item-heading']) . Html::tag('div', $task['description'], ['class' => 'list-group-item-text']), $task['url'], ['class' => 'list-group-item', 'data-handler' => $dataHandler]); }
/** * @param unknown $model (optional) * @param unknown $univeralFieldSettings (optional) * * @return unknown */ public function getFields($owner = null) { if (!isset($this->_fields)) { $disabledFields = $this->objectType->disabledFields; $modelName = self::className(); $this->_fields = []; $fieldSettings = $this->fieldSettings(); $aliases = []; foreach (self::getTableSchema()->columns as $name => $column) { if (in_array($name, $disabledFields)) { continue; } $settings = []; if (isset($fieldSettings[$name])) { $settings = array_merge_recursive($settings, $fieldSettings[$name]); } if (isset($settings['alias'])) { $aliases[$name] = $settings['alias']; unset($settings['alias']); } if (is_array($column)) { $column = $this->createColumnSchema($name, $column); } $this->_fields[$name] = $this->createField($column, $owner, $settings); } $objectTypeItem = $this->objectTypeItem; if ($objectTypeItem) { $relationRelationship = null; $relationClass = Yii::$app->classes['Relation']; $taxonomies = $objectTypeItem->taxonomies; foreach ($objectTypeItem->parents as $relationship) { $fieldName = 'parent:' . $relationship->parent->systemId; if (in_array($fieldName, $disabledFields)) { continue; } $fieldSchema = $this->createColumnSchema($fieldName, ['type' => 'relation', 'phpType' => 'object', 'dbType' => 'relation', 'allowNull' => true]); $settings = []; if (isset($fieldSettings[$fieldName])) { $settings = array_merge_recursive($settings, $fieldSettings[$fieldName]); } if (isset($settings['alias'])) { $aliases[$fieldName] = $settings['alias']; unset($settings['alias']); } $settings['modelRole'] = 'child'; $settings['relationship'] = $relationship; $this->_fields[$fieldName] = $this->createRelationField($fieldSchema, $owner, $settings); } foreach ($objectTypeItem->children as $relationship) { $fieldName = 'child:' . $relationship->child->systemId; if (in_array($fieldName, $disabledFields)) { continue; } $fieldSchema = $this->createColumnSchema($fieldName, ['type' => 'relation', 'phpType' => 'object', 'dbType' => 'relation', 'allowNull' => true]); $settings = []; if (isset($fieldSettings[$fieldName])) { $settings = array_merge_recursive($settings, $fieldSettings[$fieldName]); } if (isset($settings['alias'])) { $aliases[$fieldName] = $settings['alias']; unset($settings['alias']); } $settings['modelRole'] = 'parent'; $settings['relationship'] = $relationship; $this->_fields[$fieldName] = $this->createRelationField($fieldSchema, $owner, $settings); } foreach ($taxonomies as $taxonomy) { if (!in_array(self::className(), $taxonomy->models)) { continue; } $fieldName = 'taxonomy:' . $taxonomy->systemId; if (in_array($fieldName, $disabledFields)) { continue; } $fieldSchema = $this->createColumnSchema($fieldName, ['type' => 'taxonomy', 'phpType' => 'object', 'dbType' => 'taxonomy', 'allowNull' => true]); $settings = []; if (isset($fieldSettings[$fieldName])) { $settings = array_merge_recursive($settings, $fieldSettings[$fieldName]); } if (isset($settings['alias'])) { $aliases[$fieldName] = $settings['alias']; unset($settings['alias']); } $settings['model'] = $this; $this->_fields[$fieldName] = $this->createTaxonomyField($fieldSchema, $taxonomy, $owner); } } foreach ($this->additionalFields() as $name => $column) { if (in_array($name, $disabledFields)) { continue; } $settings = []; if (isset($fieldSettings[$name])) { $settings = array_merge_recursive($settings, $fieldSettings[$name]); } if (isset($settings['alias'])) { $aliases[$name] = $settings['alias']; unset($settings['alias']); } if (is_string($column) && isset($this->_fields[$column])) { $this->_fields[$name] = $this->duplicateField($name, $this->_fields[$column], $owner, $settings); } elseif (is_array($column)) { $column = $this->createColumnSchema($name, $column); $this->_fields[$name] = $this->createField($column, $owner, $settings); } else { $this->_fields[$name] = $this->createField($column, $owner, $settings); } } foreach ($aliases as $from => $to) { if (isset($this->_fields[$to])) { $this->_fields[$from] = $this->_fields[$to]; } } $currentKeys = array_keys($this->_fields); foreach ($this->_fields as $name => $field) { if (!isset($field->priority)) { $field->priority = (int) array_search($name, $currentKeys); $field->priority = $field->priority * 100; } } $this->_fields['relationTaxonomies'] = $this->createRelationTaxonomyField($owner, []); ArrayHelper::multisort($this->_fields, 'priority', SORT_ASC); } if (!empty($owner)) { foreach ($this->_fields as $field) { if (!$field->formField) { continue; } $field->formField->owner = $owner; } } return $this->_fields; }
/** * [[@doctodo method_description:searchLocal]]. * * @param cascade\components\dataInterface\DataItem $item [[@doctodo param_description:item]] * @param array $searchParams [[@doctodo param_description:searchParams]] [optional] * * @return [[@doctodo return_type:searchLocal]] [[@doctodo return_description:searchLocal]] */ public function searchLocal(DataItem $item, $searchParams = []) { if (empty($searchParams['searchFields'])) { $searchParams['searchFields'] = $this->localFields; } if (empty($searchParams['searchFields'])) { return; } if (!isset($searchParams['limit'])) { $searchParams['limit'] = 5; } $searchParams['skipForeign'] = true; $query = []; foreach ($this->foreignFields as $field) { if (!empty($item->foreignObject->{$field})) { $value = $item->foreignObject->{$field}; if (isset($this->foreignFilter)) { $value = call_user_func($this->foreignFilter, $value); } $query[] = $value; } } if (empty($query)) { return; } $localClass = $this->dataSource->localModel; $searchResults = $localClass::searchTerm(implode(' ', $query), $searchParams); $resultsLeft = $totalResults = count($searchResults); foreach ($searchResults as $k => $r) { // if ($r->descriptor === $query[0]) { continue; } $score = $resultsLeft / $totalResults * 100 * 0.2 + StringHelper::compareStrings($r->descriptor, implode(' ', $query)) * 0.8; $r->score = $score; if ($score < $this->threshold) { unset($searchResults[$k]); } else { $reverseKey = $this->dataSource->getReverseKeyTranslation($r->id); if (!empty($reverseKey)) { unset($searchResults[$k]); } } $resultsLeft--; } ArrayHelper::multisort($searchResults, 'scoreSort', SORT_DESC); $searchResults = array_values($searchResults); if (empty($searchResults)) { return; } elseif ($safeResult = $this->getSafeResult($searchResults)) { $this->dataSource->task->addInfo('Auto-matched "' . implode(' ', $query) . '" to "' . $safeResult->descriptor . '" (Score: ' . round($safeResult->score, 2) . ')', ['query' => $query, 'foreignObject' => $item->foreignObject->attributes, 'localObject' => ['id' => $safeResult->id, 'descriptor' => $safeResult->descriptor]]); return $safeResult->object; } else { $options = []; $resultsNice = []; $optionNumber = 1; $defaultOption = 'new'; if ($searchResults[0]->score > $this->defaultOptionThreshold) { $defaultOption = '1'; } foreach ($searchResults as $result) { $resultsNice['' . $optionNumber] = $result; $options['' . $optionNumber] = $result->descriptor . ' (' . round($result->score) . '%)'; $optionNumber++; } $options['new'] = 'Create New Object'; $options['selectObject'] = 'Select Object'; $select = false; $interactionOptions = ['inputType' => 'select', 'options' => $options]; $interactionOptions['details'] = $item->foreignObject->attributes; $interactionOptions['default'] = $defaultOption; $callback = ['callback' => function ($response) use(&$select, $options) { if (empty($response)) { return false; } if (substr($response, 0, 2) !== '*-' && !isset($options[$response])) { return false; } $select = $response; return true; }]; if (!$this->dataSource->action->createInteraction('Match Object (' . implode(' ', $query) . ')', $interactionOptions, $callback)) { return false; } if ($select === 'new') { $this->dataSource->task->addInfo('For "' . implode(' ', $query) . '" user chose to to create new object', ['query' => $query, 'foreignObject' => $item->foreignObject->attributes]); return; } elseif (substr($select, 0, 2) === '*-') { $matchedObjectId = substr($select, 2); $matchedObject = Registry::getObject($matchedObjectId, false); if (!$matchedObject) { $this->dataSource->task->addWarning('For "' . implode(' ', $query) . '" user tried to match it to a different object, but object wasn\'t found! Created new object.', ['query' => $query, 'foreignObject' => $item->foreignObject->attributes, 'matchedObject' => $matchedObjectId]); return; } $this->dataSource->task->addInfo('For "' . implode(' ', $query) . '" matched to an existing object "' . $matchedObject->descriptor . '"', ['query' => $query, 'foreignObject' => $item->foreignObject->attributes, 'matchedObject' => $matchedObject->attributes]); return $matchedObject; } else { $this->dataSource->task->addInfo('User matched "' . implode(' ', $query) . '" to "' . $resultsNice[$select]->descriptor . '"', ['query' => $query, 'foreignObject' => $item->foreignObject->attributes, 'localObject' => $resultsNice[$select]->id]); return $resultsNice[$select]->object; } } }
/** * Get taxonomy list. * * @return unknown */ public function getTaxonomyList() { return ArrayHelper::map($this->getTaxonomies(), 'id', 'name'); }
/** * Get table registry. * * @return [[@doctodo return_type:getTableRegistry]] [[@doctodo return_description:getTableRegistry]] */ public function getTableRegistry() { if (is_null($this->_tableRegistry)) { $objectTypeClass = Yii::$app->classes['ObjectTypeRegistry']; $this->_tableRegistry = []; if ($objectTypeClass::tableExists()) { $om = $objectTypeClass::find()->all(); $this->_tableRegistry = ArrayHelper::index($om, 'name'); } } return $this->_tableRegistry; }
/** * Renders the pager. * * @return string the rendering result */ public function renderPager() { $pagination = $this->dataProvider->getPagination(); //\d([get_class($this), $pagination]); if ($pagination === false || $pagination->getPageCount() <= 1) { return false; } /* @var LinkPager $class */ $pager = $this->pagerSettings; $class = ArrayHelper::remove($pager, 'class', 'canis\\widgets\\LinkPager'); $pager['pagination'] = $pagination; if (!isset($pager['options'])) { $pager['options'] = []; } $pager['maxButtonCount'] = 6; Html::addCssClass($pager['options'], 'pagination pull-right'); return $class::widget($pager); }
/** * Get widgets. * * @return [[@doctodo return_type:getWidgets]] [[@doctodo return_description:getWidgets]] */ public function getWidgets() { $widgets = $this->collectorItem->getAll(); ArrayHelper::multisort($widgets, ['object.priority', 'object.name'], [SORT_ASC, SORT_ASC]); return $widgets; }
/** * @inheritdoc */ public function getRequestors($accessingObject, $firstLevel = true) { if (!$firstLevel) { $parentAccounts = $accessingObject->parents($this->primaryModel, [], ['disableAccessCheck' => true]); if (!empty($parentAccounts)) { return ArrayHelper::getColumn($parentAccounts, 'id', false); } } return false; }
public function getMenuItems($model, $key, $index) { $objectType = $model->objectType; $menu = []; $baseUrl = ['id' => $model->primaryKey]; $queryRole = ArrayHelper::getValue($this->settings, 'queryRole', false); $relationship = ArrayHelper::getValue($this->settings, 'relationship', false); // $relationModel = $this->getObjectRelationModel($model); $baseUrl['related_object_id'] = Yii::$app->request->object->primaryKey; // $baseUrl['relationship_id'] = $relationship->systemId; if ($queryRole === 'children') { $primaryRelation = $relationship->getPrimaryObject(Yii::$app->request->object, $model, 'child'); $baseUrl['object_relation'] = 'child:' . $model->objectType->systemId; $checkField = 'child_object_id'; } else { $primaryRelation = $relationship->getPrimaryObject(Yii::$app->request->object, $model, 'parent'); $baseUrl['object_relation'] = 'parent:' . $model->objectType->systemId; $checkField = 'parent_object_id'; } if ($primaryRelation !== false && (empty($primaryRelation) || $primaryRelation && $primaryRelation->{$checkField} !== $model->primaryKey)) { $menu['primary'] = ['icon' => 'fa fa-star', 'label' => 'Set as primary', 'url' => ['/object/set-primary'] + $baseUrl, 'linkOptions' => ['data-handler' => 'background']]; } // update button $updateLabel = false; if (!$objectType->hasDashboard && $model->can('update')) { $updateLabel = 'Update'; $updateUrl = ['/object/update'] + $baseUrl; } elseif ($model->canUpdateAssociation(Yii::$app->request->object) && $relationship->hasFields) { $updateLabel = 'Update Relationship'; $updateUrl = ['/object/link'] + $baseUrl; } if ($updateLabel) { $menu['update'] = ['icon' => 'fa fa-wrench', 'label' => $updateLabel, 'url' => $updateUrl, 'linkOptions' => ['data-handler' => 'background']]; } if (!$objectType->hasDashboard && $model->can('manageAccess')) { $menu['access'] = ['icon' => 'fa fa-key', 'label' => 'Manage Access', 'url' => ['/object/access'] + $baseUrl, 'linkOptions' => ['data-handler' => 'background']]; } // delete button if ($model->can('delete') || $model->canDeleteAssociation(Yii::$app->request->object)) { $menu['delete'] = ['icon' => 'fa fa-trash-o', 'label' => 'Delete', 'url' => ['/object/delete'] + $baseUrl, 'linkOptions' => ['data-handler' => 'background']]; } return $menu; }
/** * [[@doctodo method_description:_parseParams]]. * * @throws HttpException [[@doctodo exception_description:HttpException]] * @return [[@doctodo return_type:_parseParams]] [[@doctodo return_description:_parseParams]] * */ public function _parseParams() { $paramSource = $_GET; $p = []; // primary object $p['objectId'] = ArrayHelper::getValue($paramSource, 'id', false); if ($p['objectId']) { $p['object'] = Registry::getObject($p['objectId'], false); if (empty($p['object'])) { throw new HttpException(404, "Unknown object '{$p['objectId']}."); } } // object type $p['typeName'] = ArrayHelper::getValue($paramSource, 'type', false); if ($p['typeName']) { $p['typeItem'] = Yii::$app->collectors['types']->getOne($p['typeName']); if (isset($p['typeItem']->object)) { $p['type'] = $p['typeItem']->object; } } elseif (isset($p['object'])) { $p['typeItem'] = $p['object']->objectTypeItem; $p['type'] = $p['object']->objectType; } if (empty($p['type'])) { throw new HttpException(404, "Unknown object type."); } // related object $p['relatedObjectId'] = ArrayHelper::getValue($paramSource, 'related_object_id', false); if ($p['relatedObjectId']) { $p['relatedObject'] = Registry::getObject($p['relatedObjectId'], false); if (empty($p['relatedObject'])) { throw new HttpException(404, "Unknown related object."); } $p['relatedType'] = $p['relatedObject']->objectType; } // relation $p['objectRelationName'] = ArrayHelper::getValue($paramSource, 'object_relation', false); if ($p['objectRelationName'] && isset($p['relatedType'])) { list($p['relationship'], $p['relationshipRole']) = $p['relatedType']->getRelationship($p['objectRelationName']); if (!empty($p['relationship']) && !empty($p['relatedObject']) && !empty($p['object'])) { if ($p['relationshipRole'] === 'child') { $p['parentObject'] = $p['relatedObject']; $p['childObject'] = $p['object']; } else { $p['parentObject'] = $p['object']; $p['childObject'] = $p['relatedObject']; } $p['relation'] = $p['relationship']->getModel($p['parentObject'], $p['childObject']); } if (empty($p['relationship'])) { throw new HttpException(404, "Unknown type relationship {$p['objectRelationName']}"); } } return $p; }
/** * @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; }