<?php

Lib::loadClass('View');

class ProcesLogSelectView extends View {

	function render() {
		$proces_log_list_count = $this->get('proces_log_list_count');
		$proces_log_list = $this->get('proces_log_list');
		$procesLogDao = $this->get('procesLogDao');
		$out = '';

		if ($title_out = $this->get('title')) {
			$out .= '<h1>' . $title_out . '</h1>' . "\n";
		}

		$out .= '<table cellspacing="0" cellpadding="0" border="1" class="tbl-view" style="margin:16px 0;">';
		$out .= '<thead>';
			$out .= '<tr>';
				$out .= '<td>' . "ID" . '</td>';
				$out .= '<td>' . "TYPE" . '</td>';
				$out .= '<td>' . "PROCES INIT" . '</td>';
				$out .= '<td>' . "ID_STEP" . '</td>';
				$out .= '<td>' . "ID_STEP_WSKAZNIK" . '</td>';
				$out .= '<td>' . "ID_USER" . '</td>';
				$out .= '<td>' . "ID_STANOWISKA" . '</td>';
				$out .= '<td>' . "Akcje" . '</td>';
			$out .= '</tr>';
		$out .= '</thead>';
		$out .= '<tbody>';
		if ($proces_log_list_count > 0) {
			if (!empty($proces_log_list)) {
				foreach ($proces_log_list as $modelLog) {
					$out .= '<tr>';
						$out .= '<td>' . $modelLog->get('ID') . '</td>';
						$out .= '<td>' . $modelLog->get('TYPE') . '</td>';
						$out .= '<td>' . $modelLog->get('ID_PROCES_INIT') . '</td>';
						$out .= '<td>' . $modelLog->get('ID_STEP') . '</td>';
						$out .= '<td>' . $modelLog->get('ID_STEP_WSKAZNIK') . '</td>';
						$out .= '<td>' . $modelLog->get('ID_USER') . '</td>';
						$out .= '<td>' . $modelLog->get('ID_STANOWISKA') . '</td>';
						$out .= '<td>';
							$actions = $procesLogDao->get_model_actions($modelLog);
							$actions_out = array();
							foreach ($actions as $k_task => $v_task_label) {
								$task = '';
								switch ($k_task) {
									case 'step':
										$task = 'PROCES_LOG';
										break;
									case 'quit':
										$task = 'PROCES_LOG_QUIT';
										break;
									case 'hist':
										$task = 'PROCES_LOG_HIST';
										break;
								}
								if ($task) {
									$actions_out []= App::link($v_task_label, array('task'=>$task, '_log_id'=>$modelLog->get('ID')));
								}
							}
							$out .= implode(" ", $actions_out);
						$out .= '</td>';
					$out .= '</tr>';
				}
			} else {
				$out .= '<tr><td>' . "Brak danych" . '</td></tr>';
			}
		} else {
			$out .= '<tr><td>' . "Brak danych" . '</td></tr>';
		}
		$out .= '</tbody>';
		$out .= '</table>';

		return $out;
	}

}
