/** * Save an item. * * @access public * @param array $data The post values. * * @return boolean True on success. */ public function save($data) { //Convert from a non-SQL formated date (created) $data['created'] = RtiprintHelperDates::getSqlDate($data['created'], array('Y-m-d'), true); //Convert from a non-SQL formated date (modified) $data['modified'] = RtiprintHelperDates::getSqlDate($data['modified'], array('Y-m-d'), true); //Some security checks $acl = RtiprintHelper::getActions(); //Secure the published tag if not allowed to change if (isset($data['published']) && !$acl->get('core.edit.state')) { unset($data['published']); } //Secure the author key if not allowed to change if (isset($data['created_by']) && !$acl->get('core.edit')) { unset($data['created_by']); } if (parent::save($data)) { return true; } return false; }
/** * Method to validate the form data. * This override handle the inputs of files types, (Joomla issue when they * are required) * * @access public * @param object $form The form to validate against. * @param array $data The data to validate. * @param string $group The name of the field group to validate. * * @return mixed Array of filtered data if valid, false otherwise. */ public function validate($form, $data, $group = null) { //Get the posted files if this model is concerned by files submission // JOOMLA FIX : if missing fields in $_POST -> issue in partial update when required $currentData = $this->getItem(); foreach ($currentData as $fieldName => $value) { $field = $form->getField($fieldName, $group, $value); //Skip the ID data (and other fields not in the form) if (!$field) { continue; } //Missing in $_POST and required if (!in_array($fieldName, array_keys($data)) && $field->required) { //Insert the current object value. (UPDATE) $data[$fieldName] = $currentData->{$fieldName}; } } //JOOMLA FIX : Reformate some field types not handled properly foreach ($form->getFieldset($group) as $field) { $value = null; if (isset($data[$field->fieldname])) { $value = $data[$field->fieldname]; } switch ($field->type) { //JOOMLA FIX : Reformate the date/time format comming from the post case 'ckcalendar': //cimport('helpers.dates'); if ($value && (string) $field->format && !RtiprintHelperDates::isNull((string) $value)) { $time = RtiprintHelperDates::getSqlDate($value, array($field->format)); if ($time === null) { JError::raiseWarning(1203, JText::sprintf('RTIPRINT_VALIDATOR_WRONG_DATETIME_FORMAT_FOR_PLEASE_RETRY', $field->label)); $valid = false; } else { $data[$field->fieldname] = RtiprintHelperDates::toSql($time); } } break; //JOOMLA FIX : Apply a null value if the field is in the form //JOOMLA FIX : Apply a null value if the field is in the form case 'ckcheckbox': if (!$value) { $data[$field->fieldname] = 0; } break; } } // JOOMLA FIX : always missing file names in $_POST -> issue when required //Get the posted files if this model is concerned by files submission if (count($this->fileFields)) { $fileInput = new JInput($_FILES); $files = $fileInput->get('jform', null, 'array'); if (count($files['name'])) { foreach ($files['name'] as $fieldName => $value) { //For required files, temporary insert the value comming from $_FILES if (!empty($value)) { $field = $form->getField($fieldName, $group); if ($field->required) { $data[$fieldName] = $value; } } } } } //Exec the native PHP validation (rules) $result = parent::validate($form, $data, $group); //check the result before to go further if ($result === false) { return false; } //ID key follower (in some case, ex : save2copy task) if (isset($data['id'])) { $result['id'] = $data['id']; } return $result; }