public static function generate_image_field($name, $type, $parameters, $array, $value, $data_type) { $folder = $parameters['folder']; $array['data-count'] = 0; $response = '<div class="file_container">'; $response .= '<div class="file_limitations"><p>'; if ($type == 'file') { $response .= trans('admin.file_limitations'); } else { if ($type == 'image') { $response .= trans('admin.image_limitations'); } } $response .= '</p></div>'; if (isset($array['rel'])) { $rel_attribute = ' rel="' . $array['rel'] . '"'; $array['rel'] = 'uploader_' . $array['rel']; } else { $rel_attribute = NULL; } if ($folder && $value) { $i = $parameters['i']; $multiple = false; if (isset($array['multiple'])) { $multiple = true; } if (!$i) { $action = 'temp'; } else { $action = 'saved'; } if (!$i && $multiple) { $array_value = $value; } else { if ($multiple) { $array_value = json_decode($value, true); } else { $array_value = [$value]; } } if ($multiple) { $final_name = $name . '[0]'; } else { $final_name = $name; } if (is_array($array_value) && count($array_value) > 0) { foreach ($array_value as $key => $value) { if ($multiple) { $final_name = $name . '[' . $key . ']'; } else { $final_name = $name; } $response .= '<div class="upload_thumb ' . $type . '_thumb">'; if ($type == 'image') { $response .= '<a class="lightbox" href="' . Asset::get_image_path($folder, 'normal', $value) . '">' . Asset::get_image($folder, 'mini', $value) . '</a>'; } else { $response .= '<a href="' . Asset::get_file($folder, $value) . '" target="_blank">' . $value . '</a>'; } if ($data_type != 'view') { $response .= '<input type="hidden" name="' . $final_name . '" value="' . $value . '"' . $rel_attribute . ' />'; $response .= '<a class="delete_temp" data-folder="' . $folder . '" data-action="' . $action . '" data-file="' . $value . '" data-type="' . $type . '" href="#">X</a>'; } $array['data-count'] = $key + 1; $response .= '</div>'; } } } if ($data_type == 'view' && $array['data-count'] == 0) { $response .= '<div>-</div>'; } $response .= '</div>'; if ($data_type != 'view') { $response .= '<div class="progress_bar"><div class="bar" style="width: 0%;"></div>'; $response .= '<a class="cancel_upload_button" href="#">Cancelar</a></div>'; $response .= '<div class="error_bar"></div>'; $response .= Form::file('uploader_' . $name, $array); } return $response; }
public static function make_fields_values($item, $fields, $appends, $type = 'table') { if ($type == 'excel') { $response = []; } else { $response = ''; } foreach ($fields as $field) { $field_name = $field->name; $field_trans_name = $field->trans_name; $field_type = $field->type; $item_val = $item->{$field_trans_name}; $count = 0; if ($field_type == 'string') { $value = $item_val; } else { if ($field_type == 'text') { $value = strip_tags($item_val); if (strlen($value) > 300) { $value = substr($value, 0, 300) . '...'; } } else { if (($item_val || $item_val === 0) && ($field_type == 'select' || $field_type == 'radio')) { $value = $field->field_options()->where('name', $item_val)->first()->label; } else { if ($field_type == 'relation') { if ($item->{$field_trans_name}) { $value = $item->{$field_trans_name}->name; } else { $value = NULL; } } else { if ($field_type == 'child') { $url = url('admin/model-list/' . $field->value . '?parent_id=' . $item->id); if ($appends) { $url .= '&' . $appends; } $value = 'Nº: ' . count($item_val) . ' (<a href="' . $url . '">' . trans('admin.view') . '</a>)'; } else { if ($field_type == 'subchild') { $value = 'Nº: ' . count($item_val); } else { if (($field_type == 'image' || $field_type == 'file') && $item_val) { if ($field->multiple) { $array_value = json_decode($item_val, true); } else { $array_value = [$item_val]; } $value = ''; $folder = $field->field_extras()->where('type', 'folder')->first()->value; foreach ($array_value as $key => $val) { $count++; if ($count > 1) { $value .= ' | '; } if ($field_type == 'image') { $file_url = Asset::get_image_path($folder, 'normal', $val); } else { $file_url = Asset::get_file($folder, $val); } if ($type == 'excel') { $value .= $file_url; } else { $value .= '<a href="' . $file_url . '" target="_blank">' . $val . '</a>'; } } } else { if ($item_val && $field_type == 'checkbox') { $array_value = json_decode($item_val, true); $value = ''; foreach ($array_value as $val) { $count++; if ($count > 1) { $value .= ' | '; } $value .= $field->field_options()->where('name', $val)->first()->label; } } else { if ($field_type == 'datetime' || $field->type == 'date' || $field->type == 'time') { if ($item_val) { if ($field_type == 'datetime') { $value = $item_val->format('M d, Y H:i'); } else { $value = $item_val; } } else { $value = '-'; } } else { $value = '-'; } } } } } } } } } if ($type == 'table') { $response .= '<td>' . $value . '</td>'; } else { if ($type == 'excel') { array_push($response, $value); } } } return $response; }