Last active
March 8, 2021 12:14
-
-
Save mabdelaziz77/b7c5b68d607d805f1fbeb750b9e31f42 to your computer and use it in GitHub Desktop.
Recipe View and Edit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$this->_item[$pk]->ingredientsList = $this->getIngredientsList($this->_item[$pk]->ingredients); | |
$canDo = [[[Component]]]Helper::getActions('recipe',$this->_item[$pk],'recipes'); | |
if ($canDo->get('recipe.edit')) | |
{ | |
$this->_item[$pk]->editLink = JRoute::_('index.php?option=com_[[[component]]]&view=recipe&task=recipe.edit&id=' . $this->_item[$pk]->id); | |
} | |
else | |
{ | |
$this->_item[$pk]->editLink = null; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1><!-- Recipe Name --></h1> | |
<img src="" alt=""> | |
<p>Preparation time <strong> mins</strong></p> | |
<p>Category <strong></strong></p> | |
<h2>Ingredients</h2> | |
<ul> | |
<li></li> | |
</ul> | |
<h2>Description</h2> | |
<p><!-- description --></p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1><?php echo $this->item->name; ?></h1> | |
<?php if(isset($this->item->editLink)):?> | |
<a href="<?php echo $this->item->editLink; ?>" class="btn btn-outline-dark"><?php echo JText::_('Edit Recipe'); ?></a> | |
<?php endif; ?> | |
<br /> | |
<img src="<?php echo $this->item->image; ?>" alt="<?php echo $this->item->name; ?>"> | |
<p><?php echo JText::_('Preparation time'); ?> <strong> <?php echo $this->item->preparing_time; ?> mins</strong></p> | |
<p><?php echo JText::_('Category'); ?> <strong><?php echo $this->item->categories_title; ?></strong></p> | |
<h2><?php echo JText::_('Ingredients'); ?></h2> | |
<ul> | |
<?php | |
$unitArray = array( | |
0 => 'COM_RECIPEMANAGER_INGREDIENT_TEASPOON', | |
1 => 'COM_RECIPEMANAGER_INGREDIENT_DESSERTSPOON', | |
2 => 'COM_RECIPEMANAGER_INGREDIENT_TABLESPOON', | |
3 => 'COM_RECIPEMANAGER_INGREDIENT_FLUID_OUNCE', | |
4 => 'COM_RECIPEMANAGER_INGREDIENT_CUP', | |
5 => 'COM_RECIPEMANAGER_INGREDIENT_PINT', | |
6 => 'COM_RECIPEMANAGER_INGREDIENT_QUART', | |
7 => 'COM_RECIPEMANAGER_INGREDIENT_GALLON' | |
); | |
?> | |
<?php foreach($this->item->ingredients as $key=>$value): ?> | |
<?php | |
$name = $this->item->ingredientsList[$value['ingredient']]['name']; | |
$unit = JText::_($unitArray[$this->item->ingredientsList[$value['ingredient']]['unit']]); | |
$qty = $value['quantity']; | |
?> | |
<li><?php echo "$name: $qty $unit"; ?></li> | |
<?php endforeach; ?> | |
</ul> | |
<h2><?php echo JText::_('Description'); ?></h2> | |
<p><?php echo $this->item->description; ?></p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function getIngredientsList($ingredientsArray){ | |
// Let's construct the ingredients list | |
if([[[Component]]]Helper::checkArray($ingredientsArray)){ | |
$ingredientIDs = array(); | |
foreach($ingredientsArray as $key=>$value){ | |
$ingredientIDs[] = $value['ingredient']; | |
} | |
$db = JFactory::getDbo(); | |
$query = $db->getQuery(true); | |
$query->select($db->quoteName(array("id", "name", "unit")) ) | |
->from($db->quoteName("#__[[[component]]]_ingredient")) | |
->where("id IN (" . implode(",", $ingredientIDs) . ")"); | |
$db->setQuery($query); | |
$ingredientsList = $db->loadAssocList('id'); | |
return $ingredientsList; | |
} else { | |
// No ingredient IDs, then no list | |
return array(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment