<?php
/**
 * YAWIK
 *
 * Partial for the employees collection element
 *
 * @author Mathias Gelhausen <gelhausen@cross-solution.de>
 * @filesource
 * @license MIT
 * @copyright  2013 - 2015 Cross Solution <http://cross-solution.de>
 * @since 0.18
 * @todo translations
 */

use Organizations\Entity\EmployeePermissionsInterface as Perms;

if ($this->renderSummary):

    $employees = $this->element->getObject()->getEmployees();
?>
    <table class="table table-striped table-bordered">
        <thead>
            <tr>
                <td><?php echo $this->translate('Users')?></td>
                <td><?php echo $this->translate('View Jobs')?></td>
                <td><?php echo $this->translate('Edit Jobs')?></td>
                <td><?php echo $this->translate('Create Jobs')?></td>
                <td><?php echo $this->translate('View Applications')?></td>
                <td><?php echo $this->translate('Edit Applications')?></td>
            </tr>
        </thead>
        <tbody>
        <?php foreach ($employees as $employee):
            /* @var  \Organizations\Entity\Employee $employee */
            $user = $employee->getUser();
            $info = $user->getInfo();
            $perms = $employee->getPermissions()?>
        <tr>
            <td><?php $name = $info->getDisplayName(false); if ($name): echo $name ?><br><?php endif; echo $info->getEmail() ?>
                <small><br>(<?php echo $employee->getRole()?>)
            <?php if ($employee->isPending()): ?><br><span class="label label-warning"><?php echo $this->translate('pending') ?></span>
            <?php endif; ?>
                </small></td>
            <td>
                <?php echo $perms->isAllowed(Perms::JOBS_VIEW) ? 'X' : 'O' ?> </td><td>
                <?php echo $perms->isAllowed(Perms::JOBS_CHANGE) ? 'X' : 'O' ?> </td><td>
                <?php echo $perms->isAllowed(Perms::JOBS_CREATE) ? 'X' : 'O' ?>
            </td>
            <td>
                <?php echo $perms->isAllowed(Perms::APPLICATIONS_VIEW) ? 'X' : 'O' ?> </td><td>
                <?php echo $perms->isAllowed(Perms::APPLICATIONS_CHANGE) ? ' X' : 'O' ?>
            </td>

        </tr>
        <?php endforeach?>
        </tbody>
    </table>

<?php else:
    echo $this->formCollection()->render($this->element, /* useViewPartial */ false);
endif;
