/** * Edit an element */ function edit() { global $_PROFILER; JDEBUG ? $_PROFILER->mark('edit: start') : null; $app =& JFactory::getApplication(); $user =& JFactory::getUser(); $db =& JFactory::getDBO(); $acl =& JFactory::getACL(); $model =& JModel::getInstance('element', 'FabrikModel'); if ($this->_task == 'edit') { $cid = JRequest::getVar('cid', array(0), 'method', 'array'); $cid = array((int) $cid[0]); } else { $cid = array(0); } $model->setId($cid[0]); $row =& $model->getElement(); if ($cid) { $row->checkout($user->get('id')); } // get params definitions $params =& $model->getParams(); require_once JPATH_COMPONENT . DS . 'views' . DS . 'element.php'; $pluginManager =& JModel::getInstance('Pluginmanager', 'FabrikModel'); $db->setQuery("SELECT COUNT(*) FROM #__fabrik_groups"); $total = $db->loadResult(); if ($total == 0) { $app->redirect("index.php?option=com_fabrik&c=group&task=new", JText::_('PLEASE CREATE A GROUP BEFORE CREATING AN ELEMENT')); return; } $lists = array(); if ($cid[0] != '0') { $aEls = array(); $aGroups = array(); $db->setQuery("SELECT form_id FROM #__fabrik_formgroup AS fg\n" . "WHERE fg.group_id = {$row->group_id}"); $formrow = $db->loadObject(); if (is_null($formrow)) { $aEls[] = $aGroups[] = JText::_('GROUP MUST BE IN A FORM'); } else { $formModel = JModel::getInstance('form', 'FabrikModel'); $formModel->setId($formrow->form_id); //get available element types $groups =& $formModel->getGroupsHiarachy(); foreach ($groups as $groupModel) { $group =& $groupModel->getGroup(); $o = new stdClass(); $o->label = $group->name; $o->value = "fabrik_trigger_group_group" . $group->id; $aGroups[] = $o; $elementModels =& $groupModel->getMyElements(); foreach ($elementModels as $elementModel) { $o = new stdClass(); $element =& $elementModel->getElement(); $o->label = FabrikString::getShortDdLabel($element->label); $o->value = "fabrik_trigger_element_" . $elementModel->getFullName(false, true, false); $aEls[] = $o; } } } asort($aEls); $o = new StdClass(); $o->groups = $aGroups; $o->elements = array_values($aEls); $lists['elements'] = $o; } else { // set the publish default to 1 $row->state = '1'; $lists['elements'] = array(JText::_('AVAILABLE ONCE SAVED')); } JDEBUG ? $_PROFILER->mark('edit: after element types') : null; $pluginManager->getPlugInGroup('validationrule'); $pluginManager->loadPlugInGroup('element'); $j = new JRegistry(); $lists['jsActions'] = $model->getJSActions(); //merge the js attribs back into the array foreach ($lists['jsActions'] as $js) { $j->loadINI($js->attribs); $a = $j->toArray(); foreach ($a as $k => $v) { $js->{$k} = $v; } unset($js->attribs); } $no_html = JRequest::getBool('no_html', 0); // Create the form $form = new fabrikParams('', JPATH_COMPONENT . DS . 'models' . DS . 'element.xml'); $form->bind($row); $form->loadINI($row->attribs); $row->parent_id = (int) $row->parent_id; if ($row->parent_id === 0) { $lists['parent'] = 0; } else { $sql = "SELECT * FROM #__fabrik_elements WHERE id = " . (int) $row->parent_id; $db->setQuery($sql); $parent = $db->loadObject(); if (is_null($parent)) { //perhaps the parent element was deleted? $lists['parent'] = 0; $row->parent_id = 0; } else { $lists['parent'] = $parent; } } JDEBUG ? $_PROFILER->mark('view edit: start') : null; if ($no_html != 1) { FabrikViewElement::edit($row, $pluginManager, $lists, $params, $form); } }
function _loadPluginParams() { if (isset($this->_xmlPath)) { $rule =& $this->getValidationRule(); $pluginParams = new fabrikParams($rule->attribs, $this->_xmlPath, 'fabrikplugin'); $pluginParams->bind($rule); return $pluginParams; } return false; }
function _loadPluginParams() { if (isset($this->_xmlPath)) { $element = $this->getElement(); $pluginParams = new fabrikParams($element->params, $this->_xmlPath, 'fabrikplugin'); $pluginParams->bind($element); return $pluginParams; } return false; }
/** * when saving a table that links to a database for the first time we * need to create all the elements based on the database table fields and their * column type * * @access private * @param int group id * @param array newly created table data * @param array of element objects - if this is not empty then we've come from the csv import and the elements * have already been defined, use this instead of the field analysis to create correctly typed elements */ function _createLinkedElements($groupId, $aTableData, $aSpecificElements = array()) { $db =& JFactory::getDBO(); $user =& JFactory::getUser(); $session =& JFactory::getSession(); $config =& JFactory::getConfig(); $createdate = JFactory::getDate(); $createdate = $createdate->toMySQL(); $tableName = JRequest::getVar('db_table_name'); $pluginManager =& $this->getPluginManager(); $ordering = 0; $fabrikDb =& $this->getDb(); if (!empty($aSpecificElements)) { //we're asking the method to create predefined elements - e.g. when installing sample data. foreach ($aSpecificElements as $elementModel) { $element =& $elementModel->getElement(); if ($element->label == 'id') { $element->hidden = 1; $element->primary_key = 1; $element->auto_increment = 1; } else { $element->hidden = 0; } $element->name = strtolower(str_replace(' ', '', $element->name)); $element->group_id = $groupId; $element->created = $createdate; $element->created_by = $user->get('id'); $element->created_by_alias = $user->get('username'); $element->state = 1; $element->show_in_table_summary = 1; $element->width = 30; $element->height = 6; $element->ordering = 99999; $element->attribs = $elementModel->getDefaultAttribs(); $element->store(); $where = " group_id = " . (int) $element->group_id; $element->reorder($where); } } else { //here we're importing directly from the database schema $db->setQuery("SELECT id FROM #__fabrik_tables WHERE " . $db->nameQuote('db_table_name') . " = " . $db->Quote($tableName)); $id = $db->loadResult(); $elementModel =& JModel::getInstance('Element', 'FabrikModel'); if ($id) { //a fabrik table already exists - so we can copy the formatting of its elements $groupTableModel = JModel::getInstance('table', 'FabrikModel'); $groupTableModel->setId($id); $table = $groupTableModel->getTable(); //$this->_oForm = null; //reset form so that it loads new table form $groups = $groupTableModel->getFormGroupElementData(); $newElements = array(); foreach ($groups as $groupModel) { // if we are saving a new table and the previously found tables group is a join // then don't add its elements to the table as they don't exist in the database table // we are linking to // $$$ hugh - removed id == 0 test, as this gets called from _makeNewJoin as well, see #608 //if ($groupModel->isJoin() && JRequest::getCmd('task') == 'save' && JRequest::getInt('id') == 0) { if ($groupModel->isJoin() && JRequest::getCmd('task') == 'save') { continue; } $elementModels =& $groupModel->getMyElements(); foreach ($elementModels as $elementModel) { $element =& $elementModel->getElement(); $copy = $elementModel->copyRow($element->id, '', $groupId); $newElements[$element->id] = $copy->id; } } $elementModel =& JModel::getInstance('Element', 'FabrikModel'); foreach ($newElements as $origId => $newId) { $plugin = $pluginManager->getElementPlugin($newId); $plugin->finalCopyCheck($newElements); } } else { //$$$ rob since 2.0.4 - lets see if theres a session element / plugin map set up (used in balsamiq to fabrik component) $map = (array) $session->get('com_fabrik.list.create.elementmap'); $elementTypes = JRequest::getVar('elementtype', array(), 'default', 'array'); $fields = $fabrikDb->getTableFields(array("`{$tableName}`")); $fields = $fields["`{$tableName}`"]; $key = $this->getPrimaryKeyAndExtra($tableName); // no existing fabrik table so we take a guess at the most //relavent element types to create $elementLabels = JRequest::getVar('elementlabels', array(), 'default', 'array'); foreach ($fields as $label => $type) { $element =& JTable::getInstance('Element', 'Table'); $info = array(); $element->sub_values = ''; $element->sub_labels = ''; //$element->label = str_replace("_", " ", $label); if (array_key_exists($ordering, $elementTypes)) { //if importing from a CSV file then we have userselect field definitions $plugin = $elementTypes[$ordering]; } else { //$$$ rob since 2.0.4 - lets see if theres a session element / plugin map set up (used in balsamiq to fabrik component) if (array_key_exists($tableName . '___' . $label, $map)) { $info = $map[$tableName . '___' . $label]; //check its in the right group (or not assinged if from tbl) if (!is_null($info['groupid']) && $info['groupid'] == $groupId) { $plugin = $info['plugin']; $element->bind($info); } else { continue; } } else { //if the field is the primary key and it's an INT type set the plugin to be the fabrik internal id if ($key[0]['colname'] == $label && strtolower(substr($key[0]['type'], 0, 3)) === 'int') { $plugin = 'fabrikinternalid'; } else { //otherwise guestimate! switch ($type) { case "int": case "tinyint": case "varchar": $plugin = 'fabrikfield'; break; case "text": case "tinytext": case "mediumtext": case "longtext": $plugin = 'fabriktextarea'; break; case "datetime": case "date": case "time": case "timestamp": $plugin = 'fabrikdate'; break; default: $plugin = 'fabrikfield'; break; } } } } if ($plugin == '') { continue; } $element->plugin = $plugin; $element->hidden = $element->label == 'id' ? '1' : '0'; $element->group_id = $groupId; $element->name = $label; $element->created = $createdate; $element->created_by = $user->get('id'); $element->created_by_alias = $user->get('username'); $element->state = '1'; $element->show_in_table_summary = '1'; switch ($plugin) { case 'fabriktextarea': $element->width = '40'; break; case 'fabrikdate': $element->width = '10'; break; default: $element->width = '30'; break; } $a = new fabrikParams($elementModel->getDefaultAttribs(), JPATH_SITE . '/administrator/components/com_fabrik/models/element.xml'); $aparams = JArrayHelper::getValue($info, 'params', array()); $a->bind($aparams); $element->height = '6'; $element->ordering = $ordering; $element->attribs = $a->toString(); if ($element->label == '') { $element->label = JArrayHelper::getValue($elementLabels, $ordering, str_replace("_", " ", $label)); } if (!$element->store()) { return JError::raiseError(500, $element->getError()); } $elementModel =& $pluginManager->getPlugIn($element->plugin, 'element'); $elementModel->setId($element->id); $elementModel->_element = $element; // hack for user element $details = array('group_id' => $element->group_id); JRequest::setVar('details', $details); $elementModel->onSave(); $ordering++; } } } }