Exemple #1
0
 public function __get($key)
 {
     if (config('gtcms.premium')) {
         $fullEntity = get_called_class();
         $reflection = new \ReflectionClass($fullEntity);
         $entity = $reflection->getShortName();
         $data = GtcmsPremium::getLangDependentPropertyValue($this, $key, $entity);
         if ($data['valueFound']) {
             return $data['value'];
         }
     }
     return parent::__get($key);
 }
Exemple #2
0
 public static function process($modelConfig, $fileFields, $parentProperty)
 {
     $fileData = array();
     $counter = 0;
     foreach ($fileFields as $fileField) {
         $inputProperties = array();
         if (config('gtcms.premium')) {
             GtcmsPremium::setFileHandlerInputProperties($inputProperties, $fileField);
         } else {
             $inputProperties[] = $fileField->property;
         }
         $dirs = [public_path("file"), public_path("file/modelFiles"), public_path("file/modelFiles/" . $modelConfig->name)];
         foreach ($dirs as $dir) {
             if (!is_dir($dir)) {
                 mkdir($dir, 0755);
             }
         }
         foreach ($inputProperties as $inputProperty) {
             $fileData[$counter]['property'] = $inputProperty;
             if (\Request::hasFile($inputProperty)) {
                 $file = \Request::file($inputProperty);
                 if ($file->isValid()) {
                     $ext = $file->getClientOriginalExtension();
                     $basePath = public_path() . "/file/modelFiles/" . $modelConfig->name . "/";
                     $targetName = Str::slug($file->getClientOriginalName());
                     $targetName = preg_replace('/' . $ext . '$/', '', $targetName);
                     $originalTargetName = $targetName;
                     // Check if file exists
                     $nameCounter = 0;
                     while (file_exists($basePath . $targetName . "." . $ext)) {
                         $nameCounter++;
                         $targetName = $originalTargetName . "-" . $nameCounter;
                     }
                     $targetName .= "." . $ext;
                     // End check
                     $file->move($basePath, $targetName);
                 } else {
                     throw new \Exception("File is invalid", self::INVALID_FILE_ERROR);
                 }
                 $fileData[$counter]['filename'] = $targetName;
                 $counter++;
             }
         }
     }
     return $fileData;
 }
	@foreach ($modelConfig->relatedModels as $relatedModel)
		<?php 
$displayModel = true;
if ($modelConfig->reverseConstrainingModels) {
    foreach ($modelConfig->reverseConstrainingModels as $constraint) {
        if (method_exists($object, $constraint) && $object->{$constraint}->count()) {
            $displayModel = false;
            break;
        }
    }
}
$method = $relatedModel->method;
$relatedModelConfig = AdminHelper::modelExists($relatedModel->name);
$gets = Tools::getGets(array($modelConfig->id => $object->id ? $object->id : "new_gtcms_entry"));
$configInParent = $object->relatedModelConfiguration($relatedModelConfig->name);
GtcmsPremium::setDisplayRelatedModelBasedOnModelKey($configInParent, $object, $displayModel);
?>
		@if ($displayModel)

			<div class="panel panel-default">
				<div class="panel-body">
					<?php 
// --------------- EXCEPTIONS ----------------
$addObject = true;
?>
					@if ($addObject)
						<div class="indexTableHeader">
							<a href="/admin/{{$relatedModelConfig->name}}/add{{$gets}}&addToParent=true" class="btn btn-primary btn-sm addRelatedObject">
								<i class="fa fa-plus-circle"></i> {{$relatedModelConfig->hrName}}
							</a>
						</div>
Exemple #4
0
    public static function drawObjectTable($objects, ModelConfig $modelConfig, $tableType = 'table', $parent = "", $searchDataWithFieldValues = false, $ordering = false, $quickEdit = false)
    {
        $hasPositionInParent = false;
        $parentModelName = false;
        $hidePositionControls = $modelConfig->hidePositionControls;
        if ($tableType == 'sideTable' && $objects->count()) {
            /** @var BaseModel $firstObject */
            $firstObject = $objects[0];
            $configuration = $firstObject->getRelatedModelConfigurationInParentModel($modelConfig);
            $hasPositionInParent = $configuration['position'];
            $hidePositionControls = $configuration['hidePositionControls'];
            $parentModelName = $configuration['parentModelName'];
        }
        $objectsAreMovable = ($modelConfig->position && $tableType == 'table' || $hasPositionInParent) && !$hidePositionControls && $objects->count() > 1;
        $tree = "";
        $ctrlNum = 1;
        $controls = true;
        // -------------- EXCEPTIONS ---------------
        // ------------ END EXCEPTIONS -------------
        if (!$quickEdit) {
            $tree .= '
				<table class="table table-striped table-hover table-type-' . $tableType . ($objectsAreMovable ? ' hasPositioning' : '') . '">
				<tbody class="' . ($searchDataWithFieldValues || $ordering ? ' searchDataPresent' : '') . '">
				<tr>';
            $counter = 0;
            foreach ($modelConfig->formFields as $field) {
                if ($field->restrictedToSuperadmin && !\Auth::user()->is_superadmin) {
                    continue;
                }
                $userRole = \Auth::user()->role;
                if ($field->restrictedAccess && !$field->restrictedAccess->{$userRole}) {
                    continue;
                }
                if ($field->{$tableType}) {
                    $counter++;
                    $tree .= '
						<th class="controlButtons ' . ($objectsAreMovable && $counter == 1 ? 'sortablePadding' : '') . '" ' . ($objectsAreMovable && $counter == 1 ? 'colspan="2"' : '') . '><span>' . $field->label . '</span>';
                    if ($field->order && $tableType == 'table') {
                        $tree .= '
							<div class="sortLinks">
								<a class="btn btn-xs" href="/admin/' . $modelConfig->name . '?&orderBy=' . $field->property . '&direction=asc&getIgnore_getSearchResults=true' . Tools::getSearchAndOrderGets(false, true, true) . '" class="sortLink" data-loadtype="fadeIn">
									<i class="fa fa-caret-up"></i>
								</a>
								<a class="btn btn-mini" href="/admin/' . $modelConfig->name . '?orderBy=' . $field->property . '&direction=desc&getIgnore_getSearchResults=true' . Tools::getSearchAndOrderGets(false, true, true) . '" class="sortLink" data-loadtype="fadeIn">
									<i class="fa fa-caret-down"></i>
								</a>
							</div>
						';
                    }
                    $tree .= '</th>';
                }
            }
            if ($controls) {
                $tree .= '
			<th class="controls' . $ctrlNum . '"><span>' . trans('gtcms.controls') . '</span></th>';
            }
            $tree .= '
			</tr>';
        }
        /** @var BaseModel $object */
        foreach ($objects as $object) {
            $objectName = "";
            $gets = $parent ? $parent . (Tools::getGets() ? "&" . Tools::getGets(array(), false, false) : '') : Tools::getGets();
            $tree .= '
			<tr
				class="depth ' . ($objectsAreMovable ? 'isSortable' : '') . ' ' . ($quickEdit ? 'rowSelectize' : '') . '"
				data-objectid="' . $object->id . '"
				data-modelname="' . $modelConfig->name . '"
				data-parentname="' . $parentModelName . '"
			>';
            //regular fields
            $counter = 0;
            foreach ($modelConfig->formFields as $index => $field) {
                if ($field->restrictedToSuperadmin && !\Auth::user()->is_superadmin) {
                    continue;
                }
                $userRole = \Auth::user()->role;
                if ($field->restrictedAccess && !$field->restrictedAccess->{$userRole}) {
                    continue;
                }
                if ($field->{$tableType}) {
                    $counter++;
                    $image = false;
                    $method = false;
                    if ($field->displayProperty) {
                        if ($field->displayProperty->type == 'accessor') {
                            $property = $field->displayProperty->method;
                        } else {
                            if ($field->displayProperty->type == 'image') {
                                $method = $field->displayProperty->method;
                                $image = true;
                            } else {
                                if ($field->displayProperty->type == 'model') {
                                    $property = $field->displayProperty->property;
                                    $displayProperty = $field->displayProperty ? $field->displayProperty : $field->property;
                                    $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 {
                                    $property = $field->property;
                                }
                            }
                        }
                    } else {
                        $property = $field->property;
                    }
                    if ($objectsAreMovable && $counter == 1) {
                        $tree .= "\n\t\t\t\t\t\t\t\t<td class='sortHandle'>\n\t\t\t\t\t\t\t\t\t<div class='sortHandle'>\n\t\t\t\t\t\t\t\t\t\t<i class='fa fa-ellipsis-v'></i>\n\t\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t</td>";
                    }
                    $tree .= "<td>";
                    if (property_exists($field, $tableType . 'Link') && !$image) {
                        if ($field->displayProperty && $field->displayProperty->type == 'model') {
                            $tree .= '<a href="/admin/' . $modelConfig->name . '/edit/' . $object->id . $gets . '">' . ($object->{$method} ? $object->{$method}->{$property} : '- deleted -') . '</a>';
                            if (!$objectName) {
                                $objectName = $object->{$method} ? $object->{$method}->{$property} : '';
                            }
                        } else {
                            $tree .= '<a href="/admin/' . $modelConfig->name . '/edit/' . $object->id . $gets . '">' . $object->{$property} . '</a>';
                            if (!$objectName) {
                                $objectName = $object->{$property};
                            }
                        }
                    } else {
                        if ($image) {
                            if (!$method) {
                                $method = $image;
                            }
                            $tree .= '
							<a href="/admin/' . $modelConfig->name . '/edit/' . $object->id . $gets . '">
								<img style="height: 60px;" src="' . $object->{$method}('url', 'gtcmsThumb') . '">
							</a>';
                            if (!$objectName) {
                                $objectName = "image";
                            }
                        } else {
                            if ($field->displayProperty && $field->displayProperty->type == 'model') {
                                if ($field->displayProperty->multiple) {
                                    $tree .= $value;
                                } else {
                                    $tree .= $object->{$method} ? $object->{$method}->{$property} : ' - ';
                                }
                            } else {
                                if (in_array($field->type, array('date', 'dateTime'))) {
                                    $tree .= $object->formatDate($object->{$property}, $field->displayProperty->dateFormat ? $field->displayProperty->dateFormat : $field->dateFormat);
                                } else {
                                    if ($field->type == 'checkbox') {
                                        $tree .= $object->{$property} ? self::drawCheckboxIcon(true) : self::drawCheckboxIcon(false);
                                    } else {
                                        if ($field->type == 'select' && $field->indexSelect) {
                                            $originalValue = $object->{$property};
                                            $listMethod = $field->selectType->listMethod;
                                            $options['class'] = "";
                                            $list = array();
                                            if ($field->selectType->type == 'model') {
                                                $selectModel = $field->selectType->modelName;
                                                $fullModel = ModelConfig::fullEntityName($selectModel);
                                                $list = $fullModel::$listMethod();
                                            } else {
                                                if ($field->selectType->type == 'list') {
                                                    $entity = $modelConfig->myFullEntityName();
                                                    $list = $entity::$listMethod();
                                                }
                                            }
                                            if (!is_array($list) && is_object($list)) {
                                                $reflection = new \ReflectionClass($list);
                                                if ($reflection->getShortName() == "Collection") {
                                                    /** @var \Illuminate\Support\Collection $list */
                                                    $list = $list->toArray();
                                                }
                                            }
                                            if (!$field->required) {
                                                $null = array('' => '-');
                                                $list = $null + $list;
                                            }
                                            $options['class'] .= ' doSelectize selectizeNoCreate ajaxSelectUpdate ';
                                            $options['class'] .= $field->required ? " required " : '';
                                            $options['data-classname'] = $modelConfig->name;
                                            $options['data-objectid'] = $object->id;
                                            $options['data-property'] = $property;
                                            $options['data-token'] = csrf_token();
                                            if ($field->indexClass) {
                                                $options['class'] .= ' ' . $field->indexClass . ' ';
                                            } else {
                                                $options['class'] .= ' standardSelectWidth ';
                                            }
                                            $tree .= \Form::select($field->property, $list, $originalValue, $options);
                                        } else {
                                            $tree .= $object->{$property};
                                        }
                                    }
                                }
                            }
                        }
                    }
                    $tree .= "</td>";
                }
            }
            if ($controls) {
                $quickEditControl = "";
                if (config('gtcms.premium') && $modelConfig->getQuickEditFields('all')) {
                    $quickEditControl = GtcmsPremium::getQuickEditControl($modelConfig, $object, $gets);
                }
                if ($object->isDeletable()) {
                    $tree .= '<td class="controlButtons">';
                    $tree .= $quickEditControl;
                    $tree .= '<a
						href="/admin/' . $modelConfig->name . '/delete/' . $object->id . $gets . '"
						class="btn btn-default btn-xs deleteButton"
						data-modelname="' . $modelConfig->hrName . '"
						data-objectname="' . $objectName . '"
						>
							<i class="fa fa-times"></i>
						</a>
					</td>';
                } else {
                    $tree .= '
					<td class="controlButtons">';
                    $tree .= $quickEditControl;
                    $tree .= '<a
						href="#"
						class="btn btn-default btn-xs deleteButton disabled"
						>
							<i class="fa fa-times"></i>
						</a>
					</td>';
                }
            }
            $tree .= '</tr>';
        }
        if (!$quickEdit) {
            $tree .= '
					</tbody>
				</table>';
            if ($tableType == 'table' && $objects->total() > $modelConfig->perPage) {
                $tree .= '<div class="paginationContainer">' . $objects->appends(Tools::getGets(array('page' => NULL, 'getIgnore_getSearchResults' => 'true'), TRUE))->links() . '</div>';
            }
        }
        return $tree;
    }
     if (!is_array($list)) {
         if (is_object($list)) {
             $reflection = new ReflectionClass($list);
             if ($reflection->getShortName() == "Collection") {
                 /** @var \Illuminate\Support\Collection $list */
                 $list = $list->toArray();
             }
         } else {
             $list = array();
         }
     }
     $list = array('gtcms_load_default' => 'gtcms_load_default') + $list;
     $originalValue = (is_array($originalValue) ? $originalValue : array($originalValue)) + array('gtcms_load_default' => 'gtcms_load_default');
     $selectedValues = $originalValue;
     if (config('gtcms.premium')) {
         GtcmsPremium::sortMultiSelectList($selectedValues, $list);
     }
     $options['id'] = $field->property;
     echo Form::hidden($field->property . "_exists_in_gtcms_form", 1);
     echo Form::select($field->property . "[]", $list, $selectedValues, $options);
     // ----------- IMAGE ------------
 } else {
     if ($type == 'image') {
         $options['class'] = $options['class'] . " fileUpload";
         $property = $field->property;
         $imageFieldData = AdminHelper::getImageFieldRequirements($modelConfig, $field->property);
         $method = "image";
         if ($field->displayProperty && $field->displayProperty->method) {
             $method = $field->displayProperty->method;
         }
         ?>
Exemple #6
0
 public function getQuickEditFields($fieldType)
 {
     $quickEditFields = array();
     if (config('gtcms.premium')) {
         return \GtcmsPremium::getQuickEditFields($this, $fieldType);
     }
     return $quickEditFields;
 }
Exemple #7
0
 public static function modelImageMinDimensions()
 {
     if (!empty($_GET)) {
         $parentProperty = false;
         foreach ($_GET as $requiredParent => $parentId) {
             $parentProperty = $requiredParent;
             break;
         }
         if ($parentModelConfig = AdminHelper::modelExists($parentProperty, 'id')) {
             if ($parentModelConfig->imageSizes) {
                 $parentModelConfig = AdminHelper::modelExists($parentProperty, 'id');
                 if (config('gtcms.premium') && $parentModelConfig->keyBasedSizes) {
                     $sizes = GtcmsPremium::getKeyBasedImageSizes($parentModelConfig);
                 } else {
                     $sizes = $parentModelConfig->imageSizes;
                 }
                 if ($sizes) {
                     $size = false;
                     foreach ($sizes as $size) {
                         break;
                     }
                     $size = AdminHelper::objectToArray($size);
                     $minWidth = $size[0];
                     $minHeight = $size[1];
                     $manipulationType = $size[2];
                     return array($minWidth, $minHeight, $manipulationType);
                 } else {
                     return false;
                 }
             } else {
                 return false;
             }
         }
         return false;
     } else {
         return false;
     }
 }
Exemple #8
0
 public static function process($modelConfig, $imageFields, $parentProperty)
 {
     $imageData = array();
     $counter = 0;
     foreach ($imageFields as $imageField) {
         $imageData[$counter]['property'] = $imageField->property;
         if (\Request::hasFile($imageField->property)) {
             $ext = \Request::file($imageField->property)->getClientOriginalExtension();
             if (!in_array(strtolower($ext), array('jpg', 'jpeg', 'gif', 'png'))) {
                 throw new \Exception("File is not an image");
             } else {
                 $basePath = public_path() . "/img/modelImages/" . $modelConfig->name . "/";
                 $dirs = [public_path("img"), public_path("img/modelImages"), public_path("img/modelImages/" . $modelConfig->name), public_path("img/modelImages/" . $modelConfig->name . "/original"), public_path("img/modelImages/" . $modelConfig->name . "/gtcmsThumb")];
                 foreach ($dirs as $dir) {
                     if (!is_dir($dir)) {
                         mkdir($dir, 0755);
                     }
                 }
                 //here check if file exists
                 do {
                     $name = str_random(32) . "." . $ext;
                 } while (file_exists($basePath . "original/" . $name));
                 //end check
                 //copy the image to the original folder
                 \Image::make(\Request::file($imageField->property)->getRealPath())->save($basePath . "original/" . $name);
                 $img = \Image::make($basePath . "original/" . $name);
                 if ($parentProperty && $modelConfig->name == 'ModelImage') {
                     $parentModelConfig = AdminHelper::modelExists($parentProperty, 'id');
                     if (config('gtcms.premium') && $parentModelConfig->keyBasedSizes) {
                         $sizes = GtcmsPremium::getKeyBasedImageSizes($parentModelConfig);
                     } else {
                         $sizes = $parentModelConfig->imageSizes;
                     }
                 } else {
                     $sizes = $imageField->sizes;
                 }
                 if (!$sizes) {
                     throw new \Exception("Sizes not found!");
                 }
                 // Get the first size, which has the min/max dimensions
                 foreach ($sizes as $size) {
                     break;
                 }
                 $size = AdminHelper::objectToArray($size);
                 $minWidth = $size[0];
                 $minHeight = $size[1];
                 $transformMethod = $size[2];
                 if (in_array($transformMethod, array('resizeCanvas', 'resize'))) {
                     if ($img->width() < $minWidth && $img->height() < $minHeight) {
                         throw new \Exception(trans('gtcms.imageTooSmall'), self::DIM_ERROR);
                     }
                 }
                 if (in_array($transformMethod, array('minWidth'))) {
                     if ($img->width() < $minWidth) {
                         throw new \Exception(trans('gtcms.imageTooSmall'), self::DIM_ERROR);
                     }
                 }
                 if (in_array($transformMethod, array('minHeight'))) {
                     if ($img->height() < $minHeight) {
                         throw new \Exception(trans('gtcms.imageTooSmall'), self::DIM_ERROR);
                     }
                 } else {
                     if ($img->width() < $minWidth || $img->height() < $minHeight) {
                         throw new \Exception(trans('gtcms.imageTooSmall'), self::DIM_ERROR);
                     }
                 }
                 $returnFolder = 'gtcmsThumb';
                 $gtcmsSize = array(80, 80, 'resizeCanvas', 'gtcmsThumb', 100);
                 $sizes = AdminHelper::objectToArray($sizes);
                 array_unshift($sizes, $gtcmsSize);
                 foreach ($sizes as $size) {
                     $newImg = clone $img;
                     $size = AdminHelper::objectToArray($size);
                     if (!is_dir($basePath . $size[3])) {
                         mkdir($basePath . $size[3], 0755);
                     }
                     if ($size[2] == 'crop') {
                         $newImg->fit($size[0], $size[1])->save($basePath . $size[3] . "/" . $name, $size[4]);
                     } else {
                         if (in_array($size[2], array('resize', 'minWidth', 'minHeight'))) {
                             $newImg->resize($size[0], $size[1], function ($constraint) {
                                 $constraint->aspectRatio();
                                 $constraint->upsize();
                             })->save($basePath . $size[3] . "/" . $name, $size[4]);
                         } else {
                             if ($size[2] == 'resizeCanvas') {
                                 $newImg->resize($size[0], null, function ($constraint) {
                                     $constraint->aspectRatio();
                                     $constraint->upsize();
                                 });
                                 $newImg->resize(null, $size[1], function ($constraint) {
                                     $constraint->aspectRatio();
                                     $constraint->upsize();
                                 });
                                 if ($newImg->width() < $size[0] || $newImg->height() < $size[1]) {
                                     $newImg = \Image::canvas($size[0], $size[1], '#FFFFFF')->insert($newImg, 'center');
                                 }
                                 $newImg->save($basePath . $size[3] . "/" . $name, $size[4]);
                             } else {
                                 $newImg->save($basePath . $size[3] . "/" . $name, $size[4]);
                             }
                         }
                     }
                 }
                 $imageData[$counter]['filename'] = $name;
                 $imageData[$counter]['returnFolder'] = $returnFolder;
                 $counter++;
             }
         }
     }
     return $imageData;
 }