<?php
use yii\helpers\ArrayHelper;
use yii\helpers\Url;
use yii\helpers\Html;

use common\modules\school\models\Courses;
use common\modules\testings\models\Test;

$docsLesson = '';
if ($model->files){
    foreach($model->files as $doc){
        $docsLesson[] = '<div class="tag-item" id="document-'.$doc->id.'">
            <div class="tag-title"><input type="checkbox" value="'.$doc->title.'" checked="checked" 
                name="Filenames[]" /> '.($doc->title ? $doc->title : $doc->filename).'
                    </div>
                     <a title="Редактировать документ" href="javascript:void(0);" class="upd-doc-projs" data-id="'.$doc->id.'">
                        <i class="icon-pencil"></i>
                    </a>
                    <a title="Удалить документ" href="javascript:void(0);" class="remove-doc-projs" value="'.$doc->id.'">
                        X
                    </a>
                </div>';
    }
}

$docsLesson = implode("", $docsLesson);
$newDoc = 'Добавить документ<span><a class="btn" id="add-doc-projs" href="javascript:void(0);" title="Новый документ">
            <i class="icon-plus"></i></a>
        </span>
       <div id="doc-items"></div>
       <div id="doc-upd"></div>';

$errors = '';
if ($model->errors){
    $errors[] = '<div class="alert alert-block alert-error">';
    foreach($model->errors as $error){
       $errors[] = '<p>'.$error.'</p>'; 
    } 
    $errors[] = '</div>';
$errors = implode("", $errors);     
}
         

$elements = [
    'test_id' => ['type' => 'dropdownlist', 'items' => ArrayHelper::map(Test::find()->all(), 'id', 'name', 'session.name'), 'empty' => 'Не задан'],
    'title'	=> ['type' => 'text'],
    'video_id'	=> ['type' => 'text'],
    'text' => ['type' => 'textarea'],
    'course_id' => [
            'type' => 'dropdownlist',
            'items' => ArrayHelper::map(Courses::find()->all(), 'id', 'title'),
        ],
    'number'	=> ['type' => 'text'],
    'errors'	=> $errors,
    'newDoc'	=> $newDoc,
    'docsLesson'	=> $docsLesson,
];
return [
    'activeForm'=>[
        'id' => 'lesson-form',
        'options' => [
            'enctype' => 'multipart/form-data'
        ],
    ],
    'elements'       => $elements,
    'buttons' => [
        'submit' => ['type' => 'submit', 'value' => 'Cохранить']
    ]
];


