/** * Init the filter form */ protected function initForm() { $this->form = factory::get('form_db', array_merge($this->cfg->formOpts, array('filter' => true, 'table' => $this->table, 'sectionName' => $this->cfg->formName, 'action' => request::uriDef(array('paramA' => array_merge(array_diff_key(request::get('paramA'), $this->cfg->actionPrmClear), $this->cfg->actionPrmForce)))))); $this->form->setSubmitText($this->cfg->submitText); $this->form->setSubmitplus('<a href="' . $this->clearLink() . '">' . $this->cfg->clearText . '</a>'); if (!empty($this->cfg->fields)) { foreach ($this->cfg->fields as $field) { if ($f = $this->table->getField($field)) { $f['label'] = $this->getLabel($f['name']); $f['link'] = $this->table->getLinked($f['name']); $this->form->addFromFieldFilter($f); } else { if ($r = $this->table->getRelated($field)) { $r['label'] = $this->getLabel($r['table']); $r['name'] = $r['tableLink']; $this->form->addFromRelatedFilter($r); } else { if ($this->table->hasI18n() && db::isI18nName($field) && ($f = $this->table->getI18nTable()->getField(db::unI18nName($field)))) { $name = db::unI18nName($field); $f['name'] = $field; $f['label'] = $this->getLabel($field); $f['link'] = $this->table->getI18nTable()->getLinked($name); $this->form->addFromFieldFilter($f); } } } } } else { // All fields foreach ($this->table->getField() as $f) { $f['label'] = $this->getLabel($f['name']); $f['link'] = $this->table->getLinked($f['name']); $this->form->addFromFieldFilter($f); } foreach ($this->table->getRelated() as $t => $r) { $r['name'] = $r['tableLink']; $r['label'] = $this->getLabel($r['table']); $this->form->addFromRelated($r); } } $this->fillValues(); }
protected function afterInit() { $this->table = $this->cfg->table; if (!is_array($this->cfg->query)) { $this->cfg->query = array(); } if (empty($this->cfg->module)) { $this->cfg->module = utils::getModuleName(debug::callFrom(6, null)); } if ($this->cfg->useSession) { $this->session = session::getInstance(array('nameSpace' => 'dataTable_' . ($this->cfg->sessionName ? $this->cfg->sessionName : $this->cfg->name))); } $paramFromRequest = array('page', 'sortBy', 'sortDir'); $paramA = request::get('paramA'); foreach ($paramFromRequest as $pfr) { if ($this->cfg->useSession && $this->session->check($pfr)) { $this->cfg->set($pfr, $this->session->get($pfr)); } if (array_key_exists($pfr . $this->cfg->nameParam, $paramA)) { $val = $paramA[$pfr . $this->cfg->nameParam]; if ($this->cfg->useSession) { $this->session->set(array('name' => $pfr, 'val' => $val)); } $this->cfg->set($pfr, $val); } } if ($this->cfg->check('sortBy')) { if ($this->table->isRelated($this->cfg->sortBy)) { $related = $this->table->getRelated($this->cfg->sortBy); $tmp = array(); $fields = array_filter(explode(',', $related['fk2']['link']['fields'])); $tableName = $related['fk2']['link']['table']; foreach ($fields as $f) { $tmp[] = $tableName . '.' . $f; } $fields = array_filter(explode(',', $related['fk2']['link']['i18nFields'])); $tableName .= db::getCfg('i18n'); foreach ($fields as $f) { $tmp[] = $tableName . '.' . $f; } $this->sortBy = implode(', ', $tmp); if (!$this->table->getCfg()->autoJoin) { $f = $related['tableObj']->getRawName(); $query = $this->cfg->query; if (!isset($query['join'])) { $query['join'] = array(); } $query['join'][] = array('table' => $f, 'dir' => 'left outer', 'on' => $this->table->getRawName() . '.' . $related['fk1']['link']['ident'] . '=' . $f . '.' . $related['fk1']['name']); $query['join'][] = array('table' => $related['table'], 'dir' => 'left outer', 'on' => $f . '.' . $related['fk2']['name'] . '=' . $related['table'] . '.' . $related['fk2']['link']['ident']); if ($related['fk2']['link']['i18nFields']) { $i18nTableName = $related['table'] . db::getCfg('i18n'); $i18nTable = db::get('table', $i18nTableName, array('db' => $this->table->getDb())); $primary = $i18nTable->getPrimary(); $query['join'][] = array('table' => $i18nTableName, 'dir' => 'left outer', 'on' => $f . '.' . $related['fk2']['name'] . '=' . $i18nTableName . '.' . $primary[0] . ' AND ' . $i18nTableName . '.' . $primary[1] . '="' . request::get('lang') . '"'); } $query['group'] = $this->table->getRawName() . '.' . $this->table->getIdent(); $this->cfg->query = $query; } } else { if ($this->table->isLinked($this->cfg->sortBy)) { $linked = $this->table->getLinked($this->cfg->sortBy); $tmpSort = array(); foreach (explode(',', trim($linked['fields'] . ',' . $linked['i18nFields'], ',')) as $tmp) { $tmpSort[] = $linked['field'] . '.' . $tmp; } $this->sortBy = implode(', ', $tmpSort); if (!$this->table->getCfg()->autoJoin) { $query = $this->cfg->query; if (!isset($query['join'])) { $query['join'] = array(); } $alias = $linked['field']; if ($linked['i18nFields']) { $alias1 = $alias . '1'; $query['join'][] = array('table' => $linked['table'], 'alias' => $alias1, 'dir' => 'left outer', 'on' => $this->table->getRawName() . '.' . $linked['field'] . '=' . $alias1 . '.' . $linked['ident']); $i18nTableName = $linked['table'] . db::getCfg('i18n'); $i18nTable = db::get('table', $i18nTableName, array('db' => $this->table->getDb())); $primary = $i18nTable->getPrimary(); $query['join'][] = array('table' => $i18nTableName, 'alias' => $alias, 'dir' => 'left outer', 'on' => $alias1 . '.' . $linked['ident'] . '=' . $alias . '.' . $primary[0] . ' AND ' . $alias . '.' . $primary[1] . '="' . request::get('lang') . '"'); } else { $query['join'][] = array('table' => $linked['table'], 'alias' => $alias, 'dir' => 'left outer', 'on' => $this->table->getRawName() . '.' . $linked['field'] . '=' . $alias . '.' . $linked['ident']); } $this->cfg->query = $query; } } else { if ($this->cfg->sortBy) { if (strpos($this->cfg->sortBy, $this->table->getName()) !== false || strpos($this->cfg->sortBy, ".") !== false) { $this->sortBy = $this->cfg->sortBy; } else { $this->sortBy = $this->table->getName() . '.' . $this->cfg->sortBy; } } } } } }