model = $model; } /** * Getter for absolute path to template * * @param null $mode * * @return string */ public function getPathToTemplate($mode = null) { $templateName = $this->model->template_name; $path = $this->model->templatePath; // delete namespace if given if (strpos($this->model->template_name, '::')) { list(, $templateName) = explode('::', $templateName); } // get template name, do not care about directories (they are already contained in path) $parts = explode('.', $templateName); $templateName = last($parts); // just a shortcut for this unbelievable long constant name... $_ = DIRECTORY_SEPARATOR; // path parts $absolutePath = base_path($path->path); $templatePath = str_replace('.', $_, $templateName); $file = $templatePath . ITemplate::TEMPLATE_SUFFIX; // compose two versions of path - original and with "custom" directory $original = $absolutePath . $_ . $file; $edited = $absolutePath . $_ . ITemplate::EDITED_TEMPLATES_DIRECTORY . $_ . $file; // decide which path will be returned switch ($mode) { case ITemplate::CUSTOM_EDIT_DIRECTORY: return $edited; break; case ITemplate::ORIGINAL_DIRECTORY: return $original; break; default: if (file_exists($absolutePath . $_ . ITemplate::EDITED_TEMPLATES_DIRECTORY . $_ . $file)) { return $edited; } return $original; break; } } public function getForModule(Module $module) { return Cache::rememberForever('templates-for-module', function () use ($module) { return TemplateModel::where('module_id', $module->id) ->select(['template_name', 'name', 'description']) ->get(); }); } }