Ejemplo n.º 1
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     // Item object
     $item = new Item();
     $item = $this->getRequestItem($request, $item);
     $item->comment = '';
     //// category object
     $category = new Category();
     $category->name = $request->get('category');
     $category->container_id = $request->get('container_id');
     //// save
     try {
         $item = Item::persist($item, $category)->toArray();
         $item['category'] = $category->name;
         return $item;
     } catch (\PDOException $e) {
         //// duplicate item
         if (Utils::isDbIntegrityException($e)) {
             $errorMessage = 'Item "' . $item->name . '" already exists in category "' . $category->name . '".';
             Log::info($e->getMessage());
             return response()->json(['error' => $errorMessage], 400);
         } else {
             throw $e;
         }
     }
 }
Ejemplo n.º 2
0
 protected function changelog($model, $changes)
 {
     $this->user_id = $this->user;
     $log = new Changelog();
     $log->user_id = $this->user;
     $log->before = json_encode($model);
     $log->after = json_encode($changes);
     $log->table = $this->getTable();
     try {
         $log->save();
     } catch (\PdoException $e) {
         //// hack for multiple calls for same event
         if (Utils::isDbIntegrityException($e)) {
             Log::error('ChangelogModelBase: Multiple calls for same event. ' . json_encode($log));
         } else {
             throw $e;
         }
     }
 }
 public function save_upload(UploadedFile $file_upload, $extension)
 {
     $uploads_dir = Config::get('dirs.uploads');
     $filename = pathinfo($file_upload->getClientOriginalName(), PATHINFO_FILENAME);
     $target_name = $uploads_dir . strftime('/%Y/%m%d/') . $filename . '.' . $extension;
     $n = 1;
     while (File::exists(base_path($target_name))) {
         $target_name = $uploads_dir . strftime('/%Y/%m%d/') . $filename . '(' . $n . ').' . $extension;
         $n++;
     }
     Utils::file_force_contents(base_path($target_name), File::get($file_upload));
     //Utils::gzCompressFile(base_path($target_name));
     return $target_name;
 }
Ejemplo n.º 4
0
 public function getShortDescriptionAttribute()
 {
     return Utils::getplaintextintrofromhtml($this->description);
 }
 public function save_picture($user_name, UploadedFile $file_upload)
 {
     $tmp_name = storage_path('tmp/') . str_random(16) . '.' . $file_upload->getClientOriginalExtension();
     Utils::file_force_contents($tmp_name, File::get($file_upload));
     $pictures_dir = Config::get('dirs.pìctures', '/uploads/pictures');
     $target_name = $pictures_dir . '/' . $user_name . '.jpeg';
     if (!File::isDirectory(base_path() . $pictures_dir)) {
         mkdir(base_path() . $pictures_dir, 0770, true);
     }
     $n = 1;
     while (File::exists(base_path() . $target_name)) {
         $target_name = $pictures_dir . '/' . $user_name . '(' . $n . ').jpeg';
         $n++;
     }
     Imaging::img_resize($tmp_name, base_path() . $target_name, 200, 300);
     File::delete($tmp_name);
     return $target_name;
 }