Пример #1
0
 /**
  * @deprecated
  * @param $args
  * @return mixed
  */
 public static function getRecords($args)
 {
     $query = CustomFieldResult::builder();
     if (isset($args['lang_id_028'])) {
         $query->where('lang_id_028', $args['lang_id_028']);
     }
     if (isset($args['field_id_028'])) {
         $query->where('field_id_028', $args['field_id_028']);
     }
     if (isset($args['object_id_028'])) {
         $query->where('object_id_028', $args['object_id_028']);
     }
     if (isset($args['resource_id_028'])) {
         $query->where('resource_id_028', $args['resource_id_028']);
     }
     return $query->get();
 }
Пример #2
0
 /**
  * Function to get html from custom fields
  *
  * @param $parameters
  * @return \Illuminate\Http\JsonResponse
  * @throws \Exception
  * @throws \Throwable
  */
 public static function getCustomFields($parameters)
 {
     // get custom fields
     $customFields = CustomField::getRecords(['lang_026' => $parameters['lang'], 'group_id_026' => $parameters['customFieldGroup']]);
     if ($parameters['object']) {
         if (!empty($parameters['action']) && $parameters['action'] == 'storeLang') {
             // if is a new object translated
             $langFieldResults = base_lang()->id_001;
         } else {
             $langFieldResults = $parameters['lang'];
         }
         // get results if there is a object
         $customFieldResults = CustomFieldResult::where('lang_id_028', $langFieldResults)->where('object_id_028', $parameters['object'])->where('resource_id_028', $parameters['resource'])->get();
     }
     $html = '';
     foreach ($customFields as $customField) {
         $setValue = isset($customFieldResults) && $customFieldResults->where('field_id_028', $customField->id_026)->count() > 0;
         // add suffix '_custom' to avoid conflict with other field names
         if (collect(config('pulsar.fieldTypes'))->keyBy('id')[$customField->field_type_id_026]->key == 'selectMultiple' || collect(config('pulsar.fieldTypes'))->keyBy('id')[$customField->field_type_id_026]->key == 'selectMultiple2') {
             // TODO: se pueden coger todos los valores antes del foreach para evitar multiples consultas
             $customFieldValues = $customField->getValues()->where('lang_id_027', base_lang()->id_001)->get();
             $multipleSelectValue = null;
             if ($setValue) {
                 if (collect(config('pulsar.dataTypes'))->keyBy('id')[$customField->data_type_id_026]->type == 'array') {
                     $multipleSelectValue = $customFieldResults->where('field_id_028', $customField->id_026)->first()->value_028;
                 } else {
                     $multipleSelectValue = $customFieldResults->where('field_id_028', $customField->id_026)->pluck('value_028')->toArray();
                 }
             }
             // check if is select2 plugin
             $isSelect2 = collect(config('pulsar.fieldTypes'))->keyBy('id')[$customField->field_type_id_026]->key == 'selectMultiple2';
             $html .= view(collect(config('pulsar.fieldTypes'))->keyBy('id')[$customField->field_type_id_026]->view, ['label' => $customField['label_026'], 'name' => $customField['name_026'] . '_custom[]', 'fieldSize' => empty($customField['field_size_026']) ? 10 : $customField['field_size_026'], 'objects' => $customFieldValues, 'idSelect' => 'id_027', 'nameSelect' => 'name_027', 'required' => $customField->required_026, 'class' => $isSelect2 ? 'select2' : null, 'id' => $customField['name_026'] . '_custom', 'multiple' => true, 'data' => $isSelect2 ? ['language' => config('app.locale'), 'width' => '100%', 'error-placement' => 'select2-' . $customField['name_026'] . '_custom' . '-outer-container'] : null, 'value' => $setValue ? $multipleSelectValue : null])->render();
         } elseif (collect(config('pulsar.fieldTypes'))->keyBy('id')[$customField->field_type_id_026]->key == 'select' || collect(config('pulsar.fieldTypes'))->keyBy('id')[$customField->field_type_id_026]->key == 'select2') {
             $customFieldValues = $customField->getValues()->where('lang_id_027', base_lang()->id_001)->get();
             // check if is select2 plugin
             $isSelect2 = collect(config('pulsar.fieldTypes'))->keyBy('id')[$customField->field_type_id_026]->key == 'select2';
             $html .= view(collect(config('pulsar.fieldTypes'))->keyBy('id')[$customField->field_type_id_026]->view, ['label' => $customField['label_026'], 'name' => $customField['name_026'] . '_custom', 'fieldSize' => empty($customField['field_size_026']) ? 10 : $customField['field_size_026'], 'objects' => $customFieldValues, 'idSelect' => 'id_027', 'nameSelect' => 'name_027', 'required' => $customField->required_026, 'class' => $isSelect2 ? 'select2' : null, 'id' => $customField['name_026'] . '_custom', 'data' => $isSelect2 ? ['language' => config('app.locale'), 'width' => '100%', 'error-placement' => 'select2-' . $customField['name_026'] . '_custom' . '-outer-container'] : null, 'value' => $setValue ? $customFieldResults->where('field_id_028', $customField->id_026)->first()->value_028 : null])->render();
         } elseif (collect(config('pulsar.fieldTypes'))->keyBy('id')[$customField->field_type_id_026]->key == 'checkbox') {
             $html .= view(collect(config('pulsar.fieldTypes'))->keyBy('id')[$customField->field_type_id_026]->view, ['label' => $customField['label_026'], 'name' => $customField['name_026'] . '_custom', 'fieldSize' => empty($customField['field_size_026']) ? 10 : $customField['field_size_026'], 'required' => $customField->required_026, 'checked' => $setValue ? $customFieldResults->where('field_id_028', $customField->id_026)->first()->value_028 : null])->render();
         } else {
             $html .= view(collect(config('pulsar.fieldTypes'))->keyBy('id')[$customField->field_type_id_026]->view, ['label' => $customField['label_026'], 'name' => $customField['name_026'] . '_custom', 'fieldSize' => empty($customField['field_size_026']) ? 10 : $customField['field_size_026'], 'required' => $customField->required_026, 'value' => $setValue ? $customFieldResults->where('field_id_028', $customField->id_026)->first()->value_028 : null])->render();
         }
     }
     return $html;
 }