Create the tags.

@param Collection $models

@return array
760546
private function createTags(Collection $models): array
    {
        $tags = [];

        /** @var Model $model */
        foreach ($models as $model) {
            $tags[] = static::createTagFromModel($model);
        }

        return $tags;
    }
1302484
public function addTags(array $tags)
    {
        $this->tagsChanges['added'] = array_unique(
            array_merge($this->tagsChanges['added'], $tags)
        );

        return $this;
    }
102651
protected function getTagInspectors(TagCollection $tags)
	{
		$tagInspectors = [];
		foreach ($tags as $tagName => $tag)
		{
			// Use the tag's template if applicable or XSLT's implicit default otherwise
			$template = (isset($tag->template)) ? $tag->template : '<xsl:apply-templates/>';
			$tagInspectors[$tagName] = new TemplateInspector($template);
		}

		return $tagInspectors;
	}
1048896
public static function makeTagsArray($tags)
    {
        if (is_array($tags)) {
            $tags = array_unique(array_filter($tags));
        } else if (is_string($tags)) {
            $tags = preg_split('#[' . preg_quote(',', '#' ) . ']#', $tags, null, PREG_SPLIT_NO_EMPTY);
        } else {
            $tags = $tags->toArray();
        }

        $tagSet = [];
        foreach ($tags as $tag)
            $tagSet[] = Tag::taggify($tag);

        return $tagSet;
    }
471946
public function normalizeTags($tags) {
		if (is_string($tags)) {
			$tags = explode($this->getConfig('delimiter'), $tags);
		}

		$result = [];

		$modelAlias = $this->getConfig('fkModelAlias') ?: $this->_table->getAlias();

		$common = ['_joinData' => [$this->getConfig('fkModelField') => $modelAlias]];
		$namespace = $this->getConfig('namespace');
		if ($namespace) {
			$common += compact('namespace');
		}

		$tagsTable = $this->_table->{$this->getConfig('tagsAlias')};
		$primaryKey = $tagsTable->getPrimaryKey();
		$displayField = $tagsTable->getDisplayField();

		foreach ($tags as $tag) {
			$tag = trim($tag);
			if (empty($tag)) {
				continue;
			}
			$tagKey = $this->_getTagKey($tag);
			$existingTag = $this->_tagExists($tagKey);
			if (!empty($existingTag)) {
				$result[] = $common + ['id' => $existingTag];
				continue;
			}
			list($id, $label) = $this->_normalizeTag($tag);
			$result[] = $common + compact(empty($id) ? $displayField : $primaryKey) + [
				'slug' => $tagKey,
			];
		}

		return $result;
	}
455210
public function saveMany($models)
    {
        // Convert to collection if array
        $models = is_array($models) ? collection($models) : $models;

        foreach ($models as &$model) {
            $model = $this->save($model);
        }

        return $models;
    }
1084617
protected function _generateFormFields($model)
    {
        $model = TableRegistry::get($model);
        $columns = ConnectionManager::get('default')->schemaCollection()->describe($model->table())->columns();

        $ignoredFields = [
            'created',
            'modified',
            'created_by',
            'modified_by',
            'password'
        ];

        $result = [];

        foreach ($columns as $column) {
            if (!in_array($column, $ignoredFields)) {
                $result[$column] = [];
            }
        }
        return $result;
    }
563140
public static function fillPropertyGroups(&$models)
    {

        if (count($models) === 0) {
            return [];
        }
        /** @var \yii\db\ActiveRecord|\DevGroup\DataStructure\traits\PropertiesTrait|\DevGroup\TagDependencyHelper\TagDependencyTrait $firstModel */
        $firstModel = reset($models);
        //        if ($firstModel->propertyGroupIds !== null) {
        //            // assume that we have already got them
        //            return;
        //        }

        $tags = [
            PropertyGroup::commonTag(),
        ];
        foreach ($models as $modelForTag) {
            $tags[] = $modelForTag->objectTag();
        }

        $binding_rows = Yii::$app->cache->lazy(
            function () use ($firstModel, $models) {
                $query = new Query();

                $query->select(['model_id', 'property_group_id'])->from(
                    $firstModel::bindedPropertyGroupsTable()
                )->where(PropertiesHelper::getInCondition($models))->orderBy(['sort_order' => SORT_ASC]);

                return $query->all($firstModel::getDb());

            },
            static::generateCacheKey($models, 'property_groups_ids'),
            0,
            $tags
        );

        array_walk(
            $binding_rows,
            function (&$item) {
                $item['model_id'] = (int) $item['model_id'];
                $item['property_group_id'] = (int) $item['property_group_id'];
            }
        );

        foreach ($models as &$model) {
            $id = $model->id;
            $model->propertyGroupIds = array_reduce(
                $binding_rows,
                function ($carry, $item) use ($id) {
                    if ($item['model_id'] === $id) {
                        $carry[] = (int) $item['property_group_id'];
                    }
                    return $carry;
                },
                []
            );
        }

    }
1167910
protected function createTag(string $value): Tag
    {
        /** @var TagModel $model */
        $model = $this->framework->createInstance(TagModel::class);
        $model->tstamp = \time();
        $model->name = $value;
        $model->source = $this->alias;
        $model->save();

        return ModelCollection::createTagFromModel($model);
    }
796336
private function getContextualTags(array $tags)
    {
        foreach ($tags as &$tag) {
            $tag = $this->getContextualId($tag);
        }
        unset($tag);

        return $tags;
    }
744004
protected function buildCreate(array $models)
    {
        $schemaManager = $this->connection->getSchemaManager();

        foreach ($models as $model) {
            if ($schemaManager->tablesExist([$model->table()])) {
                throw new SchemaException(sprintf('Unable to create table, table "%s" already exists', $model->table()));
            }

            $this->createTable($this->schema, $model);
        }

        $this->queries = array_merge(
            $this->queries,
            $this->schema->toSql($this->connection->getDatabasePlatform())
        );
    }
185673
protected function getEagerModelKeys(array $models)
    {
        $keys = [];

        // First we need to gather all of the keys from the parent models so we know what
        // to query for via the eager loading query. We will add them to an array then
        // execute a "where in" statement to gather up all of those related records.
        foreach ($models as $model) {
            if (is_array($this->foreignKey)) { //Check for multi-columns relationship
                $keys[] = array_map(function ($k) use ($model) {
                    return $model->{$k};
                }, $this->foreignKey);
            } else {
                if (! is_null($value = $model->{$this->foreignKey})) {
                    $keys[] = $value;
                }
            }
        }

        // If there are no keys that were not null we will just return an array with either
        // null or 0 in (depending on if incrementing keys are in use) so the query wont
        // fail plus returns zero results, which should be what the developer expects.
        if (count($keys) === 0) {
            return [$this->relationHasIncrementingId() ? 0 : null];
        }

        sort($keys);

        return array_values(array_unique($keys, SORT_REGULAR));
    }
31702
public function tags(Tags $tags = null)
    {
        if (is_null($tags)) {
            return $this->tags;
        }

        $this->tags = $tags;

        return $this;
    }
1337625
private function buildLabels($labels)
    {
        $collection = [];
        foreach ($labels as $label) {
            $collection[] = Label::createFromData($label);
        }

        return $collection;
    }
17310
public static function addTags($tags)
    {
        self::updateAllCounters(['frequency' => 1], ['name' => $tags]);

        foreach ($tags as $name) {
            if (!self::find()->where(['name' => $name])->exists()) {
                (new self([
                    'name' => $name,
                    'frequency' => 1
                ]))->save();
            }
        }
    }
883733
protected function fetchSnippetSourceFromModels($models)
    {
        if ($this->asArray) {
            throw new InvalidCallException('"' . __METHOD__ . '" unable to determine snippet source from plain array. Either disable "asArray" option or use regular "snippetCallback"');
        }
        $result = [];
        foreach ($models as $model) {
            $result[] = $model->getSnippetSource();
        }

        return $result;
    }
898759
protected function buildDictionary(Collection $models)
    {
        foreach ($models as $model) {
            $morphType = $this->morphType;

            if (isset($model->{$morphType})) {
                $type = $model->{$morphType};

                $key = $model->getAttribute($this->foreignKey);

                $this->dictionary[$type][$key][] = $model;
            }
        }
    }