10 defined(
'JPATH_PLATFORM') or die;
30 protected $_forms = array();
41 public function checkin($pk = null)
49 $table = $this->getTable();
51 if (!$table->load($pk))
53 $this->setError($table->getError());
58 if ($table->checked_out > 0 && $table->checked_out != $user->get(
'id') && !$user->authorise(
'core.admin',
'com_checkin'))
60 $this->setError(
JText::_(
'JLIB_APPLICATION_ERROR_CHECKIN_USER_MISMATCH'));
65 if (!$table->checkin($pk))
67 $this->setError($table->getError());
84 public function checkout($pk = null)
90 $table = $this->getTable();
92 if (!$table->load($pk))
94 $this->setError($table->getError());
99 if (!property_exists($table,
'checked_out') || !property_exists($table,
'checked_out_time'))
107 if ($table->checked_out > 0 && $table->checked_out != $user->get(
'id'))
109 $this->setError(
JText::_(
'JLIB_APPLICATION_ERROR_CHECKOUT_USER_MISMATCH'));
114 if (!$table->checkout($user->get(
'id'), $pk))
116 $this->setError($table->getError());
134 abstract public function getForm($data = array(), $loadData =
true);
150 protected function loadForm($name, $source = null, $options = array(), $clear =
false, $xpath =
false)
156 $hash = md5($source . serialize($options));
159 if (isset($this->_forms[$hash]) && !$clear)
161 return $this->_forms[$hash];
174 if (isset($options[
'load_data']) && $options[
'load_data'])
177 $data = $this->loadFormData();
186 $this->preprocessForm($form, $data);
194 $this->setError($e->getMessage());
199 $this->_forms[$hash] = $form;
211 protected function loadFormData()
226 protected function preprocessData($context, &$data)
230 JPluginHelper::importPlugin(
'content');
233 $results = $dispatcher->trigger(
'onContentPrepareData', array($context, $data));
236 if (count($results) > 0 && in_array(
false, $results,
true))
238 $this->setError($dispatcher->getError());
255 protected function preprocessForm(
JForm $form, $data, $group =
'content')
258 JPluginHelper::importPlugin($group);
264 $results = $dispatcher->trigger(
'onContentPrepareForm', array($form, $data));
267 if (count($results) && in_array(
false, $results,
true))
270 $error = $dispatcher->getError();
272 if (!($error instanceof Exception))
274 throw new Exception($error);
292 public function validate($form, $data, $group = null)
295 $data = $form->filter($data);
296 $return = $form->validate($data, $group);
299 if ($return instanceof Exception)
301 $this->setError($return->getMessage());
306 if ($return ===
false)
309 foreach ($form->getErrors() as $message)
311 $this->setError($message);
318 if (isset($data[
'metadata'][
'tags']) && !isset($data[
'tags']))
320 $data[
'tags'] = $data[
'metadata'][
'tags'];