Example #1
0
 /**
  * Shows the data formatted for the list view
  *
  * @param   string   $data     Elements data
  * @param   stdClass &$thisRow All the data in the lists current row
  * @param   array    $opts     Rendering options
  *
  * @return  string    formatted value
  */
 public function renderListData($data, stdClass &$thisRow, $opts = array())
 {
     $data = FabrikWorker::JSONtoData($data, true);
     $layout = $this->getLayout('list');
     $displayData = new stdClass();
     $displayData->data = $data;
     return $layout->render($displayData);
 }
Example #2
0
 /**
  * Render uploaded image
  *
  * @param   object &$model  Element model
  * @param   object &$params Element params
  * @param   string $file    Row data for this element
  * @param   object $thisRow All row's data
  *
  * @return  void
  */
 public function render(&$model, &$params, $file, $thisRow = null)
 {
     /*
      * $$$ hugh - added this hack to let people use elementname__title as a title element
      * for the image, to show in the lightbox popup.
      * So we have to work out if we're being called from a table or form
      */
     $formModel = $model->getFormModel();
     $title = basename($file);
     if ($params->get('fu_title_element') == '') {
         $title_name = $model->getFullName(true, false) . '__title';
     } else {
         $title_name = str_replace('.', '___', $params->get('fu_title_element'));
     }
     if ($this->inTableView) {
         if (array_key_exists($title_name, $thisRow)) {
             $title = $thisRow->{$title_name};
         }
     } else {
         if (is_object($formModel)) {
             if (is_array($formModel->data)) {
                 $title = FArrayHelper::getValue($formModel->data, $title_name, '');
             }
         }
     }
     $bits = FabrikWorker::JSONtoData($title, true);
     $title = FArrayHelper::getValue($bits, $model->_repeatGroupCounter, $title);
     $title = htmlspecialchars(strip_tags($title, ENT_NOQUOTES));
     $file = $model->getStorage()->getFileUrl($file);
     $fullSize = $file;
     if (!$this->fullImageInRecord($params)) {
         if ($params->get('fileupload_crop')) {
             $file = $model->getStorage()->_getCropped($fullSize);
         } else {
             $file = $model->getStorage()->_getThumb($file);
         }
     }
     list($width, $height) = $this->imageDimensions($params);
     $file = $model->storage->preRenderPath($file);
     $n = $this->inTableView ? '' : $model->getElement()->name;
     if ($params->get('restrict_lightbox', 1) == 0) {
         $n = '';
     }
     $layout = $model->getLayout('image');
     $displayData = new stdClass();
     $displayData->lightboxAttrs = FabrikHelperHTML::getLightboxAttributes($title, $n);
     $displayData->fullSize = $model->storage->preRenderPath($fullSize);
     $displayData->file = $file;
     $displayData->makeLink = $params->get('make_link', true) && !$this->fullImageInRecord($params);
     $displayData->title = $title;
     $displayData->isJoin = $model->isJoin();
     $displayData->width = $width;
     $displayData->showImage = $params->get('fu_show_image');
     $displayData->inListView = $this->inTableView;
     $displayData->height = $height;
     $displayData->isSlideShow = $this->inTableView && $params->get('fu_show_image_in_table', '0') == '2' || !$this->inTableView && !$formModel->isEditable() && $params->get('fu_show_image', '0') == '3';
     $this->output = $layout->render($displayData);
 }
Example #3
0
 /**
  * Render RSS feed format
  *
  * @param   string  $data      Elements data
  * @param   object  &$thisRow  All the data in the lists current row
  *
  * @return  string	Formatted value
  */
 public function renderListData_feed($data, &$thisRow)
 {
     $str = '';
     $data = FabrikWorker::JSONtoData($data, true);
     foreach ($data as $d) {
         $str .= $this->_georss($d);
     }
     return $str;
 }
Example #4
0
 /**
  * shows the data formatted for the table view
  * @param string data
  * @param object all the data in the tables current row
  * @return string formatted value
  */
 function renderListData($data, $oAllRowsData)
 {
     $data = FabrikWorker::JSONtoData($data, true);
     $str = '';
     foreach ($data as $d) {
         $str .= "<div style=\"width:15px;height:15px;background-color:rgb({$d})\"></div>";
     }
     return $str;
 }
Example #5
0
	/**
	 * shows the data formatted for the table view
	 * @param string data
	 * @param object all the data in the tables current row
	 * @return string formatted value
	 */

	function renderListData($data, $oAllRowsData) {
		$str = '';
		$data = FabrikWorker::JSONtoData($data, true);
		//$data = explode(GROUPSPLITTER, $data);
		foreach ($data as $d) {
			$str .= $this->_renderListData($d, $oAllRowsData);
		}
		return $str;
	}
Example #6
0
 /**
  * Shows the data formatted for the list view
  *
  * @param   string  $data      elements data
  * @param   object  &$thisRow  all the data in the lists current row
  *
  * @return  string	formatted value
  */
 public function renderListData($data, &$thisRow)
 {
     $data = FabrikWorker::JSONtoData($data, true);
     $str = '';
     foreach ($data as $d) {
         $str .= '<div style="width:15px;height:15px;background-color:rgb(' . $d . ')"></div>';
     }
     return $str;
 }
Example #7
0
 /**
  * Display the list
  *
  * @param   string $tpl template
  *
  * @return  void
  */
 public function display($tpl = null)
 {
     // Initialise variables.
     $model = $this->getModel();
     $this->form = $this->get('Form');
     $this->item = $this->get('Item');
     $formModel = $this->get('FormModel');
     $formModel->setId($this->item->form_id);
     $this->state = $this->get('State');
     $this->js = $model->getJs();
     $this->addToolbar();
     if ($this->item->id == 0) {
         $this->order_by = array(FText::_('COM_FABRIK_AVAILABLE_AFTER_SAVE'));
         $this->group_by = FText::_('COM_FABRIK_AVAILABLE_AFTER_SAVE');
     } else {
         $this->order_by = array();
         $feListModel = $formModel->getListModel();
         $orderBys = $feListModel->getOrderBys();
         foreach ($orderBys as $orderBy) {
             $this->order_by[] = $formModel->getElementList('order_by[]', $orderBy, true, false, false, 'id');
         }
         if (empty($this->order_by)) {
             $this->order_by[] = $formModel->getElementList('order_by[]', '', true, false, false, 'id');
         }
         $orderDir[] = JHTML::_('select.option', 'ASC', FText::_('COM_FABRIK_ASCENDING'));
         $orderDir[] = JHTML::_('select.option', 'DESC', FText::_('COM_FABRIK_DESCENDING'));
         $orderdirs = FabrikWorker::JSONtoData($this->item->order_dir, true);
         $this->order_dir = array();
         $attribs = 'class="inputbox" size="1" ';
         foreach ($orderdirs as $orderdir) {
             $this->order_dir[] = JHTML::_('select.genericlist', $orderDir, 'order_dir[]', $attribs, 'value', 'text', $orderdir);
         }
         if (empty($this->order_dir)) {
             $this->order_dir[] = JHTML::_('select.genericlist', $orderDir, 'order_dir[]', $attribs, 'value', 'text', '');
         }
         $this->group_by = $formModel->getElementList('group_by', $this->item->group_by, true, false, false);
     }
     FabrikAdminHelper::setViewLayout($this);
     $srcs = FabrikHelperHTML::framework();
     $srcs['Fabrik'] = FabrikHelperHTML::mediaFile('fabrik.js');
     $srcs['NameSpace'] = 'administrator/components/com_fabrik/views/namespace.js';
     $srcs['PluginManager'] = 'administrator/components/com_fabrik/views/pluginmanager.js';
     $srcs['AdminList'] = 'administrator/components/com_fabrik/views/list/tmpl/adminlist.js';
     $srcs['ListForm'] = 'administrator/components/com_fabrik/views/listform.js';
     $srcs['adminFilters'] = 'administrator/components/com_fabrik/views/list/tmpl/admin-filters.js';
     $shim = array();
     $dep = new stdClass();
     $dep->deps = array('admin/pluginmanager');
     $shim['admin/list/tmpl/adminlist'] = $dep;
     $shim['adminfields/tables'] = $dep;
     FabrikHelperHTML::iniRequireJS($shim);
     FabrikHelperHTML::script($srcs, $this->js);
     parent::display($tpl);
 }
Example #8
0
	/**
	 * shows the data formatted for the table view
	 * @param string data
	 * @param object all the data in the tables current row
	 * @return string formatted value
	 */

	function renderListData($data, $oAllRowsData)
	{
		$user = JFactory::getUser();
		$params = $this->getParams();
		$ext = $params->get('rating-pngorgif', '.png');
		$imagepath = JUri::root().'/plugins/fabrik_element/rating/images/';
		$data = FabrikWorker::JSONtoData($data, true);


		$url = COM_FABRIK_LIVESITE.'index.php?option=com_fabrik&amp;format=raw&amp;view=plugin&amp;task=pluginAjax&amp;g=element&amp;plugin=rating&amp;method=ajax_rate&amp;element_id='.$this->getElement()->id;
		FabrikHelperHTML::addPath(JPATH_SITE.DS.'plugins/fabrik_element/rating/images/', 'image', 'list', false);
		$insrc = FabrikHelperHTML::image("star_in$ext", 'list', @$this->tmpl, '', true);
		$outsrc = FabrikHelperHTML::image("star_out$ext", 'list', @$this->tmpl, '', true);

		$url .= '&amp;row_id='.$oAllRowsData->__pk_val;
		$url .= '&amp;elementname='.$this->getElement()->id;
		$url .= '&amp;userid='.$user->get('id');
		$url .= '&amp;nonajax=1';
		$row_id = isset($oAllRowsData->__pk_val) ? $oAllRowsData->__pk_val : $oAllRowsData->id;
		$ids = JArrayHelper::getColumn($this->getListModel()->getData(), '__pk_val');
		$canRate = $this->canRate($row_id, $ids);
		for ($i=0; $i <count($data); $i++) {
			$avg = $this->_renderListData($data[$i], $oAllRowsData);
			if (!$canRate) {
				$atpl = '';
				$a2 = '';
			} else {
				$atpl = "<a href=\"{$url}&amp;rating={r}\">";
				$a2 = "</a>";
			}
			$str = '<div style="width:100px">';
			for ($s=0; $s<$avg; $s++) {
				$r = $s+1;
				$a = str_replace('{r}', $r, $atpl);
				$str .= "$a<img src=\"$imagepath"."star_in$ext\" style=\"padding-left:1px;\" alt=\"$r\" class=\"starRating rate_$r\"/>$a2";
			}
			for ($s=$avg; $s<5; $s++) {
				$r = $s+1;
				$a = str_replace('{r}', $r, $atpl);
				$str .= "$a<img src=\"$imagepath"."star_out$ext\" style=\"padding-left:1px;\" alt=\"$r\" class=\"starRating rate_$r\"/>$a2";
			}
			if ($params->get('rating-mode') != 'creator-rating') {
				$str .= "<div class=\"ratingMessage\">$avg</div>";
			}
			$str .= '</div>';
			$data[$i] = $str;
		}
		//$data = implode(GROUPSPLITTER, $data);
		$data = json_encode($data);

		return parent::renderListData($data, $oAllRowsData);
	}
Example #9
0
 /**
  * Shows the data formatted for the list view
  *
  * @param   string    $data      Elements data
  * @param   stdClass  &$thisRow  All the data in the lists current row
  * @param   array     $opts      Rendering options
  *
  * @return  string	formatted value
  */
 public function renderListData($data, stdClass &$thisRow, $opts = array())
 {
     $data = FabrikWorker::JSONtoData($data, true);
     $params = $this->getParams();
     foreach ($data as &$d) {
         $d = $this->format($d);
         $this->_guessLinkType($d, $thisRow);
         if ($params->get('render_as_qrcode', '0') === '1') {
             if (!empty($d)) {
                 $d = $this->qrCodeLink($thisRow);
             }
         }
     }
     return parent::renderListData($data, $thisRow, $opts);
 }
Example #10
0
 /**
  * Shows the data formatted for the list view
  *
  * @param   string  $data      elements data
  * @param   object  &$thisRow  all the data in the lists current row
  *
  * @return  string	formatted value
  */
 public function renderListData($data, &$thisRow)
 {
     $user = JFactory::getUser();
     $params = $this->getParams();
     $ext = $params->get('rating-pngorgif', '.png');
     $imagepath = JUri::root() . '/plugins/fabrik_element/rating/images/';
     $data = FabrikWorker::JSONtoData($data, true);
     $url = COM_FABRIK_LIVESITE . 'index.php?option=com_fabrik&amp;format=raw&amp;view=plugin&amp;task=pluginAjax&amp;g=element&amp;plugin=rating&amp;method=ajax_rate&amp;element_id=' . $this->getElement()->id;
     FabrikHelperHTML::addPath(COM_FABRIK_BASE . 'plugins/fabrik_element/rating/images/', 'image', 'list', false);
     $insrc = FabrikHelperHTML::image("star_in{$ext}", 'list', @$this->tmpl, array(), true);
     $outsrc = FabrikHelperHTML::image("star_out{$ext}", 'list', @$this->tmpl, array(), true);
     $url .= '&amp;row_id=' . $thisRow->__pk_val;
     $url .= '&amp;elementname=' . $this->getElement()->id;
     $url .= '&amp;userid=' . $user->get('id');
     $url .= '&amp;nonajax=1';
     $row_id = isset($thisRow->__pk_val) ? $thisRow->__pk_val : $thisRow->id;
     $ids = JArrayHelper::getColumn($this->getListModel()->getData(), '__pk_val');
     $canRate = $this->canRate($row_id, $ids);
     for ($i = 0; $i < count($data); $i++) {
         $avg = $this->_renderListData($data[$i], $thisRow);
         if (!$canRate) {
             $atpl = '';
             $a2 = '';
         } else {
             $atpl = "<a href=\"{$url}&amp;rating={r}\">";
             $a2 = "</a>";
         }
         $str = array();
         $str[] = '<div style="width:101px">';
         for ($s = 0; $s < $avg; $s++) {
             $r = $s + 1;
             $a = str_replace('{r}', $r, $atpl);
             $str[] = $a . '<img src="' . $imagepath . 'star_in' . $ext . '" style="padding-left:1px;" alt="' . $r . '" class="starRating rate_' . $r . '"/>' . $a2;
         }
         for ($s = $avg; $s < 5; $s++) {
             $r = $s + 1;
             $a = str_replace('{r}', $r, $atpl);
             $str[] = $a . '<img src="' . $imagepath . 'star_out' . $ext . '" style="padding-left:1px;" alt="' . $r . '" class="starRating rate_' . $r . '"/>' . $a2;
         }
         if ($params->get('rating-mode') != 'creator-rating') {
             $str[] = '<div class="ratingMessage">' . $avg . '</div>';
         }
         $str[] = '</div>';
         $data[$i] = implode("\n", $str);
     }
     $data = json_encode($data);
     return parent::renderListData($data, $thisRow);
 }
Example #11
0
 /**
  * Shows the data formatted for the list view
  *
  * @param   string    $data      Elements data
  * @param   stdClass  &$thisRow  All the data in the lists current row
  * @param   array     $opts      Rendering options
  *
  * @return  string	formatted value
  */
 public function renderListData($data, stdClass &$thisRow, $opts = array())
 {
     $params = $this->getParams();
     $formId = $this->getFormModel()->getId();
     $listId = $this->getListModel()->getId();
     $rowId = isset($thisRow->__pk_val) ? $thisRow->__pk_val : $thisRow->id;
     if ($params->get('rating-mode') !== 'creator-rating') {
         $d = $this->getListModel()->getData();
         $ids = ArrayHelper::getColumn($d, '__pk_val');
         list($data, $total) = $this->getRatingAverage($data, $listId, $formId, $rowId, $ids);
     }
     $data = FabrikWorker::JSONtoData($data, true);
     FabrikHelperHTML::addPath(COM_FABRIK_BASE . 'plugins/fabrik_element/rating/images/', 'image', 'list', false);
     $colData = $this->getListModel()->getData();
     $ids = ArrayHelper::getColumn($colData, '__pk_val');
     $canRate = $this->canRate($rowId, $ids);
     for ($i = 0; $i < count($data); $i++) {
         $avg = $this->_renderListData($data[$i], $thisRow);
         $atpl = '';
         $a2 = '';
         $str = array();
         $str[] = '<div style="width:101px;position:relative;">';
         for ($s = 0; $s < $avg; $s++) {
             $r = $s + 1;
             $a = str_replace('{r}', $r, $atpl);
             $imgOpts = array('icon-class' => 'starRating rate_' . $r);
             $imgOpts['data-fabrik-rating'] = $r;
             $img = FabrikHelperHTML::image("star.png", 'list', @$this->tmpl, $imgOpts);
             $str[] = $a . $img . $a2;
         }
         for ($s = $avg; $s < 5; $s++) {
             $r = $s + 1;
             $a = str_replace('{r}', $r, $atpl);
             $imgOpts = array('icon-class' => 'starRating rate_' . $r);
             $imgOpts['data-fabrik-rating'] = $r;
             $img = FabrikHelperHTML::image("star-empty.png", 'list', @$this->tmpl, $imgOpts);
             $str[] = $a . $img . $a2;
         }
         if ($params->get('rating-mode') != 'creator-rating') {
             $str[] = '<div class="ratingMessage">' . $avg . '</div>';
         }
         $str[] = '</div>';
         $data[$i] = implode("\n", $str);
     }
     $data = json_encode($data);
     return parent::renderListData($data, $thisRow, $opts);
 }
Example #12
0
 /**
  * Display the list
  */
 public function display($tpl = null)
 {
     FabrikHelperHTML::framework();
     // Initialiase variables.
     $this->form = $this->get('Form');
     $this->item = $this->get('Item');
     $formModel = $this->get('FormModel');
     $formModel->setId($this->item->form_id);
     $this->state = $this->get('State');
     $this->js = $this->get('Js');
     // Check for errors.
     if (count($errors = $this->get('Errors'))) {
         JError::raiseError(500, implode("\n", $errors));
         return false;
     }
     $this->addToolbar();
     if ($this->item->id == 0) {
         $this->order_by = array(JText::_('COM_FABRIK_AVAILABLE_AFTER_SAVE'));
         $this->group_by = JText::_('COM_FABRIK_AVAILABLE_AFTER_SAVE');
     } else {
         $this->order_by = array();
         $orderbys = FabrikWorker::JSONtoData($this->item->order_by, true);
         foreach ($orderbys as $orderby) {
             $this->order_by[] = $formModel->getElementList('order_by[]', $orderby, true, false, false);
         }
         if (empty($this->order_by)) {
             $this->order_by[] = $formModel->getElementList('order_by[]', '', true, false, false);
         }
         $orderDir[] = JHTML::_('select.option', 'ASC', JText::_('COM_FABRIK_ASCENDING'));
         $orderDir[] = JHTML::_('select.option', 'DESC', JText::_('COM_FABRIK_DESCENDING'));
         $orderdirs = FabrikWorker::JSONtoData($this->item->order_dir, true);
         $this->order_dir = array();
         foreach ($orderdirs as $orderdir) {
             $this->order_dir[] = JHTML::_('select.genericlist', $orderDir, 'order_dir[]', 'class="inputbox" size="1" ', 'value', 'text', $orderdir);
         }
         if (empty($this->order_dir)) {
             $this->order_dir[] = JHTML::_('select.genericlist', $orderDir, 'order_dir[]', 'class="inputbox" size="1" ', 'value', 'text', '');
         }
         $this->group_by = $formModel->getElementList('group_by', $this->item->group_by, true, false, false);
     }
     parent::display($tpl);
 }
Example #13
0
 /**
  * Shows the data formatted for the list view
  *
  * @param   string    $data      elements data
  * @param   stdClass  &$thisRow  all the data in the lists current row
  *
  * @return  string	formatted value
  */
 public function renderListData($data, stdClass &$thisRow)
 {
     $params = $this->getParams();
     $data = FabrikWorker::JSONtoData($data, true);
     $format = $params->get('text_format_string');
     foreach ($data as &$d) {
         $d = $this->numberFormat($d);
         if ($format != '') {
             $d = sprintf($format, $d);
         }
         if ($params->get('password') == "1") {
             $d = str_pad('', JString::strlen($d), '*');
         }
         $this->_guessLinkType($d, $thisRow, 0);
         if ($params->get('render_as_qrcode', '0') === '1') {
             $d = $this->qrCodeLink($d, $thisRow);
         }
     }
     return parent::renderListData($data, $thisRow);
 }
Example #14
0
 /**
  * @param object element model
  * @param object element params
  * @param string row data for this element
  * @param object all row's data
  */
 function render(&$model, &$params, $file, $oAllRowsData = null)
 {
     // $$$ hugh - added this hack to let people use elementname__title as a title element
     // for the image, to show in the lightbox popup.
     // So we have to work out if we're being called from a table or form
     $title = basename($file);
     if ($params->get('fu_title_element') == '') {
         $title_name = $model->getFullName(true, true, false) . '__title';
     } else {
         $title_name = str_replace('.', '___', $params->get('fu_title_element'));
     }
     if (JRequest::getVar('view') == 'list') {
         $listModel =& $model->getlistModel();
         if (array_key_exists($title_name, $oAllRowsData)) {
             $title = $oAllRowsData->{$title_name};
         }
     } else {
         if (is_object($model->_form)) {
             if (is_array($model->_form->_data)) {
                 $group =& $model->getGroup();
                 if ($group->isJoin()) {
                     $join_id = $group->getGroup()->join_id;
                     if (isset($model->_form->_data['join'])) {
                         if (array_key_exists($join_id, $model->_form->_data['join'])) {
                             if (array_key_exists($title_name, $model->_form->_data['join'][$join_id])) {
                                 if (array_key_exists($model->_repeatGroupCounter, $model->_form->_data['join'][$join_id][$title_name])) {
                                     $title = $model->_form->_data['join'][$join_id][$title_name][$model->_repeatGroupCounter];
                                 }
                             }
                         }
                     }
                 } else {
                     if (array_key_exists($title_name, $model->_form->_data)) {
                         $title = $model->_form->_data[$title_name];
                     }
                 }
             }
         }
     }
     $bits = FabrikWorker::JSONtoData($title, true);
     $title = JArrayHelper::getValue($bits, $model->_repeatGroupCounter, $title);
     $title = htmlspecialchars(strip_tags($title, ENT_NOQUOTES));
     $element =& $model->getElement();
     $file = $model->storage->getFileUrl($file);
     $fullSize = $file;
     $width = $params->get('fu_main_max_width');
     $height = $params->get('fu_main_max_height');
     if (!$this->fullImageInRecord($params)) {
         if ($params->get('fileupload_crop')) {
             $width = $params->get('fileupload_crop_width');
             $height = $params->get('fileupload_crop_height');
             $file = $model->storage->_getCropped($fullSize);
         } else {
             $width = $params->get('thumb_max_width');
             $height = $params->get('thumb_max_height');
             $file = $model->storage->_getThumb($file);
         }
     }
     if ($model->isJoin()) {
         $this->output .= '<div class="fabrikGalleryImage" style="width:' . $width . 'px;height:' . $height . 'px; vertical-align: middle;text-align: center;">';
     }
     $img = "<img class=\"fabrikLightBoxImage\" src=\"{$file}\" alt=\"" . strip_tags($element->label) . "\" />";
     if ($params->get('make_link', true) && !$this->fullImageInRecord($params)) {
         $this->output .= "<a href=\"{$fullSize}\" rel=\"lightbox[]\" title=\"{$title}\">{$img}</a>";
     } else {
         $this->output .= $img;
     }
     if ($model->isJoin()) {
         $this->output .= '</div>';
     }
 }
Example #15
0
 /**
  * Shows the data formatted for the list view
  *
  * @param   string    $data      Elements data
  * @param   stdClass  &$thisRow  All the data in the lists current row
  * @param   array     $opts      Rendering options
  *
  * @return  string	formatted value
  */
 public function renderListData($data, stdClass &$thisRow, $opts = array())
 {
     $w = new FabrikWorker();
     $data = FabrikWorker::JSONtoData($data, true);
     $params = $this->getParams();
     $pathset = false;
     foreach ($data as $d) {
         if (strstr($d, '/')) {
             $pathset = true;
             break;
         }
     }
     if ($data === '' || empty($data) || !$pathset) {
         // No data so default to image (or simple image name stored).
         $iPath = $params->get('imagepath');
         if (!strstr($iPath, '/')) {
             // Single file specified so find it in tmpl folder
             $data = (array) FabrikHelperHTML::image($iPath, 'list', @$this->tmpl, array(), true);
         } else {
             $data = (array) $iPath;
         }
     }
     $selectImage_root_folder = $this->rootFolder();
     // $$$ hugh - tidy up a bit so we don't have so many ///'s in the URL's
     $selectImage_root_folder = JString::ltrim($selectImage_root_folder, '/');
     $selectImage_root_folder = JString::rtrim($selectImage_root_folder, '/');
     $selectImage_root_folder = $selectImage_root_folder === '' ? '' : $selectImage_root_folder . '/';
     $showImage = $params->get('show_image_in_table', 0);
     $linkURL = $params->get('link_url', '');
     if (empty($data) || $data[0] == '') {
         $data[] = $params->get('imagepath');
     }
     for ($i = 0; $i < count($data); $i++) {
         if ($showImage) {
             // $$$ rob 30/06/2011 - say if we import via csv a url to the image check that and use that rather than the relative path
             if (JString::substr($data[$i], 0, 4) == 'http') {
                 $src = $data[$i];
             } else {
                 $data[$i] = JString::ltrim($data[$i], '/');
                 $src = COM_FABRIK_LIVESITE . $selectImage_root_folder . $data[$i];
             }
             $data[$i] = '<img src="' . $src . '" alt="' . $data[$i] . '" />';
         }
         if ($linkURL) {
             $data[$i] = '<a href="' . $linkURL . '" target="_blank">' . $data[$i] . '</a>';
         }
         $data[$i] = $w->parseMessageForPlaceHolder($data[$i], $thisRow);
     }
     $data = json_encode($data);
     return parent::renderListData($data, $thisRow, $opts);
 }
Example #16
0
 /**
  * used by elements with sub-options
  *
  * $$$ hugh - started working on adding this to elementlist, as we need to handle
  * JSON-ified options for multi-select elements, which the main element model getLabelForValue()
  * doesn't do.  But I need to sort out how this gets handled in rendering as well.
  *
  * @param   string  $v             Value
  * @param   string  $defaultLabel  Default label
  *
  * @return  string	label
  */
 public function notreadyyet_getLabelForValue($v, $defaultLabel = '')
 {
     $labels = $this->getSubOptionLabels();
     $multiple = $this->isMultiple();
     $vals = is_array($v) ? $v : FabrikWorker::JSONtoData($v, true);
     foreach ($vals as $val) {
         $l = FArrayHelper::getValue($labels, $val, $defaultLabel);
         if (trim($l) !== '') {
             if ($multiple && $this->renderWithHTML) {
                 $lis[] = '<li>' . $l . '</li>';
             } else {
                 $lis[] = $l;
             }
         }
     }
     $return = '';
     if (!empty($lis)) {
         $return = $multiple && $this->renderWithHTML ? '<ul class="fabrikRepeatData">' . implode(' ', $lis) . '</ul>' : implode(' ', $lis);
     }
     /**
      * $$$ rob if we allow adding to the drop-down but not recording
      * then there will be no $key set to revert to the $val instead
      */
     /*
     if ($v === $params->get('sub_default_value'))
     {
     $v = $params->get('sub_default_label');
     }
     return ($key === false) ? $v : FArrayHelper::getValue($labels, $key, $defaultLabel);
     */
     return $return;
 }
Example #17
0
 /**
  * Create an export node presuming that the array has a params property which should be split into a child
  * node
  *
  * @param   DomDocument $doc
  * @param   string      $nodeName
  * @param   array       $data
  * @param   array       $ignore Array of keys to ignore when creating attributes
  *
  * @return DOMElement
  */
 public static function buildExportNode($doc, $nodeName, $data, $ignore = array('created_by', 'created_by_alias', 'group_id', 'modified', 'modified_by', 'checked_out', 'checked_out_time'))
 {
     $node = $doc->createElement($nodeName);
     foreach ($data as $key => $value) {
         if (in_array($key, $ignore)) {
             continue;
         }
         // Ensure elements are never listed as children.
         if ($key === 'parent_id') {
             $value = '0';
         }
         if ($key === 'params') {
             $params = FabrikWorker::JSONtoData($value);
             $p = $doc->createElement('params');
             foreach ($params as $pKey => $pValue) {
                 if (in_array($pKey, $ignore)) {
                     continue;
                 }
                 if (is_string($pValue) || is_numeric($pValue)) {
                     $p->setAttribute($pKey, $pValue);
                 } else {
                     $p->setAttribute($pKey, json_encode($pValue));
                 }
             }
             $node->appendChild($p);
         } else {
             $node->setAttribute($key, $value);
         }
     }
     return $node;
 }
Example #18
0
 /**
  * can be overwritten by plugin class
  * determines the value for the element in the form view
  * @param array data
  * @param int when repeating joinded groups we need to know what part of the array to access
  * @param array options
  * @return string default date value in GMT time
  */
 function getValue($data, $repeatCounter = 0, $opts = array())
 {
     //@TODO: allow {now} and {today} to be replaced with current datetime
     if (!isset($this->defaults) || is_null($this->defaults)) {
         $this->defaults = array();
     }
     if (!array_key_exists($repeatCounter, $this->defaults)) {
         $groupModel =& $this->getGroup();
         $group =& $groupModel->getGroup();
         $joinid = $group->join_id;
         $element =& $this->getElement();
         $params =& $this->getParams();
         $store_as_local = (int) $params->get('date_store_as_local', 0);
         if ($params->get('date_alwaystoday', false)) {
             //$value = JFactory::getDate()->toMySQL(false);
             // $$$ rob fix for http://fabrik.unfuddle.com/projects/17220/tickets/by_number/700?cycle=true
             if ($store_as_local) {
                 $localDate = date('Y-m-d H:i:s');
                 $date = JFactory::getDate(strtotime($localDate));
             } else {
                 $date = JFactory::getDate();
             }
             //bea: different than original date_time, local
             //$date = JFactory::getDate();
             //$config =& JFactory::getConfig();
             //$tzoffset = $config->get('offset');
             //$date->setTimeZone( $tzoffset );
             $value = $date->toMySQL();
         } else {
             // $$$rob - if no search form data submitted for the search element then the default
             // selecton was being applied instead
             if (array_key_exists('use_default', $opts) && $opts['use_default'] == false) {
                 $value = '';
             } else {
                 $value = $this->getDefaultValue($data);
             }
             // $$$ hugh - as we now run removeTableNameFromSaveData(), I think we just need the short name?
             $name = $this->getFullName(false, true, false);
             //$name = $element->name;
             if ($groupModel->isJoin()) {
                 if ($groupModel->canRepeat()) {
                     if (array_key_exists('join', $data) && array_key_exists($joinid, $data['join']) && is_array($data['join'][$joinid]) && array_key_exists($name, $data['join'][$joinid]) && array_key_exists($repeatCounter, $data['join'][$joinid][$name])) {
                         $value = $data['join'][$joinid][$name][$repeatCounter];
                     }
                 } else {
                     if (array_key_exists('join', $data) && array_key_exists($joinid, $data['join']) && is_array($data['join'][$joinid]) && array_key_exists($name, $data['join'][$joinid])) {
                         $value = $data['join'][$joinid][$name];
                     }
                 }
             } else {
                 if ($groupModel->canRepeat()) {
                     //repeat group NO join
                     if (array_key_exists($name, $data)) {
                         if (is_array($data[$name])) {
                             //occurs on form submission for fields at least
                             $a = $data[$name];
                         } else {
                             //occurs when getting from the db
                             $a = FabrikWorker::JSONtoData($data[$name], true);
                         }
                         if (array_key_exists($repeatCounter, $a)) {
                             $value = $a[$repeatCounter];
                         }
                     }
                 } else {
                     $value = JArrayHelper::getValue($data, $name, $value);
                 }
             }
             if (is_array($value)) {
                 //TIMEDATE option set - explode with space rather than comma
                 //url decode if it comes from ajax calendar form
                 if (array_key_exists('time', $value) && $value['time'] != '' && JArrayHelper::getValue($value, 'date') != '') {
                     $value['time'] = $this->_fixTime(urldecode($value['time']));
                     $value = implode(' ', $value);
                 } else {
                     //$value = '';
                     $value = implode('', $value);
                     //for validations in repeat groups with no time selector
                 }
             }
             $formModel =& $this->getForm();
             //stops this getting called from form validation code as it messes up repeated/join group validations
             if (array_key_exists('runplugins', $opts) && $opts['runplugins'] == 1) {
                 $formModel->getPluginManager()->runPlugins('onGetElementDefault', $formModel, 'form', $this);
             }
             //for validations (empty time and date element gives ' ')
             if ($value == ' ') {
                 $value = '';
             }
         }
         $this->defaults[$repeatCounter] = $value;
     }
     return $this->defaults[$repeatCounter];
 }
Example #19
0
 /**
  * Shows the data formatted for the list view
  *
  * @param   string    $data      Elements data
  * @param   stdClass  &$thisRow  All the data in the lists current row
  * @param   array     $opts      Rendering options
  *
  * @return  string	formatted value
  */
 public function renderListData($data, stdClass &$thisRow, $opts = array())
 {
     $params = $this->getParams();
     $groupModel = $this->getGroup();
     /*
      * Jaanus: removed condition canrepeat() from renderListData:
      * weird result such as ["00:03:45","00 when not repeating but still join and merged. Using isJoin() instead
      */
     $data = $groupModel->isJoin() ? FabrikWorker::JSONtoData($data, true) : array($data);
     $data = (array) $data;
     $ft = $params->get('list_time_format', 'H:i:s');
     $sep = $params->get('time_separatorlabel', FText::_(':'));
     $format = array();
     foreach ($data as $d) {
         if ($d) {
             $bits = explode(':', $d);
             $hour = FArrayHelper::getValue($bits, 0, '00');
             $min = FArrayHelper::getValue($bits, 1, '00');
             $sec = FArrayHelper::getValue($bits, 2, '00');
             $hms = $hour . $sep . $min . $sep . $sec;
             $hm = $hour . $sep . $min;
             $ms = $min . $sep . $sec;
             $timedisp = '';
             if ($ft == "H:i:s") {
                 list($hour, $min, $sec) = explode(':', $d);
                 $timedisp = $hour . $sep . $min . $sep . $sec;
             } else {
                 if ($ft == "H:i") {
                     list($hour, $min) = explode(':', $d);
                     $timedisp = $hour . $sep . $min;
                 }
                 if ($ft == "i:s") {
                     list($min, $sec) = explode(':', $d);
                     $timedisp = $min . $sep . $sec;
                 }
             }
             $format[] = $timedisp;
         } else {
             $format[] = '';
         }
     }
     $data = json_encode($format);
     return parent::renderListData($data, $thisRow, $opts);
 }
Example #20
0
 /**
  *
  * if editing a record which contains repeated join data then on start $data is an
  * array with each records being a row in the database.
  *
  * We need to take this structure and convert it to the same format as when the form
  * is submitted
  * @param	array	data
  */
 function setJoinData(&$data)
 {
     $this->_joinDefaultData = array();
     if (empty($data)) {
         return;
     }
     if (!array_key_exists('join', $data[0])) {
         $data[0]->join = array();
     }
     // $$$ hugh - sometimes $data[0]->join is an object not an array?
     // $$$ rob - no longer as in render we use FarrayHelper to not recurse into data when setting to object
     // $$$ rob   readding back in - was needed with cdd in repeat groups
     if (is_object($data[0]->join)) {
         $data[0]->join = JArrayHelper::fromObject($data[0]->join);
     }
     //no joins so leave !
     if (!is_array($this->_aJoinObjs)) {
         return;
     }
     if ($this->_rowId != '') {
         $groups = $this->getGroupsHiarachy();
         foreach ($groups as $groupModel) {
             if ($groupModel->isJoin()) {
                 $group = $groupModel->getGroup();
                 //$$$ rob - if loading data from session then the join structure is already in place so dont overwrite
                 if (array_key_exists($group->join_id, $data[0]->join)) {
                     continue;
                 }
                 $data[0]->join[$group->join_id] = array();
                 $elementModels = $groupModel->getMyElements();
                 foreach ($elementModels as $elementModel) {
                     $name = $elementModel->getFullName(false, true, false);
                     $fv_name = 'join[' . $group->join_id . '][' . $name . ']';
                     $rawname = $name . '_raw';
                     $fv_rawname = 'join[' . $group->join_id . '][' . $rawname . ']';
                     foreach ($data as $row) {
                         if (array_key_exists($name, $row)) {
                             $v = $row->{$name};
                             $v = FabrikWorker::JSONtoData($v, false);
                             $data[0]->join[$group->join_id][$name][] = $v;
                             unset($row->{$name});
                         } else {
                             if (array_key_exists($fv_name, $row)) {
                                 $v = $row->{$fv_name};
                                 if (is_object($v)) {
                                     $v = JArrayHelper::fromObject($v);
                                 }
                                 $data[0]->join[$group->join_id][$name] = $v;
                                 unset($row->{$fv_name});
                             }
                         }
                         if (array_key_exists($rawname, $row)) {
                             $v = $row->{$rawname};
                             $v = FabrikWorker::JSONtoData($v, false);
                             $data[0]->join[$group->join_id][$rawname][] = $v;
                             unset($row->{$rawname});
                         } else {
                             if (array_key_exists($fv_rawname, $row)) {
                                 $v = $row->{$fv_rawname};
                                 if (is_object($v)) {
                                     $v = JArrayHelper::fromObject($v);
                                 }
                                 $data[0]->join[$group->join_id][$rawname][] = $v;
                                 unset($row->{$fv_rawname});
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Example #21
0
 /**
  * add attachments to the email
  */
 function addAttachments($params)
 {
     //get attachments
     $pluginManager = FabrikWorker::getPluginManager();
     $data = $this->getEmailData();
     $groups = $this->formModel->getGroupsHiarachy();
     foreach ($groups as $groupModel) {
         $elementModels = $groupModel->getPublishedElements();
         foreach ($elementModels as $elementModel) {
             $elName = $elementModel->getFullName(false, true, false);
             if (array_key_exists($elName, $this->data)) {
                 if (method_exists($elementModel, 'addEmailAttachement')) {
                     if (array_key_exists($elName . '_raw', $data)) {
                         $val = $data[$elName . '_raw'];
                     } else {
                         $val = $data[$elName];
                     }
                     if (is_array($val)) {
                         $val = implode(',', $val);
                     }
                     $aVals = FabrikWorker::JSONtoData($val, true);
                     foreach ($aVals as $v) {
                         $file = $elementModel->addEmailAttachement($v);
                         if ($file !== false) {
                             $this->_aAttachments[] = $file;
                         }
                     }
                 }
             }
         }
     }
     // $$$ hugh - added an optional eval for adding attachments.
     // Eval'ed code should just return an array of file paths which we merge with $this->_aAttachments[]
     $w = new FabrikWorker();
     $email_attach_eval = $w->parseMessageForPlaceholder($params->get('email_attach_eval', ''), $this->data, false);
     if (!empty($email_attach_eval)) {
         $email_attach_array = @eval($email_attach_eval);
         FabrikWorker::logEval($email_attach_array, 'Caught exception on eval in email email_attach_eval : %s');
         if (!empty($email_attach_array)) {
             $this->_aAttachments = array_merge($this->_aAttachments, $email_attach_array);
         }
     }
 }
Example #22
0
 /**
  * If editing a record which contains repeated join data then on start $data is an
  * array with each records being a row in the database.
  *
  * We need to take this structure and convert it to the same format as when the form
  * is submitted
  *
  * @param   array  &$data  form data
  *
  * @return  void
  */
 public function setJoinData(&$data)
 {
     $this->_joinDefaultData = array();
     if (empty($data)) {
         return;
     }
     // No joins so leave !
     if (!is_array($this->aJoinObjs) || $this->rowId === '') {
         return;
     }
     if (!array_key_exists(0, $data)) {
         $data[0] = new stdClass();
     }
     $groups = $this->getGroupsHiarachy();
     /**
      * $$$ hugh - adding the "PK's seen" stuff, otherwise we end up adding multiple
      * rows when we have multiple repeat groups.  For instance, if we had two repeated
      * groups, one with 2 repeats and one with 3, we ended up with 6 repeats for each
      * group, with 3 and 2 copies of each respectively.  So we need to track which
      * instances of each repeat we have already copied into the main row.
      *
      * So $joinPksSeen will be indexed by $joinPksSeen[groupid][elementid]
      */
     $joinPksSeen = array();
     /**
      * Have to copy the data for the PK's seen stuff, as we're modifying the original $data
      * as we go, which screws up the PK logic once we've modified the PK value itself in the
      * original $data.  Probably only needed for $data[0], as that's the only row we actually
      * modify, but for now I'm just copying the whole thing, which then gets used for doing the ...
      * $joinPkVal = $data_copy[$row_index]->$joinPk;
      * ... inside the $data iteration below.
      *
      * PS, could probably just do a $data_copy = $data, as our usage of the copy isn't going to
      * involve nested arrays (which get copied by reference when using =), but I've been burned
      * so many times with array copying, I'm going to do a "deep copy" using serialize/unserialize!
      */
     $data_copy = unserialize(serialize($data));
     foreach ($groups as $groupId => $groupModel) {
         $group = $groupModel->getGroup();
         $joinPksSeen[$groupId] = array();
         $elementModels = $groupModel->getMyElements();
         foreach ($elementModels as $elementModelID => $elementModel) {
             if ($groupModel->isJoin() || $elementModel->isJoin()) {
                 if ($groupModel->isJoin()) {
                     $joinModel = $groupModel->getJoinModel();
                     $joinPk = $joinModel->getForeignID();
                     $joinPksSeen[$groupId][$elementModelID] = array();
                 }
                 $names = $elementModel->getJoinDataNames();
                 foreach ($data as $row_index => $row) {
                     // Might be a string if new record ?
                     $row = (object) $row;
                     if ($groupModel->isJoin()) {
                         /**
                          * If the join's PK element isn't published or for any other reason not
                          * in $data, we're hosed!
                          */
                         if (!isset($data_copy[$row_index]->{$joinPk})) {
                             continue;
                         }
                         $joinPkVal = $data_copy[$row_index]->{$joinPk};
                         /**
                          * if we've seen the PK value for this element's row before, skip it.
                          * Check for empty as well, just in case - as we're loading existing data,
                          * it darn well should have a value!
                          */
                         if (empty($joinPkVal) || in_array($joinPkVal, $joinPksSeen[$groupId][$elementModelID])) {
                             continue;
                         }
                     }
                     for ($i = 0; $i < count($names); $i++) {
                         $name = $names[$i];
                         if (array_key_exists($name, $row)) {
                             $v = $row->{$name};
                             $v = FabrikWorker::JSONtoData($v, $elementModel->isJoin());
                             // New record or csv export
                             if (!isset($data[0]->{$name})) {
                                 $data[0]->{$name} = $v;
                             }
                             if (!is_array($data[0]->{$name})) {
                                 if ($groupModel->isJoin() && $groupModel->canRepeat()) {
                                     $v = array($v);
                                 }
                                 $data[0]->{$name} = $v;
                             } else {
                                 if ($groupModel->isJoin() && $groupModel->canRepeat()) {
                                     $n =& $data[0]->{$name};
                                     $n[] = $v;
                                 }
                             }
                         }
                     }
                     if ($groupModel->isJoin()) {
                         /**
                          * Make a Note To Self that we've now handled the data for this element's row,
                          * and can skip it from now on.
                          */
                         $joinPksSeen[$groupId][$elementModelID][] = $joinPkVal;
                     }
                 }
             }
         }
     }
     // Remove the additional rows - they should have been merged into [0] above. if no [0] then use main array
     $data = ArrayHelper::fromObject(FArrayHelper::getValue($data, 0, $data));
 }
Example #23
0
 /**
  * Turn form value into email formatted value
  *
  * @param   mixed  $value          Element value
  * @param   array  $data           Form data
  * @param   int    $repeatCounter  Group repeat counter
  *
  * @return  string  email formatted value
  */
 protected function getIndEmailValue($value, $data = array(), $repeatCounter = 0)
 {
     if (is_string($value)) {
         $value = FabrikWorker::JSONtoData($value, true);
         $value['label'] = FArrayHelper::getValue($value, 0);
         $value['link'] = FArrayHelper::getValue($value, 1);
     }
     if (is_array($value)) {
         $w = new FabrikWorker();
         $link = $w->parseMessageForPlaceHolder($value['link']);
         $value = '<a href="' . $link . '" >' . $value['label'] . '</a>';
     }
     return $value;
 }
Example #24
0
 /**
  * Format JSON data
  */
 protected function implodeJSON(&$v, $k, $sepchar)
 {
     if (!FabrikString::isRawName($k) && FabrikWorker::isJSON($v)) {
         $v = FabrikWorker::JSONtoData($v, true);
         $v = implode($sepchar, $v);
     }
 }
Example #25
0
 function getValue($data, $repeatCounter = 0, $opts = array())
 {
     if (is_null($this->defaults)) {
         $this->defaults = array();
     }
     if (!array_key_exists($repeatCounter, $this->defaults)) {
         $groupModel = $this->getGroup();
         $formModel = $this->getForm();
         $element = $this->getElement();
         $listModel = $this->getlistModel();
         $params = $this->getParams();
         // $$$rob - if no search form data submitted for the search element then the default
         // selection was being applied instead
         if (array_key_exists('use_default', $opts) && $opts['use_default'] == false) {
             $value = '';
         } else {
             $value = $this->getDefaultValue($data);
         }
         $table = $listModel->getTable();
         if ($groupModel->canRepeat() == '1') {
             $fullName = $table->db_table_name . $formModel->_joinTableElementStep . $element->name;
             if (isset($data[$fullName])) {
                 if (is_array($data[$fullName])) {
                     $value = $data[$fullName][0];
                 } else {
                     $value = $data[$fullName];
                 }
                 //$value = explode(GROUPSPLITTER, $value);
                 $value = FabrikWorker::JSONtoData($value, true);
                 if (array_key_exists($repeatCounter, $value)) {
                     $value = $value[$repeatCounter];
                     if (is_array($value)) {
                         $value = implode(',', $value);
                     }
                     return $value;
                 }
             }
         }
         if ($groupModel->isJoin()) {
             $fullName = $this->getFullName(false, true, false);
             $joinid = $groupModel->getGroup()->join_id;
             if (isset($data['join'][$joinid][$fullName])) {
                 $value = $data['join'][$joinid][$fullName];
                 if (is_array($value) && array_key_exists($repeatCounter, $value)) {
                     $value = $value[$repeatCounter];
                 }
             } else {
                 // $$$ rob - prob not used but im leaving in just in case
                 if (isset($data[$fullName])) {
                     $value = $data[$fullName];
                     if (is_array($value) && array_key_exists($repeatCounter, $value)) {
                         $value = $value[$repeatCounter];
                     }
                 }
             }
         } else {
             $fullName = $table->db_table_name . $formModel->_joinTableElementStep . $element->name;
             if (isset($data[$fullName])) {
                 /* drop down  */
                 if (is_array($data[$fullName])) {
                     if (isset($data[$fullName][0])) {
                         /* if not its a file upload el */
                         $value = $data[$fullName][0];
                     }
                 } else {
                     $value = $data[$fullName];
                 }
             }
         }
         if ($value === '') {
             //query string for joined data
             $value = JArrayHelper::getValue($data, $name);
         }
         //stops this getting called from form validation code as it messes up repeated/join group validations
         if (array_key_exists('runplugins', $opts) && $opts['runplugins'] == 1) {
             $formModel->getPluginManager()->runPlugins('onGetElementDefault', $formModel, 'form', $this);
         }
         /** ensure that the data is a string **/
         if (is_array($value)) {
             $value = implode(',', $value);
         }
         $this->defaults[$repeatCounter] = $value;
     }
     return $this->defaults[$repeatCounter];
 }
Example #26
0
 /**
  * Shows the data formatted for the list view
  *
  * @param   string  $data      elements data
  * @param   object  &$thisRow  all the data in the lists current row
  *
  * @return  string	formatted value
  */
 public function renderListData($data, &$thisRow)
 {
     $data = FabrikWorker::JSONtoData($data, true);
     JArrayHelper::toInteger($data);
     $db = FabrikWorker::getDbo(true);
     $query = $db->getQuery(true);
     if (!empty($data)) {
         $query->select('title')->from('#__usergroups')->where('id IN (' . implode(',', $data) . ')');
         $db->setQuery($query);
         $data = $db->loadColumn();
     }
     $data = json_encode($data);
     return parent::renderListData($data, $thisRow);
 }
Example #27
0
 /**
  * used by elements with suboptions
  *
  * $$$ hugh - started working on adding this to elementlist, as we need to handle
  * JSON-ified options for multiselect elements, which the main element model getLabelForValue()
  * doesn't do.  But I need to sort out how this gets handled in rendering as well.
  *
  * @param   string  $v             Value
  * @param   string  $defaultLabel  Default label
  *
  * @return  string	label
  */
 public function notreadyyet_getLabelForValue($v, $defaultLabel = '')
 {
     /**
      * $$$ hugh - only needed getParent when we weren't saving changes to parent params to child
      * which we should now be doing ... and getParent() causes an extra table lookup for every child
      * element on the form.
      * $element = $this->getParent();
      */
     $element = $this->getElement();
     $params = $this->getParams();
     $values = $this->getSubOptionValues();
     $labels = $this->getSubOptionLabels();
     $multiple = $this->isMultiple();
     $vals = is_array($v) ? $v : FabrikWorker::JSONtoData($v, true);
     foreach ($vals as $val) {
         $l = FArrayHelper::getValue($labels, $val, $defaultLabel);
         if (trim($l) !== '') {
             if ($multiple && $this->renderWithHTML) {
                 $lis[] = '<li>' . $l . '</li>';
             } else {
                 $lis[] = $l;
             }
         }
     }
     $return = '';
     if (!empty($lis)) {
         $return = $multiple && $this->renderWithHTML ? '<ul class="fabrikRepeatData">' . implode(' ', $lis) . '</ul>' : implode(' ', $lis);
     }
     /**
      * $$$ rob if we allow adding to the dropdown but not recording
      * then there will be no $key set to revert to the $val instead
      */
     /*
     if ($v === $params->get('sub_default_value'))
     {
     $v = $params->get('sub_default_label');
     }
     return ($key === false) ? $v : FArrayHelper::getValue($labels, $key, $defaultLabel);
     */
     return $return;
 }
Example #28
0
 /**
  * Prepares the element data for CSV export
  *
  * @param   string $data     Element data
  * @param   object &$thisRow All the data in the lists current row
  *
  * @return  string    formatted value
  */
 public function renderListData_csv($data, &$thisRow)
 {
     // @TODO: deal with time options (currently can be defined in date_table_format param).
     $timeZone = new DateTimeZone($this->config->get('offset'));
     $params = $this->getParams();
     $this->getGroup();
     $data = FabrikWorker::JSONtoData($data, true);
     $f = $params->get('date_table_format', 'Y-m-d');
     /* $$$ hugh - see http://fabrikar.com/forums/showthread.php?p=87507
      * Really don't think we need to worry about $app->input 'incraw' here. The raw, GMT/MySQL data will get
      * included in the _raw version of the element if incraw is selected. Here we just want to output
      * the regular non-raw, formatted, TZ'ed version.
      */
     $incRaw = false;
     $format = array();
     foreach ($data as $d) {
         if (FabrikWorker::isDate($d)) {
             if ($incRaw) {
                 $format[] = $d;
             } else {
                 $date = JFactory::getDate($d);
                 if ($this->shouldApplyTz('list')) {
                     $date->setTimeZone($timeZone);
                 }
                 if ($f == '{age}') {
                     $format[] = date('Y') - $date->format('Y', true);
                 } else {
                     $format[] = $date->format($f, true);
                 }
             }
         } else {
             $format[] = '';
         }
     }
     if (count($format) > 1) {
         return json_encode($format);
     } else {
         return implode('', $format);
     }
 }
Example #29
0
 /**
  * Prepares the element data for CSV export
  *
  * @param   string  $data      Element data
  * @param   object  &$thisRow  All the data in the lists current row
  *
  * @return  string	formatted value
  */
 public function renderListData_csv($data, &$thisRow)
 {
     $ret = array();
     $raw = $this->getFullName(true, false) . '_raw';
     $rawData = $thisRow->{$raw};
     $rawData = FabrikWorker::JSONtoData($rawData, true);
     foreach ($rawData as $d) {
         $ret[] = (bool) $d ? FText::_('JYES') : FText::_('JNO');
     }
     if (count($ret) > 1) {
         $ret = json_encode($ret);
     } else {
         $ret = implode('', $ret);
     }
     return $ret;
 }
Example #30
0
 /**
  * $$$ rob 19/10/2011 now called before formatData() from getData() as otherwise element tips (created in element->renderListData())
  * only contained first merged records data and not all merged records
  *
  * Collapses 'repeated joined' rows into a single row.
  * If a group is not repeating we just use the first row's data (as subsequent rows will contain the same data
  * Otherwise if the group is repeating we append each repeated record's data into the first row's data
  * All rows except the first row for each group are then unset (as unique subsequent row's data will be contained within
  * the first row)
  *
  * @param   array  &$data  list data
  *
  * @return  void
  */
 protected function formatForJoins(&$data)
 {
     $merge = $this->mergeJoinedData();
     if (empty($merge)) {
         return;
     }
     $dbPrimaryKey = $this->getPrimaryKey(true);
     $formModel = $this->getFormModel();
     $db = $this->getDb();
     FabrikHelperHTML::debug($data, 'render:before formatForJoins');
     $last_pk = '';
     $last_i = 0;
     $count = count($data);
     $canRepeats = array();
     $canRepeatsTables = array();
     $canRepeatsKeys = array();
     $canRepeatsPkValues = array();
     $remove = array();
     $first_pk_i = array();
     if (empty($data)) {
         return;
     }
     /* First, go round first row of data, and prep some stuff.
      * Basically, if doing a "reduce data" merge (merge == 2), we need to know what the
      * PK element is for each joined group (well, for each element, really)
      */
     foreach ($data[0] as $key => $val) {
         $shortKey = FabrikString::rtrimword($key, '_raw');
         /* $$$ hugh - had to cache this stuff, because if you have a lot of rows and a lot of elements,
          * doing this many hundreds of times causes huge slowdown, exceeding max script execution time!
          * And we really only need to do it once for the first row.
          */
         if (!isset($canRepeats[$shortKey])) {
             $elementModel = $formModel->getElement($shortKey);
             // $$$ rob - testing for linking join which is repeat but linked join which is not - still need separate info from linked to join
             // $canRepeats[$shortKey] = $elementModel ? ($elementModel->getGroup()->canRepeat()) : 0;
             if ($merge == 2 && $elementModel) {
                 if ($elementModel->getGroup()->canRepeat() || $elementModel->getGroup()->isJoin()) {
                     // We need to work out the PK of the joined table.
                     // So first, get the table name.
                     $group = $elementModel->getGroup();
                     $join = $group->getJoinModel()->getJoin();
                     $join_table_name = $join->table_join;
                     // We have the table name, so see if we already have it cached ...
                     if (!isset($canRepeatsTables[$join_table_name])) {
                         // We don't have it yet, so grab the PK
                         $keys = $this->getPrimaryKeyAndExtra($join_table_name);
                         if (!empty($keys) && array_key_exists('key', $keys[0])) {
                             // OK, now we have the PK for the table
                             $canRepeatsTables[$join_table_name] = $keys[0];
                         } else {
                             // $$$ hugh - might be a view, so Hail Mary attempt to get PK
                             $query = $db->getQuery(true);
                             $query->select('db_primary_key')->from('#__{package}_lists')->where('db_table_name = ' . $db->q($join_table_name));
                             $db->setQuery($query);
                             $joinPk = $db->loadResult();
                             if (!empty($joinPk)) {
                                 $canRepeatsTables[$join_table_name] = array('colname' => FabrikString::shortColName($joinPk));
                             }
                         }
                     }
                     // Hopefully we now have the PK
                     if (isset($canRepeatsTables[$join_table_name])) {
                         $canRepeatsKeys[$shortKey] = $join_table_name . '___' . $canRepeatsTables[$join_table_name]['colname'];
                     }
                     $crk_sk = $canRepeatsKeys[$shortKey];
                     // Create the array if it doesn't exist
                     if (!isset($canRepeatsPkValues[$crk_sk])) {
                         $canRepeatsPkValues[$crk_sk] = array();
                     }
                     // Now store the
                     if (!isset($canRepeatsPkValues[$crk_sk][0]) and isset($data[0]->{$crk_sk})) {
                         $canRepeatsPkValues[$crk_sk][0] = $data[0]->{$crk_sk};
                     }
                 }
             }
             $canRepeats[$shortKey] = $elementModel ? $elementModel->getGroup()->canRepeat() || $elementModel->getGroup()->isJoin() : 0;
         }
     }
     for ($i = 0; $i < $count; $i++) {
         // $$$rob if rendering J article in PDF format __pk_val not in pdf table view
         $next_pk = isset($data[$i]->__pk_val) ? $data[$i]->__pk_val : $data[$i]->{$dbPrimaryKey};
         //if (!empty($last_pk) && ($last_pk == $next_pk))
         if (array_key_exists($next_pk, $first_pk_i)) {
             foreach ($data[$i] as $key => $val) {
                 $origKey = $key;
                 $shortKey = FabrikString::rtrimword($key, '_raw');
                 if ($canRepeats[$shortKey]) {
                     if ($merge == 2 && !isset($canRepeatsPkValues[$canRepeatsKeys[$shortKey]][$i]) && isset($data[$i]->{$canRepeatsKeys[$shortKey]})) {
                         $canRepeatsPkValues[$canRepeatsKeys[$shortKey]][$i] = $data[$i]->{$canRepeatsKeys[$shortKey]};
                     }
                     if ($origKey == $shortKey) {
                         /* $$$ rob - this was just appending data with a <br> but as we do thie before the data is formatted
                          * it was causing all sorts of issues for list rendering of links, dates etc. So now turn the data into
                          * an array and at the end of this method loop over the data to encode the array into a json object.
                          */
                         $do_merge = true;
                         if ($merge == 2) {
                             $pk_vals = array_count_values(array_filter($canRepeatsPkValues[$canRepeatsKeys[$shortKey]]));
                             if (isset($data[$i]->{$canRepeatsKeys[$shortKey]})) {
                                 if ($pk_vals[$data[$i]->{$canRepeatsKeys[$shortKey]}] > 1) {
                                     $do_merge = false;
                                 }
                             }
                         }
                         if ($do_merge) {
                             /* The raw data is not altererd at the moment - not sure that that seems correct but can't see any issues
                              * with it currently
                              * $$$ hugh - added processing of raw data, needed for _raw placeholders
                              * in things like custom links
                              */
                             /*
                             $data[$last_i]->$key = (array) $data[$last_i]->$key;
                             array_push($data[$last_i]->$key, $val);
                             */
                             $data[$first_pk_i[$next_pk]]->{$key} = (array) $data[$first_pk_i[$next_pk]]->{$key};
                             // if first occurrence is null, casting to array will give empty array
                             if (count($data[$first_pk_i[$next_pk]]->{$key}) === 0) {
                                 array_push($data[$first_pk_i[$next_pk]]->{$key}, null);
                             }
                             array_push($data[$first_pk_i[$next_pk]]->{$key}, $val);
                             $rawKey = $key . '_raw';
                             if (isset($data[$i]->{$rawKey})) {
                                 $rawval = $data[$i]->{$rawKey};
                                 /*
                                 $data[$last_i]->$rawKey = (array) $data[$last_i]->$rawKey;
                                 array_push($data[$last_i]->$rawKey, $rawval);
                                 */
                                 $data[$first_pk_i[$next_pk]]->{$rawKey} = (array) $data[$first_pk_i[$next_pk]]->{$rawKey};
                                 array_push($data[$first_pk_i[$next_pk]]->{$rawKey}, $rawval);
                             }
                         }
                     } else {
                         /* $$$ hugh - don't think we need this, now we're processing _raw data?
                         			 if (!is_array($data[$last_i]->$origKey)) {
                         			$json= $val;
                         			$data[$last_i]->$origKey = json_encode($json);
                         			}
                         			*/
                     }
                 }
             }
             $remove[] = $i;
             continue;
         } else {
             $first_pk_i[$next_pk] = $i;
             if ($merge == 2) {
                 foreach ($data[$i] as $key => $val) {
                     $origKey = $key;
                     $shortKey = FabrikString::rtrimword($key, '_raw');
                     if ($canRepeats[$shortKey] && !isset($canRepeatsPkValues[$canRepeatsKeys[$shortKey]][$i]) && isset($data[$i]->{$canRepeatsKeys[$shortKey]})) {
                         $canRepeatsPkValues[$canRepeatsKeys[$shortKey]][$i] = $data[$i]->{$canRepeatsKeys[$shortKey]};
                     }
                 }
             }
             $last_i = $i;
             // $$$rob if rendering J article in PDF format __pk_val not in pdf table view
             $last_pk = $next_pk;
         }
         // $$$ rob ensure that we have a sequential set of keys otherwise ajax json will turn array into object
         $data = array_values($data);
     }
     for ($c = count($remove) - 1; $c >= 0; $c--) {
         unset($data[$remove[$c]]);
     }
     // $$$ rob loop over any data that was merged into an array and turn that into a json object
     foreach ($data as $gKey => $d) {
         foreach ($d as $k => $v) {
             if (is_array($v)) {
                 foreach ($v as &$v2) {
                     $v2 = FabrikWorker::JSONtoData($v2);
                 }
                 $v = json_encode($v);
                 $data[$gKey]->{$k} = $v;
             }
         }
     }
     $data = array_values($data);
 }