示例#1
0
 /**
  * Returns a reference to the a Table object, always creating it
  *
  * @param type $type The table type to instantiate
  * @param string A prefix for the table class name
  * @return database A database object
  * @since 1.5
  */
 function &getInstanceAutofields($type, $prefix, $table, $key = 'id', $defaults = array())
 {
     $type = preg_replace('/[^A-Z0-9_\\.-]/i', '', $type);
     $tableClass = $prefix . ucfirst($type);
     if (!class_exists($tableClass)) {
         jimport('joomla.filesystem.path');
         if ($path = JPath::find(RdbsTable::addIncludePath(), strtolower($type) . '.php')) {
             require_once $path;
             if (!class_exists($tableClass)) {
                 $tableClass = 'RdbsTable';
             }
         } else {
             $tableClass = 'RdbsTable';
         }
     }
     $db =& RdbsFactory::getDBO();
     $instance = new $tableClass($table, $key, $db);
     $instance->setDBO($db);
     // get the table properties
     $result = $db->getTableFields(array($table));
     $fields = $result[$table];
     foreach ($fields as $key => $val) {
         if (count($defaults) != 0 and array_key_exists($key, $defaults)) {
             $instance->set($key, $defaults[$key]);
         } else {
             if (strpos($val, 'int') === false and strpos($val, 'float') === false) {
                 $instance->set($key, '');
             } else {
                 $instance->set($key, 0);
             }
         }
     }
     return $instance;
 }
示例#2
0
 function getListElement($listname, $element)
 {
     $r = '';
     if (trim($listname) != '' && trim($element) != '') {
         $db = RdbsFactory::getDBO();
         $query = 'SELECT e.name ' . ' FROM #__rd_mc_listelements as e, #__rd_mc_lists as l ' . ' WHERE l.name = "' . $listname . '" AND l.id = e.listid AND e.published = 1 AND e.value = "' . $element . '"';
         $db->setQuery($query);
         $r = $db->loadResult();
     }
     return $r;
 }