示例#1
0
 /**
  * Create the SQL select 'name AS alias' segment for list/form queries
  *
  * @param   array  &$aFields    array of element names
  * @param   array  &$aAsFields  array of 'name AS alias' fields
  * @param   array  $opts        options
  *
  * @return  void
  */
 public function getAsField_html(&$aFields, &$aAsFields, $opts = array())
 {
     if ($this->isJoin()) {
         // $$$ rob was commented out - but meant that the SELECT GROUP_CONCAT subquery was never user
         return parent::getAsField_html($aFields, $aAsFields, $opts);
     }
     $table = $this->actualTableName();
     $params = $this->getParams();
     $db = FabrikWorker::getDbo();
     $listModel = $this->getlistModel();
     $element = $this->getElement();
     $tableRow = $listModel->getTable();
     $joins = $listModel->getJoins();
     foreach ($joins as $tmpjoin) {
         if ($tmpjoin->element_id == $element->id) {
             $join = $tmpjoin;
             break;
         }
     }
     $connection = $listModel->getConnection();
     // Make sure same connection as this table
     $fullElName = JArrayHelper::getValue($opts, 'alias', $table . '___' . $element->name);
     if ($params->get('join_conn_id') == $connection->get('id') || $element->plugin != 'databasejoin') {
         $join = $this->getJoin();
         if (!$join) {
             return false;
         }
         $joinTableName = $join->table_join_alias;
         $tables = $this->getForm()->getLinkedFabrikLists($params->get('join_db_name'));
         /*	store unjoined values as well (used in non-join group table views)
          * this wasn't working for test case:
          * events -> (db join) event_artists -> el join (artist)
          * $$$ rob in csv import keytable not set
          * $$$ hugh - if keytable isn't set, the safeColName blows up!
          * Trying to debug issue with linked join elements, which don't get detected by
          * getJoins or getJoin 'cos element ID doesn't match element_id in fabrik_joins
          *$k = isset($join->keytable ) ? $join->keytable : $join->join_from_table;
          *$k = FabrikString::safeColName("`$join->keytable`.`$element->name`");
          */
         $keytable = isset($join->keytable) ? $join->keytable : $join->join_from_table;
         $k = FabrikString::safeColName($keytable . '.' . $element->name);
         $k2 = $this->getJoinLabelColumn();
         if (JArrayHelper::getValue($opts, 'inc_raw', true)) {
             $aFields[] = $k . ' AS ' . $db->quoteName($fullElName . '_raw');
             $aAsFields[] = $db->quoteName($fullElName . '_raw');
         }
         $aFields[] = $k2 . ' AS ' . $db->quoteName($fullElName);
         $aAsFields[] = $db->quoteName($fullElName);
     } else {
         $aFields[] = $db->quoteName($table . '.' . $element->name) . ' AS ' . $db->quoteName($fullElName);
         $aAsFields[] = $db->quoteName($fullElName);
     }
 }