<?php
namespace WpBookingEventFrontend\app\models;
defined('_WPBOOKINGEVENT_EXEC') or die;

use WpBookingEvent\Factory;
use WpBookingEvent\Mvc\Model\ModelForm;
use WpBookingEvent\Form\Form;
use WpBookingEvent\Mvc\Model\ModelList;
use WpBookingEvent\Registry\Registry;
class EmployeesModel extends ModelList
{
    /**
     * @var string
     */
    public $context = "employees";
    /**
     * @var string
     */
    public $table_name = "employee";
    public function getListEmployeeByEventid($event_id=0)
    {
        $query = $this->_db->getQuery(true);
        $query->select('event_employee.employee_id')
            ->from($this->getTableName('event_employee') . ' AS event_employee')
            ->where('event_employee.event_id=' . (int)$event_id);
        $list_employee_id = $this->_db->setQuery($query)->loadColumn();
        if (!empty($list_employee_id)) {
            $query->clear()
                ->select('employee.*')
                ->from($this->getTableName('employee') . ' AS employee')
                ->where('employee.id IN (' . implode(',', $list_employee_id) . ')');
            $list_employee = $this->_db->setQuery($query)->loadObjectList();
            foreach ($list_employee as &$employee) {
                $employee->full_name = $employee->first_name . ' ' . $employee->last_name;
            }
            return $list_employee;
        }
    }
}
