/** * Parse list options for options, optgroups, and evaluate IF conditions * * @param string $name The name of the form element * @param SimpleXMLElement $node The xml element for the parameter * @param string $control_name The control name * @param array $options The base array of options to extend with parsed options * @param SimpleXMLElement[] $children The child xml elements for the parameter * @param bool $otgroups If optgroups should be added to the options array * @param string $value The value of the element * @param bool $ignoreClass If option classes should be ignored or not * @param int $index The option index */ function _list_options( $name, &$node, $control_name, &$options, $children, $otgroups = true, $value = null, $ignoreClass = false, &$index = 0 ) { $translate = $node->attributes( 'translate' ); if ( $children ) foreach ( $children as $option ) { $optTranslate = ( $option->attributes( 'translate' ) !== null ? $option->attributes( 'translate' ) : $translate ); if ( $option->getName() == 'option' ) { if ( ( $option->attributes( 'index' ) !== '' ) && ( $option->attributes( 'index' ) !== null ) ) { $val = $option->attributes( 'index' ); } else { $val = $option->attributes( 'value' ); } if ( ( $option->attributes( 'selectable' ) != 'false' ) || ( (string) $val === (string) $value ) ) { $label = $option->data(); $opt = $this->_list_make_option( $optTranslate, $val, ( $label !== '' ? $label : $val ), 'value', 'text', null, ( $ignoreClass ? null : RegistryEditView::buildClasses( $option ) ) ); $opt->id = $this->control_id( $control_name, $name ) . '__cbf' . $index; $options[] = $opt; $index++; } } elseif ( $otgroups && ( $option->getName() == 'optgroup' ) ) { if ( $optTranslate == 'no' ) { $label = $option->attributes( 'label' ); } else { $label = CBTxt::T( $option->attributes( 'label' ) ); } $opt = moscomprofilerHTML::makeOptGroup( $label, 'value', 'text', null, ( $ignoreClass ? null : RegistryEditView::buildClasses( $option ) ) ); $opt->id = $this->control_id( $control_name, $name ) . '__cbf' . $index; $options[] = $opt; $index++; $this->_list_options( $name, $node, $control_name, $options, $option->children(), $otgroups, $value, $ignoreClass, $index ); $options[] = moscomprofilerHTML::makeOptGroup( null ); } elseif ( $option->getName() == 'data' ) { // TODO: Replace this usage with _getFieldValues (aslo needs upgrading to support private/custom below) once it is refactored into RegistryEditView: global $_CB_database; if ( $option->attributes( 'type' ) == 'private' ) { $privateOptions = $this->_form_private( $name, $value, $option, $control_name ); if ( is_array( $privateOptions ) ) { $options = array_merge( $options, $privateOptions ); } } elseif ( $option->attributes( 'type' ) == 'custom' ) { $customOptions = $this->_form_custom( $name, $value, $option, $control_name ); if ( is_array( $customOptions ) ) { $options = array_merge( $options, $customOptions ); } } elseif ( $option->attributes( 'dataprocessed' ) != 'true' ) { $dataTable = $option->attributes( 'table' ); $xmlsql = new XmlQuery( $_CB_database, $dataTable, $this->_pluginParams ); $xmlsql->setExternalDataTypeValues( 'modelofdata', $this->_modelOfData[0] ); $xmlsql->process_orderby( $option->getElementByPath( 'orderby') ); // <data><orderby><field> fields $xmlsql->process_fields( $option->getElementByPath( 'rows') ); // <data><rows><field> fields $xmlsql->process_where( $option->getElementByPath( 'where') ); // <data><where><column> fields $groupby = $option->getElementByPath( 'groupby' ); $xmlsql->process_groupby( ( $groupby !== false ? $groupby : 'value' ) ); // <data><groupby><field> fields $fieldValuesInDb = $xmlsql->queryLoadObjectsList( $option ); // get the records $rows = $option->getElementByPath( 'rows'); // check for type="firstwords" /** @var $rows SimpleXMLElement|null */ if ( $rows ) { $textField = $rows->getChildByNameAttr( 'field', 'as', 'text' ); /** @var $textField SimpleXMLElement|null */ if ( $textField ) { if ( $textField->attributes( 'type' ) == 'firstwords' ) { $size = $textField->attributes( 'size' ); if ( ! $size ) { $size = 45; } foreach ( array_keys( $fieldValuesInDb ) as $k ) { $strippedContent = trim( $fieldValuesInDb[$k]->text ); if ( cbIsoUtf_strlen( $strippedContent ) > $size ) { $strippedContent = cbIsoUtf_substr( $strippedContent, 0, $size ) . '...'; } $fieldValuesInDb[$k]->text = $strippedContent; } } } } if ( $fieldValuesInDb ) { foreach ( array_keys( $fieldValuesInDb ) as $k ) { $dbOptTranslate = ( isset( $fieldValuesInDb[$k]->translate ) ? $fieldValuesInDb[$k]->translate : $optTranslate ); $options[] = $this->_list_make_option( $dbOptTranslate, $fieldValuesInDb[$k]->value, ( $fieldValuesInDb[$k]->text !== '' ? $fieldValuesInDb[$k]->text : $fieldValuesInDb[$k]->value ) ); } } } } elseif ( $option->getName() == 'if' ) { if ( $option->attributes( 'type' ) == 'showhide' ) { $ifName = ( $this->_htmlId( $control_name, $option ) . $option->attributes( 'operator' ) . $option->attributes( 'value' ) . $option->attributes( 'valuetype' ) ); $this->_jsif[$ifName]['element'] = $option; $this->_jsif[$ifName]['control_name'] = $control_name; $this->_jsif[$ifName]['ifname'] = $this->_htmlId( $control_name, $option ); $ifOptions = array(); $this->_list_options( $name, $node, $control_name, $ifOptions, $option->children(), $otgroups, $value, $ignoreClass, $index ); if ( $ifOptions ) foreach ( $ifOptions as $ifOption ) { if ( isset( $ifOption->id ) ) { $this->_jsif[$ifName]['show'][] = $ifOption->id; } } $options = array_merge( $options, $ifOptions ); } else { if ( $option->attributes( 'type' ) == 'permission' ) { $showInside = Access::authorised( $option ); } else { $showInside = $this->_evalIf( $option ); } if ( $showInside ) { $then = $option->getChildByNameAttributes( 'then' ); if ( $then ) { $insideParamToRender = $then; } else { $insideParamToRender = $option; } } else { $insideParamToRender = $option->getChildByNameAttributes( 'else' ); } if ( $insideParamToRender ) { $this->_list_options( $name, $node, $control_name, $options, $insideParamToRender->children(), $otgroups, $value, $ignoreClass, $index ); } } } } }
/** * View for <param type="private" class="cbpaidParamsExt" method="data">... * * @param string $value Stored Data of Model Value associated with the element * @param ParamsInterface $pluginParams Main settigns parameters of the plugin * @param string $name Name attribute * @param CBSimpleXMLElement $param This XML node * @param string $control_name Name of the control * @param string $control_name_name css id-encode of the names of the controls surrounding this node * @param boolean $view TRUE: view, FALSE: edit * @param cbpaidTable $modelOfData Data of the Model corresponding to this View * @param cbpaidTable[] $modelOfDataRows Displayed Rows if it is a table * @param int $modelOfDataRowsNumber Total Number of rows * @return null|string */ public function data($value, &$pluginParams, $name, &$param, $control_name, $control_name_name, $view, &$modelOfData, &$modelOfDataRows, &$modelOfDataRowsNumber) { global $_CB_database; $data = $param->getElementByPath('data'); if ($data) { $dataTable = $data->attributes('table'); if (!$dataTable) { if (is_object($modelOfData) && $modelOfData instanceof TableInterface) { $dataTable = $modelOfData->getTableName(); } elseif (is_object($modelOfData) && isset($modelOfData->_tbl)) { $dataTable = $modelOfData->_tbl; } else { $dataTable = null; } } $xmlsql = new XmlQuery($_CB_database, $dataTable, $pluginParams); $xmlsql->setExternalDataTypeValues('modelofdata', $modelOfData); $xmlsql->process_orderby($data->getElementByPath('orderby')); // <data><orderby><field> fields $xmlsql->process_fields($param); // <data><rows><field> fields $xmlsql->process_where($data->getElementByPath('where')); // <data><where><column> fields $value = $xmlsql->queryloadResult(); // get the value if ($view) { if ($value === null) { $value = $param->attributes('default'); } return htmlspecialchars($value); } else { return '<input name="' . $control_name_name . '" type="text" id="' . $control_name_name . '" value="' . htmlspecialchars($value) . '"' . $this->_title($param) . ' />'; } } return null; }
/** * Prepares the XML-SQL Query * * @param boolean $allFields * @return XmlQuery */ protected function &_prepareXmlSqlQuery($allFields = true) { $xmlsql = new XmlQuery($this->_db, $this->table, $this->_pluginParams); if ($allFields === false) { // in case of complex where, we might still need the joins and AS values: foreach ($this->_filterPossibilitesArray as $value) { // <filters><filter> (preprocessed xml above) if (!$this->isValueEmpty($value['internalvalue'])) { /** @var SimpleXMLElement[] $value */ $where = $value['xml']->getElementByPath('data/where'); /** @var array $value */ if ($where) { $allFields = true; break; } } } } if ($allFields) { $xmlsql->process_fields($this->listFieldsRows); // <fields><field> fields // now check for orderings : if ($this->listFieldsRows) { foreach ($this->listFieldsRows->children() as $field) { /** @var $field SimpleXMLElement */ $orderinggroups = $field->getElementByPath('orderinggroups'); /** @var $orderinggroups SimpleXMLElement|null */ if ($orderinggroups) { foreach ($orderinggroups->children() as $group) { /** @var $group SimpleXMLElement */ if ($group->getName() == 'ordering') { if (count($group->children()) > 0) { $xmlsql->process_field($group); } } } } } } } else { if ($this->listFieldsRows) { $fieldsToProcess = array(); if ($this->search) { // search string defined: we need to process the corresponding fields: foreach ($this->quicksearchfields->children() as $searchField) { /** @var $searchField SimpleXMLElement */ if ($searchField->getName() == 'field') { $searchFieldName = $searchField->attributes('name'); if ($searchFieldName) { $fieldsToProcess[$searchFieldName] = true; } } } } if ($this->orderby) { // orderby string defined: we need to process the corresponding fields: foreach ($this->orderbyfields->children() as $orderField) { /** @var SimpleXMLElement $orderField */ if ($orderField->getName() == 'field') { $orderFieldName = $orderField->attributes('name'); if ($orderFieldName) { $fieldsToProcess[$orderFieldName] = true; } } elseif ($orderField->getName() == 'ordergroup') { foreach ($orderField->children() as $orderGroup) { if ($orderGroup->getName() == 'field') { $orderFieldName = $orderGroup->attributes('name'); if ($orderFieldName) { $fieldsToProcess[$orderFieldName] = true; } } } } } } foreach ($this->_filterPossibilitesArray as $value) { // <filters><filter> (preprocessed xml above) if (!$this->isValueEmpty($value['internalvalue'])) { // filtering defined, need to process field: if (is_array($value['valuefield'])) { foreach ($value['valuefield'] as $valueField) { $fieldsToProcess[$valueField] = true; } } else { $fieldsToProcess[$value['valuefield']] = true; } } } foreach (array_keys($fieldsToProcess) as $fName) { $selectField = $this->listFieldsRows->getChildByNameAttr('field', 'name', $fName); if ($selectField) { $xmlsql->process_field($selectField); } else { // trying to assume it's in the main table... // most times it's ok: no error: trigger_error( sprintf( 'TableBrowser: Notice: trying to select field '%s' which is not in the fields list at main level.', $fName ), E_USER_NOTICE ); } } } } $xmlsql->process_orderby($this->orderbyfields, $this->orderby); // <orderby><field> fields $xmlsql->process_search_string($this->quicksearchfields, $this->search); // <quicksearch><field> fields $xmlsql->process_where($this->whereColumns); // <where><column> fields $xmlsql->process_groupby($this->groupbyfields); // <groupby><field> fields foreach ($this->_filterPossibilitesArray as $value) { // <filters><filter> (preprocessed xml above) if (!$this->isValueEmpty($value['internalvalue'])) { $this->_filtered = true; if ($value['valuetype']) { $valueType = $value['valuetype']; } else { if (strpos($value['basetype'], ':') === false) { $valueType = 'xml:' . $value['basetype']; } else { $valueType = $value['basetype']; } } $xmlsql->process_filter($value['xml'], $value, $valueType); /* $where = $value['xml']->getElementByPath( 'data/where'); if ( $where ) { $saveReverse = $xmlsql->setReverse( true ); // $Tdata = $value['xml']->getElementByPath( 'data/where'); // $xmlsql->process_data( $Tdata ); $xmlsql->process_where( $where, $value ); $xmlsql->setReverse( $saveReverse ); } else { $joinkeys = $value['xml']->getElementByPath( 'data/joinkeys'); if ( $joinkeys ) { $data = $value['xml']->getElementByPath( 'data'); $xmlsql->changeJoinType( $data->attributes( 'name' ), $joinkeys->attributes( 'type' ) ); } else { $xmlsql->addWhere( $value['valuefield'], $value['operator'], $value['internalvalue'], $valueType ); } } */ } } return $xmlsql; }