File: /var/www/gestor-horarios.bradford/app/helpers/utilities_helper.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
function esBoolean($boleano=TRUE)
{
$result = '';
if ($boleano)
{
$result = 'SI';
}
else
{
$result = 'NO';
}
return $result;
}
function crear_nombre_imagen($file_name)
{
$replace = array('.', ' ');
$nombre_foto = str_replace($replace, '', microtime()).'-'.rand(1000, 9999);
$extension = array_pop(explode('.', $file_name));
$nombre_foto .= '-gallery.'.$extension;
return $nombre_foto;
}
function crear_carpeta($carpeta)
{
//$ruta_contenido = ROOT_PATH_BASE.'/galeria/'.$carpeta.'/';
$ruta_contenido = PORTALTERRENO_PATH.$carpeta.'/';
mkdir($ruta_contenido,0755, TRUE);
return $ruta_contenido;
}
function enviar_correo_sendgrid($data_mail, $debug = FALSE)
{
$CI =& get_instance();
$config['mailtype'] = 'html';
$config['charset'] = 'utf-8';
$CI->load->library('email', $config);
$CI->email->initialize(array(
'protocol' => 'smtp',
'smtp_host' => 'smtp.sendgrid.net',
'smtp_user' => '',
'smtp_pass' => '',
'smtp_port' => 587,
'crlf' => "\r\n",
'newline' => "\r\n"
));
if(!empty($data_mail['attach']))
{
$CI->email->clear(TRUE);
foreach ($data_mail['attach'] as $key => $value)
{
$CI->email->attach($value['path'], 'attachment', $value['file_name']);
}
}
$CI->email->to($data_mail['para']);
$CI->email->from($data_mail['remitente'], $data_mail['usuario']);
if(!empty($data_mail['bcc_remitente']))
{
$CI->email->bcc($data_mail['bcc_remitente']);
}
$CI->email->subject($data_mail['asunto']);
$CI->email->message($data_mail['mensaje']);
$CI->email->send();
if($debug)
{
echo $CI->email->print_debugger();
}
}
function data_dropdown($data, $id='id', $nombre='nombre')
{
$result[0] = 'Seleccione';
foreach ($data as $key => $value)
{
$result[$value->$id] = $value->$nombre;
}
return $result;
}
function resize_img($file="",$path_to="",$width, $height=0){
list($w, $h) = getimagesize($file['path']);
if($w < $width)
{
$width = $w;
}
if($height == 0)
{
$rat = $w / $width;
$height = round($h / $rat);
}
$ratio = max($width/$w, $height/$h);
$h = ceil($height / $ratio);
$x = ($w - $width / $ratio) / 2;
$w = ceil($width / $ratio);
//echo $path = $_SERVER['DOCUMENT_ROOT'].'/portal_terreno_produccion/imagenes/imagenes_test/'.$width.'x'.$height.'_'.$file['name'];
$imgString = file_get_contents($file['path']);
if(rename($file['path'], $file['path'].'.old.png')){
echo "REsize OK";
}else {
echo "No hay Resize";
}
//unlink($file['path']);
$image = imagecreatefromstring($imgString);
$tmp = imagecreatetruecolor($width, $height);
imagecopyresampled($tmp, $image,
0, 0,
$x, 0,
$width, $height,
$w, $h);
switch ($file['type']) {
case 'image/jpeg':
$return = imagejpeg($tmp, $path_to, 90);
break;
case 'image/png':
$return = imagepng($tmp, $path_to, 0);
break;
case 'image/gif':
$return = imagegif($tmp, $path_to);
break;
default:
exit;
break;
}
return $return;
imagedestroy($image);
imagedestroy($tmp);
}
function pondera_objetivo($valor, $porcentaje = true)
{
if ($valor <= 0.69) {
$objetivo = 'Bajo lo esperado';
$clase = 'malo';
} elseif($valor >= 0.7 && $valor < 1) {
$objetivo = 'Necesita mejorar ';
$clase = 'regular';
} elseif($valor == 1) {
$objetivo = 'Logra lo esperado';
$clase = 'lo_esperado';
} elseif($valor > 1 && $valor <= 1.19) {
$objetivo = 'Algunas veces supera lo esperado ';
$clase = 'bueno';
} elseif($valor >= 1.2) {
$objetivo = 'Excepcional ';
$clase = 'excepcional';
}
if($porcentaje){
$return['resultado'] = $objetivo.' ('. round($valor * 100, 2) .'%)';
}else{
$return['resultado'] = $objetivo.' ('. round($valor, 2) .'%)';
}
$return['clase'] = $clase;
$return['grupo'] = $objetivo;
return $return;
}
function pondera_comperencias($trabajador = [])
{
$trabajador = (object)$trabajador;
$ponderacion = 0;
if ($trabajador->excelente) {
$ponderacion = 1.20;
} elseif ($trabajador->bueno) {
$ponderacion = 1.10;
}elseif ($trabajador->lo_esperado) {
$ponderacion = 1;
}elseif ($trabajador->regular) {
$ponderacion = 0.70;
}elseif ($trabajador->malo) {
$ponderacion = 0.50;
}else {
$ponderacion = 0;
}
return $ponderacion;
}
function estado_evaluacion($estado='')
{
if (empty($estado) || $estado == 0) {
$estado_result = 'Borrador';
} elseif($estado == 1) {
$estado_result = 'Borrador';
} elseif($estado == 2) {
$estado_result = 'Feedback';
} elseif($estado == 3) {
$estado_result = 'Terminada';
}
return $estado_result;
}