/**
  * Show the form for creating a new resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function create()
 {
     $cols = Schema::getColumnListing('comments');
     unset($cols[0]);
     unset($cols[2]);
     unset($cols[3]);
     return response()->json(array_values($cols));
 }
 public function search($input)
 {
     $query = BarcodeProcess::query();
     $query->select('barcode_processes.*');
     $query->leftJoin('shelves', 'barcode_processes.shelf_id', '=', 'shelves.id');
     $columns = Schema::getColumnListing('barcode_processes');
     $attributes = array();
     foreach ($columns as $attribute) {
         $attributes[$attribute] = null;
         if (isset($input[$attribute]) and !empty($input[$attribute])) {
             $query->where($attribute, $input[$attribute]);
             $attributes[$attribute] = $input[$attribute];
         }
     }
     /**
      * Filter
      */
     $this->filter($input, $query);
     /**
      * Get count
      */
     $total = $query->count();
     /**
      * Pagination
      */
     $this->pagination($input, $query);
     /**
      * Order
      */
     $this->order($input, $query);
     return [$query->get(), $attributes, 'total' => $total];
 }
Пример #3
0
 public function translate(Request $request)
 {
     $data = $request->only('word', 'src_language', 'trans_language');
     $validator = Validator::make($data, array('word' => 'required', 'src_language' => 'required', 'trans_language' => 'required'));
     if ($validator->passes()) {
         $columns = Schema::getColumnListing('translation');
         // users table
         if (!in_array($data['src_language'], $columns)) {
             return response()->json(array('error' => 1, 'labels' => 'Source language is not available'));
         } else {
             if (!in_array($data['trans_language'], $columns)) {
                 return response()->json(array('error' => 1, 'labels' => 'Translation language is available'));
             } else {
                 $tra = Translation::where($data['src_language'], $data['word'])->first();
                 if (!$tra) {
                     return response()->json(array('error' => 1, 'labels' => 'This word is not available in our source language'));
                 } else {
                     $data = array('word' => $data['word'], 'source' => $data['src_language'], 'target' => $data['trans_language'], 'result' => $tra->{$data}['trans_language']);
                     return response()->json(array('error' => 0, 'data' => $data, 'errors' => array()));
                 }
             }
         }
     } else {
         return response()->json(array('error' => 1, 'labels' => $validator->messages()));
     }
 }
Пример #4
0
 /**
  * get OnData spec.
  *
  * @param  array  $data
  * @return array
  */
 function getTables(array $data)
 {
     $onData = [];
     $foreignKeys = [];
     $result = [];
     $tmp = '';
     $i = 0;
     $j = 0;
     foreach ($data as $key => $value) {
         if ($key == 'tbl' . $i) {
             $tmp = $value;
             if (in_array($value, $foreignKeys)) {
                 throw new \Exception($value . " Relation Already selected");
             }
             array_push($foreignKeys, $value);
             $i++;
         } elseif ($key == 'on' . $j) {
             if (!in_array($value, Schema::getColumnListing($tmp))) {
                 throw new \Exception($value . " Does not exist in " . $tmp);
             }
             array_push($onData, $value);
             $j++;
         }
     }
     $result[] = $onData;
     $result[] = $foreignKeys;
     return $result;
 }
Пример #5
0
 public function search($input)
 {
     $query = User::query();
     $columns = Schema::getColumnListing('users');
     $attributes = array();
     foreach ($columns as $attribute) {
         $attributes[$attribute] = null;
         if (isset($input[$attribute]) and !empty($input[$attribute])) {
             $query->where($attribute, $input[$attribute]);
             $attributes[$attribute] = $input[$attribute];
         }
     }
     /*
      ** Filter
      */
     $this->filter($input, $query);
     /*
      ** Get count
      */
     $total = $query->count();
     /*
      ** Pagination
      */
     $this->pagination($input, $query);
     /*
      ** Order
      */
     $this->order($input, $query);
     return [$query->get(), $attributes, 'total' => $total];
 }
Пример #6
0
 /**
  * Exclude from find
  *
  * @return \Illuminate\Database\Eloquent\Builder
  */
 public function scopeExcludeFromFind(Builder $query)
 {
     if (isset($this->excludedFromFind) == TRUE && is_array($this->excludedFromFind) == TRUE) {
         return $query->select(array_diff(Schema::getColumnListing($this->table), $this->excludedFromFind));
     } else {
         return $query;
     }
 }
 /**
  * Show the form for creating a new resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function create()
 {
     $cols = Schema::getColumnListing('products');
     unset($cols[0]);
     unset($cols[8]);
     unset($cols[9]);
     return response()->json(array_values($cols));
 }
Пример #8
0
 public function getColumns($table = null, $class = null)
 {
     $class = $class ?: get_class($this);
     $table = $table ?: $this->table;
     if (!isset(self::$loaded_columns[$class])) {
         self::$loaded_columns[$class] = Schema::getColumnListing($table);
     }
     return self::$loaded_columns[$class];
 }
Пример #9
0
 /**
  * Get attributes from an existing table.
  *
  * @return array
  */
 public function getAttributes()
 {
     //get table attributes
     $this->result = Schema::getColumnListing($this->table);
     //delete the first element, (ignore the id section)
     unset($this->result[0]);
     //get result
     return $this->result;
 }
Пример #10
0
 /**
  * Search the images.
  *
  * @param string $input
  *
  * @return Collection
  */
 public function search($input)
 {
     $query = Image::orderBy('created_at', 'desc');
     $query->where('id', 'LIKE', '%' . $input['term'] . '%');
     $columns = Schema::getColumnListing('images');
     foreach ($columns as $attribute) {
         $query->orWhere($attribute, 'LIKE', '%' . $input['term'] . '%');
     }
     return [$query, $input['term'], $query->paginate(Config::get('quarx.pagination', 25))->render()];
 }
Пример #11
0
 public function search($term)
 {
     $query = $this->model->orderBy('created_at', 'desc');
     $query->where('id', 'LIKE', '%' . $input['term'] . '%');
     $columns = Schema::getColumnListing(str_plural($this->modelName));
     foreach ($columns as $attribute) {
         $query->orWhere($attribute, 'LIKE', '%' . $input['term'] . '%');
     }
     return ['term' => $input['term'], 'result' => $query->paginate(Config::get('quarx.pagination', 25))];
 }
Пример #12
0
 /**
  * Deduce relational arttributes.
  *
  * @return void
  */
 private function getAttributes()
 {
     collect($this->foreignKeys)->each(function ($key, $value) {
         $Schema = collect(Schema::getColumnListing($key));
         $Schema = $Schema->reject(function ($value, $key) {
             return str_contains($value, 'id');
         });
         $this->relationAttributes[$key] = $Schema->toArray();
     });
 }
Пример #13
0
 public function search($input)
 {
     $query = Widget::orderBy('created_at', 'desc');
     $query->where('id', 'LIKE', '%' . $input['term'] . '%');
     $columns = Schema::getColumnListing('widgets');
     foreach ($columns as $attribute) {
         $query->orWhere($attribute, 'LIKE', '%' . $input['term'] . '%');
     }
     return [$query, $input['term'], $query->paginate(25)->render()];
 }
 /**
  * @param string $className
  *
  * @return array
  */
 protected static function getClassProperties($className)
 {
     if (\class_exists($className, true)) {
         $reflection = new ReflectionClass($className);
         $value = $reflection->newInstanceWithoutConstructor();
         if (\is_subclass_of($value, Model::class, true)) {
             $attributes = Schema::getColumnListing($value->getTable());
             self::$eloquentClasses[$className] = $attributes;
         }
     }
     return !empty(self::$eloquentClasses[$className]) ? self::$eloquentClasses[$className] : parent::getClassProperties($className);
 }
Пример #15
0
 /**
  * Analyse data and attributes
  *
  * @param Array $data
  */
 private function getAttr($data)
 {
     foreach ($this->foreignKeys as $key => $value) {
         $Schema = Schema::getColumnListing($value);
         unset($Schema[0]);
         foreach ($Schema as $SchemaKey => $SchemaValue) {
             if (strpos($SchemaValue, '_id')) {
                 unset($Schema[$SchemaKey]);
             }
         }
         $this->relationAttr[$value] = $Schema;
     }
 }
Пример #16
0
 public function initialRows()
 {
     $table = $this->table_name;
     $columns = Schema::getColumnListing($table);
     foreach ($columns as $column) {
         if (0 != TableRow::where(['column_name' => $column])->count()) {
             continue;
         }
         TableRow::create(['table_name' => $table, 'column_name' => $column, 'type' => 'text', 'creatable' => true, 'editable' => true, 'listable' => true]);
     }
     //Delete unused columns
     TableRow::whereNotIn('column_name', $columns)->delete();
 }
 /**
  * @param string $className
  *
  * @return array
  */
 protected static function getClassProperties($className)
 {
     if (\class_exists($className, true)) {
         $reflection = new ReflectionClass($className);
         $value = $reflection->newInstanceWithoutConstructor();
         if (\is_subclass_of($value, Model::class, true)) {
             $attributes = \array_merge(Schema::getColumnListing($value->getTable()), self::getRelationshipMethodsAsPropertyName($value, $className, $reflection));
             self::$eloquentClasses[$className] = $attributes;
             return self::$eloquentClasses[$className];
         }
     }
     return parent::getClassProperties($className);
 }
Пример #18
0
 public function exportCsv()
 {
     $contestants = DB::table("contestants")->get();
     $filename = "contestants.csv";
     $handle = fopen($filename, 'w+');
     $keys = Schema::getColumnListing("contestants");
     fputcsv($handle, $keys);
     foreach ($contestants as $c) {
         fputcsv($handle, array($c->id, $c->email, $c->verification_code, $c->verification_received, $c->ip_address));
     }
     fclose($handle);
     $headers = array('Content-Type' => 'text/csv');
     return Response::download($filename, $filename, $headers);
 }
Пример #19
0
 /**
  * Show Setting Page
  *
  * @Get("table/{table_name}/settings", as="setting.show")
  */
 public function settings($table)
 {
     $type_options = ['text' => 'Text', 'password' => 'Password', 'number' => 'Number', 'radio' => 'Radio', 'checkbox' => 'Checkbox', 'select' => 'Select', 'range' => 'Range', 'content_editor' => 'Content Editor', 'belongs_to' => 'Belongs To', 'has_one' => 'Has One'];
     if (!Schema::hasTable($table)) {
         Flash::error('Specified table not found.');
         return view('tables.settings');
     }
     $columns_count = count(Schema::getColumnListing($table));
     if ($columns_count != TableRow::where('table_name', $table)->count()) {
         Table::where('table_name', $table)->first()->initialRows();
     }
     $columns = TableRow::where('table_name', $table)->get();
     return view('tables.settings', compact('columns', 'table', 'type_options'));
 }
Пример #20
0
 /**
  * Get all searchable fields
  *
  * @return array
  */
 public static function getSearchFields()
 {
     $model = new static();
     $fields = $model->search;
     if (empty($fields)) {
         $fields = Schema::getColumnListing($model->getTable());
         $others[] = $model->primaryKey;
         $others[] = $model->getUpdatedAtColumn() ?: 'created_at';
         $others[] = $model->getCreatedAtColumn() ?: 'updated_at';
         $others[] = method_exists($model, 'getDeletedAtColumn') ? $model->getDeletedAtColumn() : 'deleted_at';
         $fields = array_diff($fields, $model->getHidden(), $others);
     }
     return $fields;
 }
Пример #21
0
 public function search($input)
 {
     $query = ppm_pais::query();
     $columns = Schema::getColumnListing('ppm_pais');
     $attributes = array();
     foreach ($columns as $attribute) {
         if (isset($input[$attribute])) {
             $query->where($attribute, $input[$attribute]);
             $attributes[$attribute] = $input[$attribute];
         } else {
             $attributes[$attribute] = null;
         }
     }
     return [$query->get(), $attributes];
 }
Пример #22
0
 public function search($input)
 {
     $query = $this->getModel()->query();
     $columns = Schema::getColumnListing('users');
     $attributes = array();
     foreach ($columns as $attribute) {
         if (isset($input[$attribute])) {
             $query->where(DB::raw($attribute . '::text'), 'ilike', $input[$attribute] . '%');
             $attributes[$attribute] = $input[$attribute];
         } else {
             $attributes[$attribute] = null;
         }
     }
     return [$query->orderBy('username', 'asc')->paginate($this->paginate)->appends($input), $attributes];
 }
 public function getColumnsOptions()
 {
     $class = $this->model;
     if (!class_exists($class)) {
         return [];
     }
     $table = (new $class())->getTable();
     $columns = array_filter(Schema::getColumnListing($table), function ($column) {
         return $column != 'created_at' && $column != 'updated_at';
     });
     $preparedColumns = [];
     foreach ($columns as $column) {
         $preparedColumns[$column] = $column;
     }
     return $preparedColumns;
 }
 public function addTable(Request $request)
 {
     $table = [];
     //Setting table defaults
     $permission = json_encode(['c' => false, 'r' => false, 'u' => false, 'd' => false]);
     $form_type = 'page';
     $data = $request->input('data');
     for ($i = 0; $i < count($data); $i++) {
         DB::table('solar_tables')->insert(['name' => $data[$i], 'permission' => $permission, 'form_type' => $form_type]);
         //Setting field defaults
         $columns = Schema::getColumnListing($data[$i]);
         foreach ($columns as $c) {
             $parent = $data[$i];
             DB::table('solar_table_columns')->insert(['table' => $parent, 'column' => $c]);
         }
     }
     return response()->json(['status' => true]);
 }
 /**
  * Show new crud creation page
  * @return \Illuminate\View\View
  */
 public function create()
 {
     $fieldTypes = FieldsDescriber::types();
     $fieldValidation = FieldsDescriber::validation();
     $defaultValuesCbox = FieldsDescriber::default_cbox();
     $crudsSelect = Crud::lists('title', 'id');
     // Get columns for relationship
     $models = [];
     foreach (Crud::all() as $crud) {
         // We are having a default User model
         if ($crud->title == 'User' && $crud->is_crud == 0) {
             $tableName = 'users';
         } else {
             $tableName = strtolower($crud->name);
         }
         $models[$crud->id] = Schema::getColumnListing($tableName);
     }
     return view("qa::cruds.create", compact('fieldTypes', 'fieldValidation', 'defaultValuesCbox', 'crudsSelect', 'models'));
 }
 /**
  * Show new menu creation page
  * @return \Illuminate\View\View
  */
 public function createCrud()
 {
     $fieldTypes = FieldsDescriber::types();
     $fieldValidation = FieldsDescriber::validation();
     $defaultValuesCbox = FieldsDescriber::default_cbox();
     $menusSelect = Menu::lists('title', 'id');
     $parentsSelect = Menu::where('menu_type', 2)->lists('title', 'id')->prepend('-- no parent --', 'null');
     // Get columns for relationship
     $models = [];
     foreach (Menu::all() as $menu) {
         // We are having a default User model
         if ($menu->title == 'User' && $menu->is_menu == 0) {
             $tableName = 'users';
         } else {
             $tableName = strtolower($menu->name);
         }
         $models[$menu->id] = Schema::getColumnListing($tableName);
     }
     return view("qa::menus.createCrud", compact('fieldTypes', 'fieldValidation', 'defaultValuesCbox', 'menusSelect', 'models', 'parentsSelect'));
 }
Пример #27
0
 protected function createEntity()
 {
     $tableName = $this->argument('tableName');
     $columns = Schema::getColumnListing($tableName);
     $entitiesPath = $this->appPath . 'Entities';
     $this->info('Creating entity...');
     $this->helper->makeDir($entitiesPath);
     $newEntity = $entitiesPath . '/' . $this->crudName . '.php';
     $columns = array_diff($columns, ['id']);
     // Verify if exist softdelete in table
     if (in_array('deleted_at', $columns)) {
         $this->info('Softdelete detected...');
         $columns = array_diff($columns, ['deleted_at']);
         $softDelete = 'TransformableTrait, SoftDeletes';
     } else {
         $softDelete = 'TransformableTrait';
     }
     if (in_array('created_at', $columns)) {
         $this->info('Created and updated control detected...');
         $columns = array_diff($columns, ['created_at', 'updated_at']);
         $timestamps = '$timestamps = true';
     } else {
         $timestamps = '$timestamps = false';
     }
     if (in_array('password', $columns)) {
         $columns = array_diff($columns, ['remember_token']);
         $hidden = 'protected $hidden = [\'password\', \'remember_token\'];';
     }
     $fillable = "\$fillable = ['" . implode("','", $columns) . "']";
     if (!$this->verifyFileExists($newEntity)) {
         $this->helper->replaceAndSave(__DIR__ . '/stub/app/Entities/Entity.stub', $this->patterns, $this->patternsValues, $newEntity);
         $this->helper->replaceAndSave($newEntity, '$fillable', $fillable, $newEntity);
         $this->helper->replaceAndSave($newEntity, '$timestamps = false', $timestamps, $newEntity);
         $this->helper->replaceAndSave($newEntity, 'TransformableTrait', $softDelete, $newEntity);
     }
     $this->output->progressAdvance();
 }
Пример #28
0
 /**
  * Define the application's command schedule.
  *
  * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
  * @return void
  */
 protected function schedule(Schedule $schedule)
 {
     $schedule->command('inspire')->hourly();
     $schedule->call(function () {
         $file = public_path("report/contestants.csv");
         $contestants = DB::table("contestants")->get();
         $handle = fopen($file, 'w+');
         $keys = Schema::getColumnListing("contestants");
         fputcsv($handle, $keys);
         foreach ($contestants as $c) {
             fputcsv($handle, array($c->id, $c->email, $c->verification_code, $c->verification_received, $c->ip_address));
         }
         fclose($handle);
         $administrators = DB::table("administrators")->get();
         foreach ($administrators as $admin) {
             Mail::send("email.admin", array(), function ($message) use($admin, $file) {
                 $message->from("*****@*****.**", "Wedstrijd admin panel");
                 $message->subject("Overzicht deelnemers - " . date("m.d.y"));
                 $message->to($admin->email);
                 $message->attach($file);
             });
         }
     })->daily();
 }
 /**
  * Devuelve un array con los nombres de las columnas.
  *
  * @return array
  */
 public function getFields()
 {
     $field_names = array();
     $disallowed = array('id', 'created_at', 'updated_at', 'deleted_at');
     $columns = Schema::getColumnListing($this->models_name);
     foreach ($columns as $c) {
         $field = $c;
         if (!in_array($field, $disallowed)) {
             $field_names[$field] = $field;
         }
     }
     return $field_names;
 }
Пример #30
0
 /**
  * Allows all columns on the current database table to be sorted through
  * query scope.
  *
  * @param object $query
  * @param string $field
  * @param string $sort
  *
  * @return object
  */
 public function scopeSort($query, $field = null, $sort = null)
 {
     /*
      * Make sure both the field and sort variables are present
      */
     if ($field && $sort) {
         /*
          * Retrieve all column names for the current model table
          */
         $columns = Schema::getColumnListing($this->getTable());
         /*
          * Make sure the field inputted is available on the current table
          */
         if (in_array($field, $columns)) {
             /*
              * Make sure the sort input is equal to asc or desc
              */
             if ($sort === 'asc' || $sort === 'desc') {
                 /*
                  * Return the query sorted
                  */
                 return $query->orderBy($field, $sort);
             }
         }
     }
     /*
      * Default to latest scope
      */
     return $query->latest();
 }