示例#1
0
 /**
  * Save the form
  *
  * @param   array $data the jForm part of the request data
  *
  * @return  bool
  */
 public function save($data)
 {
     $this->populateState();
     $input = $this->app->input;
     $jForm = $input->get('jform', array(), 'array');
     $date = JFactory::getDate();
     $row = $this->getTable();
     $id = FArrayHelper::getValue($data, 'id');
     $row->load($id);
     $params = new Registry($row->get('params'));
     $isView = $this->setIsView($params);
     $data['params']['isView'] = (string) $isView;
     $this->setState('list.id', $id);
     $this->setState('list.form_id', $row->get('form_id'));
     $feModel = $this->getFEModel();
     /** @var $contentTypeModel FabrikAdminModelContentTypeImport */
     $contentTypeModel = JModelLegacy::getInstance('ContentTypeImport', 'FabrikAdminModel', array('listModel' => $this));
     $contentType = ArrayHelper::getValue($jForm, 'contenttype', '');
     if ($contentType !== '') {
         $contentTypeModel->check($contentType);
     }
     // Get original collation
     $db = $feModel->getDb();
     $origCollation = $this->getOriginalCollation($params, $db, FArrayHelper::getValue($data, 'db_table_name', ''));
     $row->bind($data);
     $row->set('order_by', json_encode($input->get('order_by', array(), 'array')));
     $row->set('order_dir', json_encode($input->get('order_dir', array(), 'array')));
     $row->check();
     $isNew = true;
     if ($row->id != 0) {
         $this->collation($feModel, $origCollation, $row);
         $dateNow = JFactory::getDate();
         $row->set('modified', $dateNow->toSql());
         $row->set('modified_by', $this->user->get('id'));
     }
     if ($id == 0) {
         if ($row->get('created', '') == '') {
             $row->set('created', $date->toSql());
         }
         $isNew = false;
         $existingTable = ArrayHelper::getValue($data, 'db_table_name', '');
         $newTable = $existingTable === '' ? trim(FArrayHelper::getValue($data, '_database_name')) : '';
         // Mysql will force db table names to lower case even if you set the db name to upper case - so use clean()
         $newTable = FabrikString::clean($newTable);
         // Check the entered database table doesn't already exist
         if ($newTable != '' && $this->databaseTableExists($newTable)) {
             throw new RuntimeException(FText::_('COM_FABRIK_DATABASE_TABLE_ALREADY_EXISTS'));
         }
         if (!$this->canCreateDbTable()) {
             throw new RuntimeException(FText::_('COM_FABRIK_INSUFFICIENT_RIGHTS_TO_CREATE_TABLE'));
         }
         // Save the row now
         $row->store();
         // Create fabrik form
         $this->createLinkedForm();
         $row->set('form_id', $this->getState('list.form_id'));
         $groupData = FabrikWorker::formDefaults('group');
         $groupData['name'] = $row->label;
         $groupData['label'] = $row->label;
         if ($newTable == '') {
             // Create fabrik group
             $input->set('_createGroup', 1);
             $groupId = $this->createLinkedGroup($groupData, false);
             // New fabrik list but existing db table
             $this->createLinkedElements($groupId);
         } else {
             $row->set('db_table_name', $newTable);
             $row->set('auto_inc', 1);
             $dbOpts = array();
             $params = new Registry($row->get('params'));
             $dbOpts['COLLATE'] = $params->get('collation', '');
             $fields = $contentTypeModel->import($contentType, $row->get('db_table_name'), $groupData);
             $res = $this->createDBTable($newTable, $fields, $dbOpts);
             if (is_array($res)) {
                 $row->set('db_primary_key', $newTable . '.' . $res[0]);
             }
         }
     }
     $row->set('publish_down', FabrikAdminHelper::prepareSaveDate($row->get('publish_down')));
     $row->set('created', FabrikAdminHelper::prepareSaveDate($row->get('created')));
     $row->set('publish_up', FabrikAdminHelper::prepareSaveDate($row->get('publish_up')));
     $pk = FArrayHelper::getValue($data, 'db_primary_key');
     if ($pk == '') {
         $pk = $feModel->getPrimaryKeyAndExtra($row->get('db_table_name'));
         $key = $pk[0]['colname'];
         $extra = $pk[0]['extra'];
         // Store without qns as that's db specific
         $row->set('db_primary_key', $row->get('db_primary_key', '') == '' ? $row->get('db_table_name') . '.' . $key : $row->get('db_primary_key'));
         $row->set('auto_inc', JString::stristr($extra, 'auto_increment') ? true : false);
     }
     $row->store();
     $this->updateJoins($data);
     // Needed to ensure pk field is not quoted
     $feModel->setTable($row);
     if (!$feModel->isView()) {
         $this->updatePrimaryKey($row->get('db_primary_key'), $row->get('auto_inc'));
     }
     // Make an array of elements and a presumed index size, map is then used in creating indexes
     $this->createIndexes($params, $row);
     $pkName = $row->getKeyName();
     if (isset($row->{$pkName})) {
         $this->setState($this->getName() . '.id', $row->get($pkName));
     }
     /**
      * $$$ hugh - I don't know what this state gets used for, but $iNew is
      * currently ending up the wrong way round.  New tables it's false,
      * existing tables it's true.
      */
     $this->setState($this->getName() . '.new', $isNew);
     parent::cleanCache('com_fabrik');
     if ($id == 0) {
         $contentTypeModel->finalise($row);
     }
     return true;
 }
示例#2
0
文件: element.php 项目: LGBGit/tierno
 /**
  * Method to save the form data.
  *
  * @param   array $data The form data.
  *
  * @return  boolean  True on success, False on error.
  */
 public function save($data)
 {
     $config = JComponentHelper::getParams('com_fabrik');
     if ($config->get('fbConf_wysiwyg_label', 0) == 0) {
         // Ensure the data is in the same format as when saved by the wysiwyg element e.g. < becomes &lt;
         $data['label'] = htmlspecialchars($data['label']);
     }
     jimport('joomla.utilities.date');
     $input = $this->app->input;
     $new = $data['id'] == 0 ? true : false;
     $params = $data['params'];
     $data['name'] = FabrikString::iclean($data['name']);
     $name = $data['name'];
     $params['validations'] = FArrayHelper::getValue($data, 'validationrule', array());
     $elementModel = $this->getElementPluginModel($data);
     $elementModel->getElement()->bind($data);
     $origId = $input->getInt('id');
     $row = $elementModel->getElement();
     if ($new) {
         // Have to forcefully set group id otherwise listmodel id is blank
         $elementModel->getElement()->group_id = $data['group_id'];
     }
     $listModel = $elementModel->getListModel();
     $item = $listModel->getTable();
     // Are we updating the name of the primary key element?
     if ($row->name === FabrikString::shortColName($item->db_primary_key)) {
         if ($name !== $row->name) {
             // Yes we are so update the table
             $item->db_primary_key = str_replace($row->name, $name, $item->db_primary_key);
             $item->store();
         }
     }
     $jsons = array('sub_values', 'sub_labels', 'sub_initial_selection');
     foreach ($jsons as $json) {
         if (array_key_exists($json, $data)) {
             $data[$json] = json_encode($data[$json]);
         }
     }
     // Only update the element name if we can alter existing columns, otherwise the name and field name become out of sync
     $data['name'] = $listModel->canAlterFields() || $new || $listModel->noTable() ? $name : $input->get('name_orig', '');
     $ar = array('published', 'use_in_page_title', 'show_in_list_summary', 'link_to_detail', 'can_order', 'filter_exact_match');
     foreach ($ar as $a) {
         if (!array_key_exists($a, $data)) {
             $data[$a] = 0;
         }
     }
     /**
      * $$$ rob - test for change in element type
      * (eg if changing from db join to field we need to remove the join
      * entry from the #__{package}_joins table
      */
     $elementModel->beforeSave($row);
     // Unlink linked elements
     if ($input->get('unlink') == 'on') {
         $data['parent_id'] = 0;
     }
     $dateNow = new JDate();
     if ($row->id != 0) {
         $data['modified'] = $dateNow->toSql();
         $data['modified_by'] = $this->user->get('id');
     } else {
         $data['created'] = $dateNow->toSql();
         $data['created_by'] = $this->user->get('id');
         $data['created_by_alias'] = $this->user->get('username');
     }
     /**
      * $$$ hugh
      * This insane chunk of code is needed because the validation rule params are not in sequential,
      * completely indexed arrays.  What we have is single item arrays, with specific numeric
      * keys, like foo-something[0], bar-otherthing[2], etc.  And if you json_encode an array with incomplete
      * or out of sequence numeric indexes, it encodes it as an object instead of an array.  Which means the first
      * validation plugin will encode as an array, as it's params are single [0] index, and the rest as objects.
      * This foobars things, as we then don't know if validation params are arrays or objects!
      *
      * One option would be to modify every validation, and test every param we use, and if necessary convert it,
      * but that would be a major pain in the ass.
      *
      * So ... we need to fill in the blanks in the arrays, and ksort them.  But, we need to know the param names
      * for each validation.  But as they are just stuck in with the rest of the element params, there is no easy
      * way of knowing which are validation params and which are element params.
      *
      * So ... we need to load the validation objects, then load the XML file for each one, and iterate through
      * the fieldsets!  Well, that's the only way I could come up with doing it.  Hopefully Rob can come up with
      * a quicker and simpler way of doing this!
      */
     $validations = FArrayHelper::getValue($params['validations'], 'plugin', array());
     $num_validations = count($validations);
     $validation_plugins = $this->getValidations($elementModel, $validations);
     foreach ($validation_plugins as $plugin) {
         $plugin_form = $plugin->getJForm();
         JForm::addFormPath(JPATH_SITE . '/plugins/fabrik_validationrule/' . $plugin->get('pluginName'));
         $xmlFile = JPATH_SITE . '/plugins/fabrik_validationrule/' . $plugin->get('pluginName') . '/forms/fields.xml';
         $xml = $plugin->jform->loadFile($xmlFile, false);
         foreach ($plugin_form->getFieldsets() as $fieldset) {
             foreach ($plugin_form->getFieldset($fieldset->name) as $field) {
                 if (isset($params[$field->fieldname])) {
                     if (is_array($params[$field->fieldname])) {
                         for ($x = 0; $x < $num_validations; $x++) {
                             if (!array_key_exists($x, $params[$field->fieldname])) {
                                 $params[$field->fieldname][$x] = '';
                             }
                         }
                         ksort($params[$field->fieldname]);
                     }
                 }
             }
         }
     }
     $data['params'] = json_encode($params);
     $row->params = $data['params'];
     $cond = 'group_id = ' . (int) $row->group_id;
     if ($new) {
         $data['ordering'] = $row->getNextOrder($cond);
     }
     $row->reorder($cond);
     /**
      * $$$ hugh - shouldn't updateChildIds() happen AFTER we save the main row?
      * Same place we do updateJavascript()?
      */
     $this->updateChildIds($row);
     $elementModel->getElement()->bind($data);
     $origName = $input->get('name_orig', '');
     list($update, $q, $oldName, $newdesc, $origDesc) = $listModel->shouldUpdateElement($elementModel, $origName);
     if ($update && $input->get('task') !== 'save2copy') {
         $origPlugin = $input->get('plugin_orig');
         $prefix = $this->config->get('dbprefix');
         $tableName = $listModel->getTable()->db_table_name;
         $hasPrefix = strstr($tableName, $prefix) === false ? false : true;
         $tableName = str_replace($prefix, '#__', $tableName);
         if (in_array($tableName, $this->core)) {
             $this->app->enqueueMessage(FText::_('COM_FABRIK_WARNING_UPDATE_CORE_TABLE'), 'notice');
         } else {
             if ($hasPrefix) {
                 $this->app->enqueueMessage(FText::_('COM_FABRIK_WARNING_UPDATE_TABLE_WITH_PREFIX'), 'notice');
             }
         }
         $this->app->setUserState('com_fabrik.confirmUpdate', 1);
         $this->app->setUserState('com_fabrik.plugin_orig', $origPlugin);
         $this->app->setUserState('com_fabrik.q', $q);
         $this->app->setUserState('com_fabrik.newdesc', $newdesc);
         $this->app->setUserState('com_fabrik.origDesc', $origDesc);
         $this->app->setUserState('com_fabrik.origplugin', $origPlugin);
         $this->app->setUserState('com_fabrik.oldname', $oldName);
         $this->app->setUserState('com_fabrik.newname', $data['name']);
         $this->app->setUserState('com_fabrik.origtask', $input->get('task'));
         $this->app->setUserState('com_fabrik.plugin', $data['plugin']);
         $task = $input->get('task');
         $url = 'index.php?option=com_fabrik&view=element&layout=confirmupdate&id=' . (int) $origId . '&origplugin=' . $origPlugin . '&origtask=' . $task . '&plugin=' . $row->plugin;
         $this->app->setUserState('com_fabrik.redirect', $url);
     } else {
         $this->app->setUserState('com_fabrik.confirmUpdate', 0);
     }
     if ((int) $listModel->getTable()->id !== 0) {
         $this->updateIndexes($elementModel, $listModel, $row);
     }
     $return = parent::save($data);
     if ($return) {
         $this->updateJavascript($data);
         $elementModel->setId($this->getState($this->getName() . '.id'));
         $row->id = $elementModel->getId();
         $data['id'] = $row->id;
         $this->createRepeatElement($elementModel, $row);
         // If new, check if the element's db table is used by other tables and if so add the element  to each of those tables' groups
         if ($new) {
             $this->addElementToOtherDbTables($elementModel, $row);
         }
         if (!$elementModel->onSave($data)) {
             $this->setError(FText::_('COM_FABRIK_ERROR_SAVING_ELEMENT_PLUGIN_OPTIONS'));
             return false;
         }
     }
     parent::cleanCache('com_fabrik');
     return $return;
     /**
      * used for prefab
      * return $elementModel;
      */
 }
示例#3
0
 /**
  * Save the form
  *
  * @param   array $data posted jForm data
  *
  * @return  bool
  */
 public function save($data)
 {
     $input = $this->app->input;
     $jForm = $input->get('jform', array(), 'array');
     $data['params']['plugins'] = (array) FArrayHelper::getValue($jForm, 'plugin');
     $data['params']['plugin_locations'] = (array) FArrayHelper::getValue($jForm, 'plugin_locations');
     $data['params']['plugin_events'] = (array) FArrayHelper::getValue($jForm, 'plugin_events');
     $data['params']['plugin_description'] = (array) FArrayHelper::getValue($jForm, 'plugin_description');
     /**
      * Move back into the main data array some values we are rendering as
      * params (did that for ease of rendering admin output)
      */
     $opts = array('reset_button_label', 'submit_button_label');
     foreach ($opts as $opt) {
         $data[$opt] = $data['params'][$opt];
     }
     $tmpName = FArrayHelper::getValue($data, 'db_table_name');
     unset($data['db_table_name']);
     $return = parent::save($data);
     if ($return) {
         $data['db_table_name'] = $tmpName;
         $this->saveFormGroups($data);
     }
     parent::cleanCache('com_fabrik');
     return $return;
 }
示例#4
0
 /**
  * Save the form
  *
  * @param   array  $data  the jform part of the request data
  *
  * @return  bool
  */
 public function save($data)
 {
     $this->populateState();
     $app = JFactory::getApplication();
     $input = $app->input;
     $user = JFactory::getUser();
     $config = JFactory::getConfig();
     $date = JFactory::getDate();
     $row = $this->getTable();
     $id = JArrayHelper::getValue($data, 'id');
     $row->load($id);
     $params = new JRegistry($row->params);
     $this->setState('list.id', $id);
     $this->setState('list.form_id', $row->form_id);
     $feModel = $this->getFEModel();
     $formModel = $this->getFormModel();
     // Get original collation
     $db = $feModel->getDb();
     if (!empty($data['db_table_name'])) {
         $db->setQuery('SHOW TABLE STATUS LIKE ' . $db->quote($data['db_table_name']));
         $info = $db->loadObject();
         $origCollation = is_object($info) ? $info->Collation : $params->get('collation', 'none');
     } else {
         $origCollation = $params->get('collation', 'none');
     }
     $row->bind($data);
     $row->order_by = json_encode($input->get('order_by', array(), 'array'));
     $row->order_dir = json_encode($input->get('order_dir', array(), 'array'));
     $row->check();
     $this->collation($feModel, $origCollation, $row);
     $isNew = true;
     if ($row->id != 0) {
         $datenow = JFactory::getDate();
         $row->modified = $datenow->toSql();
         $row->modified_by = $user->get('id');
     }
     if ($id == 0) {
         if ($row->created == '') {
             $row->created = $date->toSql();
         }
         // Save the row now
         $row->store();
         $isNew = false;
         $newtable = trim(JArrayHelper::getValue($data, '_database_name'));
         // Mysql will force db table names to lower case even if you set the db name to upper case - so use clean()
         $newtable = FabrikString::clean($newtable);
         // Check the entered database table doesnt already exist
         if ($newtable != '' && $this->databaseTableExists($newtable)) {
             throw new RuntimeException(JText::_('COM_FABRIK_DATABASE_TABLE_ALREADY_EXISTS'));
             return false;
         }
         if (!$this->canCreateDbTable()) {
             throw new RuntimeException(Jtext::_('COM_FABRIK_INSUFFICIENT_RIGHTS_TO_CREATE_TABLE'));
             return false;
         }
         // Create fabrik form
         $formModel = $this->createLinkedForm();
         $row->form_id = $this->getState('list.form_id');
         // Create fabrik group
         $groupData = FabrikWorker::formDefaults('group');
         $groupData['name'] = $row->label;
         $groupData['label'] = $row->label;
         $input->set('_createGroup', 1, 'post');
         $groupId = $this->createLinkedGroup($groupData, false);
         if ($newtable == '') {
             // New fabrik list but existing db table
             $this->createLinkedElements($groupId);
         } else {
             $row->db_table_name = $newtable;
             $row->auto_inc = 1;
             $dbOpts = array();
             $params = new JRegistry($row->params);
             $dbOpts['COLLATE'] = $params->get('collation', '');
             $res = $this->createDBTable($newtable, $input->get('defaultfields', array('id' => 'internalid', 'date_time' => 'date'), 'array'), $dbOpts);
             if (is_array($res)) {
                 $row->db_primary_key = $newtable . '.' . $res[0];
             }
         }
     }
     $params = new JRegistry($row->params);
     $params->set('isview', $feModel->isView());
     $row->params = (string) $params;
     FabrikAdminHelper::prepareSaveDate($row->publish_down);
     FabrikAdminHelper::prepareSaveDate($row->created);
     FabrikAdminHelper::prepareSaveDate($row->publish_up);
     $pk = JArrayHelper::getValue($data, 'db_primary_key');
     if ($pk == '') {
         $pk = $feModel->getPrimaryKeyAndExtra($row->db_table_name);
         $key = $pk[0]['colname'];
         $extra = $pk[0]['extra'];
         // Store without quoteNames as thats db specific
         $row->db_primary_key = $row->db_primary_key == '' ? $row->db_table_name . "." . $key : $row->db_primary_key;
         $row->auto_inc = JString::stristr($extra, 'auto_increment') ? true : false;
     }
     $row->store();
     $pk = $row->db_primary_key;
     $this->updateJoins($data);
     // Needed to ensure pk field is not quoted
     $feModel->setTable($row);
     if (!$feModel->isView()) {
         $this->updatePrimaryKey($row->db_primary_key, $row->auto_inc);
     }
     // Make an array of elments and a presumed index size, map is then used in creating indexes
     $map = array();
     $groups = $this->getFormModel()->getGroupsHiarachy();
     foreach ($groups as $groupModel) {
         $elementModels = $groupModel->getMyElements();
         foreach ($elementModels as $element) {
             // Int and DATETIME elements cant have a index size attrib
             $coltype = $element->getFieldDescription();
             if (JString::stristr($coltype, 'int')) {
                 $size = '';
             } elseif (JString::stristr($coltype, 'datetime')) {
                 $size = '';
             } else {
                 $size = '10';
             }
             $map[$element->getFullName(false, false)] = $size;
             $map[$element->getElement()->id] = $size;
         }
     }
     // Update indexes (added array_key_exists check as these may be during after CSV import)
     if (!empty($aOrderBy) && array_key_exists($row->order_by, $map)) {
         foreach ($aOrderBy as $orderBy) {
             if (array_key_exists($orderBy, $map)) {
                 $feModel->addIndex($orderBy, 'tableorder', 'INDEX', $map[$orderBy]);
             }
         }
     }
     if ($row->group_by !== '' && array_key_exists($row->group_by, $map)) {
         $feModel->addIndex($row->group_by, 'groupby', 'INDEX', $map["{$row->group_by}"]);
     }
     if (trim($params->get('group_by_order')) !== '') {
         $feModel->addIndex($params->get('group_by_order'), 'groupbyorder', 'INDEX', $map[$params->get('group_by_order')]);
     }
     $afilterFields = (array) $params->get('filter-fields', array());
     foreach ($afilterFields as $field) {
         if (array_key_exists($field, $map)) {
             $feModel->addIndex($field, 'prefilter', 'INDEX', $map[$field]);
         }
     }
     $pkName = $row->getKeyName();
     if (isset($row->{$pkName})) {
         $this->setState($this->getName() . '.id', $row->{$pkName});
     }
     /**
      * $$$ hugh - I don't know what this state gets used for, but $iNew is
      * currently ending up the wrong way round.  New tables it's false,
      * existing tables it's true.
      */
     $this->setState($this->getName() . '.new', $isNew);
     parent::cleanCache('com_fabrik');
     return true;
 }
示例#5
0
 /**
  * Method to save the form data.
  *
  * @param   array  $data  The form data.
  *
  * @return  boolean  True on success, False on error.
  */
 public function save($data)
 {
     if ($data['id'] == 0) {
         $user = JFactory::getUser();
         $data['created_by'] = $user->get('id');
         $data['created_by_alias'] = $user->get('username');
         $data['created'] = JFactory::getDate()->toSql();
     }
     $makeJoin = false;
     $unMakeJoin = false;
     if ($this->checkRepeatAndPK($data)) {
         $makeJoin = $data['params']['repeat_group_button'] == 1;
         if ($makeJoin) {
             $data['is_join'] = 1;
         } else {
             if ($data['is_join'] == 1) {
                 $unMakeJoin = true;
                 $data['is_join'] = 0;
             }
         }
     } else {
         if ($data['params']['repeat_group_button'] == 1) {
             $data['params']['repeat_group_button'] = 0;
             JError::raiseNotice(500, 'You can not set the group containing the list primary key to be repeatable');
         }
     }
     $data['params'] = json_encode($data['params']);
     $return = parent::save($data);
     $data['id'] = $this->getState($this->getName() . '.id');
     if ($return) {
         $this->makeFormGroup($data);
         if ($makeJoin) {
             /**
              * $$$ rob added this check as otherwise toggling group from repeat
              * to norepeat back to repeat incorrectly created a 2nd join
              */
             if (!$this->joinedGroupExists($data['id'])) {
                 $return = $this->makeJoinedGroup($data);
             }
             // Update for the is_join change
             if ($return) {
                 $return = parent::save($data);
             }
         } else {
             // $data['is_join'] =  0; // NO! none repeat joined groups were getting unset here - not right!
             if ($unMakeJoin) {
                 $this->unMakeJoinedGroup($data);
             }
             $return = parent::save($data);
         }
     }
     parent::cleanCache('com_fabrik');
     return $return;
 }
示例#6
0
文件: group.php 项目: LGBGit/tierno
 /**
  * Method to save the form data.
  *
  * @param   array $data The form data.
  *
  * @return  boolean  True on success, False on error.
  */
 public function save($data)
 {
     if ($data['id'] == 0) {
         $data['created_by'] = $this->user->get('id');
         $data['created_by_alias'] = $this->user->get('username');
         $data['created'] = JFactory::getDate()->toSql();
     }
     $makeJoin = false;
     $unMakeJoin = false;
     if ($this->checkRepeatAndPK($data)) {
         $makeJoin = $data['params']['repeat_group_button'] == 1;
         if ($makeJoin) {
             $data['is_join'] = 1;
         } elseif ($data['is_join'] == 1) {
             /*
              * $$$ rob - this was destroying legitimate joins on saving the group
              * see http://fabrikar.com/forums/showthread.php?t=29385
              * commenting out for now until Hugh can take another look at what ever he was trying to solve
              * in commit #ee697dd
              *
             $unMakeJoin = true;
             $data['is_join'] = 0;
             */
         }
     } else {
         if ($data['params']['repeat_group_button'] == 1) {
             $data['params']['repeat_group_button'] = 0;
             $this->app->enqueueMessage('You can not set the group containing the list primary key to be repeatable', 'notice');
         }
     }
     $data['params'] = json_encode($data['params']);
     $return = parent::save($data);
     $data['id'] = $this->getState($this->getName() . '.id');
     if ($return) {
         $this->makeFormGroup($data);
         if ($makeJoin) {
             /**
              * $$$ rob added this check as otherwise toggling group from repeat
              * to norepeat back to repeat incorrectly created a 2nd join
              */
             if (!$this->joinedGroupExists($data['id'])) {
                 $return = $this->makeJoinedGroup($data);
             } else {
                 $this->checkFKIndex($data);
             }
             // Update for the is_join change
             if ($return) {
                 $return = parent::save($data);
             }
         } else {
             // $data['is_join'] =  0; // NO! none repeat joined groups were getting unset here - not right!
             if ($unMakeJoin) {
                 $this->unMakeJoinedGroup($data);
             }
             $return = parent::save($data);
         }
     }
     parent::cleanCache('com_fabrik');
     return $return;
 }
示例#7
0
文件: list.php 项目: rogeriocc/fabrik
 /**
  * Save the form
  *
  * @param   array  $data  the jform part of the request data
  *
  * @return  bool
  */
 public function save($data)
 {
     $this->populateState();
     $app = JFactory::getApplication();
     $user = JFactory::getUser();
     $config = JFactory::getConfig();
     $date = JFactory::getDate();
     $row = $this->getTable();
     $id = $data['id'];
     $row->load($id);
     $this->setState('list.id', $id);
     $this->setState('list.form_id', $row->form_id);
     $feModel = $this->getFEModel();
     $formModel = $this->getFormModel();
     if (!$row->bind($data)) {
         $this->setError($row->getError());
         return false;
     }
     $filter = new JFilterInput(null, null, 1, 1);
     $introduction = JArrayHelper::getValue(JRequest::getVar('jform', array(), 'post', 'array', JREQUEST_ALLOWRAW), 'introduction');
     $row->introduction = $filter->clean($introduction);
     $row->order_by = json_encode(JRequest::getVar('order_by', array(), 'post', 'array'));
     $row->order_dir = json_encode(JRequest::getVar('order_dir', array(), 'post', 'array'));
     if (!$row->check()) {
         $this->setError($row->getError());
         return false;
     }
     $isNew = true;
     if ($id == 0) {
         if ($row->created == '') {
             $row->created = $date->toSql();
         }
         // Save the row now
         $row->store();
         $isNew = false;
         $newtable = trim(JArrayHelper::getValue($data, '_database_name'));
         // Mysql will force db table names to lower case even if you set the db name to upper case - so use clean()
         $newtable = FabrikString::clean($newtable);
         // Check the entered database table doesnt already exist
         if ($newtable != '' && $this->databaseTableExists($newtable)) {
             $this->setError(JText::_('COM_FABRIK_DATABASE_TABLE_ALREADY_EXISTS'));
             return false;
         }
         if (!$this->canCreateDbTable()) {
             $this->setError(Jtext::_('COM_FABRIK_INSUFFICIENT_RIGHTS_TO_CREATE_TABLE'));
             return false;
         }
         // Create fabrik form
         $formModel = $this->createLinkedForm();
         $row->form_id = $this->getState('list.form_id');
         // Create fabrik group
         $groupData = FabrikWorker::formDefaults('group');
         $groupData['name'] = $row->label;
         $groupData['label'] = $row->label;
         JRequest::setVar('_createGroup', 1, 'post');
         $groupId = $this->createLinkedGroup($groupData, false);
         if ($newtable == '') {
             // New fabrik list but existing db table
             $this->createLinkedElements($groupId);
         } else {
             $row->db_table_name = $newtable;
             $row->auto_inc = 1;
             $res = $this->createDBTable($newtable, JRequest::getVar('defaultfields', array('id' => 'internalid', 'date_time' => 'date')));
             if (is_array($res)) {
                 $row->db_primary_key = $newtable . '.' . $res[0];
             }
         }
     }
     $params = new JRegistry($row->params);
     if ($row->id != 0) {
         $datenow = JFactory::getDate();
         $row->modified = $datenow->toSql();
         $row->modified_by = $user->get('id');
     }
     FabrikAdminHelper::prepareSaveDate($row->publish_down);
     FabrikAdminHelper::prepareSaveDate($row->created);
     FabrikAdminHelper::prepareSaveDate($row->publish_up);
     $pk = JArrayHelper::getValue($data, 'db_primary_key');
     if ($pk == '') {
         $fields = $row->getFields();
         $key = $row->getKeyName();
         // Store without quoteNames as thats db specific
         $row->db_primary_key = $row->db_primary_key == '' ? $row->db_table_name . "." . $key : $row->db_primary_key;
         $row->auto_inc = JString::stristr($fields[$key]->Extra, 'auto_increment') ? true : false;
     }
     if (!$row->store()) {
         $this->setError($row->getError());
         return false;
     }
     $pk = $row->db_primary_key;
     $this->updateJoins($data);
     // Needed to ensure pk field is not quoted
     $feModel->setTable($row);
     if (!$feModel->isView()) {
         $this->updatePrimaryKey($row->db_primary_key, $row->auto_inc);
     }
     // Make an array of elments and a presumed index size, map is then used in creating indexes
     $map = array();
     $groups = $this->getFormModel()->getGroupsHiarachy();
     foreach ($groups as $groupModel) {
         $elementModels = $groupModel->getMyElements();
         foreach ($elementModels as $element) {
             // Int and DATETIME elements cant have a index size attrib
             $coltype = $element->getFieldDescription();
             if (JString::stristr($coltype, 'int')) {
                 $size = '';
             } elseif (JString::stristr($coltype, 'datetime')) {
                 $size = '';
             } else {
                 $size = '10';
             }
             $map[$element->getFullName(false, false, false)] = $size;
             $map[$element->getElement()->id] = $size;
         }
     }
     // Update indexes (added array_key_exists check as these may be during after CSV import)
     if (!empty($aOrderBy) && array_key_exists($row->order_by, $map)) {
         foreach ($aOrderBy as $orderBy) {
             if (array_key_exists($orderBy, $map)) {
                 $feModel->addIndex($orderBy, 'tableorder', 'INDEX', $map[$orderBy]);
             }
         }
     }
     if ($row->group_by !== '' && array_key_exists($row->group_by, $map)) {
         $feModel->addIndex($row->group_by, 'groupby', 'INDEX', $map["{$row->group_by}"]);
     }
     if (trim($params->get('group_by_order')) !== '') {
         $feModel->addIndex($params->get('group_by_order'), 'groupbyorder', 'INDEX', $map[$params->get('group_by_order')]);
     }
     $afilterFields = (array) $params->get('filter-fields', array());
     foreach ($afilterFields as $field) {
         if (array_key_exists($field, $map)) {
             $feModel->addIndex($field, 'prefilter', 'INDEX', $map[$field]);
         }
     }
     $this->updateElements($row);
     /* $$$rob - joomfish not available for j1.7
     		 if (JFolder::exists(JPATH_ADMINISTRATOR . '/components/com_joomfish/contentelements')) {
     		if ($params->get('allow-data-translation')) {
     		if (!$this->makeJoomfishXML()) {
     		$this->setError(JTEXT::_( "Unable to make Joomfish XML file"));
     		return false;
     		}
     		} else {
     		$this->removeJoomfishXML();
     		}
     		} */
     $pkName = $row->getKeyName();
     if (isset($row->{$pkName})) {
         $this->setState($this->getName() . '.id', $row->{$pkName});
     }
     $this->setState($this->getName() . '.new', $isNew);
     parent::cleanCache('com_fabrik');
     return true;
 }
示例#8
0
 /**
  * Method to save the form data.
  *
  * @param   array  $data  The form data.
  *
  * @return  boolean  True on success, False on error.
  */
 public function save($data)
 {
     parent::cleanCache('com_fabrik');
     return parent::save($data);
 }