src/Repository/AguilaLibre.php line 140

Open in your IDE?
  1. <?php
  2. namespace App\Repository;
  3. class AguilaLibre {
  4.     
  5.     public static function scheduleUser($professional_id,$category_id,$date_to_search) {
  6.        
  7.         
  8.         $weekday date("N"strtotime($date_to_search));
  9.         
  10.         $user     $em->getRepository('AppBundle:User')->findOneBy(array("status" => 'ACTIVO''id' => $professional_id));
  11.         $category $em->getRepository('AppBundle:Category')->findOneBy(array("isActive" => 1"categoryId" => $category_id));
  12.         $user_schedule $em->getRepository('AppBundle:UserSchedule')->findBy(array("user" => $user'weekday' => $weekday),array('startAt' => 'ASC'));
  13.         
  14.         if(strlen($category->getAppointmentConsumeMinutes()) == 0)
  15.         {
  16.             return new JsonResponse(array('status' => "error"));
  17.         }
  18.         
  19.         $time_matrix = array();
  20.         $i 0;
  21.         
  22.         foreach($user_schedule as $scheduled)
  23.         {
  24.             
  25.             $start_at $date_to_search." ".$scheduled->getStartAt()->format("H:i");
  26.             $end_at $date_to_search." ".$scheduled->getEndAt()->format("H:i");
  27.             
  28.             $appointments $em->getRepository('AppBundle:UserSchedule')->getAppointments($professional_id$date_to_search$start_at$end_at);
  29.             
  30.             foreach($appointments as $appointment)
  31.             {
  32.                 if($start_at == $appointment["scheduled_at"])
  33.                 {
  34.                     $start_at $this->addMinutes($start_at$appointment["appointment_consume_minutes"] );
  35.                 } else {
  36.                     $compare_start_at $start_at;
  37.                     $compare_end_at $appointment["scheduled_at"];
  38.                     $flag false;
  39.                     while($flag == false)
  40.                     {
  41.                         $tmp_start_at $start_at;
  42.                         $tmp_end_at $this->addMinutes($start_at$category->getAppointmentConsumeMinutes());
  43.                         if($appointment["scheduled_at"] >= $tmp_end_at)
  44.                         {
  45.                             $time_matrix[$i]["start_date"] = $tmp_start_at;
  46.                             $time_matrix[$i]["end_date"] = $tmp_end_at;
  47.                             $start_at $tmp_end_at;
  48.                             $i++;
  49.                         } else {
  50.                             $flag true;
  51.                         }
  52.                     }
  53.                     //Reseteamos la hora de inicio que el usuario esta habilitado.
  54.                     $start_at $this->addMinutes($appointment["scheduled_at"], $appointment ["appointment_consume_minutes"] );
  55.                     
  56.                 }
  57.             }
  58.             
  59.             if($end_at $start_at)
  60.             {
  61.                 $flag false;
  62.                 while($flag == false)
  63.                 {
  64.                     $tmp_start_at $start_at;
  65.                     $tmp_end_at $this->addMinutes($start_at$category->getAppointmentConsumeMinutes());
  66.                     
  67.                     if($end_at >= $tmp_end_at)
  68.                     {
  69.                         $time_matrix[$i]["start_date"] = $tmp_start_at;
  70.                         $time_matrix[$i]["end_date"] = $tmp_end_at;
  71.                         $start_at $tmp_end_at;
  72.                         $i++;
  73.                     } else {
  74.                         $flag true;
  75.                     }
  76.                     
  77.                 }
  78.             }
  79.         }
  80.         
  81.         $available_hours = array();
  82.         foreach($time_matrix as $info)
  83.         {
  84.             $available_hours[]= date("H:i"strtotime($info["start_date"]));
  85.         }
  86.         
  87.         $available_hours_json $available_hours;
  88.         return new JsonResponse(array('status' => "success"'data' => $available_hours_json));
  89.     }
  90.     
  91.     
  92.     
  93.     
  94.     
  95.     
  96.     /**
  97.      *
  98.      * Enter description here ...
  99.      * @param unknown_type $array
  100.      */
  101.     public static function printr($array) {
  102.         echo "<pre>";
  103.         print_r($array);
  104.         echo "</pre>";
  105.     }
  106.     
  107.     public static function checkPm($moduleId$pm 'viewm') {
  108.         $checkModuleView false;
  109.         foreach ($userModules as $module) {
  110.             if ($module["mcid"] == $moduleId && $pm == 1) {
  111.                 $checkModuleView true;
  112.             }
  113.         }
  114.         return $checkModuleView;
  115.     }
  116.     
  117.     //YA NO SE USA EN SYMFONY 5
  118.     public static function getModulePermission($moduleId$userModules) {
  119.         
  120.         foreach ($userModules as $module) {
  121.             if ($module["mcid"] == $moduleId) {
  122.                 return $module;
  123.             }
  124.         }
  125.         return false;
  126.     }
  127.     /**
  128.      *
  129.      * Enter description here ...
  130.      * @param unknown_type $files
  131.      * @param unknown_type $thumbnail
  132.      * @param unknown_type $path
  133.      * @param unknown_type $onlyThisExtensions
  134.      */
  135.     public function uploadImages($files$thumbnail false$path$onlyThisExtensions false)
  136.     {
  137.         try {
  138.             if (is_array($files)) {
  139.                 foreach ($files as $picture) {
  140.                     if (!$picture["error"]) {
  141.                         // si no hay error en la subida realizar el upload de la imagen
  142.                         // obtener data
  143.                         $size $picture["size"];
  144.                         $type $picture["type"];
  145.                         $name $picture["name"];
  146.                         $tmp =  $picture['tmp_name'];
  147.                         $file_name substr($name0strlen($name) - 4);
  148.                         $ext substr($namestrlen($name) - 3strlen($name));
  149.                         $prefix substr(md5($name time()),05);
  150.                         $xpath $path $name "-" $prefix "." $ext;
  151.                         // Validar extenciones
  152.                         if ($onlyThisExtensions) {
  153.                             if (!in_array($ext$onlyThisExtensions))
  154.                             return false;
  155.                         }
  156.                         // subir imagen
  157.                         if (copy($tmp$xpath))
  158.                         $rsImages[] = $file_name " - " $prefix "." $ext;
  159.                         else
  160.                         $rsImages[] = "error";
  161.                         if ($thumbnail) {
  162.                             $thumb = new Thumbnail($xpath);
  163.                             $thumb->size_width(800);
  164.                             $thumb->save($xpath);
  165.                         }
  166.                     }
  167.                 }
  168.                 if (isset($rsImages))
  169.                 return $rsImages;
  170.                 else
  171.                 return false;
  172.             }
  173.         } catch (Exception $ex) {
  174.             Doctrine::getTable('BackendErrorLog')->saveErrorLog(array(
  175.             'description' => $ex->getMessage(),
  176.             'modules' => "AguilaLibre:$modelName::uploadImages",
  177.             'backend_action_log_id' => 5,
  178.             ));
  179.             return false;
  180.         }
  181.     }
  182.     /**
  183.      *
  184.      * @param string $text
  185.      * @return string
  186.      */
  187.     static public function slugify($text)
  188.     {
  189.         
  190.         $titleUrl AguilaLibre::replaceAccents($text);
  191.         // replace all non letters or digits by -
  192.         //$xtext = preg_replace('/\W+/', '-', $titleUrl);
  193.         // trim and lowercase
  194.         $xtext strtolower(trim($titleUrl'-'));
  195.         return $xtext;
  196.     } 
  197.     static public function replaceAccents($str) { 
  198.         $a = array('Ã�''É''Ã�''Ó''Ú''á''é''í''ó''ú'' '',''ñ''.'' ''?''¡'';''"''#''!''¿'':');
  199.         $b = array('A''E''I''O''U''a''e''i''o''u''-''-''n''',  '',  '',  '''',  '',  '',  '',  '',  '-');
  200.         return str_replace($a$b$str);
  201.     }
  202.     
  203.     static public function replaceBadWords($str) {
  204.         $bad = array("cerote""serote""culo",  "tumadre""tu madre""mierda""culero""eshta",  "huevo",  "hueco",  "weco",   "verga",  "moronga""puta",   "talega""caca",   "pija");
  205.         $good = array("&/#$%#","&/#$%#""&/#$%#","&/#$%#",  "&/#$%#",   "&/#$%#""&/#$%#""&/#$%#""&/#$%#""&/#$%#""&/#$%#""&/#$%#""&/#$%#",  "&/#$%#""&/#$%#""&/#$%#""&/#$%#");
  206.         return str_replace($bad$good$str);
  207.     }
  208.     static public function base64_to_jpeg($base64_string$output_file) {
  209.         $ifp fopen$output_file'wb' );
  210.         $data explode','$base64_string );
  211.         fwrite$ifpbase64_decode$data] ) );
  212.         fclose$ifp );
  213.         return true;
  214.     }
  215. }