/**
  * Handle the fields.
  *
  * @param PermissionFormBuilder $builder
  * @param AddonCollection       $addons
  * @param Translator            $translator
  * @param Repository            $config
  */
 public function handle(PermissionFormBuilder $builder, AddonCollection $addons, Translator $translator, Repository $config)
 {
     /* @var UserInterface $user */
     $user = $builder->getEntry();
     $fields = [];
     $namespaces = ['streams'];
     /* @var Addon $addon */
     foreach ($addons->withConfig('permissions') as $addon) {
         $namespaces[] = $addon->getNamespace();
     }
     foreach ($namespaces as $namespace) {
         foreach ($config->get($namespace . '::permissions', []) as $group => $permissions) {
             $label = $namespace . '::permission.' . $group . '.name';
             if (!$translator->has($warning = $namespace . '::permission.' . $group . '.warning')) {
                 $warning = null;
             }
             if (!$translator->has($instructions = $namespace . '::permission.' . $group . '.instructions')) {
                 $instructions = null;
             }
             $fields[$namespace . '::' . $group] = ['label' => $label, 'warning' => $warning, 'instructions' => $instructions, 'type' => 'anomaly.field_type.checkboxes', 'value' => function () use($user, $namespace, $group) {
                 return array_map(function ($permission) use($user, $namespace, $group) {
                     return str_replace($namespace . '::' . $group . '.', '', $permission);
                 }, $user->getPermissions());
             }, 'config' => ['options' => function () use($group, $permissions, $namespace) {
                 return array_combine($permissions, array_map(function ($permission) use($namespace, $group) {
                     return $namespace . '::permission.' . $group . '.option.' . $permission;
                 }, $permissions));
             }]];
         }
     }
     $builder->setFields($fields);
 }
 /**
  * Guess the sections title.
  *
  * @param ControlPanelBuilder $builder
  */
 public function guess(ControlPanelBuilder $builder)
 {
     $sections = $builder->getSections();
     foreach ($sections as &$section) {
         // If title is set then skip it.
         if (isset($section['title'])) {
             continue;
         }
         $module = $this->modules->active();
         $title = $module->getNamespace('section.' . $section['slug'] . '.title');
         if (!isset($section['title']) && $this->translator->has($title)) {
             $section['title'] = $title;
         }
         $title = $module->getNamespace('addon.section.' . $section['slug']);
         if (!isset($section['title']) && $this->translator->has($title)) {
             $section['title'] = $title;
         }
         if (!isset($section['title']) && $this->config->get('streams::system.lazy_translations')) {
             $section['title'] = ucwords($this->string->humanize($section['slug']));
         }
         if (!isset($section['title'])) {
             $section['title'] = $title;
         }
     }
     $builder->setSections($sections);
 }
Example #3
0
 /**
  * Format a timestamp based on translation
  *
  * @param  mixed $timestamp    accepts string, unix timestamp and DateTime object
  * @param  string $format
  * @return string
  */
 public function format($format = 'date', $timestamp = null)
 {
     $timestamp = is_numeric($timestamp) ? '@' . intval($timestamp) : $timestamp;
     $timestamp = is_a($timestamp, 'DateTime') ? $timestamp : new DateTime($timestamp);
     $key = $this->getTranslationKey("date.formats.{$format}");
     $format = $this->translator->has($key) ? $this->translator->get($key) : null;
     if (is_null($format)) {
         throw new \InvalidArgumentException('Date format is invalid or does not exists in current language');
     }
     return strftime($format, $timestamp->format('U'));
 }
Example #4
0
 /**
  * Get localized name of zodiac sign
  *
  * @return string
  */
 public function localized()
 {
     if (!is_a($this->translator, 'Illuminate\\Translation\\Translator')) {
         return "zodiacs.{$this->name}";
     }
     if ($this->translator->has("zodiacs.{$this->name}")) {
         // return error message from validation translation file
         return $this->translator->get("zodiacs.{$this->name}");
     }
     // return packages default message
     return $this->translator->get("zodiacs::zodiacs.{$this->name}");
 }
Example #5
0
 private function shareTitle()
 {
     $langKey = "titles.{$this->router->currentRouteName()}";
     if ($this->lang->has($langKey)) {
         $this->view->share('title', $this->lang->get($langKey));
     }
 }
 /**
  * Translate a target array.
  *
  * @param array $target
  * @return array
  */
 public function translate($target)
 {
     if (is_string($target)) {
         return $this->translator->trans($target);
     }
     if (is_array($target)) {
         foreach ($target as &$value) {
             if (is_string($value) && $this->translator->has($value)) {
                 $value = $this->translator->trans($value);
             } elseif (is_array($value)) {
                 $value = $this->translate($value);
             }
         }
     }
     return $target;
 }
 /**
  * tries to translate the message if existing, otherwise returns the original message string
  *
  * @param string $message
  * @return string
  */
 private function translateMessage($message)
 {
     if ($this->translator->has($message)) {
         return $this->translator->get($message);
     }
     return $message;
 }
 /**
  * Guess the button from the hint.
  *
  * @param ControlPanelBuilder $builder
  */
 public function guess(ControlPanelBuilder $builder)
 {
     $buttons = $builder->getButtons();
     $module = $this->modules->active();
     /**
      * This will break if we can't figure
      * out what the active module is.
      */
     if (!$module instanceof Module) {
         return;
     }
     foreach ($buttons as &$button) {
         if (!isset($button['button'])) {
             continue;
         }
         $text = $module->getNamespace('button.' . $button['button']);
         if (!isset($button['text']) && $this->translator->has($text)) {
             $button['text'] = $text;
         }
         $text = $module->getNamespace('button.' . $button['button']);
         if (!isset($button['text']) && $this->translator->has($text)) {
             $button['text'] = $text;
         }
         if ((!isset($button['text']) || !$this->translator->has($button['text'])) && $this->config->get('streams::system.lazy_translations')) {
             $button['text'] = $this->string->humanize(array_get($button, 'slug', $button['button']));
         }
     }
     $builder->setButtons($buttons);
 }
 /**
  * Guess the sections description.
  *
  * @param ControlPanelBuilder $builder
  */
 public function guess(ControlPanelBuilder $builder)
 {
     $sections = $builder->getSections();
     foreach ($sections as &$section) {
         // If description is set then skip it.
         if (isset($section['description'])) {
             continue;
         }
         $module = $this->modules->active();
         $description = $module->getNamespace('section.' . $section['slug'] . '.description');
         if ($this->translator->has($description)) {
             $section['description'] = $description;
         }
     }
     $builder->setSections($sections);
 }
 /**
  * Handle the command.
  *
  * @param Repository $config
  * @param Evaluator  $evaluator
  */
 public function handle(Repository $config, Evaluator $evaluator, Translator $translator)
 {
     if (!($fields = $config->get($this->fieldType->getNamespace('config/config')))) {
         $fields = $config->get($this->fieldType->getNamespace('config'), []);
     }
     $fields = $evaluator->evaluate($fields);
     foreach ($fields as $slug => $field) {
         /**
          * Determine the field label.
          */
         $label = $this->fieldType->getNamespace('config.' . $slug . '.label');
         if (!$translator->has($label)) {
             $label = $this->fieldType->getNamespace('config.' . $slug . '.name');
         }
         $field['label'] = array_get($field, 'label', $label);
         /**
          * Determine the instructions.
          */
         $instructions = $this->fieldType->getNamespace('config.' . $slug . '.instructions');
         if ($translator->has($instructions)) {
             $field['instructions'] = $instructions;
         }
         /**
          * Determine the placeholder.
          */
         $placeholder = $this->fieldType->getNamespace('config.' . $slug . '.placeholder');
         if ($translator->has($placeholder)) {
             $field['placeholder'] = $placeholder;
         }
         /**
          * Determine the warning.
          */
         $warning = $this->fieldType->getNamespace('config.' . $slug . '.warning');
         if ($translator->has($warning)) {
             $field['warning'] = $warning;
         }
         /**
          * Set the configuration value.
          */
         $field['value'] = array_get($this->fieldType->getConfig(), $slug);
         // Prefix the slugs.
         $field['field'] = 'config.' . $slug;
         $fields['config.' . $slug] = $field;
         $this->builder->addField($field);
     }
 }
 /**
  * Handle the fields.
  *
  * @param PermissionFormBuilder $builder
  * @param AddonCollection       $addons
  * @param Translator            $translator
  * @param Repository            $config
  */
 public function handle(PermissionFormBuilder $builder, AddonCollection $addons, Translator $translator, Repository $config)
 {
     /* @var UserInterface $user */
     $user = $builder->getEntry();
     $roles = $user->getRoles();
     $inherited = $roles->permissions();
     $fields = [];
     $namespaces = array_merge(['streams'], $addons->withConfig('permissions')->namespaces());
     /**
      * gather all the addons with a
      * permissions configuration file.
      *
      * @var Addon $addon
      */
     foreach ($namespaces as $namespace) {
         foreach ($config->get($namespace . '::permissions', []) as $group => $permissions) {
             /**
              * Determine the general
              * form UI components.
              */
             $label = $namespace . '::permission.' . $group . '.name';
             if (!$translator->has($warning = $namespace . '::permission.' . $group . '.warning')) {
                 $warning = null;
             }
             if (!$translator->has($instructions = $namespace . '::permission.' . $group . '.instructions')) {
                 $instructions = null;
             }
             /**
              * Gather the available
              * permissions for the group.
              */
             $available = array_combine(array_map(function ($permission) use($namespace, $group) {
                 return $namespace . '::' . $group . '.' . $permission;
             }, $permissions), array_map(function ($permission) use($namespace, $group) {
                 return $namespace . '::permission.' . $group . '.option.' . $permission;
             }, $permissions));
             /**
              * Build the checkboxes field
              * type to handle the UI.
              */
             $fields[$namespace . '::' . $group] = ['label' => $label, 'warning' => $warning, 'instructions' => $instructions, 'type' => 'anomaly.field_type.checkboxes', 'value' => array_merge($user->getPermissions(), $inherited), 'config' => ['disabled' => $inherited, 'options' => $available]];
         }
     }
     $builder->setFields($fields);
 }
 /**
  * Format the label to the proper format
  *
  * @param $name
  * @return string
  */
 public function formatLabel($name)
 {
     if (!$name) {
         return null;
     }
     if ($this->translator->has($name)) {
         return $this->translator->get($name);
     }
     return ucfirst(str_replace('_', ' ', $name));
 }
 /**
  * Guess the button from the hint.
  *
  * @param ControlPanelBuilder $builder
  */
 public function guess(ControlPanelBuilder $builder)
 {
     $buttons = $builder->getButtons();
     $module = $this->modules->active();
     /*
      * This will break if we can't figure
      * out what the active module is.
      */
     if (!$module instanceof Module) {
         return;
     }
     foreach ($buttons as &$button) {
         /*
          * If the button starts with "new_" just use
          * "new" and move the rest to the text.
          */
         if (isset($button['button']) && starts_with($button['button'], 'new_')) {
             if (!isset($button['text'])) {
                 $text = $module->getNamespace('button.' . $button['button']);
                 if ($this->translator->has($text)) {
                     $button['text'] = $text;
                 }
             }
             // Change this to slug for later.
             $button['slug'] = $button['button'];
             array_set($button, 'button', substr($button['button'], 0, 3));
         }
         /*
          * If the button starts with "add_" just use
          * "add" and move the rest to the text.
          */
         if (isset($button['button']) && starts_with($button['button'], 'add_')) {
             if (!isset($button['text'])) {
                 $button['text'] = $module->getNamespace('button.' . $button['button']);
             }
             // Change this to slug for later.
             $button['slug'] = $button['button'];
             array_set($button, 'button', substr($button['button'], 0, 3));
         }
     }
     $builder->setButtons($buttons);
 }
Example #14
0
 /**
  * Gera uma excecao e retorna o Exception
  * @param $msg
  * @return \Exception
  */
 public function create($msg)
 {
     // Verificar se mensagem pode ser traduzida pelo sistema da Lang do Laravel
     if (is_string($msg) && $this->lang->has($msg)) {
         $msg = $this->lang->get($msg);
     }
     // Se msg for um objeto ou array deve fazer um print_r
     if (is_object($msg) || is_array($msg)) {
         $msg = print_r($msg, true);
     }
     $args = func_get_args();
     $args[0] = $msg;
     $msg = trim(call_user_func_array('sprintf', $args));
     $code = $args[count($args) - 1];
     if (is_numeric($code)) {
         return new \Exception($msg, $code);
     } else {
         return new \Exception($msg);
     }
 }
 /**
  * Guess some table table filter placeholders.
  *
  * @param TableBuilder $builder
  */
 public function guess(TableBuilder $builder)
 {
     $filters = $builder->getFilters();
     $stream = $builder->getTableStream();
     foreach ($filters as &$filter) {
         // Skip if we already have a placeholder.
         if (isset($filter['placeholder'])) {
             continue;
         }
         // Get the placeholder off the assignment.
         if ($stream && ($assignment = $stream->getAssignment(array_get($filter, 'field')))) {
             /**
              * Always use the field name
              * as the placeholder. Placeholders
              * that are assigned otherwise usually
              * feel out of context:
              *
              * "Choose an option..." in the filter
              * would just be weird.
              */
             $filter['placeholder'] = $assignment->getFieldName();
         }
         if (!($module = $this->modules->active())) {
             continue;
         }
         $placeholder = $module->getNamespace('field.' . $filter['slug'] . '.placeholder');
         if (!isset($filter['placeholder']) && $this->translator->has($placeholder)) {
             $filter['placeholder'] = $placeholder;
         }
         $placeholder = $module->getNamespace('field.' . $filter['slug'] . '.name');
         if (!isset($filter['placeholder']) && $this->translator->has($placeholder)) {
             $filter['placeholder'] = $placeholder;
         }
         if (!array_get($filter, 'placeholder')) {
             $filter['placeholder'] = $filter['slug'];
         }
     }
     $builder->setFilters($filters);
 }
Example #16
0
 /**
  * @param $message
  * @param $replacements
  * @return mixed
  */
 protected function translateMessage($message, $replacements)
 {
     if (static::$translator and static::$translator->has($message)) {
         // if there is a language entry which matches this message, use that instead
         if (isset($replacements) && is_array($replacements)) {
             // there are replacements specified
             $message = static::$translator->get($message, $replacements);
         } else {
             // no replacement, just a plain language entry
             $message = static::$translator->get($message);
         }
     }
     return $message;
 }
 /**
  * Returns an URL adapted to the route name and the locale given
  *
  * @throws SupportedLocalesNotDefined
  * @throws UnsupportedLocaleException
  *
  * @param  string|boolean $locale Locale to adapt
  * @param  string $transKeyName Translation key name of the url to adapt
  * @param  array $attributes Attributes for the route (only needed if transKeyName needs them)
  *
  * @return string|false    URL translated
  */
 public function getURLFromRouteNameTranslated($locale, $transKeyName, $attributes = array())
 {
     if (!$this->checkLocaleInSupportedLocales($locale)) {
         throw new UnsupportedLocaleException('Locale \'' . $locale . '\' is not in the list of supported locales.');
     }
     if (!is_string($locale)) {
         $locale = $this->getDefaultLocale();
     }
     $route = "";
     if (!($locale === $this->defaultLocale && $this->hideDefaultLocaleInURL())) {
         $route = '/' . $locale;
     }
     if (is_string($locale) && $this->translator->has($transKeyName, $locale)) {
         $translation = $this->translator->trans($transKeyName, [], "", $locale);
         $route .= "/" . $translation;
         $route = $this->substituteAttributesInRoute($attributes, $route);
     }
     if (empty($route)) {
         // This locale does not have any key for this route name
         return false;
     }
     return rtrim($this->createUrlFromUri($route));
 }
Example #18
0
 /**
  * Determine if a translation exists.
  *
  * @param string $key
  * @param string|null $locale
  * @param bool $fallback
  * @return bool 
  * @static 
  */
 public static function has($key, $locale = null, $fallback = true)
 {
     return \Illuminate\Translation\Translator::has($key, $locale, $fallback);
 }
Example #19
0
 /**
  * @param Request    $request
  * @param Store      $settings
  * @param Translator $trans
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function postPreferences(Request $request, Store $settings, Translator $trans)
 {
     $this->validate($request, ['dst' => 'required|in:0,1,2', 'follow_started_topics' => 'boolean', 'follow_replies_topics' => 'boolean', 'show_editor' => 'boolean', 'topics_per_page' => 'integer|min:5|max:50', 'posts_per_page' => 'integer|min:5|max:50', 'style' => '', 'language' => 'required', 'message_order' => 'in:asc,desc', 'notify_on_like' => 'boolean', 'notify_on_quote' => 'boolean', 'notify_on_reply' => 'boolean', 'notify_on_new_post' => 'boolean', 'notify_on_new_comment' => 'boolean', 'notify_on_comment_like' => 'boolean', 'notify_on_my_comment_like' => 'boolean', 'notify_on_comment_reply' => 'boolean', 'notify_on_my_comment_reply' => 'boolean', 'notify_on_new_message' => 'boolean', 'notify_on_reply_message' => 'boolean', 'notify_on_group_request' => 'boolean', 'notify_on_moderation_post' => 'boolean', 'notify_on_report' => 'boolean', 'notify_on_username_change' => 'boolean', 'notification_mails' => 'required|in:0,1,2']);
     $input = $request->except(['_token']);
     // Make checkboxes booleans
     $input['follow_started_topics'] = isset($input['follow_started_topics']);
     $input['follow_replied_topics'] = isset($input['follow_replied_topics']);
     $input['show_editor'] = isset($input['show_editor']);
     $input['notify_on_like'] = isset($input['notify_on_like']);
     $input['notify_on_quote'] = isset($input['notify_on_quote']);
     $input['notify_on_reply'] = isset($input['notify_on_reply']);
     $input['notify_on_new_post'] = isset($input['notify_on_new_post']);
     $input['notify_on_new_comment'] = isset($input['notify_on_new_comment']);
     $input['notify_on_comment_like'] = isset($input['notify_on_comment_like']);
     $input['notify_on_my_comment_like'] = isset($input['notify_on_my_comment_like']);
     $input['notify_on_comment_reply'] = isset($input['notify_on_comment_reply']);
     $input['notify_on_my_comment_reply'] = isset($input['notify_on_my_comment_reply']);
     $input['notify_on_new_message'] = isset($input['notify_on_new_message']);
     $input['notify_on_reply_message'] = isset($input['notify_on_reply_message']);
     $input['notify_on_group_request'] = isset($input['notify_on_group_request']);
     $input['notify_on_moderation_post'] = isset($input['notify_on_moderation_post']);
     $input['notify_on_report'] = isset($input['notify_on_report']);
     $input['notify_on_username_change'] = isset($input['notify_on_username_change']);
     // Unset non existant language and default (don't override the board default)
     if ($input['language'] == 'default' || !$trans->has('general.language', $input['language'])) {
         $input['language'] = null;
     }
     if ($input['date_format'] == 'default') {
         $input['date_format'] = null;
     }
     $timezones = \DateTimeZone::listIdentifiers();
     if ($input['timezone'] == trans('general.timezone') || !in_array($input['timezone'], $timezones)) {
         $input['timezone'] = null;
     }
     if ($input['time_format'] == trans('general.timeformat')) {
         $input['time_format'] = null;
     }
     $modifiedSettings = [];
     $modifiedSettings['conversations.message_order'] = $input['message_order'];
     unset($input['message_order']);
     // Prefix all settings with "user."
     foreach ($input as $key => $value) {
         $modifiedSettings["user.{$key}"] = $value;
     }
     $settings->set($modifiedSettings, null, true);
     return redirect()->route('account.preferences')->withSuccess(trans('account.saved_preferences'));
 }
 /**
  * Get voucher types
  *
  * @return array
  *  An array of arrays as follows: array( array('label'=>$name0, 'value'=>$id0), array('label'=>$name1, 'value'=>$id1),…)
  */
 public function getVoucherTypes()
 {
     $voucherTypes = array();
     $this->VoucherType->byOrganization($this->AuthenticationManager->getCurrentUserOrganizationId())->each(function ($VoucherType) use(&$voucherTypes) {
         array_push($voucherTypes, array('label' => $this->Lang->has($VoucherType->lang_key) ? $this->Lang->get($VoucherType->lang_key) : $VoucherType->name, 'value' => $VoucherType->id));
     });
     return $voucherTypes;
 }
Example #21
0
 /**
  * Determine if a translation exists.
  *
  * @param string $key
  * @param string $locale
  * @return bool 
  * @static 
  */
 public static function has($key, $locale = null)
 {
     return \Illuminate\Translation\Translator::has($key, $locale);
 }
 /**
  * Update accounting setting
  *
  * @param array $input
  *   An array as follows: array('courses'=> array($id0, $id1,…), 'costCenters'=> array($key0, $key1,…));
  *
  * @return JSON encoded string
  *  A string as follows:
  *  {
  *  	totalEmployees: $totalEmployees
  *  	payrollEmployees: $payrollEmployees
  *  	serviceEmployees: $serviceEmployees
  *  }
  */
 public function updateAccountingSettings(array $input = array())
 {
     $organizationId = $this->AuthenticationManager->getCurrentUserOrganization('id');
     $loggedUserId = $this->AuthenticationManager->getLoggedUserId();
     $Setting = $this->Setting->byOrganization($organizationId)->first();
     $this->DB->transaction(function () use($Setting, $input, $organizationId, $loggedUserId) {
         $SettingJournal = $this->Journal->create(array('journalized_id' => $Setting->id, 'journalized_type' => $this->Setting->getTable(), 'user_id' => $loggedUserId, 'organization_id' => $organizationId));
         if (empty($Setting->is_configured)) {
             $organizationAccountsType = array();
             $this->SystemAccountType->all()->each(function ($AccountType) use($organizationId, &$organizationAccountsType, $loggedUserId) {
                 $accountType = $AccountType->toArray();
                 $accountType = array_add($accountType, 'organization_id', $organizationId);
                 $accountType['name'] = $this->Lang->has($accountType['lang_key']) ? $this->Lang->get($accountType['lang_key']) : $accountType['name'];
                 unset($accountType['id'], $accountType['created_at'], $accountType['updated_at'], $accountType['deleted_at']);
                 $AccountType = $this->AccountType->create($accountType);
                 $organizationAccountsType = array_add($organizationAccountsType, $AccountType->key, $AccountType->id);
                 $Journal = $this->Journal->create(array('journalized_id' => $AccountType->id, 'journalized_type' => $this->AccountType->getTable(), 'user_id' => $loggedUserId, 'organization_id' => $organizationId));
                 $this->Journal->attachDetail($Journal->id, array('note' => $this->Lang->get('decima-accounting::initial-accounting-setup.accountTypeAddedJournal', array('type' => $this->Lang->has($AccountType->lang_key) ? $this->Lang->get($AccountType->lang_key) : $AccountType->name))), $Journal);
             });
             $this->Journal->attachDetail($SettingJournal->id, array('note' => $this->Lang->get('decima-accounting::initial-accounting-setup.accountTypeSettingAddedJournal')), $SettingJournal);
             $this->SystemVoucherType->all()->each(function ($VoucherType) use($organizationId, $loggedUserId) {
                 $voucherType = $VoucherType->toArray();
                 $voucherType = array_add($voucherType, 'organization_id', $organizationId);
                 $voucherType['name'] = $this->Lang->has($voucherType['lang_key']) ? $this->Lang->get($voucherType['lang_key']) : $voucherType['name'];
                 unset($voucherType['id'], $voucherType['created_at'], $voucherType['updated_at'], $voucherType['deleted_at']);
                 $VoucherType = $this->VoucherType->create($voucherType);
                 $Journal = $this->Journal->create(array('journalized_id' => $VoucherType->id, 'journalized_type' => $this->VoucherType->getTable(), 'user_id' => $loggedUserId, 'organization_id' => $organizationId));
                 $this->Journal->attachDetail($Journal->id, array('note' => $this->Lang->get('decima-accounting::initial-accounting-setup.voucherTypeAddedJournal', array('type' => $this->Lang->has($VoucherType->lang_key) ? $this->Lang->get($VoucherType->lang_key) : $VoucherType->name))), $Journal);
             });
             $this->Journal->attachDetail($SettingJournal->id, array('note' => $this->Lang->get('decima-accounting::initial-accounting-setup.voucherTypeSettingAddedJournal')), $SettingJournal);
             $firstDayYear = date($input['year'] . '-01-01');
             $lastDayYear = date($input['year'] . '-12-31');
             $FiscalYear = $this->FiscalYear->create(array('year' => $input['year'], 'start_date' => $firstDayYear, 'end_date' => $lastDayYear, 'organization_id' => $organizationId));
             $Journal = $this->Journal->create(array('journalized_id' => $FiscalYear->id, 'journalized_type' => $this->FiscalYear->getTable(), 'user_id' => $loggedUserId, 'organization_id' => $organizationId));
             $this->Journal->attachDetail($Journal->id, array('note' => $this->Lang->get('decima-accounting::initial-accounting-setup.fiscalYearAddedJournal', array('year' => $input['year']))), $Journal);
             $this->Journal->attachDetail($SettingJournal->id, array('note' => $this->Lang->get('decima-accounting::initial-accounting-setup.fiscalYearAddedJournal', array('year' => $input['year']))), $SettingJournal);
             if ($input['create_opening_period'] == '1') {
                 $Period = $this->Period->create(array('month' => 0, 'start_date' => $firstDayYear, 'end_date' => $firstDayYear, 'fiscal_year_id' => $FiscalYear->id, 'organization_id' => $organizationId));
                 $Journal = $this->Journal->create(array('journalized_id' => $Period->id, 'journalized_type' => $this->Period->getTable(), 'user_id' => $loggedUserId, 'organization_id' => $organizationId));
                 $this->Journal->attachDetail($Journal->id, array('note' => $this->Lang->get('decima-accounting::initial-accounting-setup.periodAddedJournal', array('period' => 0))), $Journal);
             }
             for ($i = 1; $i <= 12; $i++) {
                 $Date = new \DateTime($input['year'] . '-' . $i . '-01');
                 $firstDay = $Date->format('Y-m-d');
                 $Date->modify('last day of this month');
                 $lastDay = $Date->format('Y-m-d');
                 $Period = $this->Period->create(array('month' => $i, 'start_date' => $firstDay, 'end_date' => $lastDay, 'fiscal_year_id' => $FiscalYear->id, 'organization_id' => $organizationId));
                 $Journal = $this->Journal->create(array('journalized_id' => $Period->id, 'journalized_type' => $this->Period->getTable(), 'user_id' => $loggedUserId, 'organization_id' => $organizationId));
                 $this->Journal->attachDetail($Journal->id, array('note' => $this->Lang->get('decima-accounting::initial-accounting-setup.periodAddedJournal', array('period' => $i))), $Journal);
             }
             if ($input['create_closing_period'] == '1') {
                 $Period = $this->Period->create(array('month' => 13, 'start_date' => $lastDayYear, 'end_date' => $lastDayYear, 'fiscal_year_id' => $FiscalYear->id, 'organization_id' => $organizationId));
                 $Journal = $this->Journal->create(array('journalized_id' => $Period->id, 'journalized_type' => $this->Period->getTable(), 'user_id' => $loggedUserId, 'organization_id' => $organizationId));
                 $this->Journal->attachDetail($Journal->id, array('note' => $this->Lang->get('decima-accounting::initial-accounting-setup.periodAddedJournal', array('period' => 13))), $Journal);
             }
             $this->Journal->attachDetail($SettingJournal->id, array('note' => $this->Lang->get('decima-accounting::initial-accounting-setup.periodAddedSettingJournal')), $SettingJournal);
             $CostCenter = $this->CostCenter->create(array('name' => $this->AuthenticationManager->getCurrentUserOrganizationName(), 'key' => $this->Config->get('accounting-general.default_organization_cc_key'), 'is_group' => true, 'organization_id' => $organizationId));
             $Journal = $this->Journal->create(array('journalized_id' => $CostCenter->id, 'journalized_type' => $this->CostCenter->getTable(), 'user_id' => $loggedUserId, 'organization_id' => $organizationId));
             $this->Journal->attachDetail($Journal->id, array('note' => $this->Lang->get('decima-accounting::initial-accounting-setup.costCenterAddedJournal', array('costCenter' => $CostCenter->key . ' ' . $CostCenter->name))), $Journal);
             $CostCenter = $this->CostCenter->create(array('name' => $this->Lang->get('decima-accounting::cost-center.main'), 'key' => $this->Config->get('accounting-general.default_main_cc_key'), 'is_group' => false, 'parent_cc_id' => $CostCenter->id, 'organization_id' => $organizationId));
             $Journal = $this->Journal->create(array('journalized_id' => $CostCenter->id, 'journalized_type' => $this->CostCenter->getTable(), 'user_id' => $loggedUserId, 'organization_id' => $organizationId));
             $this->Journal->attachDetail($Journal->id, array('note' => $this->Lang->get('decima-accounting::initial-accounting-setup.costCenterAddedJournal', array('costCenter' => $CostCenter->key . ' ' . $CostCenter->name))), $Journal);
             $this->Journal->attachDetail($SettingJournal->id, array('note' => $this->Lang->get('decima-accounting::initial-accounting-setup.costCenterAddedSettingJournal')), $SettingJournal);
             $organizationAccounts = array();
             $this->SystemAccount->accountsByAccountChartsTypes($input['account_chart_type_id'])->each(function ($SystemAccount) use($organizationId, $organizationAccountsType, &$organizationAccounts, &$systemAccountsCounter, $loggedUserId) {
                 $account = $SystemAccount->toArray();
                 $account = array_add($account, 'organization_id', $organizationId);
                 $account = array_add($account, 'account_type_id', $organizationAccountsType[$account['account_type_key']]);
                 if (!empty($account['parent_key'])) {
                     $account = array_add($account, 'parent_account_id', $organizationAccounts[$account['parent_key']]);
                 }
                 unset($account['id'], $account['parent_key'], $account['account_type_key'], $account['account_chart_type_id'], $account['created_at'], $account['updated_at'], $account['deleted_at']);
                 $OrganizationAccount = $this->Account->create($account);
                 $Journal = $this->Journal->create(array('journalized_id' => $OrganizationAccount->id, 'journalized_type' => $this->Account->getTable(), 'user_id' => $loggedUserId, 'organization_id' => $organizationId));
                 $this->Journal->attachDetail($Journal->id, array('note' => $this->Lang->get('decima-accounting::initial-accounting-setup.accountAddedJournal', array('account' => $OrganizationAccount->key . ' ' . $OrganizationAccount->name))), $Journal);
                 $organizationAccounts[$OrganizationAccount->key] = $OrganizationAccount->id;
             });
             if (!empty($organizationAccounts)) {
                 $AccountChartType = $this->AccountChartType->byId($input['account_chart_type_id']);
                 $this->Journal->attachDetail($SettingJournal->id, array('note' => $this->Lang->get('decima-accounting::initial-accounting-setup.accountAddedSettingJournal', array('catalog' => $AccountChartType->name))), $SettingJournal);
             }
             $input['id'] = $Setting->id;
             $input['initial_year'] = $input['year'];
             $input['is_configured'] = true;
             unset($input['_token'], $input['year']);
             $this->Setting->update($input);
         } else {
             $input['id'] = $Setting->id;
             $unchangedSettingValues = $Setting->toArray();
             unset($input['_token'], $input['year'], $input['account_chart_type_id']);
             $this->Setting->update($input);
             $diff = 0;
             foreach ($input as $key => $value) {
                 if ($unchangedSettingValues[$key] != $value) {
                     $diff++;
                     if ($diff == 1) {
                         $Journal = $this->Journal->create(array('journalized_id' => $Setting->id, 'journalized_type' => $this->Setting->getTable(), 'user_id' => $loggedUserId, 'organization_id' => $organizationId));
                     }
                     $fieldLangKey = 'decima-accounting::initial-accounting-setup.' . camel_case($key);
                     if ($key == 'voucher_numeration_type') {
                         $this->Journal->attachDetail($Journal->id, array('field' => $this->Lang->get($fieldLangKey), 'field_lang_key' => $fieldLangKey, 'old_value' => $this->Lang->get('decima-accounting::initial-accounting-setup.' . $unchangedSettingValues[$key]), 'new_value' => $this->Lang->get('decima-accounting::initial-accounting-setup.' . $value)), $Journal);
                     } else {
                         $this->Journal->attachDetail($Journal->id, array('field' => $this->Lang->get($fieldLangKey), 'field_lang_key' => $fieldLangKey, 'old_value' => $this->Lang->get('journal.' . $unchangedSettingValues[$key]), 'new_value' => $this->Lang->get('journal.' . $value)), $Journal);
                     }
                 }
             }
         }
     });
     return json_encode(array('success' => $this->Lang->get('decima-accounting::initial-accounting-setup.successUpdateMessage')));
 }
 /**
  * Guess the field for a column.
  *
  * @param TableBuilder $builder
  */
 public function guess(TableBuilder $builder)
 {
     $columns = $builder->getColumns();
     $stream = $builder->getTableStream();
     $module = $this->modules->active();
     foreach ($columns as &$column) {
         /*
          * If the heading is already set then
          * we don't have anything to do.
          */
         if (isset($column['heading'])) {
             continue;
         }
         /*
          * If the heading is false, then no
          * header is desired at all.
          */
         if (isset($column['heading']) && $column['heading'] === false) {
             continue;
         }
         /*
          * No stream means we can't
          * really do much here.
          */
         if (!$stream instanceof StreamInterface) {
             continue;
         }
         if (!isset($column['field']) && is_string($column['value'])) {
             $column['field'] = $column['value'];
         }
         /*
          * If the heading matches a field
          * with dot format then reduce it.
          */
         if (isset($column['field']) && preg_match("/^entry.([a-zA-Z\\_]+)/", $column['field'], $match)) {
             $column['field'] = $match[1];
         }
         /*
          * Detect some built in columns.
          */
         if (in_array($column['field'], ['id', 'created_at', 'created_by', 'updated_at', 'updated_by'])) {
             $column['heading'] = 'streams::entry.' . $column['field'];
             continue;
         }
         /*
          * Detect entry title.
          */
         if (in_array($column['field'], ['view_link', 'edit_link']) && ($field = $stream->getTitleField())) {
             $column['heading'] = $field->getName();
             continue;
         }
         $field = $stream->getField(array_get($column, 'field'));
         /*
          * Detect the title column.
          */
         $title = $stream->getTitleField();
         if ($title && !$field && $column['field'] == 'title' && $this->translator->has($heading = $title->getName())) {
             $column['heading'] = $heading;
         }
         /*
          * Use the name from the field.
          */
         if ($field && ($heading = $field->getName())) {
             $column['heading'] = $heading;
         }
         /*
          * If no field look for
          * a name anyways.
          */
         if ($module && !$field && $this->translator->has($heading = $module->getNamespace('field.' . $column['field'] . '.name'))) {
             $column['heading'] = $heading;
         }
         /*
          * If no translatable heading yet and
          * the heading matches the value (default)
          * then humanize the heading value.
          */
         if (!isset($column['heading']) && $this->config->get('streams::system.lazy_translations')) {
             $column['heading'] = ucwords($this->string->humanize($column['field']));
         }
         /*
          * If we have a translatable heading and
          * the heading does not have a translation
          * then humanize the heading value.
          */
         if (isset($column['heading']) && str_is('*.*.*::*', $column['heading']) && !$this->translator->has($column['heading']) && $this->config->get('streams::system.lazy_translations')) {
             $column['heading'] = ucwords($this->string->humanize($column['field']));
         }
         /*
          * Last resort.
          */
         if ($module && !isset($column['heading'])) {
             $column['heading'] = $module->getNamespace('field.' . $column['field'] . '.name');
         }
     }
     $builder->setColumns($columns);
 }
Example #24
0
 /**
  * {@inheritdoc}
  *
  * @param  string  $key
  * @param  string  $locale
  * @return bool
  */
 public function has($key, $locale = null)
 {
     return $this->lang->has($key, $locale);
 }
Example #25
0
 /**
  * Determine if a translation exists.
  *
  * @param  string  $key
  * @param  string  $locale
  *
  * @return bool
  */
 public function hasTranslation($key, $locale = null)
 {
     return $this->translator->has($key, $locale);
 }
 /**
  * Handle the command.
  */
 public function handle(MessageBag $messages, Translator $translator)
 {
     // If we can't save or there are errors then skip it.
     if ($this->builder->hasFormErrors() || !$this->builder->canSave()) {
         return;
     }
     // If there is no model and there isn't anything specific to say, skip it.
     if (!$this->builder->getFormEntry() && !$this->builder->getFormOption('success_message')) {
         return;
     }
     $mode = $this->builder->getFormMode();
     // False means no message is desired.
     if ($this->builder->getFormOption('success_message') === false) {
         return;
     }
     $entry = $this->builder->getFormEntry();
     $stream = $this->builder->getFormStream();
     $parameters = ['title' => is_object($entry) ? $entry->getTitle() : null, 'name' => is_object($stream) ? $stream->getName() : null];
     // If the name doesn't exist we need to be clever.
     if (str_contains($parameters['name'], '::') && !$translator->has($parameters['name']) && $stream) {
         $parameters['name'] = ucfirst(str_singular(str_replace('_', ' ', $stream->getSlug())));
     } elseif ($parameters['name']) {
         $parameters['name'] = str_singular(trans($parameters['name']));
     } else {
         $parameters['name'] = trans('streams::entry.name');
     }
     /**
      * Set the default success message.
      */
     if ($this->builder->getFormOption('success_message') === null) {
         $this->builder->setFormOption('success_message', trans('streams::message.' . $mode . '_success', $parameters));
     }
     $messages->{$this->builder->getFormOption('success_message_type', 'success')}($this->builder->getFormOption('success_message'));
 }