Esempio n. 1
0
 public function prepareCategorySelection($dynaList)
 {
     $x = new Services_Search_QueryParser($this->_db->getDbHandle());
     return $x->prepareCategorySelection($dynaList);
 }
Esempio n. 2
0
 public function filtersToXml($filterList)
 {
     $svcSearchQP = new Services_Search_QueryParser($this->_daoFactory->getConnection());
     # create the XML document
     $doc = new DOMDocument('1.0', 'utf-8');
     $doc->formatOutput = true;
     $mainElm = $doc->createElement('spotwebfilter');
     $mainElm->appendChild($doc->createElement('version', '1.0'));
     $mainElm->appendChild($doc->createElement('generator', 'SpotWeb v' . SPOTWEB_VERSION));
     $doc->appendChild($mainElm);
     $filterListElm = $doc->createElement('filters');
     foreach ($filterList as $filter) {
         $filterElm = $doc->createElement('filter');
         $filterElm->appendChild($doc->createElement('id', $filter['id']));
         $filterElm->appendChild($doc->createElement('title', $filter['title']));
         $filterElm->appendChild($doc->createElement('icon', $filter['icon']));
         $filterElm->appendChild($doc->createElement('parent', $filter['tparent']));
         $filterElm->appendChild($doc->createElement('order', $filter['torder']));
         $filterElm->appendChild($doc->createElement('enablenotify', $filter['enablenotify']));
         /* 
          * Now add the tree. We get the list of filters as a tree, but we 
          * want to keep the XML as clean as possible so we try to compress it.
          *
          * First we have to extract the tree to a list of selections, strongnots
          * and excludes
          */
         $dynaList = explode(',', $filter['tree']);
         list($categoryList, $strongNotList) = $svcSearchQP->prepareCategorySelection($dynaList);
         $treeList = explode(',', $svcSearchQP->compressCategorySelection($categoryList, $strongNotList));
         $tree = $doc->createElement('tree');
         foreach ($treeList as $treeItem) {
             if (!empty($treeItem)) {
                 # determine what type of element this is
                 $treeType = 'include';
                 if ($treeItem[0] == '~') {
                     $treeType = 'strongnot';
                     $treeItem = substr($treeItem, 1);
                 } elseif ($treeItem[1] == '!') {
                     $treeType = 'exclude';
                     $treeItem = substr($treeItem, 1);
                 }
                 # else
                 # and create the XML item
                 $treeElm = $doc->createElement('item', $treeItem);
                 $treeElm->setAttribute('type', $treeType);
                 if (!empty($treeItem)) {
                     $tree->appendChild($treeElm);
                 }
                 # if
             }
             # if
         }
         # treeItems
         $filterElm->appendChild($tree);
         /* 
          * Prepare the filtervalue list to make it usable for the XML
          */
         $tmpFilterValues = explode('&', $filter['valuelist']);
         $filterValueList = array();
         foreach ($tmpFilterValues as $filterValue) {
             $tmpFilter = explode(':', urldecode($filterValue));
             /*
              * If the filter is missing the booloper, set it to be the default
              */
             if (count($tmpFilter) == 3) {
                 // old style filter
                 $tmpFilter = array(0 => $tmpFilter[0], 1 => $tmpFilter[1], 2 => 'DEF', 3 => $tmpFilter[2]);
             }
             // if
             # and create the actual filter
             if (count($tmpFilter) >= 4) {
                 $filterValueList[] = array('fieldname' => $tmpFilter[0], 'operator' => $tmpFilter[1], 'booloper' => $tmpFilter[2], 'value' => join(":", array_slice($tmpFilter, 3)));
             }
             # if
         }
         # foreach
         /* 
          * Now add the filter items (text searches etc)
          */
         if (!empty($filterValueList)) {
             $valuesElm = $doc->createElement('values');
             foreach ($filterValueList as $filterValue) {
                 # Create the value XML item
                 $itemElm = $doc->createElement('item');
                 $itemElm->appendChild($doc->createElement('fieldname', $filterValue['fieldname']));
                 $itemElm->appendChild($doc->createElement('operator', $filterValue['operator']));
                 $itemElm->appendChild($doc->createElement('booloper', $filterValue['booloper']));
                 $itemElm->appendChild($doc->createElement('value', $filterValue['value']));
                 $valuesElm->appendChild($itemElm);
             }
             # foreach
             $filterElm->appendChild($valuesElm);
         }
         # if
         /* 
          * Add the sorting items
          */
         if (!empty($filter['sorton'])) {
             $sortElm = $doc->createElement('sort');
             $itemElm = $doc->createElement('item');
             $itemElm->appendChild($doc->createElement('fieldname', $filter['sorton']));
             $itemElm->appendChild($doc->createElement('direction', $filter['sortorder']));
             $sortElm->appendChild($itemElm);
             $filterElm->appendChild($sortElm);
         }
         # if
         $filterListElm->appendChild($filterElm);
     }
     # foreach
     $mainElm->appendChild($filterListElm);
     /*
      * Create a new result object
      */
     $result = new Dto_FormResult('success');
     $result->addData('filters', $doc->saveXML());
     return $result;
 }