예제 #1
0
 /**
  * @param Menu $menu
  * @param MenuItem $item
  * @param Request $request
  * @param Page $page
  * @param Locale $locale
  * @param ModuleRoute $route
  * @return
  */
 public function store(Menu $menu, MenuItem $item, Request $request, Page $page, Locale $locale, ModuleRoute $route)
 {
     $input = translation_input($request, ['name']);
     if (isset($input['page_id'])) {
         //make sure to set the default labels for the menu item
         $page = $page->findOrFail($input['page_id']);
         foreach ($locale->all() as $locale) {
             $translation = $page->translate($locale->slug);
             if ($translation) {
                 $input[$locale->slug]['name'] = $translation->title;
             }
         }
     } elseif (isset($input['module_route_id'])) {
         //make sure to set the default labels for the menu item
         $route = $route->findOrFail($input['module_route_id']);
         foreach ($locale->all() as $locale) {
             $translation = $route->translate($locale->slug);
             if ($translation) {
                 $input[$locale->slug]['name'] = $translation->title;
             }
         }
     } else {
         $rules = ['url' => 'required'];
         foreach ($this->account->account()->locales as $locale) {
             $rules = array_merge($rules, ["translations.{$locale->slug}.name" => 'required']);
         }
         $this->validate($request, $rules);
     }
     return $this->menu->createItem($input);
 }
예제 #2
0
 /**
  * @param Request $request
  * @param Locale $locale
  * @return mixed
  */
 public function store(Request $request, Locale $locale)
 {
     $owner = $this->owner($request);
     $file = $request->file('file');
     $infographic = $this->dispatch(new UploadNewInfographic($owner, $file, $locale->whereSlug($request->get('locale'))->firstOrFail()));
     $infographic->load('sizes');
     return $infographic;
 }
예제 #3
0
 /**
  * @param Request $request
  * @param Locale $locale
  * @return array|JsonResponse|mixed|null|\Symfony\Component\HttpFoundation\File\UploadedFile
  */
 public function store(Request $request, Locale $locale)
 {
     $owner = $this->owner($request);
     $file = $request->file('file');
     $file = $this->dispatch(new UploadNewFile($owner, $file, $locale->whereSlug($request->get('locale'))->firstOrFail()));
     if (!$file) {
         return new JsonResponse('Something went wrong, check for duplicate filename', 400);
     }
     return $file;
 }
예제 #4
0
 protected function system_locales()
 {
     $accountLocales = app('Modules\\Account\\AccountManager')->account()->locales;
     $systemLocales = Locale::with('translations')->get();
     $systemLocales->each(function ($locale) use($accountLocales) {
         $locale->activated = $accountLocales->contains($locale->id);
         $locale->active = app()->getLocale();
     });
     return $systemLocales->keyBy('slug');
 }
 public function setUp()
 {
     parent::setUp();
     $data = Locale::unguarded(function () {
         return [new Locale(['id' => 1, 'slug' => 'nl']), new Locale(['id' => 2, 'slug' => 'fr']), new Locale(['id' => 3, 'slug' => 'en'])];
     });
     $locales = m::mock(Locale::class);
     $locales->shouldReceive('all')->andReturn(new Collection($data));
     $this->app[Locale::class] = $locales;
 }
예제 #6
0
 /**
  * Get the collection of items as a plain array.
  *
  * @return array
  */
 public function toArray()
 {
     $locales = Locale::all();
     $translations = with(new Collection($this->items))->keyBy('locale_id')->toArray();
     $result = [];
     foreach ($locales as $locale) {
         if (isset($translations[$locale->id])) {
             $result[$locale->slug] = $translations[$locale->id];
         }
     }
     return $result;
 }
예제 #7
0
 /**
  * @param Request $request
  * @param Product $product
  * @param Guard $guard
  * @param AccountManager $accounts
  * @return Product|string|static
  */
 public function store(Request $request, Product $product, Guard $guard, AccountManager $accounts)
 {
     $this->validate($request, ['brand_id' => 'required|exists:product_brands,id', 'name' => 'required|string', 'ean' => 'string|size:13']);
     $input = translation_input($request);
     $name = $request->get('name');
     foreach (Locale::all() as $locale) {
         $input[$locale->slug] = ['name' => $name];
     }
     $product = $product->newInstance($input);
     $product->account_id = $accounts->account()->id;
     if ($product->save()) {
         return $product;
     }
     return json_encode(['status' => 'noke']);
 }
예제 #8
0
 /**
  * Set the slug manually.
  *
  * $slug
  * @param $uri
  */
 protected function setSlug($uri)
 {
     if (empty($uri)) {
         return;
     }
     //for site sluggables, we do not need to configure anything as we know how we'll name our slug
     //and what relation it uses.
     //all we need to check is.. does it exist? if not, create a new one.
     //if so, update it.
     //old way of handling locales with simple string values
     if (isset($this->attributes['locale'])) {
         $locale = Locale::whereSlug($this->attributes['locale'])->first();
     } else {
         $locale = $this->locale;
     }
     //to find the account id, we'd need the parent document, not the translation document
     //since we didn't define our translation to use a general name, we need to use an interface function
     //which returns a value for us. (and which we can define on each model)
     //both this part and the part for the locales should be cleaned up once we upgrade our system
     //to only use the locale class and not the locale string values.
     //do not change it into :
     //
     //# $account = app('Modules\Account\AccountManager')->account();
     //
     //that would be wrong when we're doing some sort of console command
     //without an actual account reference within accountmanager
     $account = $this->getAccount();
     $this->load('slug');
     if (!($slug = $this->slug)) {
         //slugs should always be account specific, at least for now
         $slug = new Uri(['account_id' => $account->id, 'locale_id' => $locale->id, 'uri' => $uri]);
         $this->slug()->save($slug);
     } else {
         //consider a post as our example resource from now on
         //whenever we update a post its title... we'll be working in a draft.
         //this means that we do not need to save a new uri instance.
         //an uri only becomes active and should then be inserted, when an actual draft is published.
         //the same goes for editing an existing post.
         //when editing a post, you'll actually edit a revision. which will not be online until you publish it.
         //when you publish it, the old post will be taken 'offline'
         //the new post will be created, which will trigger the new uri insertion.
         //the canonical is probably something that needs to be implemented together with the allowRevisions trait
         //instead of implementing it in the uri table
         //when updating the slug, we need to insert a new uri, and set the canonical
         $this->slug->uri = $uri;
         $this->slug->save();
     }
 }
예제 #9
0
 public function run()
 {
     $account = $this->account('digiredo');
     if (env('APP_MULTIPLE_LOCALES')) {
         $account->locales()->attach(Locale::where('slug', 'en')->first());
     }
     $this->roles($account);
     $this->contactInformation($account);
     $this->membershipInvitations($account);
     $account = $this->account('cloudcreations');
     if (env('APP_MULTIPLE_LOCALES')) {
         $account->locales()->attach(Locale::where('slug', 'en')->first());
     }
     $this->roles($account);
     $this->contactInformation($account);
     $this->membershipInvitations($account);
 }
예제 #10
0
 /**
  * @param $field
  * @return bool
  */
 protected function getSeoCustomisation($field)
 {
     static $locale;
     if (!$locale) {
         $locale = app()->getLocale();
         $locale = Locale::whereSlug($locale)->first();
     }
     if ($this->seo) {
         $localised = $this->seo->first(function ($key, $item) use($locale) {
             return $item->locale_id == $locale->id;
         });
         if ($localised) {
             return $localised->{$field};
         }
     }
     return false;
 }
 /**
  * Run the migrations.
  *
  * @return void
  */
 public function up()
 {
     Schema::create('locales', function (Blueprint $table) {
         $table->increments('id');
         $table->string('slug', 5);
     });
     Schema::create('locales_translations', function (Blueprint $table) {
         $table->increments('id');
         $table->integer('locale_id', false, true);
         $table->foreign('locale_id', 'translation_to_locale')->references('id')->on('locales')->onDelete('cascade');
         $table->string('locale', 5);
         $table->string('name');
     });
     Locale::create(['slug' => 'nl', 'nl' => ['name' => 'nederlands'], 'fr' => ['name' => 'néerlandais'], 'de' => ['name' => 'holländisch'], 'en' => ['name' => 'dutch']]);
     Locale::create(['slug' => 'fr', 'nl' => ['name' => 'frans'], 'fr' => ['name' => 'français'], 'de' => ['name' => 'französisch'], 'en' => ['name' => 'french']]);
     Locale::create(['slug' => 'en', 'nl' => ['name' => 'engels'], 'fr' => ['name' => 'anglais'], 'de' => ['name' => 'englisch'], 'en' => ['name' => 'english']]);
     Locale::create(['slug' => 'de', 'nl' => ['name' => 'duits'], 'fr' => ['name' => 'allemand'], 'de' => ['name' => 'deutsch'], 'en' => ['name' => 'german']]);
 }
예제 #12
0
 /**
  * keep this public, this allows for easy searching inheriting.
  *
  * @param Searchable $inheritFrom
  * @return array
  */
 public function getSearchableSuggestData(Searchable $inheritFrom = null)
 {
     $data = [];
     if (uses_trait($this, Translatable::class)) {
         //foreach locale we add a different suggest
         foreach (Locale::all() as $locale) {
             $translation = $this->translate($locale->slug);
             if (!$translation) {
                 continue;
             }
             $data[$this->getSearchableSuggestName($locale, $inheritFrom)] = $this->getSearchableSuggestPayload($translation);
         }
     }
     return $data;
 }