當前位置: 首頁>>代碼示例>>PHP>>正文


PHP FOFModel::onBeforeSave方法代碼示例

本文整理匯總了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;
 }
開發者ID:rdeutz,項目名稱:babioon-event,代碼行數:76,代碼來源:events.php


注:本文中的FOFModel::onBeforeSave方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。