コード例 #1
0
 public function prepareSessionWithUniquePairs()
 {
     // lege array
     $array = [];
     // tel aantal users
     $count = $this->users->count();
     // geef elke user een andere user voor combo
     foreach (range(1, $count) as $value1) {
         foreach (range(1, $count) as $value2) {
             $pair = [$value1, $value2];
             // zolang users niet aan elkaar gelijk zijn en wanneer ook decombinatie omgedraaid niet wordt teruggevonden in de array van arrays
             if ($value1 != $value2 && !str_contains(json_encode($array), json_encode(array_sort_recursive($pair)))) {
                 $array[] = $pair;
             }
         }
     }
     // shuffle cards pls
     shuffle($array);
     // maak beginnende key een 1 ipv 0
     $array = array_filter(array_merge(array(0), $array));
     //steek ze in de sessie
     //$this->request->session()->put( 'combos' , $array );
     Cache::forever('combos', $array);
     return true;
 }
コード例 #2
0
 /**
  * all braches by date //dailysales/all
  */
 public function allBranchByDate(Carbon $date)
 {
     $ads = [];
     // array of dailysales
     //$bb = Branch::orderBy('code', 'ASC')->get();
     $bb = $this->branch->all(['code', 'descriptor', 'mancost', 'id']);
     //return $bb = $this->branch->getByCriteria(new ActiveBranch)->all(['code', 'descriptor', 'mancost', 'id']);
     foreach ($bb as $b) {
         // each bossbranch
         $ds = DailySales::whereBranchid($b->id)->where('date', $date->format('Y-m-d'))->first();
         if (is_null($ds)) {
             $ads[$b->code]['ds'] = NULL;
         }
         $ads[$b->code]['ds'] = $ds;
         $ads[$b->code]['br'] = $b;
     }
     return array_sort_recursive($ads);
     return array_sort($ads, function ($value) {
         return $value;
     });
 }
コード例 #3
0
ファイル: CrawlerTrait.php プロジェクト: ncusoho/framework
 /**
  * Assert that the response contains the given JSON.
  *
  * @param  array  $data
  * @param  bool  $negate
  * @return $this
  */
 protected function seeJsonContains(array $data, $negate = false)
 {
     $method = $negate ? 'assertFalse' : 'assertTrue';
     $actual = json_encode(array_sort_recursive(json_decode($this->response->getContent(), true)));
     foreach (array_sort_recursive($data) as $key => $value) {
         $expected = $this->formatToExpectedJson($key, $value);
         $this->{$method}(Str::contains($actual, $expected), ($negate ? 'Found unexpected' : 'Unable to find') . " JSON fragment [{$expected}] within [{$actual}].");
     }
     return $this;
 }
コード例 #4
0
 /**
  * Recursively sort an array by keys and values.
  *
  * @param  array  $array
  * @return array
  */
 function array_sort_recursive($array)
 {
     foreach ($array as &$value) {
         if (is_array($value) && isset($value[0])) {
             sort($value);
         } elseif (is_array($value)) {
             array_sort_recursive($value);
         }
     }
     ksort($array);
     return $array;
 }
コード例 #5
0
ファイル: CrawlerTrait.php プロジェクト: Calky/uas
 /**
  * Assert that the response contains the given JSON.
  *
  * @param  array  $data
  * @return $this
  */
 protected function seeJsonContains(array $data)
 {
     $actual = json_encode(array_sort_recursive(json_decode($this->response->getContent(), true)));
     foreach (array_sort_recursive(json_decode(json_encode($data), true)) as $key => $value) {
         $expected = $this->formatToExpectedJson($key, $value);
         $this->assertTrue(str_contains($actual, $this->formatToExpectedJson($key, $value)), "Unable to find JSON fragment [{$expected}] within [{$actual}].");
     }
     return $this;
 }
コード例 #6
0
ファイル: PostsController.php プロジェクト: vizovteam/vizov
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update(PostRequest $request, $id)
 {
     $post = Auth::user()->posts()->find($id);
     if ($request->hasFile('images')) {
         $i = 0;
         $introImage = null;
         $images = unserialize($post->images) ? unserialize($post->images) : [];
         foreach ($request->file('images') as $key => $image) {
             if (isset($image)) {
                 $imageName = $key . '-image-' . str_random(10) . '.' . $image->getClientOriginalExtension();
                 if (!file_exists('img/posts/' . $post->user_id)) {
                     Storage::makeDirectory('img/posts/' . $post->user_id);
                 }
                 if ($key == 0) {
                     if ($post->image != NULL and file_exists('img/posts/' . $post->user_id . '/' . $post->image)) {
                         Storage::delete('img/posts/' . $post->user_id . '/' . $post->image);
                     }
                     $mainFile = Image::canvas(300, 200, '#ffffff');
                     $introFile = Image::make($image);
                     $this->file = $introFile;
                     $this->optimalResize(300, 200);
                     $mainFile->insert($this->file, 'center');
                     $mainFile->rectangle(0, 0, 299, 199, function ($draw) {
                         $draw->border(1, '#dddddd');
                     });
                     $mainFile->save('img/posts/' . $post->user_id . '/main-' . $imageName);
                     $introImage = 'main-' . $imageName;
                 }
                 // Creating images
                 $moreFile = Image::canvas(634, 432, '#ffffff');
                 $file = Image::make($image);
                 $this->file = $file;
                 $this->optimalResize(634, 432);
                 $moreFile->insert($this->file, 'center');
                 $moreFile->insert('img/watermark-blue.png', 'bottom-left', 10, 10);
                 $moreFile->rectangle(0, 0, 633, 431, function ($draw) {
                     $draw->border(1, '#dddddd');
                 });
                 $moreFile->save('img/posts/' . $post->user_id . '/' . $imageName);
                 // Creating mini images
                 $miniFile = Image::canvas(95, 71, '#ffffff');
                 $this->file = $file;
                 $this->optimalResize(95, 71);
                 $miniFile->insert($this->file, 'center');
                 $miniFile->rectangle(0, 0, 94, 70, function ($draw) {
                     $draw->border(1, '#dddddd');
                 });
                 $miniFile->save('img/posts/' . $post->user_id . '/mini-' . $imageName);
                 if (isset($images[$key])) {
                     Storage::delete(['img/posts/' . $post->user_id . '/' . $images[$key]['image'], 'img/posts/' . $post->user_id . '/' . $images[$key]['mini_image']]);
                     $images[$key]['image'] = $imageName;
                     $images[$key]['mini_image'] = 'mini-' . $imageName;
                 } else {
                     $images[$key]['image'] = $imageName;
                     $images[$key]['mini_image'] = 'mini-' . $imageName;
                 }
             }
         }
         $images = array_sort_recursive($images);
         $images = serialize($images);
     }
     $post->city_id = $request->city_id;
     $post->category_id = $request->category_id;
     $post->slug = str_slug($request->title);
     $post->title = $request->title;
     $post->price = $request->price;
     $post->deal = $request->deal;
     $post->description = $request->description;
     if (isset($introImage)) {
         $post->image = $introImage;
     }
     if (isset($images)) {
         $post->images = $images;
     }
     $post->address = $request->address;
     $contacts = ['phone' => $request->phone, 'telegram' => $request->telegram, 'whatsapp' => $request->whatsapp, 'viber' => $request->viber, 'phone2' => $request->phone2, 'telegram2' => $request->telegram2, 'whatsapp2' => $request->whatsapp2, 'viber2' => $request->viber2];
     $post->phone = json_encode($contacts);
     $post->email = $request->email;
     $post->comment = $request->comment;
     if ($tags_id = $request->input('tags_id')) {
         $post->detachTags();
         $post->attachTags($tags_id);
     }
     $post->save();
     return redirect('my_posts')->with('status', 'Объявление добавлено!');
 }
コード例 #7
0
 /**
  * Assert that the response contains the given JSON.
  *
  * @param  array  $data
  * @param  bool  $negate
  * @return $this
  */
 protected function seeJsonContains(array $data, $negate = false)
 {
     $method = $negate ? 'assertFalse' : 'assertTrue';
     $actual = json_decode($this->response->getContent(), true);
     if (is_null($actual) || $actual === false) {
         return $this->fail('Invalid JSON was returned from the route. Perhaps an exception was thrown?');
     }
     $actual = json_encode(array_sort_recursive((array) $actual));
     foreach (array_sort_recursive($data) as $key => $value) {
         $expected = $this->formatToExpectedJson($key, $value);
         $this->{$method}(Str::contains($actual, $expected), ($negate ? 'Found unexpected' : 'Unable to find') . " JSON fragment [{$expected}] within [{$actual}].");
     }
     return $this;
 }
コード例 #8
0
 /**
  * Assert that the response contains an exact JSON array.
  *
  * @param  array $data
  * @return $this
  */
 public function seeJsonEqualsExt(array $data)
 {
     $actual = json_encode(array_sort_recursive(json_decode($this->response->getContent(), true)), JSON_FORCE_OBJECT);
     $this->assertEquals(json_encode(array_sort_recursive($data), JSON_FORCE_OBJECT), $actual);
     return $this;
 }