コード例 #1
0
/**
 * Performs a shallow toArray to a Collection.
 *
 * @param Illuminate\Support\Collection $collection An instance of collection be transformed
 * @return array
 */
function collection_shallow_to_array($collection)
{
    $array = [];
    $collection->each(function ($data) use(&$array) {
        $array[] = $data;
    });
    return $array;
}
コード例 #2
0
 public function getData()
 {
     $models = new \Illuminate\Support\Collection();
     for ($x = 0; $x < 5; $x++) {
         $models->push($this->generateSet());
     }
     return $models;
 }
コード例 #3
0
 /**
  * create a collection of all descendant sections
  *
  * @param Nexus\Section - a section
  * @return collection of all descendant sections
  */
 public static function allChildSections(\Nexus\Section $section)
 {
     $allChildSections = new \Illuminate\Support\Collection();
     foreach ($section->sections as $child) {
         $allChildSections->prepend($child);
         $allChildSections = self::listChildren($child, $allChildSections);
     }
     return $allChildSections;
 }
コード例 #4
0
ファイル: Builder.php プロジェクト: jhaut/eloquent-enhanced
 /**
  * Extends of the lists function.
  * Allowing use table name or a subquery for each column and key parameter
  * @param  string $column
  * @param  string $key
  * @return array
  */
 public function lists($column, $key = null)
 {
     $select = is_null($key) ? array($column) : array($column, $key);
     $columns = $this->getListSelect($column, $key);
     $results = new \Illuminate\Support\Collection($this->get($select));
     $values = $results->fetch($columns[0])->all();
     if (!is_null($key) && count($results) > 0) {
         $keys = $results->fetch($columns[1])->all();
         return array_combine($keys, $values);
     }
     return $values;
 }
コード例 #5
0
 /**
  * Prepare calculation to help with sorting tour
  * @param  [type] $model [description]
  * @return [type]        [description]
  */
 function calculate_min_max_price($model)
 {
     //////////////////////////////////////////////////////////
     // Loop thru each schedules and set the min & max price //
     //////////////////////////////////////////////////////////
     $prices = new \Illuminate\Support\Collection();
     foreach ($model->cheapest_upcoming_schedules as $k => $v) {
         $prices->push($v['price']);
     }
     $calculation = $model->calculation;
     $calculation['price']['upcoming_min'] = $prices->min();
     $calculation['price']['upcoming_max'] = $prices->max();
     $model->calculation = $calculation;
 }
コード例 #6
0
ファイル: AlertsTest.php プロジェクト: augstudios/alerts
 /** @test */
 public function it_gets_alerts_by_type()
 {
     $type = Augstudios\Alerts\AlertType::Info;
     $this->store->shouldReceive('priorOfType')->with($type)->andReturn(Illuminate\Support\Collection::make());
     $result = $this->alerts->ofType($type);
     $this->assertInstanceOf('Illuminate\\Support\\Collection', $result);
 }
コード例 #7
0
 /**
 * Process a collection of reminders and send them to the right methods based on their 'remind_on' date. 
 Today's reminders get turned into new Instances. 
 Future reminders check their parent symbol's 'is_muted' property and set it to true if necessary.
 *
 * @param Illuminate\Support\Collection $reminders
 */
 public function runReminders($reminders)
 {
     //get and process the reminders
     Log::info('runReminders(), $reminders:' . $reminders->toJson());
     //Get reminders due today
     $todays_reminders = $reminders->where('remind_on', date('Y-m-d' . ' 00:00:00'))->values();
     //Get reminders due in the future
     $future_reminders = $reminders->filter(function ($reminder) {
         if ($reminder->remind_on > date('Y-m-d' . ' 00:00:00')) {
             return $reminder;
         }
     });
     //If we have any reminders due today, send them off to become instances
     if (!$todays_reminders->isEmpty()) {
         Log::info('TR: ' . $todays_reminders->toJson());
         $this->createInstanceFromReminder($todays_reminders);
     }
     //For reminders due in the future, make sure we're muting correctly
     if (!$future_reminders->isEmpty()) {
         Log::info('FR: ' . $future_reminders->toJson());
         $this->muteSymbolFromReminder($future_reminders);
     }
 }
コード例 #8
0
ファイル: CommonSeeder.php プロジェクト: ankhzet/Ankh
 function faker()
 {
     $single = count($this->locales) < 2;
     if (!$this->fakers) {
         if (!$this->locales) {
             $this->locales = [env('locale')];
         }
         if ($single) {
             $this->fakers = Faker\Factory::create(array_values($this->locales)[0]);
         } else {
             foreach ($this->locales as $locale) {
                 $this->fakers[] = Faker\Factory::create($locale);
             }
             $this->fakers = Illuminate\Support\Collection::make($this->fakers);
         }
     }
     return $single ? $this->fakers : $this->fakers->random();
 }
コード例 #9
0
ファイル: Spot.php プロジェクト: vanderlin/halp
 public static function findInLocation($lat, $lng, $max_distance = 25, $units = 'miles', $paginate = true)
 {
     switch ($units) {
         case 'miles':
             //radius of the great circle in miles
             $gr_circle_radius = 3959;
             break;
         case 'kilometers':
             //radius of the great circle in kilometers
             $gr_circle_radius = 6371;
             break;
     }
     $haversine = '(' . $gr_circle_radius . ' * acos(cos(radians(' . $lat . ')) * cos(radians(lat)) * cos(radians(lng) - radians(' . $lng . ')) + sin(radians(' . $lat . ')) * sin(radians(lat))))';
     $radius = 1;
     $locations = DB::table('locations')->select(array('*', DB::raw($haversine . ' as distance')))->orderBy('distance', 'ASC')->having('distance', '<=', $max_distance)->having('locationable_type', '=', 'Spot')->get();
     $spots = [];
     foreach ($locations as $loc) {
         $location = Location::find($loc->id);
         if ($location->locationable && $location->locationable->status == 'Publish') {
             array_push($spots, $location->locationable);
         }
     }
     $collection = new Illuminate\Support\Collection($spots);
     $collection->sort(function ($a, $b) {
         return $a->created_at->lt($b->created_at);
     });
     if ($paginate) {
         $page = 1;
         if (Input::has('page')) {
             $page = Input::get('page');
         }
         $perPage = 200;
         $offset = ($page - 1) * $perPage;
         return Paginator::make($collection->slice($offset, $perPage, true)->all(), $collection->count(), $perPage);
     }
     return $collection;
 }
コード例 #10
0
 /** @test */
 public function it_creates_named_form()
 {
     $model = new \Illuminate\Support\Collection(['name' => 'John Doe', 'gender' => 'f']);
     $expectModel = ['test_name' => $model->all()];
     $this->plainForm->add('name', 'text')->add('address', 'static');
     $this->assertEquals('name', $this->plainForm->getField('name')->getName());
     $this->assertEquals('address', $this->plainForm->getField('address')->getName());
     $this->plainForm->setName('test_name')->setModel($model);
     $this->plainForm->renderForm();
     $this->assertEquals('test_name[name]', $this->plainForm->getField('name')->getName());
     $this->assertEquals('test_name[address]', $this->plainForm->getField('address')->getName());
     $this->assertEquals($expectModel, $this->plainForm->getModel());
 }
コード例 #11
0
/**
 * 优雅CMF后台分页helper
 *
 * @param Illuminate\Support\Collection $model
 * @param array $data 追加的参数数组
 * @return string 返回分页
 */
function page_links($model, $data = [])
{
    $presenter = new \YouYa\Extensions\YouYaPresenter($model);
    if (empty($data)) {
        $links = $model->render($presenter);
    } else {
        $links = $model->appends($data)->render($presenter);
    }
    return $links;
}
コード例 #12
0
ファイル: Menu.php プロジェクト: Faisalawanisee/laravel-menu
 /**
  * Return Menu instance from the collection by key
  *
  * @param  string  $key
  * @return \Lavary\Menu\Item
  */
 public function get($key)
 {
     return $this->collection->get($key);
 }
コード例 #13
0
ファイル: TestWrapper.php プロジェクト: muratsplat/multilang
 public function testCachedFeatureFirst()
 {
     $this->createContent(10);
     $this->createContentLang(10);
     $this->assertCount(10, Content::all());
     $this->assertCount(100, Model\ContentLang::all());
     $collection = new \Illuminate\Support\Collection();
     \DB::flushQueryLog();
     Content::all()->each(function ($item) use($collection) {
         $wrapper = $this->wrapper->createNew($item, 1);
         $collection->push($wrapper);
     });
     Content::all()->each(function ($item) use($collection) {
         $wrapper = $this->wrapper->createNew($item, 2);
         $collection->push($wrapper);
     });
     $this->assertCount(20, $collection);
     for ($i = 0; $i < 10; $i++) {
         foreach ($collection as $one) {
             $one->title;
             $one->content;
             $one->enable;
             $one->visible;
         }
     }
     $this->assertCount(5, \DB::getQueryLog());
 }
コード例 #14
0
ファイル: routes.php プロジェクト: kamaroly/rahasitc
               <v3:consumerID>XXXXX</v3:consumerID>
               <!--Optional:-->
               <v3:transactionID>56488</v3:transactionID>
               <v3:country>RWA</v3:country>
               <v3:correlationID>56488</v3:correlationID>
            </v3:GeneralConsumerInformation>
         </v3:RequestHeader>
         <v1:requestBody>
            <v1:initiatorAccount>
               <!--You have a CHOICE of the next 2 items at this level-->
              <v1:msisdn>250726049698</v1:msisdn>             
            </v1:initiatorAccount>
            <v1:password>1515</v1:password>
            <v1:transactionId>85300</v1:transactionId>  //RequestId
           
         </v1:requestBody>
      </v1:GetPurchaseStatusRequest>
   </soapenv:Body>
</soapenv:Envelope>';
    $xml = $response;
    //file_get_contents($response);
    // SimpleXML seems to have problems with the colon ":" in the <xxx:yyy> response tags, so take them out
    $xml = preg_replace("/(<\\/?)(\\w+):([^>]*>)/", "\$1\$2\$3", $xml);
    $xml = simplexml_load_string($xml);
    $json = json_encode($xml);
    $responseArray = json_decode($json, true);
    $collections = new Illuminate\Support\Collection($responseArray);
    $responseBody = $collections->get('soapenvBody');
    dd(key($responseBody));
    dd($xml, $json, $responseArray, $collections->get('soapenvBody'));
});
コード例 #15
0
ファイル: routes.php プロジェクト: johannesponader/Onepager
});
Route::get('/live', function () {
    return redirect('https://www.youtube.com/watch?v=gS65yoNcq88', 307);
});
/*
 * Newsletter routes
 *
 * Muig9%41
 */
Route::group(['middleware' => 'auth', 'prefix' => 'dashboard', 'namespace' => 'Dashboard'], function () {
    Route::get('/', function () {
        return redirect()->route('dashboard.newsletter.index');
    });
    Route::get('/export', function () {
        $newsletters = \App\Newsletter::get();
        $subscriber = new \Illuminate\Support\Collection();
        foreach ($newsletters as $newsletter) {
            $subscriber->push(['id' => $newsletter->id, 'email' => $newsletter->email]);
        }
        Excel::create('Newsletter_Subscriber', function ($excel) use($subscriber) {
            $excel->sheet('Subscriber', function ($sheet) use($subscriber) {
                $sheet->fromArray($subscriber, null, 'A1', false);
            });
        })->download('csv');
    });
    Route::get('/newsletter', ['as' => 'dashboard.newsletter.index', 'uses' => 'NewsletterController@index']);
});
/*
 * Authentication routes
 */
Route::get('auth/login', 'Auth\\AuthController@getLogin');
コード例 #16
0
 /**
  * Returns a Collection for all weapons..
  *
  * @return \Illuminate\Support\Collection
  */
 public function AllWeapons()
 {
     $weapons_data = $this->alias->weapons->sortBy('name')->groupBy('name');
     $weaponTotal = new \Illuminate\Support\Collection();
     $weaponTotal->primary = new \Illuminate\Support\Collection();
     $weaponTotal->secondary = new \Illuminate\Support\Collection();
     $weaponTotal->tactical = new \Illuminate\Support\Collection();
     $weaponTotal->others = new \Illuminate\Support\Collection();
     foreach ($weapons_data as $key => $weapons) {
         if (in_array($key, [1, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12])) {
             $weaponTotal->primary->{$key} = new \Illuminate\Support\Arr();
             $weaponTotal->primary->push($weaponTotal->primary->{$key});
             $weaponTotal->primary->{$key}->family = "Primary";
             $weaponTotal->primary->{$key}->name = Server\Utils::getEquipmentTitleById($key);
             $weaponTotal->primary->{$key}->id = $key;
             $weaponTotal->primary->{$key}->shots_fired = $weapons->sum('shots_fired');
             $weaponTotal->primary->{$key}->shots_hit = $weapons->sum('shots_hit');
             $weaponTotal->primary->{$key}->kills = $weapons->sum('kills');
             $weaponTotal->primary->{$key}->accuracy = $weaponTotal->primary->{$key}->shots_fired == 0 ? 0 : round($weaponTotal->primary->{$key}->shots_hit / $weaponTotal->primary->{$key}->shots_fired * 100, 2);
             $weaponTotal->primary->{$key}->kills_per_min = $weapons->sum('seconds_used') == 0 ? 0 : round($weaponTotal->primary->{$key}->kills / $weapons->sum('seconds_used') * 60, 2);
             $weaponTotal->primary->{$key}->distance = $weapons->max('distance');
             $weaponTotal->primary->{$key}->time_used = Server\Utils::getHMbyS($weapons->sum('seconds_used'), "%dh %dm");
         } elseif (in_array($key, [13, 14, 15, 16, 17])) {
             $weaponTotal->secondary->{$key} = new \Illuminate\Support\Arr();
             $weaponTotal->secondary->push($weaponTotal->secondary->{$key});
             $weaponTotal->secondary->{$key}->family = "Secondary";
             $weaponTotal->secondary->{$key}->name = Server\Utils::getEquipmentTitleById($key);
             $weaponTotal->secondary->{$key}->id = $key;
             $weaponTotal->secondary->{$key}->shots_fired = $weapons->sum('shots_fired');
             $weaponTotal->secondary->{$key}->shots_hit = $weapons->sum('shots_hit');
             $weaponTotal->secondary->{$key}->kills = $weapons->sum('kills');
             $weaponTotal->secondary->{$key}->accuracy = $weaponTotal->secondary->{$key}->shots_fired == 0 ? 0 : round($weaponTotal->secondary->{$key}->shots_hit / $weaponTotal->secondary->{$key}->shots_fired * 100, 2);
             $weaponTotal->secondary->{$key}->kills_per_min = $weapons->sum('seconds_used') == 0 ? 0 : round($weaponTotal->secondary->{$key}->kills / $weapons->sum('seconds_used') * 60, 2);
             $weaponTotal->secondary->{$key}->distance = $weapons->max('distance');
             $weaponTotal->secondary->{$key}->time_used = Server\Utils::getHMbyS($weapons->sum('seconds_used'), "%dh %dm");
         } elseif (in_array($key, [18, 23, 24, 45, 25, 26])) {
             $weaponTotal->tactical->{$key} = new \Illuminate\Support\Arr();
             $weaponTotal->tactical->push($weaponTotal->tactical->{$key});
             $weaponTotal->tactical->{$key}->family = "Tactical";
             $weaponTotal->tactical->{$key}->name = Server\Utils::getEquipmentTitleById($key);
             $weaponTotal->tactical->{$key}->id = $key;
             $weaponTotal->tactical->{$key}->shots_fired = $weapons->sum('shots_fired');
             $weaponTotal->tactical->{$key}->shots_hit = $weapons->sum('shots_hit');
             $weaponTotal->tactical->{$key}->kills = $weapons->sum('kills');
             $weaponTotal->tactical->{$key}->accuracy = $weaponTotal->tactical->{$key}->shots_fired == 0 ? 0 : round($weaponTotal->tactical->{$key}->shots_hit / $weaponTotal->tactical->{$key}->shots_fired * 100, 2);
             $weaponTotal->tactical->{$key}->stuns_per_min = $weapons->sum('seconds_used') == 0 ? 0 : round($weaponTotal->tactical->{$key}->shots_fired / $weapons->sum('seconds_used') * 60, 2);
             $weaponTotal->tactical->{$key}->distance = $weapons->max('distance');
             $weaponTotal->tactical->{$key}->time_used = Server\Utils::getHMbyS($weapons->sum('seconds_used'), "%dh %dm");
         } else {
             $weaponTotal->others->{$key} = new \Illuminate\Support\Arr();
             $weaponTotal->others->push($weaponTotal->others->{$key});
             $weaponTotal->others->{$key}->family = "Others";
             $weaponTotal->others->{$key}->name = Server\Utils::getEquipmentTitleById($key);
             $weaponTotal->others->{$key}->id = $key;
             $weaponTotal->others->{$key}->shots_fired = $weapons->sum('shots_fired');
             $weaponTotal->others->{$key}->shots_hit = $weapons->sum('shots_hit');
             $weaponTotal->others->{$key}->kills = $weapons->sum('kills');
             $weaponTotal->others->{$key}->accuracy = $weaponTotal->others->{$key}->shots_fired == 0 ? 0 : round($weaponTotal->others->{$key}->shots_hit / $weaponTotal->others->{$key}->shots_fired * 100, 2);
             $weaponTotal->others->{$key}->kills_per_min = $weapons->sum('seconds_used') == 0 ? 0 : round($weaponTotal->others->{$key}->kills / $weapons->sum('seconds_used') * 60, 2);
             $weaponTotal->others->{$key}->distance = $weapons->max('distance');
             $weaponTotal->others->{$key}->time_used = Server\Utils::getHMbyS($weapons->sum('seconds_used'), "%dh %dm");
         }
     }
     $weaponTotal->push($weaponTotal->primary->sortByDesc('kills'))->push($weaponTotal->secondary->sortByDesc('kills'))->push($weaponTotal->tactical->sortByDesc('shots_fired'))->push($weaponTotal->others->sortByDesc('kills'));
     return $weaponTotal;
 }
コード例 #17
0
 /**
  * Sort the array using the given Closure.
  *
  * @param  array  $array
  * @param  \Closure  $callback
  * @return array
  */
 function array_sort($array, Closure $callback)
 {
     return Illuminate\Support\Collection::make($array)->sortBy($callback)->all();
 }
コード例 #18
0
ファイル: LOFaker.php プロジェクト: vanderlin/halp
 public function findNotifications()
 {
     $notifications = [];
     $commentRepository = App::make('CommentRepository');
     // -------------------------------------
     Comment::withTrashed()->withSpot()->get()->each(function ($item) use(&$notifications, &$commentRepository) {
         $spot = $item->spot()->withTrashed()->first();
         if ($spot == NULL) {
             // remove this comment its dead
             $commentRepository->destroy($item->id);
             return;
         }
         if ($spot->user !== null) {
             $from_user_id = $item->user_id;
             $to_user_id = $spot->user_id;
             if ($from_user_id !== $to_user_id) {
                 $notification_event = array('event' => Notification::NOTIFICATION_USER_COMMENTED, 'from_user_id' => $from_user_id, 'to_user_id' => $to_user_id, 'parent' => $item, 'timestamp' => $this->timestamp($item->created_at), 'is_read' => false);
                 array_push($notifications, $notification_event);
             }
         }
     });
     // -------------------------------------
     Visit::withTrashed()->get()->each(function ($item) use(&$notifications) {
         $spot = $item->spot()->withTrashed()->first();
         if ($spot == NULL) {
             // remove this comment its dead
             dd($spot);
             return;
         }
         if ($spot->user !== null) {
             $from_user_id = $item->user_id;
             $to_user_id = $spot->user_id;
             if ($from_user_id !== $to_user_id) {
                 $notification_event = array('event' => Notification::NOTIFICATION_USER_VISITED, 'from_user_id' => $from_user_id, 'to_user_id' => $to_user_id, 'parent' => $item, 'timestamp' => $this->timestamp($item->created_at), 'is_read' => false);
                 array_push($notifications, $notification_event);
             }
         }
     });
     // -------------------------------------
     Illuminate\Support\Collection::make(DB::table('userables')->get())->each(function ($item) use(&$notifications) {
         $type = $item->userable_type;
         $parent = $type::withTrashed()->whereId($item->userable_id)->first();
         $notification_event = array('event' => Notification::NOTIFICATION_USER_ITINERARY_SHARED, 'to_user_id' => $item->user_id, 'from_user_id' => $parent->user->id, 'parent' => $parent, 'timestamp' => $this->timestamp(new Carbon($item->created_at)), 'is_read' => false);
         array_push($notifications, $notification_event);
     });
     // -------------------------------------
     User::all()->each(function ($user) use(&$notifications) {
         // welcome message
         $notification_event = array('event' => Notification::NOTIFICATION_USER_WELCOME, 'to_user_id' => $user->id, 'from_user_id' => null, 'parent' => $user, 'timestamp' => $this->timestamp($user->created_at), 'is_read' => false);
         array_push($notifications, $notification_event);
         // when someone added your spot to favs
         foreach ($user->favorites->getLocations() as $location) {
             if ($location->hasSpot() && $location->spot->user_id !== $user->id) {
                 // send to the owner of the spot
                 $to_user_id = $location->spot->user_id;
                 // who is doing this...?
                 $from_user_id = $user->id;
                 // welcome message
                 $notification_event = array('event' => Notification::NOTIFICATION_USER_FAVORITED, 'to_user_id' => $to_user_id, 'from_user_id' => $from_user_id, 'parent' => $location->spot, 'timestamp' => $this->timestamp($location->pivot->created_at), 'is_read' => false);
                 array_push($notifications, $notification_event);
             }
         }
     });
     foreach ($notifications as $notice) {
         Notification::fireNotification($notice);
     }
     return $notifications;
 }