public function fromDBToExternal($value) { $obj = Factory::createObject($this->fi->getConnectedClass()); $select = new base_database_statement_Select(); $table = DB::table($obj->getTable()); $where = DB::where($table->getColumn('LK'), DB::intTerm((int) $value)); $select->setTable($table); $select->setWhere($where); $select->setColumns(array($table->getColumn($this->fi->getFieldsOfConnectedClass()))); $result = $select->fetchDatabase(); $value = current($result); return $value[$this->fi->getFieldsOfConnectedClass()]; }
/** * show the data without input element, because editing is not possible * * @return string */ protected function getReadOnlyDisplay() { $table = DB::table('selectionListEntry'); $where = DB::where($table->getColumn('PK'), DB::intTerm($this->value)); $select = new base_database_statement_Select(); $select->setTable($table); $select->setWhere($where); $select->setColumns([$table->getColumn('name')]); $res = $select->fetchDatabase(); if (empty($res)) { return 'keine Angabe'; } return $res[0]['name']; }
/** * @param $identifier * @throws base_exception_SelectionList */ public function load($identifier) { $table = DB::table($this->table); $where = DB::where($table->getColumn('identifier'), DB::stringTerm($identifier)); $select = new base_database_statement_Select(); $select->setTable($table); $select->setWhere($where); $result = $select->fetchDatabase(); if (count($result) > 1) { throw new base_exception_SelectionList(TMS(base_exception_SelectionList::DUPLICATED_IDENTIFIER)); } if (!empty($result)) { foreach ($result[0] as $propName => $value) { $this->$propName = $value; } $this->_loadEntries(); } }
/** * get all selectionlist entries for a given selectionlist PK * * @param $FK_selectionList * @return SelectionListEntry[] */ public static function loadAllSelectionListEntries($FK_selectionList) { $table = DB::table('selectionListEntry'); $where = DB::where($table->getColumn('FK_selectionList'), DB::intTerm($FK_selectionList)); $select = new base_database_statement_Select(); $select->setTable($table); $select->setWhere($where); $result = $select->fetchDatabase(); $selectionListEntries = []; foreach ($result as $row) { $selectionListEntry = new self(); foreach ($row as $propName => $value) { $selectionListEntry->setProperty($propName, $value); } $selectionListEntries[] = $selectionListEntry; } return $selectionListEntries; }
private function _load() { $table = DB::table('sequence'); $colNum = $table->getColumn('num'); $colClass = $table->getColumn('class'); $statement = new base_database_statement_Select(); $statement->setColumns(array($colNum)); $statement->setTable($table); $where = DB::where($colClass, DB::term($this->class)); $statement->setWhere($where); $result = $statement->fetchDatabase(); if (empty($result)) { $this->actSeq = 0; } else { $values = $result[0]; $this->actSeq = $values['num']; } $this->nextSeq = $this->actSeq + 1; }
/** * load the data for the object to load * * @param $key * @param $keyField * @param $historic * * @throws BaseException * @throws base_database_Exception * @return array */ private function _loadData($key, $keyField, $historic) { $table = DB::table($this->getTable()); $where = DB::where($table->getColumn($keyField), DB::intTerm($key)); if (!empty($historic)) { $where->addAnd($table->getColumn('histtop'), DB::stringTerm($historic)); } $selectStatement = new base_database_statement_Select(); $selectStatement->setTable($table); $selectStatement->setWhere($where); $result = $selectStatement->fetchDatabase(); if (count($result) > 1) { throw new BaseException('Einfügen Zeile 160 BaseObject'); } if (empty($result)) { return null; } return $result[0]; }
public function findSingleConnection($lkLeft, $lkRight) { $table = DB::table($this->getTable()); $where = DB::where($table->getColumn('lkLeft'), DB::intTerm($lkLeft)); $where->addAnd($table->getColumn('lkRight'), DB::intTerm($lkRight)); $selectStatement = new base_database_statement_Select(); $selectStatement->setTable($table); $selectStatement->setWhere($where); $result = $selectStatement->fetchDatabase(); if (count($result) > 1) { Logger::output('BaseConnectionObject.log', "Duplicated entry for '" . get_class($this) . "' with lkLeft '$lkLeft' and lkRight '$lkRight'"); } if (count($result) == 0) { return null; } $this->_setObject($result); return $this; }
/** * @param $where * @return array */ private function getExistingObjects($where) { $colPK = $this->table->getColumn('PK'); $selectStatement = new base_database_statement_Select(); $selectStatement->setTable($this->table); $selectStatement->setWhere($where); $selectStatement->setColumns(array($colPK)); $result = $selectStatement->fetchDatabase(); if (empty($result)) { return null; } return $result[0]['PK']; }
/** * create the select statement * * @param $columns * @return base_database_statement_Select */ private function _createSelectStatement($columns) { $select = new base_database_statement_Select(); $select->setTable($this->table); $select->setColumns($columns); if (!empty($this->order)) { $select->setOrder($this->order); } if (!empty($this->limit)) { $select->setLimit($this->limit); } if (!empty($this->where)) { $select->setWhere($this->where); } return $select; }
/** * set the select statement for the db fetch * * @return base_database_statement_Select * @throws base_database_Exception */ private function _setSelectStatement() { $table = DB::table('tms'); $colName = $table->getColumn('name'); $colValue = $table->getColumn(Language::get()->getSelectedLanguage()); $where = DB::where($colName, DB::stringTerm($this->module)); $select = new base_database_statement_Select(); $select->setTable($table); $select->setColumns(array($colValue)); $select->setWhere($where); return $select; }
private static function _loadDataPermissionClass($className) { $table = DB::table('datapermission'); $where = DB::where($table->getColumn('objClass'), DB::term($className)); $selectStatement = new base_database_statement_Select(); $selectStatement->setTable($table); $selectStatement->setWhere($where); $selectStatement->setColumns(array($table->getColumn('dpClass'))); $result = $selectStatement->fetchDatabase(); /** @todo tabelle anlegen!!!!! */ if (count($result) != 1) { return ucfirst('nobody'); } return ucfirst($result[0]['dpClass']); }
/** * get all fieldNames for the given class * * @return array * @throws base_database_Exception */ public function getAllFieldNames() { $table = DB::table($this->table); $colClass = $table->getColumn('class'); $where = DB::where($colClass, DB::stringTerm($this->class)); $sqlStatement = new base_database_statement_Select(); $sqlStatement->setTable($table); $sqlStatement->setWhere($where); $sqlStatement->setColumns(array($table->getColumn('fieldName'))); $result = $sqlStatement->fetchDatabase(); $fieldNames = []; foreach ($result as $row) { $fieldNames[] = $row['fieldName']; } return $fieldNames; }