Created
March 16, 2017 13:27
-
-
Save rederlo/e91481df90886a6d7c923572a6e2b534 to your computer and use it in GitHub Desktop.
Exemplo de calendario
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Class Calendario | |
*/ | |
class Calendario | |
{ | |
/** | |
* @var int | |
*/ | |
public $dia; | |
/** | |
* @var | |
*/ | |
public $mes; | |
/** | |
* @var | |
*/ | |
public $ano; | |
/** | |
* @var | |
*/ | |
public $tstamp; | |
/** | |
* @var | |
*/ | |
public $dtmanip; | |
/** | |
* @var | |
*/ | |
public $dsprimdia; | |
/** | |
* @var bool | |
*/ | |
public $linhafechada; | |
/** | |
* @var | |
*/ | |
public $agendas; | |
/** | |
* @var | |
*/ | |
public $eventos; | |
/** | |
* @var array | |
*/ | |
public $nome = []; | |
/** | |
* @var array | |
*/ | |
public $cor = []; | |
/** | |
* Calendario constructor. | |
* @param $pmes | |
* @param $pano | |
*/ | |
public function __construct($pmes, $pano) | |
{ | |
$this->linhafechada = true; | |
$this->dia = 1; | |
$this->mes = $pmes; | |
$this->ano = $pano; | |
$this->calcula_tstamp(); | |
$this->data_manipulavel(); | |
$this->primeiro_dia_mes(); | |
} | |
/** | |
* | |
*/ | |
public function calcula_tstamp() | |
{ | |
$this->tstamp = mktime(0, 0, 0, $this->mes, $this->dia, $this->ano); | |
} | |
/** | |
* | |
*/ | |
public function data_manipulavel() | |
{ | |
$this->dtmanip = getdate($this->tstamp); | |
} | |
/** | |
* | |
*/ | |
public function primeiro_dia_mes() | |
{ | |
$this->dsprimdia = $this->dtmanip["wday"]; | |
} | |
/** | |
* | |
*/ | |
public function proximo_dia() | |
{ | |
$this->dia++; | |
$this->calcula_tstamp(); | |
} | |
/** | |
* @return string | |
*/ | |
public function exibe_calendario() | |
{ | |
$html = ""; | |
$larg = 100.0 / 7.0; | |
$html .= "<table id='tblLista' class='table table-bordered table-striped table-condensed table-hover' border='1' width='100%' cellpadding='0' cellspacing='0' align='center' bordercolor='#333333'>"; | |
$html .= "<tr class='bold' style='height: 50px; vertical-align: middle'>\n"; | |
$html .= "<td class='text-center info' align='center' width='" . $larg . "%'>Dom</td>"; | |
$html .= "<td class='text-center info' align='center' width='" . $larg . "%'>Seg</td>"; | |
$html .= "<td class='text-center info' align='center' width='" . $larg . "%'>Ter</td>"; | |
$html .= "<td class='text-center info' align='center' width='" . $larg . "%'>Qua</td>"; | |
$html .= "<td class='text-center info' align='center' width='" . $larg . "%'>Qui</td>"; | |
$html .= "<td class='text-center info' align='center' width='" . $larg . "%'>Sex</td>"; | |
$html .= "<td class='text-center info' align='center' width='" . $larg . "%'>Sab</td>"; | |
$html .= "</tr>"; | |
$ccol = 0; | |
$casa = 0; | |
while (checkdate($this->mes, $this->dia, $this->ano)) { | |
$data = date('Y-m-d', strtotime("{$this->ano}-{$this->mes}-{$this->dia}")); | |
if ($this->linhafechada) { | |
$html .= "<tr>\n"; | |
$this->linhafechada = false; | |
} | |
if ($casa < $this->dsprimdia) { | |
$html .= "<td style='height: 95px; vertical-align: middle'> </td>"; | |
} else { | |
$background = subDateCompare($data, "=") ? "background: #fdf9e7" : null; | |
$html .= "<td style=\"height: 95px;$background\" align='center'>"; | |
$html .= $this->dia . "<br />"; | |
$html .= $this->getEventoDia($data); | |
$html .= "</td>"; | |
$this->proximo_dia(); | |
} | |
$ccol++; | |
$ccol = $ccol % 7; | |
$casa++; | |
if (($casa % 7) == 0) { | |
$html .= "</tr>"; | |
$this->linhafecha = true; | |
} | |
} | |
while ($ccol != 0) { | |
$ccol++; | |
$ccol = $ccol % 7; | |
$html .= "<td style='height: 95px; vertical-align: middle'> </td>"; | |
} | |
$html .= "</tr>"; | |
$html .= "</table>"; | |
return $html; | |
} | |
/** | |
* @param $data | |
* @return null|string | |
*/ | |
public function getEventoDia($data) | |
{ | |
$eventos = null; | |
$html = null; | |
$atrazos = 0; | |
foreach ((array)$this->eventos[$data] as $k => $evento) { | |
$agendamentos = 0; | |
$livres = 0; | |
if (is_array($evento['agendados'])) { | |
array_walk($evento['agendados'], function ($v) use (&$agendamentos, &$atrazos) { | |
$agendamentos += sizeof($v); | |
foreach ((array)$v as $item) { | |
if (intval($item['status']) == 0 && subDateCompare($item['data'], "<")) { | |
$atrazos++; | |
} | |
} | |
}); | |
} | |
if (is_array($evento['horarios'])) { | |
array_walk($evento['horarios'], function ($v) use (&$livres) { | |
if (is_array($v)) { | |
$livres += sizeof($v); | |
} | |
}); | |
} | |
$html .= "<a href='#' class='ev-cal' style='text-decoration: none' data-dt='" . toUserDate($data) . "' data-id='" . $k . "'>"; | |
$html .= "<div class='text-center' style='padding: 1px; vertical-align: middle'>"; | |
$html .= "<span class='label label-sm' style='background:" . $evento['cor'] . "'>{$this->nome[$k]}: {$agendamentos} de {$livres}</span> <br />"; | |
$html .= "</div>"; | |
$html .= "</a>"; | |
} | |
if ($atrazos > 0) { | |
$html .= "<a href='#' class='ev-cal' style='text-decoration: none' data-dt='" . toUserDate($data) . "'>"; | |
$html .= "<div class='text-center ev-cal' style='padding: 1px; vertical-align: middle'>"; | |
$html .= "<span class='label label-sm' style='background:red'>ATRASOS: {$atrazos}</span> <br />"; | |
$html .= "</div>"; | |
$html .= "</a>"; | |
} | |
return $html; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment