123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- <?php
- /**
- * Created by PhpStorm.
- * User: tatu
- * Date: 6/23/20
- * Time: 12:10 AM
- */
- use App\Models\AppSession;
- if(!function_exists('get_current_session')) {
- function get_current_session(){
- return AppSession::where('session_key', request()->cookie('sessionKey'))->first();
- }
- }
- if(!function_exists('friendly_date_time')) {
- function friendly_date_time($value, $includeTime = true, $default = '-') {
- if(!$value || empty($value)) return $default;
- try {
- $result = strtotime($value);
- $result = date("jS M Y" . ($includeTime ? ", h:ia" : ""), $result);
- return $result;
- }
- catch (Exception $e) {
- return $value;
- }
- }
- }
- if(!function_exists('friendly_date_time_short')) {
- function friendly_date_time_short($value, $includeTime = true, $default = '-') {
- if(!$value || empty($value)) return $default;
- try {
- $result = strtotime($value);
- $result = date("m/d/y" . ($includeTime ? ", h:ia" : ""), $result);
- return $result;
- }
- catch (Exception $e) {
- return $value;
- }
- }
- }
- if(!function_exists('friendly_time')) {
- function friendly_time($value, $default = '-') {
- if(!$value || empty($value)) return $default;
- try {
- $result = strtotime($value);
- $result = date("h:ia", $result);
- return $result;
- }
- catch (Exception $e) {
- return $value;
- }
- }
- }
- if(!function_exists('friendly_month')) {
- function friendly_month($value) {
- if(!$value || empty($value)) return "-";
- try {
- $result = strtotime($value);
- $result = date("M o", $result);
- return $result;
- }
- catch (Exception $e) {
- return $value;
- }
- }
- }
- if(!function_exists('time_in_hrminsec')) {
- function time_in_hrminsec($value, $default = '-') {
- if(!$value || empty($value)) return $default;
- $value = intval($value);
- $minutes = intval($value / 60);
- $seconds = $value % 60;
- $hours = 0;
- if($minutes >= 60) {
- $hours = intval($minutes / 60);
- $minutes = $minutes % 60;
- }
- $output = [];
- if($hours > 0) {
- $output[] = "{$hours}h";
- }
- if($minutes > 0) {
- $output[] = "{$minutes}m";
- }
- if($seconds > 0) {
- $output[] = "{$seconds}s";
- }
- return implode(" ", $output);
- }
- }
- if(!function_exists('sanitize_field_name')) {
- function sanitize_field_name($name) {
- $result = strtolower($name);
- return preg_replace("/[^0-9a-z]/i", "_", $result);
- }
- }
- if(!function_exists('renderNoteTemplate')) {
- function renderNoteTemplate($template, $topLevel)
- {
- echo
- '<div class="note-template-item" ' .
- 'template="' . (isset($template->template) ? $template->template : $template->text) . '" ' .
- 'type="' . (isset($template->type) ? $template->type : "value") . '" ' .
- '>' .
- '<div class="note-template-text d-flex align-items-center">' .
- '<span class="label">' .
- '<input type="checkbox" />' .
- '<span>' . $template->text . '</span>' .
- '</span>';
- if (isset($template->type) && $template->type === 'plus-minus') {
- echo '<div class="ml-auto mr-2 text-nowrap">';
- echo '<a href="#" class="plus-trigger"><i class="fa fa-plus-circle"></i></a>';
- echo '<a href="#" class="minus-trigger ml-1"><i class="fa fa-minus-circle"></i></a>';
- echo '</div>';
- }
- echo '</div>';
- if (isset($template->children) && count($template->children)) {
- echo '<i class="fa fa-chevron-right has-children"></i>';
- echo '<div class="note-template-children">';
- foreach ($template->children as $t) {
- renderNoteTemplate($t, false);
- }
- echo '</div>';
- } else if (isset($template->type) && $template->type !== 'plus-minus') {
- echo '<i class="fa fa-chevron-right has-children"></i>';
- echo '<div class="note-template-children">';
- if ($template->type === 'alpha') {
- echo '<textarea class="form-control form-control-sm"></textarea>';
- } else {
- echo '<input type="' . $template->type . '" class="form-control form-control-sm">';
- }
- echo '</div>';
- }
- echo '</div>';
- }
- }
- if(!function_exists('renderNoteTemplates')) {
- function renderNoteTemplates($path)
- {
- $templates = json_decode(file_get_contents($path));
- foreach ($templates->templates as $template) {
- renderNoteTemplate($template, true);
- }
- }
- }
- if(!function_exists('renderNoteExamTemplates')) {
- function renderNoteExamTemplates($parentPath, $childPath)
- {
- $templates = json_decode(file_get_contents($parentPath));
- $templates = $templates->templates;
- // override as needed with what is in template set
- if(file_exists($childPath)) {
- $orTemplates = json_decode(file_get_contents($parentPath));
- $orTemplates = $orTemplates->templates;
- for ($i = 0; $i < count($templates); $i++) {
- for ($j = 0; $j < count($orTemplates); $j++) {
- if($templates[$i]->text === $orTemplates[$j]->text) {
- $templates[$i] = $orTemplates[$j];
- }
- }
- }
- }
- foreach ($templates as $template) {
- renderNoteTemplate($template, true);
- }
- }
- }
- if(!function_exists('getVal')) {
- function getVal($object, $prop)
- {
- if (isset($object->$prop)) {
- return $object->$prop;
- } else {
- return '';
- }
- }
- }
|