protected function getLanguages()
 {
     return Yii::$app->cache->getAuthTimeCached(86400, [], function () {
         // 1d
         $result = [];
         $templates = Template::find()->joinWith('texts')->all();
         foreach (ArrayHelper::getColumn($templates, 'texts') as $texts) {
             foreach ($texts as $text) {
                 $result[$text->lang] = ['name' => Yii::t('hipanel', $text->lang), 'code' => $text->lang];
             }
         }
         return $result;
     });
 }
 public function collectionLoader($scenario, Collection $collection)
 {
     $templateModel = $this->newModel(['scenario' => $scenario]);
     $articleDataModel = new ArticleData(['scenario' => $scenario]);
     $templateModels = [$templateModel];
     for ($i = 1; $i < count(Yii::$app->request->post($templateModel->formName(), [])); ++$i) {
         $templateModels[] = clone $templateModel;
     }
     if (Template::loadMultiple($templateModels, Yii::$app->request->post())) {
         /** @var Template $template */
         foreach ($templateModels as $i => $template) {
             $articleDataModels = [$articleDataModel];
             $texts = ArrayHelper::getValue(Yii::$app->request->post($articleDataModel->formName(), []), $i, []);
             for ($i = 1; $i < count($texts); ++$i) {
                 $articleDataModels[] = clone $articleDataModel;
             }
             ArticleData::loadMultiple($articleDataModels, [$articleDataModel->formName() => $texts]);
             /** @var ArticleData $text */
             foreach ($articleDataModels as $text) {
                 if ($text->article_id === $template->id && $text->validate()) {
                     $template->addText($text);
                 }
             }
         }
         $collection->set($templateModels);
     }
 }