{% extends 'admin/layout.html.twig' %}

{% set script_controller = 'course/questions' %}

{% set menu = 'admin_course_question_manage' %}

{% block main %}

{% include 'admin/course-question/tab.html.twig' %}
<br>

  <div class="well well-sm mtl">
    <form class="form-inline">

      <div class="form-group">
        <select class="form-control" name="keywordType">
          {{ select_options({title:'标题'|trans, content: '内容'|trans, courseId:'课程编号'|trans, courseTitle:'课程名'|trans }, app.request.get('keywordType')) }}
        </select>
      </div>

      <div class="form-group">
        <input class="form-control" type="text" placeholder="{{'关键词'|trans}}" name="keyword" value="{{ app.request.get('keyword') }}">
      </div>

      <span class="divider"></span>

      <div class="form-group">
        <input class="form-control" type="text" placeholder="{{'作者'|trans}}" name="author" value="{{ app.request.get('author') }}">
      </div>


      <button class="btn btn-primary" type="submit">{{'搜索'|trans}}</button>
    </form>
  </div>

  <div id="question-table-container">
    <table id="question-table" class="table table-striped table-hover">
      <thead>
        <tr>
          <th width="5%"><input type="checkbox" data-role="batch-select"></th>
          <th width="50%">{{'问答'|trans}}</th>
          {% if type == 'unPosted' %}
            <th width="10%">{{'查看'|trans}}</th>
          {% elseif type == 'all' %}
            <th width="10%">{{'回复/查看'|trans}}</th>
          {% endif %}
          <th width="10%">{{'作者'|trans}}</th>
          <th width="10%">{{'创建时间'|trans}}</th>
          <th width="15%">{{'操作'|trans}}</th>
        </tr>
      </thead>
      <tbody class="tbody">
        {% for question in questions %}

          {% set author = users[question.userId]|default(null) %}
          {% set courseSet = courseSets[question.courseSetId]|default(null) %}
          {% set course = courses[question.courseId]|default(null) %}
          {% set task = tasks[question.taskId]|default(null) %}
          <tr data-role="item">
            <td><input value="{{question.id}}" type="checkbox" data-role="batch-item"> </td>
            <td>
              <a href="{{ path('course_thread_show', {courseId:question.courseId, threadId:question.id}) }}" target="_blank"><strong>{{ question.title }}</strong></a>

              <div class="short-long-text">
                <div class="short-text text-sm text-muted">{{ question.content|plain_text(60) }} <span class="trigger">({{'展开'|trans}})</span></div>
                <div class="long-text">{{ question.content|raw }} <span class="trigger">({{'收起'|trans}})</span></div>
              </div>

              <div class="text-sm mts">
                {% if courseSet %}
                  <a href="{{ path('course_show', {id:course.id}) }}" class="text-success" target="_blank">{{ courseSet.title }}</a>
                {% endif %}

                {% if course %}
                  <span class="text-muted mhs">&raquo;</span>
                  <a href="{{ path('course_show', {id:course.id}) }}" class="text-success" target="_blank">{{ course.title }}</a>
                {% endif %}

                {% if task %}
                  <span class="text-muted mhs">&raquo;</span>
                  <a class="text-success"  href="{{ path('course_task_show', {courseId:question.courseId, id:task.id}) }}" target="_blank">{{'任务'|trans}}{{task.number}}：{{ task.title }}</a>
                {% endif %}
              </div>
            </td>
            <td>
            <span class="text-sm">
              {% if type == 'unPosted' %}
               {{ question.hitNum }}
               {% elseif type == 'all' %}
              {{ question.postNum }} / {{ question.hitNum }}
                {% endif %}
            </span>
            </td>
            <td>
              {{ admin_macro.user_link(author) }} <br />
            </td>
            <td>
              {{ question.createdTime|date('Y-n-d H:i:s') }}
            </td>
            <td>
            {% include 'admin/course-question/td-operations.html.twig' %}
            </td>
          </tr>
        {% else %}
          <tr><td colspan="20"><div class="empty">{{'暂无问答记录'|trans}}</div></td></tr>
        {% endfor %}
      </tbody>
    </table>

    <div class="mbm">
        <label class="checkbox-inline"><input type="checkbox" data-role="batch-select"> {{'全选'|trans}}</label>
        <button class="btn btn-default btn-sm mlm" data-role="batch-delete" data-name="{{'问答'|trans}}" data-url="{{ path('admin_thread_batch_delete') }}">{{'删除'|trans}}</button>
    </div>
  </div>

  {{ admin_macro.paginator(paginator) }}
{% endblock %}
