Esempio n. 1
0
 /**
  * Modify the query to filter list objects by n:n relation.
  *
  * @param F0FModel       $model The model on which operate.
  * @param JDatabaseQuery $query The query to alter.
  */
 public function onAfterBuildQuery(&$model, &$query)
 {
     $input = new F0FInput();
     $db = $model->getDbo();
     // Retrieve the relations configuration for this table
     $table = $model->getTable();
     $key = $table->getConfigProviderKey() . '.relations';
     $relations = $table->getConfigProvider()->get($key, array());
     // For each multiple type relation add the filter query
     foreach ($relations as $relation) {
         if ($relation['type'] == 'multiple') {
             // Get complete relation fields
             $relation = array_merge(array('itemName' => $relation['itemName']), $table->getRelations()->getRelation($relation['itemName'], $relation['type']));
             // Model only save $table->getKnownFields as state, so we look into the input
             $filter_name = $relation['itemName'];
             $model_filter_value = $input->getInt($filter_name);
             // Build the conditions based on relation configuration
             if (!empty($model_filter_value)) {
                 $query->innerJoin(sprintf('%1$s ON %1$s.%2$s = %3$s.%4$s', $db->qn($relation['pivotTable']), $db->qn($relation['ourPivotKey']), $db->qn($table->getTableName()), $db->qn($relation['localKey'])));
                 $query->where(sprintf('%s.%s = %s', $db->qn($relation['pivotTable']), $db->qn($relation['theirPivotKey']), $model_filter_value));
             }
         }
     }
 }
Esempio n. 2
0
 /**
  * Renders a F0FForm for an Edit view and returns the corresponding HTML
  *
  * @param   F0FForm   &$form  The form to render
  * @param   F0FModel  $model  The model providing our data
  * @param   F0FInput  $input  The input object
  *
  * @return  string    The HTML rendering of the form
  */
 protected function renderFormEdit(F0FForm &$form, F0FModel $model, F0FInput $input)
 {
     // Get the key for this model's table
     $key = $model->getTable()->getKeyName();
     $keyValue = $model->getId();
     JHTML::_('behavior.tooltip');
     $html = '';
     $validate = strtolower($form->getAttribute('validate'));
     $class = '';
     if (in_array($validate, array('true', 'yes', '1', 'on'))) {
         JHtml::_('behavior.formvalidation');
         $class = 'form-validate ';
         $this->loadValidationScript($form);
     }
     // Check form enctype. Use enctype="multipart/form-data" to upload binary files in your form.
     $template_form_enctype = $form->getAttribute('enctype');
     if (!empty($template_form_enctype)) {
         $enctype = ' enctype="' . $form->getAttribute('enctype') . '" ';
     } else {
         $enctype = '';
     }
     // Check form name. Use name="yourformname" to modify the name of your form.
     $formname = $form->getAttribute('name');
     if (empty($formname)) {
         $formname = 'adminForm';
     }
     // Check form ID. Use id="yourformname" to modify the id of your form.
     $formid = $form->getAttribute('name');
     if (empty($formid)) {
         $formid = 'adminForm';
     }
     // Check if we have a custom task
     $customTask = $form->getAttribute('customTask');
     if (empty($customTask)) {
         $customTask = '';
     }
     // Get the form action URL
     $actionUrl = F0FPlatform::getInstance()->isBackend() ? 'index.php' : JUri::root() . 'index.php';
     if (F0FPlatform::getInstance()->isFrontend() && $input->getCmd('Itemid', 0) != 0) {
         $itemid = $input->getCmd('Itemid', 0);
         $uri = new JUri($actionUrl);
         if ($itemid) {
             $uri->setVar('Itemid', $itemid);
         }
         $actionUrl = JRoute::_($uri->toString());
     }
     $html .= '<form action="' . $actionUrl . '" method="post" name="' . $formname . '" id="' . $formid . '"' . $enctype . ' class="' . $class . '">' . PHP_EOL;
     $html .= "\t" . '<input type="hidden" name="option" value="' . $input->getCmd('option') . '" />' . PHP_EOL;
     $html .= "\t" . '<input type="hidden" name="view" value="' . $input->getCmd('view', 'edit') . '" />' . PHP_EOL;
     $html .= "\t" . '<input type="hidden" name="task" value="' . $customTask . '" />' . PHP_EOL;
     $html .= "\t" . '<input type="hidden" name="' . $key . '" value="' . $keyValue . '" />' . PHP_EOL;
     $html .= "\t" . '<input type="hidden" name="' . JFactory::getSession()->getFormToken() . '" value="1" />' . PHP_EOL;
     $html .= $this->renderFormRaw($form, $model, $input, 'edit');
     $html .= '</form>';
     return $html;
 }
Esempio n. 3
0
 /**
  * Renders a F0FForm for an Edit view and returns the corresponding HTML
  *
  * @param   F0FForm   &$form  The form to render
  * @param   F0FModel  $model  The model providing our data
  * @param   F0FInput  $input  The input object
  *
  * @return  string    The HTML rendering of the form
  */
 protected function renderFormEdit(F0FForm &$form, F0FModel $model, F0FInput $input)
 {
     // Get the key for this model's table
     $key = $model->getTable()->getKeyName();
     $keyValue = $model->getId();
     $html = '';
     $validate = strtolower($form->getAttribute('validate'));
     if (in_array($validate, array('true', 'yes', '1', 'on'))) {
         JHTML::_('behavior.framework', true);
         JHTML::_('behavior.formvalidation');
         $class = ' form-validate';
         $this->loadValidationScript($form);
     } else {
         $class = '';
     }
     // Check form enctype. Use enctype="multipart/form-data" to upload binary files in your form.
     $template_form_enctype = $form->getAttribute('enctype');
     if (!empty($template_form_enctype)) {
         $enctype = ' enctype="' . $form->getAttribute('enctype') . '" ';
     } else {
         $enctype = '';
     }
     // Check form name. Use name="yourformname" to modify the name of your form.
     $formname = $form->getAttribute('name');
     if (empty($formname)) {
         $formname = 'adminForm';
     }
     // Check form ID. Use id="yourformname" to modify the id of your form.
     $formid = $form->getAttribute('name');
     if (empty($formid)) {
         $formid = 'adminForm';
     }
     $html .= '<form action="index.php" method="post" name="' . $formname . '" id="' . $formid . '"' . $enctype . ' class="form-horizontal' . $class . '">' . PHP_EOL;
     $html .= "\t" . '<input type="hidden" name="option" value="' . $input->getCmd('option') . '" />' . PHP_EOL;
     $html .= "\t" . '<input type="hidden" name="view" value="' . $input->getCmd('view', 'edit') . '" />' . PHP_EOL;
     $html .= "\t" . '<input type="hidden" name="task" value="" />' . PHP_EOL;
     $html .= "\t" . '<input type="hidden" name="' . $key . '" value="' . $keyValue . '" />' . PHP_EOL;
     if (F0FPlatform::getInstance()->isFrontend() && $input->getCmd('Itemid', 0) != 0) {
         $html .= "\t" . '<input type="hidden" name="Itemid" value="' . $input->getCmd('Itemid', 0) . '" />' . PHP_EOL;
     }
     $html .= "\t" . '<input type="hidden" name="' . JFactory::getSession()->getFormToken() . '" value="1" />' . PHP_EOL;
     $html .= $this->renderFormRaw($form, $model, $input, 'edit');
     $html .= '</form>';
     return $html;
 }