Exemplo n.º 1
0
 /**
  * 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;
 }