예제 #1
0
 public function getPropertyValue($property, $value)
 {
     $returnValue = "Undefined";
     $list = array();
     foreach ($this->formFields as $field) {
         if ($field->property == $property) {
             if (in_array($field->type, array('select', 'multiSelect'))) {
                 $listMethod = $field->selectType->listMethod;
                 if ($field->selectType->type == 'model') {
                     $selectModel = ModelConfig::fullEntityName($field->selectType->modelName);
                     if ($field->selectType->callMethodOnInstance) {
                         $list = array();
                         /** @var BaseModel $modelName */
                         $modelName = ModelConfig::fullEntityName($field->selectType->modelName);
                         $idField = $field->selectType->callMethodOnInstance->id;
                         $valueField = $field->selectType->callMethodOnInstance->value;
                         $object = $modelName::where($idField, $value)->first();
                         if ($object) {
                             $list[$value] = $object->{$valueField};
                         }
                     } else {
                         //id is passed to the list method so automatic Search can work
                         $list = $selectModel::$listMethod('id');
                     }
                 } else {
                     if ($field->selectType->type == 'list') {
                         $entity = ModelConfig::fullEntityName($this->name);
                         $list = $entity::$listMethod();
                     }
                 }
                 foreach ($list as $actualValue => $frontValue) {
                     if ($actualValue == $value) {
                         $returnValue = $frontValue;
                         break;
                     }
                 }
             } else {
                 if ($field->type == 'checkbox') {
                     $returnValue = $value ? Front::drawCheckboxIcon(true) : Front::drawCheckboxIcon(false);
                 } else {
                     $returnValue = $value;
                 }
             }
             return $returnValue;
             break;
         }
     }
     return $returnValue;
 }
예제 #2
0
 public static function getModelConfigFieldValue($modelConfig, $originalField, BaseModel $object, $currentLanguage = NULL, $returnLabel = false, $export = false)
 {
     $languages = config('gtcmslang.languages');
     if (is_numeric($currentLanguage)) {
         foreach ($languages as $key => $language) {
             if ($key == $currentLanguage) {
                 $lang = $language;
             }
         }
     } else {
         if (!is_null($currentLanguage)) {
             $lang = $languages[$currentLanguage];
         } else {
             $lang = "";
         }
     }
     $field = clone $originalField;
     if (config('gtcms.premium') && $field->langDependent) {
         $field->property .= "_" . $lang;
         $field->label .= " [{$lang}]";
     }
     if ($returnLabel) {
         return $field->label;
     }
     $value = "";
     $displayProperty = $field->displayProperty ? $field->displayProperty : $field->property;
     if (is_object($displayProperty)) {
         if ($displayProperty->type == 'model') {
             $method = $displayProperty->method;
             $relatedProperty = $displayProperty->property;
             if ($object->{$method}()->count()) {
                 if ($displayProperty->multiple) {
                     $relatedModels = $object->{$method}()->withPivot('position')->orderBy('pivot_position', 'asc')->get();
                     $value = "";
                     foreach ($relatedModels as $relModel) {
                         $value .= $relModel->{$relatedProperty} . ", ";
                     }
                     $value = rtrim($value, ", ");
                 } else {
                     $value = $object->{$method}->{$relatedProperty};
                 }
             } else {
                 $value = " - ";
             }
         } else {
             if ($displayProperty->type == 'accessor') {
                 $method = $displayProperty->method;
                 if ($method == 'indexDate' && $export) {
                     $value = $object->getIndexDateAttribute();
                 } else {
                     $value = $object->{$method};
                 }
             } else {
                 if ($displayProperty->type == 'image') {
                     $method = $displayProperty->method;
                     if ($object->{$method}('name')) {
                         if ($displayProperty->display == 'image' && !$export) {
                             $value = "<img style='max-width: 300px; max-height: 300px' src='" . $object->{$method}('url', 'original', $field->property) . "' >";
                         } else {
                             if ($displayProperty->display == 'name' || $export) {
                                 $value = $object->{$method}('name');
                             }
                         }
                     } else {
                         $value = "This " . $modelConfig->hrName . " has no " . $field->label . ".";
                     }
                 } else {
                     if (in_array($displayProperty->type, array('date', 'dateTime'))) {
                         $property = $field->property;
                         $value = $object->formatDate($object->{$property}, $displayProperty->dateFormat ? $displayProperty->dateFormat : $property->dateFormat);
                     } else {
                         if ($displayProperty->type == 'file') {
                             $method = $displayProperty->method;
                             if ($object->{$method}('name')) {
                                 if ($displayProperty->display == 'url' && !$export) {
                                     $value = "<a href='" . $object->{$method}() . "' target='_blank'>" . $object->{$method}('name') . "</a>";
                                 } else {
                                     if ($displayProperty->display == 'name' || $export) {
                                         $value = $object->{$method}('name');
                                     }
                                 }
                             } else {
                                 $value = "This " . $modelConfig->hrName . " has no " . $field->label . ".";
                             }
                         }
                     }
                 }
             }
         }
     } else {
         if ($field->type == 'checkbox') {
             $value = $object->{$displayProperty} ? Front::drawCheckboxIcon(true) : Front::drawCheckboxIcon(false);
         } else {
             $value = $object->{$displayProperty};
         }
     }
     return $value;
 }