Ejemplo n.º 1
0
 public function getFilteredEntries($lastNames)
 {
     $entries = Entry::with('restorationType')->with('folders')->whereIn('last_name', $lastNames)->get();
     //Transform
     $resource = createCollection($entries, new EntryTransformer());
     return transform($resource)['data'];
 }
Ejemplo n.º 2
0
 /**
  * Change to a static constructor or not, up to you
  * @param null $budgets
  */
 public function __construct($budgets = NULL)
 {
     $this->type = Budget::TYPE_FIXED;
     $this->budgets = $budgets ?: Budget::forCurrentUser()->whereType(Budget::TYPE_FIXED)->get();
     $this->amount = $this->calculate('amount');
     $this->remaining = $this->calculate('remaining');
     $this->cumulative = $this->calculate('cumulative');
     $this->spentBeforeStartingDate = $this->calculate('spentBeforeStartingDate');
     $this->spentOnOrAfterStartingDate = $this->calculate('spentOnOrAfterStartingDate');
     $this->receivedOnOrAfterStartingDate = $this->calculate('receivedOnOrAfterStartingDate');
     //Transform budgets
     $resource = createCollection($this->budgets, new BudgetTransformer());
     $this->budgets = transform($resource);
 }
 /**
  * Insert an exercise entry.
  * It can be an exercise set.
  * @param Request $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $exercise = Exercise::find($request->get('exercise_id'));
     if ($request->get('exerciseSet')) {
         // We are inserting an exercise set
         $quantity = $exercise->default_quantity;
         $unit = Unit::find($exercise->default_unit_id);
     } else {
         $quantity = $request->get('quantity');
         $unit = Unit::find($request->get('unit_id'));
     }
     $entry = new Entry(['date' => $request->get('date'), 'quantity' => $quantity]);
     $entry->user()->associate(Auth::user());
     $entry->exercise()->associate($exercise);
     $entry->unit()->associate($unit);
     $entry->save();
     //Return the entries for the day
     $entries = transform(createCollection($this->exerciseEntriesRepository->getEntriesForTheDay($request->get('date')), new ExerciseEntryTransformer()))['data'];
     return response($entries, Response::HTTP_CREATED);
 }
 /**
  * Get recipe contents and steps.
  * Contents should include the foods that belong to the recipe,
  * along with the description, quantity, and unit
  * for the food when used in the recipe (from food_recipe table),
  * and with the tags for the recipe.
  * Redoing after refactor. Still need description, quantity, unit.
  * @param $recipe
  * @return array
  */
 public function getRecipeInfo($recipe)
 {
     $recipe = transform(createItem($recipe, new RecipeWithIngredientsTransformer()))['data'];
     //For some reason the units for each food aren't being added to the food
     //from my IngredientTransformer, so add them here
     foreach ($recipe['ingredients']['data'] as $index => $ingredient) {
         $units = Food::find($ingredient['food']['data']['id'])->units;
         $units = transform(createCollection($units, new UnitTransformer()));
         $recipe['ingredients']['data'][$index]['food']['data']['units'] = $units;
     }
     return $recipe;
 }
 /**
  * Get all exercises for the current user,
  * along with their tags, default unit name
  * and the name of the series each exercise belongs to.
  * Order first by series name, then by step number.
  * @return mixed
  */
 public function getExercises()
 {
     $exercises = Exercise::forCurrentUser('exercises')->with('defaultUnit')->orderBy('step_number')->with('series')->with('tags')->get();
     return transform(createCollection($exercises, new ExerciseTransformer()))['data'];
 }
 /**
  *
  * @param Series $series
  * @return \League\Fractal\Resource\Collection
  */
 public function includeExercises(Series $series)
 {
     return createCollection($series->exercises, new ExerciseTransformer());
 }
 /**
  *
  * @param Request $request
  * @return mixed
  */
 public function index(Request $request)
 {
     $typing = '%' . $request->get('typing') . '%';
     $matches = Journal::where('user_id', Auth::user()->id)->where('text', 'LIKE', $typing)->orderBy('date', 'desc')->get();
     return transform(createCollection($matches, new JournalTransformer()));
 }
 /**
  *
  * @param Recipe $recipe
  * @return \League\Fractal\Resource\Collection
  */
 public function includeTags(Recipe $recipe)
 {
     $tags = $recipe->tags;
     return createCollection($tags, new TagTransformer());
 }
Ejemplo n.º 9
0
 /**
  * Get all foods, along with their default unit, default calories,
  * and all their units.
  * Also, add the calories for each food's units. Todo?
  * @return mixed
  */
 public function getFoods()
 {
     $foods = Food::forCurrentUser()->with('defaultUnit')->orderBy('foods.name', 'asc')->get();
     $foods = transform(createCollection($foods, new FoodTransformer()));
     return $foods['data'];
 }
 /**
  * Get all the user's entries for an exercise series.
  * This could be expressed two ways:
  * 1: $series->entries
  * 2: $entry->where('series_id', $series->id)
  * @param Request $request
  * @return array
  */
 public function show($series_id)
 {
     //Fetch the series (singular-the series that was clicked on)
     $series = Series::find($series_id);
     return transform(createCollection($this->exerciseSeriesRepository->getExerciseSeriesHistory($series), new ExerciseEntryTransformer()))['data'];
 }
 /**
  * Get a user's menu (food/recipe) entries for one day
  * @param $date
  * @return array
  */
 public function getEntriesForTheDay($date)
 {
     $entries = Entry::forCurrentUser()->where('date', $date)->get();
     return transform(createCollection($entries, new MenuEntryTransformer()))['data'];
 }
 /**
  *
  * @return mixed
  */
 public function index()
 {
     return transform(createCollection($this->exerciseSeriesRepository->getExerciseSeries(), new SeriesTransformer()))['data'];
 }
 /**
  *
  * @return mixed
  */
 public function getExerciseTags()
 {
     $tags = Tag::forCurrentUser()->where('for', 'exercise')->orderBy('name', 'asc')->get();
     return transform(createCollection($tags, new TagTransformer()))['data'];
 }
Ejemplo n.º 14
0
    $collection = array();
    for ($i = 0; $i < 50; $i++) {
        $collection[] = createObject();
    }
    return $collection;
}
function createObject()
{
    $post = new \JMS\Serializer\Tests\Fixtures\BlogPost('FooooooooooooooooooooooBAR', new \JMS\Serializer\Tests\Fixtures\Author('Foo'), new \DateTime());
    for ($i = 0; $i < 10; $i++) {
        $post->addComment(new \JMS\Serializer\Tests\Fixtures\Comment(new \JMS\Serializer\Tests\Fixtures\Author('foo'), 'foobar'));
    }
    return $post;
}
$serializer = \JMS\Serializer\SerializerBuilder::create()->build();
$collection = createCollection();
$metrics = array();
$f = function () use($serializer, $collection, $format) {
    $serializer->serialize($collection, $format);
};
// Load all necessary classes into memory.
benchmark($f, 1);
printf('Benchmarking collection for format "%s".' . PHP_EOL, $format);
$metrics['benchmark-collection-' . $format] = benchmark($f, $iterations);
$output = json_encode(array('metrics' => $metrics));
if (isset($_SERVER['argv'][3])) {
    file_put_contents($_SERVER['argv'][3], $output);
    echo "Done." . PHP_EOL;
} else {
    echo $output . PHP_EOL;
}
 /**
  *
  * @param Exercise $exercise
  * @return \League\Fractal\Resource\Collection
  */
 public function includeTags(Exercise $exercise)
 {
     $tags = $exercise->tags;
     return createCollection($tags, new TagTransformer());
 }