Ejemplo n.º 1
0
 protected function createComponentTable()
 {
     $session = $this->session;
     $admin = new AdminGrid($this->loginRepository);
     // columns
     $table = $admin->getTable();
     if ($this->user->identity instanceof UserEntity) {
         $table->setModel(new Doctrine($this->loginRepository->createQueryBuilder('a')->andWhere('a.user = :user')->setParameter('user', $this->user->identity)));
     } else {
         $table->setModel(new Doctrine($this->loginRepository->createQueryBuilder('a')->andWhere('a.user IS NULL')));
     }
     $table->setTranslator($this->translator);
     $table->addColumnDate('current', 'Current')->setCustomRender(function (LoginEntity $entity) use($session) {
         $el = Html::el('span');
         $el->class[] = 'glyphicon ' . ($session->id == $entity->getSessionId() ? 'glyphicon-ok' : 'glyphicon-remove');
         return $el;
     })->getCellPrototype()->width = '10%';
     $table->addColumnDate('created', 'Date')->setSortable()->getCellPrototype()->width = '40%';
     $table->addColumnText('sessionId', 'Session ID')->getCellPrototype()->width = '50%';
     // actions
     $table->addAction('delete', 'Delete')->setConfirm(function ($entity) {
         return "Really delete session '{$entity->sessionId}'?";
     })->getElementPrototype()->class[] = 'ajax';
     $admin->connectActionAsDelete($table->getAction('delete'));
     return $admin;
 }