/** * Create the data Table out * * @param string $type Out type * @return string */ public function to($type) { $tpl = factory::get('tpl', array('module' => $this->cfg->module, 'action' => $this->cfg->name, 'default' => 'dataTable', 'cache' => $this->cfg->cache, 'layout' => false)); $data = $this->getData(); if (count($data)) { if (empty($this->cfg->fields)) { $headersT = $data->getFields('flatReal'); if ($keyRelated = array_search('related', $headersT)) { unset($headersT[$keyRelated]); } foreach ($this->table->getI18nFields() as $f) { $headersT[] = db::getCfg('i18n') . $f['name']; } } else { $headersT = $this->cfg->fields; if ($this->cfg->addIdentField && !in_array($this->table->getIdent(), $headersT)) { array_unshift($headersT, $this->table->getIdent()); } } $headers = array(); $prmReplaceSortBy = '[sortBy]'; $prmReplaceSortDir = '[sortDir]'; $paramUrlA = request::get('paramA'); unset($paramUrlA['page' . $this->cfg->nameParam]); $paramUrlA['sortBy' . $this->cfg->nameParam] = $prmReplaceSortBy; $paramUrlA['sortDir' . $this->cfg->nameParam] = $prmReplaceSortDir; $paramUrlA['page' . $this->cfg->nameParam] = 1; $tmpSortLink = request::uriDef(array('paramA' => $paramUrlA)); foreach ($headersT as $k => $h) { $typeField = $this->table->getField($h, 'type'); if ($typeField == 'file' && is_array($tmp = $this->table->getField($h, 'comment')) && array_key_exists(0, $tmp)) { $typeField = $tmp[0]; } $headers[$k] = array('label' => $this->table->getLabel($h), 'name' => $h, 'url' => str_replace(array($prmReplaceSortBy, $prmReplaceSortDir), array(db::isI18nName($h) ? $this->table->getI18nTable()->getName() . '_' . db::unI18nName($h) : $h, $this->cfg->sortBy == $h && $this->cfg->sortDir == 'asc' ? 'desc' : 'asc'), $tmpSortLink), 'type' => $typeField); } $actions = null; $actionsAlt = null; $actionsImg = null; if (is_array($this->cfg->actions) && !empty($this->cfg->actions)) { $actions = array(); if (!$this->cfg->addIdentField) { array_unshift($headersT, $this->table->getIdent()); } array_walk($headersT, create_function('&$h', '$h = "[".$h."]";')); $dataK = null; $i = 0; foreach ($data as $d) { $tmp = $this->getActions($d); $tmpVals = $d->getValues('flatNoRelated'); $vals = array(); foreach ($headersT as $k => $v) { $v = substr($v, 1, -1); $vals[$k] = array_key_exists($v, $tmpVals) ? $tmpVals[$v] : null; } $curData = $d->getValues('data'); unset($curData['related']); unset($curData['linked']); if (is_null($dataK)) { $dataK = array_keys($curData); array_walk($dataK, create_function('&$h', '$h = "[".$h."]";')); } foreach ($tmp as &$t) { $t = str_replace($dataK, $curData, $t); } $actions[$i] = $tmp; $i++; } if (!empty($actions) && $this->cfg->actionsConfirmDelete) { response::getInstance()->addJs('actionsConfirmDelete'); } $actionsKey = array_keys($this->cfg->actions); $actionsAlt = $this->cfg->actionsAlt; if (!is_array($actionsAlt) || count($actionsAlt) < count($actionsKey)) { foreach ($actionsKey as $v) { if (!array_key_exists($v, $actionsAlt)) { $actionsAlt[$v] = ucfirst($v); } } } $actionsImg = $this->cfg->actionsImg; foreach ($actionsKey as $v) { if (!array_key_exists($v, $actionsImg)) { $actionsImg[$v] = utils::getIcon(array('name' => $v, 'attr' => array('title' => $actionsAlt[$v]), 'alt' => $actionsAlt[$v], 'type' => $this->cfg->iconType)); } } } if ($this->cfg->sortBy) { $paramUrlA['sortBy' . $this->cfg->nameParam] = $this->cfg->sortBy; $paramUrlA['sortDir' . $this->cfg->nameParam] = $this->cfg->sortDir; } else { unset($paramUrlA['sortBy' . $this->cfg->nameParam]); unset($paramUrlA['sortDir' . $this->cfg->nameParam]); } $nbPage = $this->getNbPage(); $pageLinks = array(); $prmReplace = $this->cfg->pageLinkReplace; if (!$this->cfg->pageLinkTpl) { $paramUrlA['page' . $this->cfg->nameParam] = $prmReplace; $tmpPageLink = request::uriDef(array('paramA' => $paramUrlA)); } else { $tmpPageLink = $this->cfg->pageLinkTpl; } for ($i = 1; $i <= $nbPage; $i++) { $pageLinks[$i] = str_replace($prmReplace, $i, $tmpPageLink); } if ($this->cfg->pageLinkTpl1) { $pageLinks[1] = $this->cfg->pageLinkTpl1; } $hasMultiple = count($this->cfg->multiple) > 0; if ($hasMultiple && $this->cfg->addCheckAllJs) { response::getInstance()->addJs('checkAll'); } $tpl->setA(array_merge(array('headers' => $headers, 'list' => $data, 'nbPage' => $nbPage, 'currentPage' => $this->cfg->page, 'pageLinks' => $pageLinks, 'actions' => $actions, 'actionsImg' => $actionsImg, 'actionsAlt' => $actionsAlt, 'iconType' => $this->cfg->iconType, 'tblName' => $this->table->getName(), 'sortBy' => $this->cfg->sortBy, 'sortByReal' => $this->sortBy, 'sortDir' => $this->cfg->sortDir, 'hasMultiple' => $hasMultiple, 'multipleLabel' => $this->cfg->multipleLabel, 'multipleSubmit' => $this->cfg->multipleSubmit, 'multipleAction' => $this->cfg->multipleAction, 'multipleIdent' => $this->table->getIdent(), 'multiple' => $this->cfg->multiple), $this->cfg->tplVars)); } else { // No data if ($this->cfg->page > 1) { $newPage = $this->cfg->page - 1; $uri = null; if ($newPage == 1 && $this->cfg->pageLinkTpl1) { $uri = $this->cfg->pageLinkTpl1; } if (!$uri) { $prmReplace = $this->cfg->pageLinkReplace; if (!$this->cfg->pageLinkTpl) { $paramUrlA = request::get('paramA'); unset($paramUrlA['page' . $this->cfg->nameParam]); $prmReplaceSortBy = '[sortBy]'; $prmReplaceSortDir = '[sortDir]'; $paramUrlA['sortBy' . $this->cfg->nameParam] = $prmReplaceSortBy; $paramUrlA['sortDir' . $this->cfg->nameParam] = $prmReplaceSortDir; $paramUrlA['page' . $this->cfg->nameParam] = 1; if ($this->cfg->sortBy) { $paramUrlA['sortBy' . $this->cfg->nameParam] = $this->cfg->sortBy; $paramUrlA['sortDir' . $this->cfg->nameParam] = $this->cfg->sortDir; } else { unset($paramUrlA['sortBy' . $this->cfg->nameParam]); unset($paramUrlA['sortDir' . $this->cfg->nameParam]); } $paramUrlA['page' . $this->cfg->nameParam] = $prmReplace; $tmpPageLink = request::uriDef(array('paramA' => $paramUrlA)); } else { $tmpPageLink = $this->cfg->pageLinkTpl; } $uri = str_replace($prmReplace, $newPage, $tmpPageLink); } response::getInstance()->redirect($uri); } $tpl->set('noData', utils::htmlOut($this->cfg->noData)); $tpl->set('list', null); $tpl->setA($this->cfg->tplVars); } return $tpl->fetch(array('tplExt' => $type)); }
/** * Get the label for a fieldname or a tablename * * @param string $name * @return string The label */ public function getLabel($name) { return array_key_exists($name, $this->cfg->label) ? $this->cfg->getInArray('label', $name) : $this->table->getLabel($name); }
/** * Get the label for the i18n fields * * @param null|string $field Fieldname or null to retrieve an all of them as an array * @return array|string */ public function getI18nLabel($field = null) { return $this->i18nTable->getLabel($field); }