/** * 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; }
/** * Loads the rows of menu * * @param SimpleXMLElement $child */ protected function _loadMenuRows(&$child) { if ($child->getName() == 'menu') { $listFieldsRows = $child->getElementByPath('fields'); $menuName = $child->attributes('name'); $this->rows[$menuName] = new Table(); if ($listFieldsRows) { foreach ($listFieldsRows->children() as $field) { /** @var $field SimpleXMLElement */ if ($field->attributes('type') == 'private') { $name = $field->attributes('name'); // $className = $field->attributes( 'class' ); // $methodName = $field->attributes( 'method' ); $value = $field->attributes('value'); $content = $value; // it will be called at rendering time: /* if ( $className && $methodName && class_exists( $className ) ) { $obj = new $className( $this->_db ); //TBD: implement the singleton similarly/calling _form_private if ( method_exists( $obj, $methodName ) ) { /* $row = $this->_modelOfData[0]; //TBD: checked.... foreach (get_object_vars($obj) as $key => $v) { if( substr( $key, 0, 1 ) != '_' ) { // internal attributes of an object are ignored if (isset($row->$key)) { $obj->$key = $row->$key; } } } * $content = $obj->$methodName( $value, $this->_pluginParams ); //TBD: pluginParams should be available by the method params() of $obj, not as function parameter } else { $content = 'Missing method ' . $methodName; } } else { $content = 'Missing class, or method in xml'; } */ $this->rows[$menuName]->{$name} = $content; } else { $xmlsql = new XmlQuery($this->_db, null, $this->_pluginParams); $xmlsql->process_field($field); $obj = null; if ($xmlsql->queryLoadObject($obj)) { // get the resulting object foreach (get_object_vars($obj) as $k => $v) { if (substr($k, 0, 1) != '_') { // internal attributes of an object are ignored $this->rows[$menuName]->{$k} = $v; } } // } else { // error in query... } } } } } }