Current Path :
/
home
/
develito
/
public_html
/
components
/
com_raforms
/
models
/
Or
Select Your Path :
Upload File :
New :
File
Dir
/home/develito/public_html/components/com_raforms/models/formresult.php
<?php /* ------------------------------------------------------------------------ # com_raforms - rootArea Forms # ------------------------------------------------------------------------ # author Markus Döhla # copyright Copyright (C) 2012 rootarea.de. All Rights Reserved. # @license - http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL # @license - Please read policy about plugins development in administrator/components/com_raforms/license-plugins.txt carefully # @license - Additional EULA on www.rootarea.de DOES NOT apply to ANY lite packages # Websites: http://www.rootarea.de # Technical Support: Forum - http://www.rootarea.de/en/forum ------------------------------------------------------------------------- */ //-- No direct access defined('_JEXEC') or die('=;)'); jimport('joomla.application.component.model'); class RAformsModelFormResult extends JModelLegacy { var $id; var $formid; var $data; var $formData; var $_pagination = null; protected $_context = 'com_raforms'; function __construct() { $app = JFactory::getApplication(); $this->params = $app->getParams(); $this->getState(); parent::__construct(); } function getId() { if (empty($this->id)) { $this->setId(); } } function setId($id = null) { $this->id = (empty($id)) ? $this->getState() : $id; $this->getData(); return $this->id; } protected function populateState($ordering = null, $direction = null) { $app = JFactory::getApplication(); $this->id = $app->getUserStateFromRequest($this->_context . '.id', 'id', 0); $formid = $app->getUserStateFromRequest($this->_context . '.formid', 'formid', $this->params->get('formid')); $paramFormid = $this->params->get('formid'); $this->formid = (!empty($paramFormid)) ? $paramFormid : $formid; // if we came from a category page, rip off alias from slug $this->formid = (strpos($this->formid, ':')) ? substr($this->formid, 0, strpos($this->formid, ':')) : $this->formid; $app->setUserState($this->_context . '.formid', $formid); // List state information. parent::populateState($ordering, $direction); } function _buildQuery() { $db = JFactory::getDBO(); //JTable::addIncludePath( JPATH_COMPONENT_ADMINISTRATOR . DIRECTORY_SEPARATOR . 'tables' ); JLoader::import( 'raform', JPATH_ADMINISTRATOR . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_raforms' . DIRECTORY_SEPARATOR . 'models' ); $raform = JModelLegacy::getInstance( 'raform', 'RAformsModel' ); $formData = $raform->getData(); $formresulttable = $this->getTable('formresultlist'); $formresulttable->initialize($db, $this->formid); $foreign_field = array(); $sql = $db->getQuery('true'); foreach ( $formData->data as $k => $field ) { if ( (array_key_exists('hidden', $field) && $field['hidden'] == 1) || (array_key_exists('nodata', $field) && $field['nodata'] == 1) ) { continue; } switch ($field['elementtype']) { case 'select': case 'checkbox': case 'radio': $foreign_field[] = $field['fieldname']; break; default: $own_field[] = $field['fieldname']; break; } } $sql->select('a.id AS id'); $sql->select('b.asset_id AS asset_id'); $sql->select('b.access AS access'); foreach ( $own_field as $k => $fname ) { $sql->select('GROUP_CONCAT(DISTINCT ' . $fname . ' SEPARATOR "\0") AS ' . $fname); //$sql->select($fname . ' AS ' . $fname); } if (count($foreign_field) > 0) { foreach ( $foreign_field as $k => $fname ) { $sql->select('GROUP_CONCAT(DISTINCT ' . $formresulttable->getTableName() . '_' . $fname . '.data SEPARATOR "\0") AS ' . $fname); //$sql->select($formresulttable->getTableName() . '_' . $fname . '.data AS ' . $fname); $sql->join('left', $formresulttable->getTableName() . '_' . $fname . ' ON a.id = ' . $formresulttable->getTableName() . '_' . $fname . '.dataset_id'); } } $sql->from($formresulttable->getTableName() . ' a'); $sql->join('left', '#__raforms b ON ' . $formresulttable->getTableNameId() . ' = b.id'); $sql->where('a.id = ' . $this->id); $sql->group('a.id'); return $sql; } function getData($formData = array()) { $db = JFactory::getDBO(); // increase max concat value to a really high value $maxConcat = 'SET group_concat_max_len = 40960'; $db->setQuery($maxConcat); $db->query($maxConcat); if (!empty($this->id)) { $query = $this->_buildQuery(); $db->setQuery($query); $data = $db->loadAssoc(); //print "<pre>"; //print_r($data); //print "</pre>"; $sortedData = array(); foreach ($data as $k => $v) { $fieldtype = preg_replace("/([^_]*)_.*/", "$1", $k); if (preg_match("#\\0#", $v)) { $data[$k] = array(); $data[$k] = preg_split("#\\0#", $v); } if (!is_array($data[$k])) { switch ($fieldtype) { case 'select': case 'checkbox': case 'radio': $data[$k] = array($v); break; } } if ( is_array( $unserialized = @unserialize( $data[$k] ) ) ) { $data[$k] = $unserialized; } // now we sort the values back to the correct page // and data / plugins array if (!isset($formData->data[$k])) { $sortedData['data'][$k] = $data[$k]; } else { $page = (isset($formData->data[$k]['page'])) ? $formData->data[$k]['page'] : 1; $isPlugin = (isset($formData->data[$k]['isPlugin']) && $formData->data[$k]['isPlugin'] == 'true') ? true : false; if (!$isPlugin) { $sortedData[$page]['data'][$k] = $data[$k]; } else { $sortedData[$page]['plugins'][$fieldtype][$k] = $data[$k]; } } } $this->data = $sortedData; } else { $this->data = array(); } return $this->data; } function getDataVar($key = null) { $this->data = $this->getData(); if (!empty($key)) { return $this->data[$key]; } else { return $this->data; } } }