/** * Shows the welcome view with a list with all plants in system * and a list with all recipes in system */ public function showWelcome() { $plants = Plants::all(); $recipes = Recipes::all(); $data = array('plants' => $plants, 'recipes' => $recipes); return View::make('welcomeView')->with('data', $data); }
/** * Finds all the plant associated with the given recipe * @param $recipeId * @return array */ public function findPlantsForRecipe($recipeId) { $plants = PlantRecipe::where('recipe_id', '=', $recipeId)->get(); $plantArray = array(); foreach ($plants as $plant) { $plantArray[] = Plants::where('id', '=', $plant['plant_id'])->get()[0]; } return $plantArray; }
public function edit($plantID, $attributeArray) { $thePlant = Plants::find($plantID); $thePlant->name = $attributeArray['plant']['name']; $thePlant->name_latin = $attributeArray['plant']['latin']; $thePlant->description = $attributeArray['plant']['description']; $thePlant->history = $attributeArray['plant']['history']; $thePlant->save(); $this->sizeHandler->edit($plantID, $attributeArray['size']); $this->seasonHandler->edit($plantID, $attributeArray['season']); $this->habitatHandler->edit($plantID, $attributeArray['habitat']); $this->colorHandler->edit($plantID, $attributeArray['color']); $this->applicationHandler->edit($plantID, $attributeArray['application']); /*if(!empty($attributeArray['photo'])) for ($index = 0; $index < sizeof($attributeArray['photo']); $index++) $this->photoHandler->edit($plantID, $index, $attributeArray['photo'][$index]);*/ }
public function addNewRecipeToDb() { // @todo add all otherIngredients to the recipe as well $newRecipe = new Recipes(); $plantRecipe = new PlantRecipe(); $recipeId = sizeof(Recipes::all()) + 1; $plants = Plants::all(); $otherIngredients = Otheringredients::all(); $plantsAddedToRecipeArray = array(); $this->recipeSetup($newRecipe); foreach ($plants as $plant) { if (Input::get('plantId_' . $plant->id) === 'yes') { $plantsAddedToRecipeArray[] = $plant->id; } } $plantRecipe->savePlantRecipeConnectionToDb($recipeId, $plantsAddedToRecipeArray); $newRecipe->save(); $data = array('plants' => $plants, 'otherIngredients' => $otherIngredients); return View::make('addRecipeView')->with('data', $data); }
public function delete($plantID) { File::deleteDirectory(public_path() . '/PlantPictures/' . $plantID); Plants::where('id', '=', $plantID)->delete(); }
/** * Finds the plant from the id and all its relationships in the database * and passes it to the view, so the user can edit the data. * @return edit plant view with all the data as default from the plant */ public function showEditPlant() { $plantId = Input::get('plantId'); $thePlant = Plants::find($plantId); $sizeArray = $this->sizeHandler->get($plantId); $habitatArray = $this->habitatHandler->get($plantId); $seasonArray = $this->seasonHandler->get($plantId); $colorArray = $this->colorHandler->get($plantId); $photoArray = $this->photoHandler->get($plantId); $applicationArray = $this->applicationHandler->get($plantId); $data = array('plant' => $thePlant, 'seasons' => $seasonArray, 'colors' => $colorArray, 'habitats' => $habitatArray, 'sizes' => $sizeArray, 'photos' => $photoArray, 'applications' => $applicationArray); return View::make('editPlantView')->with('data', $data); }