本文整理匯總了PHP中FOFModel::onBeforeSave方法的典型用法代碼示例。如果您正苦於以下問題:PHP FOFModel::onBeforeSave方法的具體用法?PHP FOFModel::onBeforeSave怎麽用?PHP FOFModel::onBeforeSave使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類FOFModel
的用法示例。
在下文中一共展示了FOFModel::onBeforeSave方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: onBeforeSave
/**
* This method runs before the $data is saved to the $table. Return false to
* stop saving.
*
* @param array &$data The data to save
* @param FOFTable &$table The table to save the data to
*
* @return boolean Return false to prevent saving, true to allow it
*/
protected function onBeforeSave(&$data, &$table)
{
if (!parent::onBeforeSave($data, $table)) {
return false;
}
$isAdmin = FOFPlatform::getInstance()->isBackend();
if (!$isAdmin) {
$data['enabled'] = 0;
} else {
if ($this->getGeoCoordinates($data) === false) {
$this->setError(JText::_('COM_BABIOONEVENT_GET_GEOCOORDINATES_FAILED'));
return false;
}
$dtFields = array('s', 'e');
foreach ($dtFields as $dtf) {
// Preset default values
$data[$dtf . 'time'] = '00:00:00';
$data[$dtf . 'timeset'] = 0;
// Check time and date
$result = $this->checkDate($dtf . 'date');
if ($result !== false) {
$data[$dtf . 'date'] = $result;
$result = $this->checkTime($dtf . 'time');
if ($result !== false) {
$data[$dtf . 'time'] = $result;
$data[$dtf . 'timeset'] = 1;
}
}
}
}
if ($this->_isNewRecord) {
$data['created'] = JFactory::getDate()->toSql();
if ($isAdmin) {
$data['created_by'] = JFactory::getUser()->get('id');
$data['created_by_alias'] = JFactory::getUser()->get('name');
} else {
$data['created_by'] = 0;
$data['created_by_alias'] = 'WebsiteForm';
}
} else {
if ($isAdmin) {
$data['modified'] = JFactory::getDate()->toSql();
$data['modified_by'] = JFactory::getUser()->get('id');
} else {
// Confused
return false;
}
}
$params = JComponentHelper::getParams('com_babioonevent');
if ($params->get('showcategory', 1) == 0) {
$defaultcategory = $params->get('defaultcategory', 0);
if ($defaultcategory != 0) {
$data['catid'] = $defaultcategory;
}
}
// Make sure the dates have the correct format
foreach (array('sdate', 'edate') as $d) {
if (array_key_exists($d, $data) && $data[$d] != '') {
$data[$d] = $this->formatDate($data[$d]);
if ($data[$d] === false) {
$this->setError('Date format not valid: ' . $d);
return false;
}
}
}
return true;
}