/** * Removes localized content files from templates collection * @param \October\Rain\Database\Collection $templates * @return \October\Rain\Database\Collection */ public function pruneTranslatedContentTemplates($templates) { $locales = LocaleModel::listAvailable(); $extensions = array_map(function ($ext) { return '.' . $ext; }, array_keys($locales)); return $templates->filter(function ($template) use($extensions) { return !Str::endsWith($template->getBaseFileName(), $extensions); }); }
/** * Gets an array with values of a given column. Values are indented according to their depth. * @param string $column Array values * @param string $key Array keys * @param string $indent Character to indent depth * @return array */ public function scopeListsNested($query, $column, $key = null, $indent = ' ') { $columns = [$this->getDepthColumnName(), $column]; if ($key !== null) { $columns[] = $key; } $results = new Collection($query->getQuery()->get($columns)); $values = $results->pluck($columns[1])->all(); $indentation = $results->pluck($columns[0])->all(); if (count($values) !== count($indentation)) { throw new Exception('Column mismatch in listsNested method. Are you sure the columns exist?'); } foreach ($values as $_key => $value) { $values[$_key] = str_repeat($indent, $indentation[$_key]) . $value; } if ($key !== null && count($results) > 0) { $keys = $results->pluck($key)->all(); return array_combine($keys, $values); } return $values; }