FEATURE: add another repositories
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
namespace App\Cms\Repositories\Templates;
|
||||
|
||||
use App\CMS\Contracts\Repositories\Template as ITemplate;
|
||||
use App\CMS\Repositories\Repository;
|
||||
use App\Models\Module;
|
||||
use App\Models\Templates\Template as TemplateModel;
|
||||
|
||||
class Template extends Repository implements ITemplate
|
||||
{
|
||||
public function __construct(TemplateModel $model)
|
||||
{
|
||||
$this->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->path()->get();
|
||||
|
||||
// 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 Template::where('module_id', $module->id)
|
||||
->select(['template_name', 'name', 'description'])
|
||||
->get();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user