/** * Relation constructor. * @param $name * @param null $value * @param array $options */ public function __construct($name, $value = null, $options = []) { parent::__construct($name, $value, $options); $this->modelManager = Artificer::modelManager(); $this->modelSettings = $this->modelManager->current(); $this->currentModel = $this->modelSettings->model; }
public static function to($action) { return true; $model = ModelManager::getCurrent()->name; $modelPermissions = Artificer::modelManager()->getOption('action_permissions.' . $action, [], $model); return self::hasPermission($modelPermissions); }
public function guessModel() { $method = $this->guessRelatedMethod(); $modelName = Str::studly($method); if ($method && Artificer::modelManager()->has($modelName)) { return $modelName; } }
/** * Bootstrap the application events. * * @return void */ public function boot() { foreach ($this->hooks as $hook => $handlers) { if (empty($handlers)) { continue; } Artificer::hook()->to($hook, $handlers); } }
/** * @param $extension * @param $action * @return \Illuminate\Http\RedirectResponse * @throws \Exception */ protected function doAction($extension, $action) { $extension = $this->getExtensionSlug($extension); if ($action == self::ACTION_UNINSTALL && Artificer::isCoreExtension($extension->namespace)) { throw new \Exception('Core extensions can not be uninstalled'); } $this->getManager()->installer()->{$action}($extension->namespace); return \Redirect::back(); }
public function __construct() { $this->theme = AdminOption::get('theme') . '::'; $this->masterLayout = 'base'; $this->modelManager = Artificer::modelManager(); if ($this->isStandAlone()) { $this->masterLayout = 'standalone'; $this->standalone = true; } $this->shareMainViewData(); }
public static function isInstalled() { if (!self::isExtensionDriverReady()) { return false; } $pluginManager = Artificer::pluginManager(); $widgetManager = Artificer::widgetManager(); foreach (Artificer::getCoreExtensions() as $coreExtension) { if (!$pluginManager->isInstalled($coreExtension) && !$widgetManager->isInstalled($coreExtension)) { return false; } } return true; }
/** * @param bool $outputCore */ public function outputRoutes($outputCore = false) { $installedPlugins = $this->installer()->getInstalled(); foreach ($installedPlugins as $extension) { $extensionInstance = $this->get($extension); $isCoreExtension = Artificer::isCoreExtension($extension); if ($isCoreExtension && $outputCore) { $extensionInstance->getRoutes(); } if (!$isCoreExtension && !$outputCore) { \Route::group(['prefix' => $extensionInstance->getSlug()], function () use($extensionInstance) { $extensionInstance->getRoutes(); }); } } }
protected function installCoreExtensions() { $pluginManager = Artificer::pluginManager(); $widgetManager = Artificer::widgetManager(); // Enable install events Artificer::pluginManager()->boot(); Artificer::widgetManager()->boot(); foreach (Artificer::getCoreExtensions() as $coreExtension) { if (!$pluginManager->isInstalled($coreExtension) && !$widgetManager->isInstalled($coreExtension)) { // Todo: know if its plugin or widget $installed = $pluginManager->installer()->install($coreExtension); if (!$installed) { throw new \Exception("Unable to install Artificer core extension {$coreExtension}"); } } } }
public function input() { if (!$this->relation->getRelatedModel()) { throw new \Exception('missing relation in config for the current model.'); } $this->fields = array_get(\View::getShared(), 'fields'); $id = $this->fields['id']->value; $modelName = $this->relation->getRelatedModel(); $model = Artificer::modelManager()->get($modelName); $this->modelManager = $model; if ((Route::currentRouteName() == 'admin.model.create' || Route::currentRouteName() == 'admin.model.field') && Session::has('_set_relation_on_create_' . $this->modelSettings->name)) { $relateds = Session::get('_set_relation_on_create_' . $this->modelSettings->name); $related_ids = []; foreach ($relateds as $related) { $related_ids[] = $related['id']; } $data = $relateds[0]['modelClass']::whereIn('id', $related_ids)->get()->toArray(); } else { $data = $model['class']::where($this->relation->getForeignKey(), '=', $id)->get(['id', $this->relation->getShow()])->toArray(); } $this->showItems($data); $this->createRoute = $this->createRoute($this->modelManager['route']) . '?' . http_build_query([$this->relation->getForeignKey() => $id, '_standalone' => 'true']); if (!Request::ajax() || $this->showFullField) { $this->relationModal($this->modelManager['route'], $id); ?> <div class="text-right"> <div class="btn-group"> <button class="btn btn-default" data-toggle="modal" data-url="<?php echo $this->createRoute; ?> " data-target="#form-modal-<?php echo $this->modelManager['route']; ?> "> <i class="fa fa-plus"></i> </button> </div> </div> <?php } }
protected function applyAfterHook($data) { $hook = $this->isUpdating() ? Hook::UPDATED : Hook::CREATED; /* * @var $data [Array] of Mascame\Artificer\Fields\Field */ return Artificer::hook()->fire($hook, $data); }
/** * @param $instance AbstractExtension */ protected function addAssets($instance) { $assetsManager = Artificer::assetManager(); $instance->assets($assetsManager); }
private function addPublishableFiles() { $this->autoPublishes(function () { $this->publishes([__DIR__ . '/../resources/assets' => public_path(Artificer::getAssetsPath())], 'public'); $this->publishes([__DIR__ . '/../config/' => $this->getConfigPath()], 'config'); $this->loadTranslationsFrom(__DIR__ . '/../resources/lang', $this->name); }); }
Route::group(['middleware' => 'artificer-installed', 'prefix' => 'install'], function () { Route::get('/', ['as' => 'admin.install', 'uses' => InstallController::class . '@home']); Route::post('/', InstallController::class . '@install'); }); \Mascame\Artificer\Artificer::pluginManager()->outputCoreRoutes(); Route::group(['middleware' => ['artificer-auth']], function () { Route::get('/', ['as' => 'admin.home', 'uses' => HomeController::class . '@home']); Route::get('extensions', ExtensionController::class . '@extensions')->name('admin.extensions'); foreach (['plugins', 'widgets'] as $extensionType) { Route::group(['prefix' => $extensionType], function () use($extensionType) { Route::get('{slug}/install', ExtensionController::class . '@install')->name('admin.' . $extensionType . '.install'); Route::get('{slug}/uninstall', ExtensionController::class . '@uninstall')->name('admin.' . $extensionType . '.uninstall'); }); } Route::group(['prefix' => 'model'], function () { Route::get('{slug}', ModelController::class . '@all')->name('admin.model.all'); Route::get('{slug}/filter', ModelController::class . '@filter')->name('admin.model.filter'); Route::get('{slug}/create', ModelController::class . '@create')->name('admin.model.create'); Route::get('{slug}/{id}', ModelController::class . '@show')->name('admin.model.show'); Route::get('{slug}/{id}/edit', ModelController::class . '@edit')->name('admin.model.edit'); Route::get('{slug}/{id}/edit/{field}', ModelController::class . '@field')->name('admin.model.field.edit'); Route::post('{slug}/store', ModelController::class . '@updateOrCreate')->name('admin.model.store'); Route::put('{slug}/{id}', ModelController::class . '@updateOrCreate')->name('admin.model.update'); Route::delete('{slug}/{id}', ModelController::class . '@destroy')->name('admin.model.destroy'); Route::get('{slug}/{id}/field/{name}', ModelController::class . '@getRelatedFieldOutput')->name('admin.model.field'); }); Route::group(['prefix' => 'plugin'], function () { \Mascame\Artificer\Artificer::pluginManager()->outputRoutes(); }); }); });
public function isFillable() { $fillable = Artificer::modelManager()->current()->getFillable(); return $this->isAll($fillable) || in_array($this->getName(), $fillable); }
/** * @param array|string $plugin * @return bool */ protected function addPlugin($plugin) { return Artificer::pluginManager()->add($this->package, $plugin); }