Ejemplo n.º 1
0
 /**
  * Format options
  *
  * @param array $res
  * @param       $valueFormat
  *
  * @return array
  * @throws Exception
  */
 private function _formatOptions(array $res, $valueFormat)
 {
     $aEls = array();
     $input = JFactory::getApplication()->input;
     $controller = $input->get('view', $input->get('task'));
     if ($controller == 'element') {
         foreach ($res as $o) {
             $s = new stdClass();
             // Element already contains correct key
             if ($controller != 'element') {
                 $s->value = $valueFormat == 'tableelement' ? $o->table_name . '.' . $o->text : $o->value;
             } else {
                 $s->value = $o->value;
             }
             $s->text = FabrikString::getShortDdLabel($o->text);
             $aEls[] = $s;
         }
     } else {
         foreach ($res as &$o) {
             $o->text = FabrikString::getShortDdLabel($o->text);
         }
         $aEls = $res;
     }
     // Paul - Prepend rather than append "none" option.
     array_unshift($aEls, JHTML::_('select.option', '', '-'));
     return $aEls;
 }
Ejemplo n.º 2
0
 public function getElements()
 {
     $db = FabrikWorker::getDbo(true);
     $item = $this->getItem();
     $aEls = array();
     $aGroups = array();
     $query = $db->getQuery(true);
     $query->select('form_id');
     $query->from($db->nameQuote('#__{package}_formgroup') . ' AS fg');
     $query->where('fg.group_id = ' . (int) $item->group_id);
     $db->setQuery($query);
     $formrow = $db->loadObject();
     if (is_null($formrow)) {
         $aEls[] = $aGroups[] = JText::_('COM_FABRIK_GROUP_MUST_BE_IN_A_FORM');
     } else {
         $formModel = JModel::getInstance('Form', 'FabrikFEModel');
         $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);
     return $o;
 }
Ejemplo n.º 3
0
 /**
  * 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);
     }
 }
Ejemplo n.º 4
0
 /**
  * Get a list of fields
  *
  * @return  string  json encoded list of fields
  */
 public function ajax_fields()
 {
     $app = JFactory::getApplication();
     $input = $app->input;
     $tid = $input->get('t');
     $keyType = $input->getInt('k', 1);
     // If true show all fields if false show fabrik elements
     $showAll = $input->getBool('showall', false);
     // Should we highlight the PK as a recommended option
     $highlightpk = $input->getBool('highlightpk');
     // Only used if showall = false, includes validations as separate entries
     $incCalculations = $input->get('calcs', false);
     $arr = array();
     try {
         if ($showAll) {
             // Show all db columns
             $cid = $input->get('cid', -1);
             $cnn = JModelLegacy::getInstance('Connection', 'FabrikFEModel');
             $cnn->setId($cid);
             $db = $cnn->getDb();
             if ($tid != '') {
                 if (is_numeric($tid)) {
                     // If loading on a numeric list id get the list db table name
                     $jDb = FabrikWorker::getDbo(true);
                     $query = $jDb->getQuery(true);
                     $query->select('db_table_name')->from('#__{package}_lists')->where('id = ' . (int) $tid);
                     $jDb->setQuery($query);
                     $tid = $jDb->loadResult();
                 }
                 $db->setQuery('DESCRIBE ' . $db->quoteName($tid));
                 $rows = $db->loadObjectList();
                 if (is_array($rows)) {
                     foreach ($rows as $r) {
                         $c = new stdClass();
                         $c->value = $r->Field;
                         $c->label = $r->Field;
                         if ($highlightpk && $r->Key === 'PRI') {
                             $c->label .= ' [' . JText::_('COM_FABRIK_RECOMMENDED') . ']';
                             array_unshift($arr, $c);
                         } else {
                             $arr[$r->Field] = $c;
                         }
                     }
                     ksort($arr);
                     $arr = array_values($arr);
                 }
             }
         } else {
             /*
              * show fabrik elements in the table
              * $keyType 1 = $element->id;
              * $keyType 2 = tablename___elementname
              */
             $model = JModelLegacy::getInstance('List', 'FabrikFEModel');
             $model->setId($tid);
             $table = $model->getTable();
             $db = $model->getDb();
             $groups = $model->getFormGroupElementData();
             $published = $input->get('published', false);
             $showintable = $input->get('showintable', false);
             foreach ($groups as $g => $groupModel) {
                 if ($groupModel->isJoin()) {
                     if ($input->get('excludejoined') == 1) {
                         continue;
                     }
                     $joinModel = $groupModel->getJoinModel();
                     $join = $joinModel->getJoin();
                 }
                 if ($published == true) {
                     $elementModels = $groups[$g]->getPublishedElements();
                 } else {
                     $elementModels = $groups[$g]->getMyElements();
                 }
                 foreach ($elementModels as $e => $eVal) {
                     $element = $eVal->getElement();
                     if ($showintable == true && $element->show_in_list_summary == 0) {
                         continue;
                     }
                     if ($keyType == 1) {
                         $v = $element->id;
                     } else {
                         /*
                          * @TODO if in repeat group this is going to add [] to name - is this really
                          * what we want? In timeline viz options I've simply stripped out the [] off the end
                          * as a temp hack
                          */
                         $useStep = $keyType === 2 ? true : false;
                         $v = $eVal->getFullName($useStep);
                     }
                     $c = new stdClass();
                     $c->value = $v;
                     $label = FabrikString::getShortDdLabel($element->label);
                     if ($groupModel->isJoin()) {
                         $label = $join->table_join . '.' . $label;
                     }
                     $c->label = $label;
                     // Show hightlight primary key and shift to top of options
                     if ($highlightpk && $table->db_primary_key === $db->quoteName($eVal->getFullName(false, false))) {
                         $c->label .= ' [' . JText::_('COM_FABRIK_RECOMMENDED') . ']';
                         array_unshift($arr, $c);
                     } else {
                         $arr[] = $c;
                     }
                     if ($incCalculations) {
                         $params = $eVal->getParams();
                         if ($params->get('sum_on', 0)) {
                             $c = new stdClass();
                             $c->value = 'sum___' . $v;
                             $c->label = JText::_('COM_FABRIK_SUM') . ': ' . $label;
                             $arr[] = $c;
                         }
                         if ($params->get('avg_on', 0)) {
                             $c = new stdClass();
                             $c->value = 'avg___' . $v;
                             $c->label = JText::_('COM_FABRIK_AVERAGE') . ': ' . $label;
                             $arr[] = $c;
                         }
                         if ($params->get('median_on', 0)) {
                             $c = new stdClass();
                             $c->value = 'med___' . $v;
                             $c->label = JText::_('COM_FABRIK_MEDIAN') . ': ' . $label;
                             $arr[] = $c;
                         }
                         if ($params->get('count_on', 0)) {
                             $c = new stdClass();
                             $c->value = 'cnt___' . $v;
                             $c->label = JText::_('COM_FABRIK_COUNT') . ': ' . $label;
                             $arr[] = $c;
                         }
                         if ($params->get('custom_calc_on', 0)) {
                             $c = new stdClass();
                             $c->value = 'cnt___' . $v;
                             $c->label = JText::_('COM_FABRIK_CUSTOM') . ': ' . $label;
                             $arr[] = $c;
                         }
                     }
                 }
             }
         }
     } catch (RuntimeException $err) {
         // Ignore errors as you could be swapping between connections, with old db table name selected.
     }
     array_unshift($arr, JHTML::_('select.option', '', JText::_('COM_FABRIK_PLEASE_SELECT'), 'value', 'label'));
     echo json_encode($arr);
 }
Ejemplo n.º 5
0
 function getInput()
 {
     if (is_null($this->results)) {
         $this->results = array();
     }
     $controller = JRequest::getVar('view', JRequest::getVar('task'));
     $aEls = array();
     $pluginFilters = trim($this->element['filter']) == '' ? array() : explode("|", $this->element['filter']);
     $bits = array();
     $c = ElementHelper::getRepeatCounter($this);
     $connection = $this->element['connection'];
     // 27/08/2011 - changed from default tableelement to id - for juser form plugin - might cause havock
     //else where but loading elements by id as default seems more robust (and is the default behaviour in f2.1
     $valueformat = JArrayHelper::getValue($this->element, 'valueformat', 'id');
     $onlylistfields = (int) JArrayHelper::getValue($this->element, 'onlylistfields', 0);
     switch ($controller) {
         case 'element':
             //@TODO this seems like we could refractor it to use the formModel class as per the table and form switches below?
             $connectionDd = $c === false ? $connection : $connection . '-' . $c;
             if ($connection == '') {
                 $groupModel = JModel::getInstance('Group', 'FabrikFEModel');
                 $groupId = isset($this->form->rawData) ? JArrayHelper::getValue($this->form->rawData, 'group_id', 0) : $this->form->getValue('group_id');
                 $groupModel->setId($groupId);
                 $optskey = $valueformat == 'tableelement' ? 'name' : 'id';
                 $res = $groupModel->getForm()->getElementOptions(false, $optskey, $onlylistfields, false, $pluginFilters);
                 $hash = "{$controller}." . implode('.', $bits);
                 if (array_key_exists($hash, $this->results)) {
                     $res = $this->results[$hash];
                 } else {
                     $this->results[$hash] =& $res;
                 }
             } else {
                 //****************************//
                 $repeat = ElementHelper::getRepeat($this);
                 $tableDd = $this->element['table'];
                 $opts = new stdClass();
                 $opts->table = $repeat ? 'jform_' . $tableDd . "-" . $c : 'jform_' . $tableDd;
                 $opts->conn = 'jform_' . $connectionDd;
                 $opts->value = $this->value;
                 $opts->repeat = $this->value;
                 $opts = json_encode($opts);
                 $script = "new ListFieldsElement('{$this->id}', {$opts});\n";
                 FabrikHelperHTML::script('administrator/components/com_fabrik/models/fields/listfields.js', $script);
                 $rows = array(JHTML::_('select.option', '', JText::_('SELECT A CONNECTION FIRST')), 'value', 'text');
                 $o = new stdClass();
                 $o->table_name = '';
                 $o->name = '';
                 $o->value = '';
                 $o->text = JText::_('COM_FABRIK_SELECT_A_TABLE_FIRST');
                 $res[] = $o;
                 //****************************//
             }
             break;
         case 'listform':
         case 'list':
         case 'module':
         case 'item':
             //menu item
             if ($controller === 'item') {
                 $id = $this->form->getValue('request.listid');
             } else {
                 $id = $this->form->getValue('id');
             }
             if (!isset($this->form->model)) {
                 echo "not set ";
                 if (!in_array($controller, array('item', 'module'))) {
                     //seems to work anyway in the admin module page - so lets not raise notice
                     JError::raiseNotice(500, 'Model not set in listfields field ' . $this->id);
                 }
                 echo "form model no set";
                 return;
             }
             $listModel = $this->form->model;
             if ($id !== 0) {
                 $formModel = $listModel->getFormModel();
                 $valfield = $valueformat == 'tableelement' ? 'name' : 'id';
                 $res = $formModel->getElementOptions(false, $valfield, $onlylistfields, false, $pluginFilters);
             } else {
                 $res = array();
             }
             break;
         case 'form':
             if (!isset($this->form->model)) {
                 JError::raiseNotice(500, 'Model not set in listfields field ' . $this->id);
                 return;
             }
             $formModel = $this->form->model;
             $valfield = $valueformat == 'tableelement' ? 'name' : 'id';
             $res = $formModel->getElementOptions(false, $valfield, $onlylistfields, false, $pluginFilters);
             break;
         default:
             return JText::_('THE LISTFIELDS ELEMENT IS ONLY USABLE BY LISTS AND ELEMENTS');
             break;
     }
     $return = '';
     if (is_array($res)) {
         if ($controller == 'element') {
             foreach ($res as $o) {
                 $s = new stdClass();
                 //element already contains correct key
                 if ($controller != 'element') {
                     $s->value = $valueformat == 'tableelement' ? $o->table_name . '.' . $o->text : $o->value;
                 } else {
                     $s->value = $o->value;
                 }
                 $s->text = FabrikString::getShortDdLabel($o->text);
                 $aEls[] = $s;
             }
         } else {
             foreach ($res as &$o) {
                 $o->text = FabrikString::getShortDdLabel($o->text);
             }
             $aEls = $res;
         }
         $aEls[] = JHTML::_('select.option', '', '-');
         // for pk fields - we are no longer storing the key with '`' as thats mySQL specific
         $this->value = str_replace('`', '', $this->value);
         $return = JHTML::_('select.genericlist', $aEls, $this->name, 'class="inputbox" size="1" ', 'value', 'text', $this->value, $this->id);
         $return .= "<img style=\"margin-left:10px;display:none\" id=\"" . $this->id . "_loader\" src=\"components/com_fabrik/images/ajax-loader.gif\" alt=\"" . JText::_('LOADING') . "\" />";
     }
     return $return;
 }
Ejemplo n.º 6
0
	function ajax_fields()
	{
		$tid = JRequest::getVar('t');
		$keyType = JRequest::getVar('k', 1);
		$showAll = JRequest::getVar('showall', false);//if true show all fields if false show fabrik elements

		//only used if showall = false, includes validations as separate entries
		$incCalculations = JRequest::getVar('calcs', false);
		$arr = array(JHTML::_('select.option', '', JText::_('COM_FABRIK_PLEASE_SELECT'), 'value', 'label'));
		if ($showAll) { //show all db columns
			$cid = JRequest::getVar('cid', -1);
			$cnn = JModel::getInstance('Connection', 'FabrikFEModel');
			$cnn->setId($cid);
			$db = $cnn->getDb();
			if ($tid != '') {
				$db->setQuery("DESCRIBE ".$db->nameQuote($tid));

				$rows = $db->loadObjectList();
				if (is_array($rows)) {
					foreach ($rows as $r) {
						$c = new stdClass();
						$c->value = $r->Field;
						$c->label = $r->Field;
						$arr[] = $c; //dont use =
					}
				}
			}
		} else {
			//show fabrik elements in the table
			//$keyType 1 = $element->id;
			//$keyType 2 = tablename___elementname
			$model = JModel::getInstance('List', 'FabrikFEModel');
			$model->setId($tid);
			$table = $model->getTable();
			$groups = $model->getFormGroupElementData();
			$published = JRequest::getVar('published', false);
			$showintable = JRequest::getVar('showintable', false);
			foreach ($groups as $g => $groupModel) {
				if ($groupModel->isJoin()) {
					if (JRequest::getVar('excludejoined') == 1) {
						continue;
					}
					$joinModel = $groupModel->getJoinModel();
					$join = $joinModel->getJoin();
				}
				if ($published == true) {
					$elementModels = $groups[$g]->getPublishedElements();
				} else {
					$elementModels = $groups[$g]->getMyElements();
				}

				foreach ($elementModels as $e => $eVal) {
					$element = $eVal->getElement();
					if ($showintable == true && $element->show_in_list_summary == 0) {
						continue;
					}
					if ($keyType == 1) {
						$v = $element->id;
					} else {
						//@TODO if in repeat group this is going to add [] to name - is this really
						// what we want? In timeline viz options i've simply stripped out the [] off the end
						// as a temp hack
						$v = $eVal->getFullName(false);
					}
					$c = new stdClass();
					$c->value = $v;
					$label = FabrikString::getShortDdLabel( $element->label);
					if ($groupModel->isJoin()) {
						$label = $join->table_join.'.'.$label;
					}
					$c->label = $label;
					$arr[] = $c; //dont use =
					if ($incCalculations) {
						$params = $eVal->getParams();
						if ($params->get('sum_on', 0)) {
							$c = new stdClass();
							$c->value = 'sum___'.$v;
							$c->label = JText::_('COM_FABRIK_SUM') . ": " .$label;
							$arr[] = $c; //dont use =
						}
						if ($params->get('avg_on', 0)) {
							$c = new stdClass();
							$c->value = 'avg___'.$v;
							$c->label = JText::_('COM_FABRIK_AVERAGE') . ": " .$label;
							$arr[] = $c; //dont use =
						}
						if ($params->get('median_on', 0)) {
							$c = new stdClass();
							$c->value = 'med___'.$v;
							$c->label = JText::_('COM_FABRIK_MEDIAN') . ": " .$label;
							$arr[] = $c; //dont use =
						}
						if ($params->get('count_on', 0)) {
							$c = new stdClass();
							$c->value = 'cnt___'.$v;
							$c->label = JText::_('COM_FABRIK_COUNT') . ": " .$label;
							$arr[] = $c; //dont use =
						}
					}
				}
			}
		}
		echo json_encode($arr);
	}
Ejemplo n.º 7
0
 /**
  * Method to get the field input markup.
  *
  * @return  string	The field input markup.
  */
 protected function getInput()
 {
     if (is_null($this->results)) {
         $this->results = array();
     }
     $app = JFactory::getApplication();
     $input = $app->input;
     $controller = $input->get('view', $input->get('task'));
     $formModel = false;
     $aEls = array();
     $pluginFilters = trim($this->element['filter']) == '' ? array() : explode('|', $this->element['filter']);
     $c = (int) FabrikAdminElementHelper::getRepeatCounter($this);
     $connection = $this->element['connection'];
     /*
      * 27/08/2011 - changed from default table-element to id - for juser form plugin - might cause havoc
      * else where but loading elements by id as default seems more robust (and is the default behaviour in f2.1
      */
     $valueformat = (string) JArrayHelper::getValue($this->element, 'valueformat', 'id');
     $onlylistfields = (int) JArrayHelper::getValue($this->element, 'onlylistfields', 0);
     $showRaw = (bool) JArrayHelper::getValue($this->element, 'raw', false);
     $labelMethod = (string) JArrayHelper::getValue($this->element, 'label_method');
     $nojoins = (bool) JArrayHelper::getValue($this->element, 'nojoins', false);
     $mode = (string) JArrayHelper::getValue($this->element, 'mode', false);
     $useStep = (bool) JArrayHelper::getValue($this->element, 'usestep', false);
     switch ($controller) {
         case 'validationrule':
             $id = $input->getInt('id');
             $pluginManager = FabrikWorker::getPluginManager();
             $elementModel = $pluginManager->getElementPlugin($id);
             $element = $elementModel->getElement();
             $res = $this->loadFromGroupId($element->group_id);
             break;
         case 'visualization':
         case 'element':
             $repeat = FabrikAdminElementHelper::getRepeat($this) || $this->element['repeat'];
             // @TODO this seems like we could re-factor it to use the formModel class as per the table and form switches below?
             // $connectionDd = ($c === false) ? $connection : $connection . '-' . $c;
             $connectionDd = $repeat ? $connection . '-' . $c : $connection;
             if ($connection == '') {
                 $groupId = isset($this->form->rawData) ? JArrayHelper::getValue($this->form->rawData, 'group_id', 0) : $this->form->getValue('group_id');
                 $res = $this->loadFromGroupId($groupId);
             } else {
                 $this->js();
                 $o = new stdClass();
                 $o->table_name = '';
                 $o->name = '';
                 $o->value = '';
                 $o->text = JText::_('COM_FABRIK_SELECT_A_TABLE_FIRST');
                 $res[] = $o;
             }
             break;
         case 'listform':
         case 'list':
         case 'module':
         case 'item':
             // Menu item
             if ($controller === 'item') {
                 $id = $this->form->getValue('request.listid');
             } else {
                 $id = $this->form->getValue('id');
             }
             if (!isset($this->form->model)) {
                 if (!in_array($controller, array('item', 'module'))) {
                     // Seems to work anyway in the admin module page - so lets not raise notice
                     $app->enqueueMessage('Model not set in listfields field ' . $this->id, 'notice');
                 }
                 return;
             }
             $listModel = $this->form->model;
             if ($id !== 0) {
                 $formModel = $listModel->getFormModel();
                 $valfield = $valueformat == 'tableelement' ? 'name' : 'id';
                 $res = $formModel->getElementOptions($useStep, $valfield, $onlylistfields, $showRaw, $pluginFilters, $labelMethod, $nojoins);
             } else {
                 $res = array();
             }
             break;
         case 'form':
             if (!isset($this->form->model)) {
                 throw new RuntimeException('Model not set in listfields field ' . $this->id);
                 return;
             }
             $formModel = $this->form->model;
             $valfield = $valueformat == 'tableelement' ? 'name' : 'id';
             $res = $formModel->getElementOptions($useStep, $valfield, $onlylistfields, $showRaw, $pluginFilters, $labelMethod, $nojoins);
             $jsres = $formModel->getElementOptions($useStep, $valfield, $onlylistfields, $showRaw, $pluginFilters, $labelMethod, $nojoins);
             array_unshift($jsres, JHTML::_('select.option', '', JText::_('COM_FABRIK_PLEASE_SELECT')));
             $this->js($jsres);
             break;
         case 'group':
             $valfield = $valueformat == 'tableelement' ? 'name' : 'id';
             $id = $this->form->getValue('id');
             $groupModel = JModelLegacy::getInstance('Group', 'FabrikFEModel');
             $groupModel->setId($id);
             $formModel = $groupModel->getFormModel();
             $res = $formModel->getElementOptions($useStep, $valfield, $onlylistfields, $showRaw, $pluginFilters, $labelMethod, $nojoins);
             break;
         default:
             return JText::_('The ListFields element is only usable by lists and elements');
             break;
     }
     $return = '';
     if (is_array($res)) {
         if ($controller == 'element') {
             foreach ($res as $o) {
                 $s = new stdClass();
                 // Element already contains correct key
                 if ($controller != 'element') {
                     $s->value = $valueformat == 'tableelement' ? $o->table_name . '.' . $o->text : $o->value;
                 } else {
                     $s->value = $o->value;
                 }
                 $s->text = FabrikString::getShortDdLabel($o->text);
                 $aEls[] = $s;
             }
         } else {
             foreach ($res as &$o) {
                 $o->text = FabrikString::getShortDdLabel($o->text);
             }
             $aEls = $res;
         }
         // Paul - Prepend rather than append "none" option.
         array_unshift($aEls, JHTML::_('select.option', '', '-'));
         // For pk fields - we are no longer storing the key with '`' as that's mySQL specific
         $this->value = str_replace('`', '', $this->value);
         // Some elements were stored as names but subsequently changed to ids (need to check for old values an substitute with correct ones)
         if ($valueformat == 'id' && !is_numeric($this->value) && $this->value != '') {
             if ($formModel) {
                 $elementModel = $formModel->getElement($this->value);
                 $this->value = $elementModel ? $elementModel->getId() : $this->value;
             }
         }
         if ($mode === 'gui') {
             $this->js($aEls);
             $return = $this->gui();
         } else {
             $return = JHTML::_('select.genericlist', $aEls, $this->name, 'class="inputbox" size="1" ', 'value', 'text', $this->value, $this->id);
             $return .= '<img style="margin-left:10px;display:none" id="' . $this->id . '_loader" src="components/com_fabrik/images/ajax-loader.gif" alt="' . JText::_('LOADING') . '" />';
         }
     }
     FabrikHelperHTML::framework();
     FabrikHelperHTML::iniRequireJS();
     return $return;
 }
Ejemplo n.º 8
0
 function fetchElement($name, $value, &$node, $control_name)
 {
     if (is_null($this->results)) {
         $this->results = array();
     }
     $db =& JFactory::getDBO();
     $controller = JRequest::getVar('c');
     $session =& JFactory::getSession();
     $aEls = array();
     $onlytablefields = (int) $node->attributes('onlytablefields', 1);
     $onlytablefields = $onlytablefields === 1 ? "show_in_table_summary = 1" : "";
     $pluginFilters = trim($node->attributes('filter')) == '' ? array() : explode("|", $node->attributes('filter'));
     $bits = array();
     $id = ElementHelper::getId($this, $control_name, $name);
     $fullName = ElementHelper::getFullName($this, $control_name, $name);
     $c = ElementHelper::getRepeatCounter($this);
     switch ($controller) {
         case 'element':
             //@TODO this seems like we could refractor it to use the formModel class as per the table and form switches below?
             //$connectionDd = $node->attributes( 'connection', '');
             $connectionDd = $c === false ? $node->attributes('connection') : $node->attributes('connection') . '-' . $c;
             if ($node->attributes('connection', '') == '') {
                 $oGroup =& JModel::getInstance('Group', 'FabrikModel');
                 $groupid = $this->_parent->get('group_id');
                 if ($groupid == '') {
                     $cid = JRequest::getVar('cid');
                     if (is_array($cid)) {
                         $cid = $cid[0];
                     }
                     $db->setQuery("select group_id from #__fabrik_elements where id = " . (int) $cid);
                     $groupid = $db->loadResult();
                 }
                 $oGroup->setId($groupid);
                 $formModel =& $oGroup->getForm();
                 $optskey = $node->attributes('valueformat', 'tableelement') == 'tableelement' ? 'name' : 'id';
                 $onlytablefields = (int) $node->attributes('onlytablefields', 0);
                 $res = $formModel->getElementOptions(false, $optskey, $onlytablefields, false, $pluginFilters);
                 $hash = "{$controller}." . implode('.', $bits);
                 if (array_key_exists($hash, $this->results)) {
                     $res = $this->results[$hash];
                 } else {
                     $this->results[$hash] =& $res;
                 }
             } else {
                 //****************************//
                 $repeat = ElementHelper::getRepeat($this);
                 $tableDd = $node->attributes('table', '');
                 FabrikHelperHTML::script('tablefields.js', 'administrator/components/com_fabrik/elements/', true);
                 $opts = new stdClass();
                 $opts->table = $repeat ? 'params' . $tableDd . "-" . $c : 'params' . $tableDd;
                 $opts->livesite = COM_FABRIK_LIVESITE;
                 $opts->conn = 'params' . $connectionDd;
                 $opts->value = $value;
                 $opts->repeat = $value;
                 $opts = FastJSON::encode($opts);
                 $script = "window.addEvent('domready', function() {\n";
                 $script .= "new tablefieldsElement('{$id}', {$opts});\n";
                 $script .= "});\n";
                 $document =& JFactory::getDocument();
                 $document->addScriptDeclaration($script);
                 $rows = array(JHTML::_('select.option', '', JText::_('SELECT A CONNECTION FIRST')), 'value', 'text');
                 $o = new stdClass();
                 $o->table_name = '';
                 $o->name = '';
                 $o->value = '';
                 $o->text = JText::_('SELECT A TABLE FIRST');
                 $res[] = $o;
                 //****************************//
             }
             break;
         case 'table':
             $id = $this->_parent->get('id', false);
             if ($id === false) {
                 $id = JRequest::getVar('cid', array(0));
                 if (is_array($id)) {
                     $id = $id[0];
                 }
             }
             $tableModel =& $session->get('com_fabrik.admin.table.edit.model');
             $formModel =& $tableModel->getForm();
             $valfield = $node->attributes('valueformat', 'tableelement') == 'tableelement' ? 'name' : 'id';
             $onlytablefields = (int) $node->attributes('onlytablefields', 1);
             $incraw = $node->attributes('incraw', 0) == 1 ? true : false;
             $res = $formModel->getElementOptions(false, $valfield, $onlytablefields, $incraw, $pluginFilters);
             break;
         case 'form':
             $id = $this->_parent->get('id');
             $id = JRequest::getVar('cid', array(0));
             if (is_array($id)) {
                 $id = $id[0];
             }
             $formModel =& $session->get('com_fabrik.admin.form.edit.model');
             $valfield = $node->attributes('valueformat', 'tableelement') == 'tableelement' ? 'name' : 'id';
             $onlytablefields = (int) $node->attributes('onlytablefields', 1);
             $incraw = $node->attributes('incraw', 0) == 1 ? true : false;
             $res = $formModel->getElementOptions(false, $valfield, $onlytablefields, $incraw, $pluginFilters);
             break;
         default:
             return JText::_('THE TABLEFIELDS ELEMENT IS ONLY USABLE BY TABLES AND ELEMENTS');
             break;
     }
     $return = '';
     if (is_array($res)) {
         if ($controller == 'element') {
             foreach ($res as $o) {
                 $s = new stdClass();
                 //element already contains correct key
                 if ($controller != 'element') {
                     $s->value = $node->attributes('valueformat', 'tableelement') == 'tableelement' ? $o->table_name . '.' . $o->text : $o->value;
                 } else {
                     $s->value = $o->value;
                 }
                 $s->text = FabrikString::getShortDdLabel($o->text);
                 $aEls[] = $s;
             }
         } else {
             foreach ($res as &$o) {
                 $o->text = FabrikString::getShortDdLabel($o->text);
             }
             $aEls = $res;
         }
         $id = ElementHelper::getId($this, $control_name, $name);
         $aEls[] = JHTML::_('select.option', '', '-');
         $return = JHTML::_('select.genericlist', $aEls, $fullName, 'class="inputbox" size="1" ', 'value', 'text', $value, $id);
         $return .= "<img style='margin-left:10px;display:none' id='" . $id . "_loader' src='components/com_fabrik/images/ajax-loader.gif' alt='" . JText::_('LOADING') . "' />";
     }
     return $return;
 }