Ejemplo n.º 1
0
 protected function loadOptions()
 {
     $repository = new BaseRepository($this->model());
     $display = explode('|', $this->display());
     $key = $repository->model()->getKeyName();
     $model = $repository->query();
     if (!is_null($this->with())) {
         $model = $model->with($this->with());
     }
     $model = $model->get();
     $options = [];
     $value = "";
     if ($model instanceof Collection) {
         $datasets = $model->all();
         foreach ($datasets as $dataset) {
             $itemCount = count($display);
             if ($itemCount > 1) {
                 $count = 0;
                 foreach ($display as $item) {
                     $count++;
                     $value .= $dataset->{$item};
                     if ($count <= $itemCount) {
                         if ($dataset->{$item}) {
                             $value .= $dataset->{$item} == $key ? '#' : $this->seperator();
                         }
                     }
                 }
             } else {
                 $value = $dataset->{$display}[0];
             }
             $options[$dataset->{$key}] = $value;
         }
     }
     $this->options($options);
 }
Ejemplo n.º 2
0
 protected function loadOptions()
 {
     $repository = new BaseRepository($this->model());
     $key = $repository->model()->getKeyName();
     $options = $repository->query()->get()->lists($this->display(), $key);
     if ($options instanceof Collection) {
         $options = $options->all();
     }
     $this->options($options);
 }
Ejemplo n.º 3
0
 public function getAllPermissions()
 {
     $repository = new BaseRepository($this->model());
     $model = $repository->query();
     if ($this->groupedPermissions()) {
         $collection = $repository->model()->all()->groupBy(function ($item, $key) {
             return empty($item['group_name']) ? 'admin::lang.permission.without_group' : $item['group_name'];
         });
     } else {
         $collection = $repository->model()->all();
     }
     return $collection;
 }
Ejemplo n.º 4
0
 /**
  * Set currently loaded model id
  * @param int $id
  */
 public function setId($id)
 {
     if (is_null($this->id)) {
         $this->id = $id;
         $this->instance($this->repository->find($id));
     }
 }
Ejemplo n.º 5
0
 protected function loadOptions()
 {
     $repository = new BaseRepository($this->model());
     $display = explode('|', $this->display());
     $seperator = explode('|', $this->seperator());
     $key = $repository->model()->getKeyName();
     $model = $repository->query();
     if (!is_null($this->with())) {
         $model = $model->with($this->with());
     }
     if (count($this->scope())) {
         $this->modifyQuery($model);
     }
     $model = $model->get();
     $options = [];
     $value = "";
     if ($model instanceof Collection) {
         $datasets = $model->all();
         foreach ($datasets as $dataset) {
             $itemCount = count($display);
             if ($itemCount > 1) {
                 $count = 0;
                 $value = null;
                 foreach ($display as $item) {
                     $count++;
                     $valueTmp = $dataset->{$item};
                     if (is_null($valueTmp) && !is_null($with = $this->with())) {
                         $valueTmp = $dataset->{$with}->{$item};
                     }
                     $value .= $valueTmp;
                     if ($count < $itemCount) {
                         if ($valueTmp) {
                             if (array_has($seperator, $count - 1)) {
                                 $sep = $seperator[$count - 1];
                             } else {
                                 $sep = '-';
                             }
                             $value .= $dataset->{$item} == $key ? '#' : ' ' . $sep . ' ';
                         }
                     }
                 }
             } else {
                 $value = $dataset->{$display}[0];
             }
             $optionValue = $this->optionValue();
             $options[is_null($optionValue) ? $dataset->{$key} : $dataset->{$optionValue}] = $value;
         }
     }
     $this->options($options);
 }
Ejemplo n.º 6
0
 /**
  * @param string $class
  */
 function __construct($class)
 {
     parent::__construct($class);
     $this->detectType();
 }
Ejemplo n.º 7
0
 protected function loadOptions()
 {
     $repository = new BaseRepository($this->model());
     $display = explode('|', $this->display());
     $key = $repository->model()->getKeyName();
     $model = $repository->query();
     if (!is_null($this->with())) {
         $model = $model->with($this->with());
     }
     if (count($this->scope())) {
         $this->modifyQuery($model);
     }
     $model = $model->get();
     $options = [];
     if ($model instanceof Collection) {
         $datasets = $model->all();
         foreach ($datasets as $dataset) {
             $itemCount = count($display);
             $count = 0;
             $tmpOptions = [];
             $tmpOptions[$key] = $dataset->{$key};
             if ($itemCount > 1) {
                 foreach ($display as $item) {
                     $count++;
                     $valueTmp = $dataset->{$item};
                     if (is_null($valueTmp) && !is_null($with = $this->with())) {
                         $valueTmp = $dataset->{$with}->{$item};
                     }
                     $tmpOptions[$item] = $valueTmp;
                 }
             } else {
                 $tmpOptions[$display[0]] = $dataset->{$display}[0];
             }
             $options[$count] = $tmpOptions;
         }
     }
     $this->options($options);
 }