Beispiel #1
0
 /**
  *
  * Process api operations of Model
  *
  * @param $version
  * @param $operation
  * @param null $id
  * @param null $relationships
  * @param null $json
  * @return mixed
  */
 public function api($version, $operation, $id = null, $relationships = null, $json = null)
 {
     if (is_null($id)) {
         $collection = $this->model->{$operation}();
     } else {
         $collection = $this->model->{$operation}($id);
     }
     if ($relationships) {
         if (is_array($collection)) {
             $collection = $collection[0];
         }
         $relationships = explode(',', $relationships);
         foreach ($relationships as $relationship) {
             $collection->{$relationship} = $collection->{$relationship};
         }
     }
     if ($version === 'debug') {
         dd(Json::decode(Json::encode($collection)));
     } else {
         if ($json) {
             $collection = Json::decode(Json::encode($collection));
         }
         return $collection;
     }
 }
Beispiel #2
0
 /**
  * @param $operation
  * @param $module
  * @param $entity
  * @param $spell
  */
 private static function language($operation, $module, $entity, $spell)
 {
     $__default = 'default';
     if ($spell === $__default) {
         $spell = AwesovelServiceProvider::$LANGUAGE;
     }
     $filename = Path::app([config('awesovel')['root'], $module, 'Language', $entity, $spell . '.lng']);
     $content = file_get_contents($filename);
     $translations = Json::decode($content);
     $id = $operation->id;
     $default = $translations->{$__default};
     $language = $default;
     if (isset($translations->{$id})) {
         $language = $translations->{$id};
     }
     /*
      * recover spell to label
      */
     $operation->label = $language->label;
     /*
      * recover spell to items
      */
     foreach ($operation->items as $key => $item) {
         if (isset($language->items->{$key})) {
             foreach ($language->items->{$key} as $__property => $__stub) {
                 $operation->items->{$key}->{$__property} = $language->items->{$key}->{$__property};
             }
         } else {
             if (isset($default->items->{$key})) {
                 foreach ($default->items->{$key} as $__property => $__stub) {
                     $operation->items->{$key}->{$__property} = $default->items->{$key};
                 }
             }
         }
         $operation->items->{$key}->id = $key;
     }
     /*
      * recover spell to operations
      */
     foreach ($operation->operations as $key => $__operation) {
         $id = $__operation->id;
         $properties = ['label' => $default->label, 'title' => ""];
         foreach ($properties as $property => $__default) {
             $__operation->{$property} = $__default;
             if (isset($language->operations) && isset($language->operations->{$id}) && isset($language->operations->{$id}->{$property})) {
                 $__operation->{$property} = $language->operations->{$id}->{$property};
             } else {
                 if (isset($translations->{$id}) && isset($translations->{$id}->{$property})) {
                     $__operation->{$property} = $translations->{$id}->{$property};
                 }
             }
         }
         $operation->operations[$key] = $__operation;
     }
     return $operation;
 }