本文整理汇总了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;
}