本文整理汇总了PHP中SibdietHelper::convertFoods方法的典型用法代码示例。如果您正苦于以下问题:PHP SibdietHelper::convertFoods方法的具体用法?PHP SibdietHelper::convertFoods怎么用?PHP SibdietHelper::convertFoods使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SibdietHelper
的用法示例。
在下文中一共展示了SibdietHelper::convertFoods方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: batchCopy
/**
* Batch copy items to a new default.
*
* @param integer $value The new diet.
* @param array $pks An array of row IDs.
* @param array $contexts An array of item contexts.
*
* @return mixed An array of new IDs on success, boolean false on failure.
*/
protected function batchCopy($value, $pks, $contexts)
{
$defaultId = (int) $value;
$table = $this->getTable();
$i = 0;
// Check that the diet exists
if ($defaultId) {
$defaultTable = JTable::getInstance('default', 'SibdietTable');
if (!$defaultTable->load($defaultId)) {
if ($error = $defaultTable->getError()) {
// Fatal error
$this->setError($error);
return false;
} else {
$this->setError(JText::_('COM_SIBDIET_ERROR_BATCH_COPY_DEFAULT_NOT_FOUND'));
return false;
}
}
}
foreach ($pks as $pk) {
$defaultExistSQL = "SELECT id FROM #__sibdiet_defaults_weeklys WHERE defaults_id = " . $defaultId . " AND title = (SELECT title FROM #__sibdiet_defaults_weeklys WHERE id = " . $pk . ")";
$db = JFactory::getDBO();
$db->setQuery($defaultExistSQL);
$db->query();
if ($db->getNumRows()) {
unset($pks[array_search($pk, $pks, true)]);
}
}
if (empty($defaultId)) {
$this->setError(JText::_('COM_SIBDIET_ERROR_BATCH_COPY_DEFAULT_NOT_FOUND'));
return false;
}
// Check that the user has create permission for the component
$extension = JFactory::getApplication()->input->get('option', '');
$user = JFactory::getUser();
if (!$user->authorise('core.create', $extension)) {
$this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_CANNOT_CREATE'));
return false;
}
// Parent exists so we let's proceed
while (!empty($pks)) {
// Pop the first ID off the stack
$pk = array_shift($pks);
$table->reset();
// Check that the row actually exists
if (!$table->load($pk)) {
if ($error = $table->getError()) {
// Fatal error
$this->setError($error);
return false;
} else {
// Not fatal error
$this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_BATCH_MOVE_ROW_NOT_FOUND', $pk));
continue;
}
}
// Reset the ID because we are making a copy
$table->id = 0;
// New default ID
$table->defaults_id = $defaultId;
// Check the row.
if (!$table->check()) {
$this->setError($table->getError());
return false;
}
require_once JPATH_COMPONENT . '/helpers/sibdiet.php';
$table->foods = SibdietHelper::convertFoods($table->foods, $table->defaults_id);
// Store the row.
if (!$table->store()) {
$this->setError($table->getError());
return false;
}
// Get the new item ID
$newId = $table->get('id');
// Add the new ID to the array
$newIds[$i] = $newId;
$i++;
}
// Clean the cache
$this->cleanCache();
return $newIds;
}