示例#1
0
 public function save($data)
 {
     $table = JTable::getInstance('RSForm_Directory', 'Table');
     $input = JFactory::getApplication()->input;
     $db = JFactory::getDbo();
     if (isset($data['groups']) && is_array($data['groups'])) {
         $registry = new JRegistry();
         $registry->loadArray($data['groups']);
         $data['groups'] = $registry->toString();
     } else {
         $data['groups'] = '';
     }
     // Check if the entry exists
     $this->_db->setQuery('SELECT COUNT(' . $this->_db->qn('formId') . ') FROM ' . $this->_db->qn('#__rsform_directory') . ' WHERE ' . $this->_db->qn('formId') . ' = ' . (int) $data['formId'] . ' ');
     if (!$this->_db->loadResult()) {
         $this->_db->setQuery('INSERT INTO ' . $this->_db->qn('#__rsform_directory') . ' SET ' . $this->_db->qn('formId') . ' = ' . (int) $data['formId'] . ' ');
         $this->_db->execute();
     }
     // Bind the data.
     if (!$table->bind($data)) {
         $this->setError($table->getError());
         return false;
     }
     // Store the data.
     if (!$table->store()) {
         $this->setError($table->getError());
         return false;
     }
     // Store directory fields
     $fields = RSFormProHelper::getAllDirectoryFields($table->formId);
     $listingFields = $input->get('dirviewable', array(), 'array');
     $searchableFields = $input->get('dirsearchable', array(), 'array');
     $editableFields = $input->get('direditable', array(), 'array');
     $detailsFields = $input->get('dirindetails', array(), 'array');
     $csvFields = $input->get('dirincsv', array(), 'array');
     $cids = $input->get('dircid', array(), 'array');
     $orderingFields = $input->get('dirorder', array(), 'array');
     // empty
     $db->setQuery('DELETE FROM ' . $db->qn('#__rsform_directory_fields') . ' WHERE ' . $db->qn('formId') . ' = ' . (int) $table->formId . '');
     $db->execute();
     foreach ($fields as $field) {
         $viewable = (int) in_array($field->FieldId, $listingFields);
         $searchable = (int) in_array($field->FieldId, $searchableFields);
         $editable = (int) in_array($field->FieldId, $editableFields);
         $indetails = (int) in_array($field->FieldId, $detailsFields);
         $incsv = (int) in_array($field->FieldId, $csvFields);
         $ordering = $orderingFields[array_search($field->FieldId, $cids)];
         $values = array("`formId`='" . $table->formId . "'", "`componentId`='" . $field->FieldId . "'", "`viewable`='" . $viewable . "'", "`searchable`='" . $searchable . "'", "`editable`='" . $editable . "'", "`indetails`='" . $indetails . "'", "`incsv`='" . $incsv . "'", "`ordering`='" . $ordering . "'");
         $db->setQuery("INSERT INTO #__rsform_directory_fields SET " . implode(", ", $values));
         $db->execute();
     }
     return true;
 }