diff --git a/src/Controller/RecipesController.php b/src/Controller/RecipesController.php index 9e3017f..2714743 100644 --- a/src/Controller/RecipesController.php +++ b/src/Controller/RecipesController.php @@ -86,7 +86,8 @@ public function view($id = null, $servings=null) ], 'Units' => [ 'fields' => ['name', 'abbreviation'] - ] + ], + 'sort' => ['IngredientMappings.sort_order' => 'ASC'] ], 'RelatedRecipes' => [ 'Recipes' => [ @@ -94,10 +95,11 @@ public function view($id = null, $servings=null) 'IngredientMappings' => [ 'Ingredients' => [ 'fields' => ['name'] - ], - 'Units' => [ - 'fields' => ['name', 'abbreviation'] - ] + ], + 'Units' => [ + 'fields' => ['name', 'abbreviation'] + ], + 'sort' => ['IngredientMappings.sort_order' => 'ASC'] ] ] ], @@ -143,7 +145,8 @@ public function edit($id = null) ], 'Units' => [ 'fields' => ['name', 'abbreviation'] - ] + ], + 'sort' => ['IngredientMappings.sort_order' => 'ASC'] ], 'RelatedRecipes' => [ 'Recipes' => [ @@ -154,7 +157,8 @@ public function edit($id = null) ], 'Units' => [ 'fields' => ['name', 'abbreviation'] - ] + ], + 'sort' => ['IngredientMappings.sort_order' => 'ASC'] ] ] ], @@ -170,21 +174,18 @@ public function edit($id = null) $recipe->user_id = $this->Auth->user('id'); if ($this->Recipes->save($recipe)) { $this->Flash->success(__('The recipe has been saved.')); - return $this->redirect(['action' => 'index']); + } else { + $this->Flash->error(__('The recipe could not be saved. Please, try again.')); } - /* - NOTE: Helpful debug info - - $x = $recipe->getErrors(); + //NOTE: Helpful debug info + /*$x = $recipe->getErrors(); if ($x) { debug($recipe); debug($x); return false; - } - */ - $this->Flash->error(__('The recipe could not be saved. Please, try again.')); + }*/ } $ethnicities = $this->Recipes->Ethnicities->find('list', ['limit' => 200, 'order' => ['Ethnicities.name']]); $baseTypes = $this->Recipes->BaseTypes->find('list', ['limit' => 200, 'order' => ['BaseTypes.name']]); @@ -211,6 +212,15 @@ public function delete($id = null) return $this->redirect(['action' => 'index']); } + public function removeIngredientMapping($recipeId, $mappingId) { + $entity = $this->Recipes->IngredientMappings->get($mappingId); + if ($this->Recipes->IngredientMappings->delete($entity)) { + $this->Flash->success(__('The ingredient has been removed.')); + } else { + $this->Flash->error(__('The ingredient could not be removed. Please, try again.')); + } + } + public function findByBase($baseId) { $this->filterConditions['Recipes.base_type_id'] = $baseId; diff --git a/src/Model/Table/AttachmentsTable.php b/src/Model/Table/AttachmentsTable.php index 2c64626..675ee16 100644 --- a/src/Model/Table/AttachmentsTable.php +++ b/src/Model/Table/AttachmentsTable.php @@ -72,8 +72,8 @@ public function validationDefault(Validator $validator) ->notEmptyString('name'); $validator - ->scalar('attachment') - ->maxLength('attachment', 255) + //->scalar('attachment') + //->maxLength('attachment', 255) ->requirePresence('attachment', 'create') ->notEmptyString('attachment'); diff --git a/src/Template/Recipes/edit.ctp b/src/Template/Recipes/edit.ctp index da4acef..1be98f5 100644 --- a/src/Template/Recipes/edit.ctp +++ b/src/Template/Recipes/edit.ctp @@ -167,8 +167,6 @@ $recipeId = isset($recipe->id) ? $recipe->id : ""; return; // Not good if we get here } - console.log("Regex:" + regMatch); - // Don't delete the last table row if (thisRow.is(":last-child")) { return; @@ -406,21 +404,22 @@ $recipeId = isset($recipe->id) ? $recipe->id : ""; echo $this->Form->control('preparation_time_id', array('empty'=>true)); echo $this->Form->control('difficulty_id', array('empty'=>true)); echo $this->Form->control('serving_size'); - $imageCount = (isset($recipe) && isset($recipe->image))? count($recipe->image) : 0; - + $imageCount = (isset($recipe) && isset($recipe->attachments))? count($recipe->attachments) : 0; + $newImageIndex = $imageCount-1; + echo "
"; - echo $this->Form->control('new_attachments.attachment', array('type' => 'file', 'label' => 'Add Image')); - echo $this->Form->control('new_attachments.name', array('label' => 'Caption')); - echo $this->Form->hidden('new_attachment.id'); + echo $this->Form->control('attachments.'. $newImageIndex . '.attachment', array('type' => 'file', 'label' => 'Add Image')); + echo $this->Form->control('attachments.'. $newImageIndex . '.name', array('label' => 'Caption')); + echo $this->Form->hidden('attachment.'. $newImageIndex . '.id'); echo "
"; for ($imageIndex = 0; $imageIndex < $imageCount; $imageIndex++) { - $imageName = $recipe['Image'][$imageIndex]['attachment']; - $imageDir = $recipe['Image'][$imageIndex]['dir']; + $imageName = $recipe->attachments[$imageIndex]->attachment; + $imageDir = $recipe->attachments[$imageIndex]->dir; $imageThumb = preg_replace('/(.*)\.(.*)/i', 'thumb_${1}.$2', $imageName); - $imageCaption = $recipe['Image'][$imageIndex]['name']; - $imageId = $recipe['Image'][$imageIndex]['id']; + $imageCaption = $recipe->attachments[$imageIndex]->name; + $imageId = $recipe->attachments[$imageIndex]->id; echo '
'; echo $this->Form->hidden('Image.' . $imageIndex . '.id'); echo $this->Form->hidden('Image.' . $imageIndex . '.sort_order'); diff --git a/src/Template/Recipes/remove_ingredient_mapping.ctp b/src/Template/Recipes/remove_ingredient_mapping.ctp index 21490bc..bf453b6 100644 --- a/src/Template/Recipes/remove_ingredient_mapping.ctp +++ b/src/Template/Recipes/remove_ingredient_mapping.ctp @@ -1 +1 @@ -Session->flash(); ?> \ No newline at end of file +Flash->render() ?> \ No newline at end of file diff --git a/src/Template/Recipes/remove_recipe_mapping.ctp b/src/Template/Recipes/remove_recipe_mapping.ctp index 21490bc..bf453b6 100644 --- a/src/Template/Recipes/remove_recipe_mapping.ctp +++ b/src/Template/Recipes/remove_recipe_mapping.ctp @@ -1 +1 @@ -Session->flash(); ?> \ No newline at end of file +Flash->render() ?> \ No newline at end of file diff --git a/src/Template/Recipes/view.ctp b/src/Template/Recipes/view.ctp index d72d5a2..fad2de0 100644 --- a/src/Template/Recipes/view.ctp +++ b/src/Template/Recipes/view.ctp @@ -153,7 +153,7 @@ if (isset($recipe->reviews)) {

image)? count($recipe->image) : 0; + $imageCount = (isset($recipe) && $recipe->attachments)? count($recipe->attachments) : 0; if ($imageCount > 0) { echo '
'; @@ -195,10 +195,10 @@ if (isset($recipe->reviews)) { 0) { - $imageName = $recipe['Image'][0]['attachment']; - $imageDir = $recipe['Image'][0]['dir']; + $imageName = $recipe->attachments[0]->attachment; + $imageDir = $recipe->attachments[0]->dir; $imagePreview = preg_replace('/(.*)\.(.*)/i', 'preview_${1}.$2', $imageName); - $imageCaption = $recipe['Image'][0]['name']; + $imageCaption = $recipe->attachments[0]->name; echo "
"; echo '