/** * Delete the file and all associated rows (done by foreign keys) and files * $params object should be a json like * <code> * { * "pathsref": "roksprocket.providers.registered.joomla.path", * "file": "filters.xml" * } * </code> * * @param $params * * @throws #C\Exception|? * @throws RokSprocket_Exception * @return \RokCommon_Ajax_Result * * */ public function getFilters($params) { /* After everything fine, i'll handle via js and domready the call to filters ajax model Something along these lines: model: 'Filters', action: 'getData', params: JSON.encoded( [{ id1: {pathrefs: .., file: ..} }], [{ id2: {pathrefs: .., file: ..} }], [{ id3: {pathrefs: .., file: ..} }], ... ) */ $result = new RokCommon_Ajax_Result(); try { $container = RokCommon_Service::getContainer(); $filters = $params->filters; $output = array(); foreach ($filters as $filterid => $filter) { $filter_file = $container[$filter->pathsref] . '/' . $filter->file; if (!file_exists($filter_file)) { throw new RokSprocket_Exception(rc__('Unable to find filter file %s', $filter_file)); } $xmlfile = simplexml_load_file($filter_file); $outfilter = new RokCommon_Filter($xmlfile); $output[$filterid] = $outfilter->getJson(); } $result->setPayload(array('json' => $output)); } catch (Exception $e) { throw $e; } return $result; }
/** * @param $filters * * @return array */ protected function format_filters($filters) { $filter_lines = array(); if (!empty($filters)) { $root_type = $this->filter->getRootType(); if (!empty($filters)) { foreach ($filters as $row_number => $full_row) { foreach ($full_row[$root_type] as $filter_type => $filter_data) { if (!array_key_exists($filter_type, $filter_lines)) { $filter_lines[$filter_type] = array(); } $filter_lines[$filter_type][] = $filter_data; } } } } return $filter_lines; }