/** * @since 3.0b * helper function get get a connection * @param mixed - a list table or connection id */ public function getConnection($item = null) { $jform = JRequest::getVar('jform', array(), 'post'); if (is_object($item)) { $item = is_null($item->connection_id) ? JArrayHelper::getValue($jform, 'connection_id', -1) : $item->connection_id; } $connId = (int) $item; $config = JFactory::getConfig(); if (!self::$connection) { self::$connection = array(); } if (!array_key_exists($connId, self::$connection)) { $connectionModel = JModel::getInstance('connection', 'FabrikFEModel'); $connectionModel->setId($connId); if ($connId === -1) { //-1 for creating new table $connectionModel->loadDefaultConnection(); $connectionModel->setId($connectionModel->getConnection()->id); } $connection = $connectionModel->getConnection(); self::$connection[$connId] = $connectionModel; if (JError::isError(self::$connection[$connId])) { JError::handleEcho(self::$connection[$connId]); } } return self::$connection[$connId]; }
/** * function get the tables connection object * sets $this->_oConn to the tables connection * @return object connection */ function &getConnection() { $config = JFactory::getConfig(); if (!isset($this->_oConn)) { $table =& $this->getTable(); $connectionModel = JModel::getInstance('connection', 'FabrikFEModel'); $jform = JRequest::getVar('jform', array(), 'post'); $connId = is_null($table->connection_id) ? JArrayHelper::getValue($jform, 'connection_id', null) : $table->connection_id; $connectionModel->setId($connId); if ($connId == '' || is_null($connId) || $connId == '-1') { //-1 for creating new table $connectionModel->loadDefaultConnection(); $connectionModel->setId($connectionModel->getConnection()->id); } $connection =& $connectionModel->getConnection(); $this->_oConn =& $connectionModel; if (JError::isError($this->_oConn)) { JError::handleEcho($this->_oConn); } } return $this->_oConn; }