我会尽量简单地描述我的问题。
我有一个应用程序,用户可以在一个月内每天安排一个预定的活动。 (每天一个事件* 31(三月的天数)= 31个事件)
class Schedule extends Day
{
use Timestampable;
use Bleamable;
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* FOSUserBundle...
* @ORM\ManyToOne(targetEntity="User")
* @ORM\JoinColumn(name="user", referencedColumnName="id")
*/
protected $user;
/**
* @ORM\Column(type="date", nullable=false)
*/
protected $day;
/**
* @ORM\ManyToOne(targetEntity="EventType")
* @ORM\JoinColumn(name="event_type", referencedColumnName="id")
*/
protected $eventType;
(...)
}
我为它创建了两种表单类型,一种用于编辑计划:
class ScheduleType extends AbstractType
{
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('user')
->add('day')
->add('eventType', TextType::class, [
'label' => false,
])
;
}
}
还有一个表单集合:
class ScheduleMultiType extends AbstractType
{
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('schedule', CollectionType::class, [
'type' => new ScheduleType(), 'allow_add' => true
])
->add('submit', 'submit')
;
}
班长:
public function MonthlyEditAction($year, $month)
{
$date = new \DateTime(sprintf('%d-%02d-01', $year, $month));
//array of days
$dates = $this->get('app.calendar_manager')->getDaysPeriod($date);
$scheduleEnt = $this->getDoctrine()->getRepository('AppBundle:Schedule')
->getSchedule([
'start' => new \DateTime('2016-03-01')
'end' => new \DateTime('2016-03-31')
]);
$userList = $this->getDoctrine()->getRepository('AppBundle:User')
->findAll();
$test['schedule'] = $scheduleEnt;
$form = $this->createForm(new ScheduleMultiType(), $test, array(
'action' => $this->generateUrl('admin_holiday_create'),
'method' => 'POST',
));
return array(
'form' => $form->createView(),
'calendarDate' => $date,
'days' => $dates,
'userList' => $userList
);
}
并在树枝上:
{% for useraa in userList %}
<tr>
{% for asd in form.schedule %}
{% if asd.user.vars.value == useraa.id %}
{% for day in days %}
{% if day.date|date('d') == asd.day.vars.value.day %}
<td>
{{ scheduleMacro.monthly_td_inputBox(day,asd) }}
</td>
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}
</tr>
{% endfor %}
我想要显示所有用户的日程安排如下:
user | 1 | 2 | 3 | ... | 31 |
u1 | 8-16 | 15-23 | 8-16 | ... | 8-16 |
u2 | 9-17 | 16-00 | 7-15 | ... | 8-16 |
u3 | 6-14 | 13-22 | 6-14 | ... | 8-16 |
u4 | 5-13 | 13-22 | 9-17 | ... | 2-10 |
现在我的问题:
我知道这是一个丑陋的解决方案(twig,循环所有用户和日程安排)但我真的不知道如何在&#34;右边&#34;方式...
第二,现在花了 怎么加快?问题是由于计划实体造成的。如果我加载较少的数据,它会更快,但我需要为所有用户加载整月......