getDBArray() публичный Метод

Laedt das komplette Resultset in ein Array und gibt dieses zurueck und wechselt die DBID falls vorhanden.
public getDBArray ( string $query = null, array $params = [], integer $fetchType = PDO::FETCH_ASSOC ) : array
$query string The sql-query
$params array An optional array of statement parameter
$fetchType integer
Результат array
 /**
  * Fügt Optionen anhand der Übergeben DBSQL-Select-Abfrage hinzu.
  */
 function addDBSqlOptions($qry)
 {
     $sql = new rex_sql();
     $this->addOptions($sql->getDBArray($qry, MYSQL_NUM));
 }
/**
 * Erstellt den nötigen HTML Code um ein Formular zu erweitern
 *
 * @param $sqlFields rex_sql-objekt, dass die zu verarbeitenden Felder enthält
 * @param $activeItem objekt, dass mit getValue() die Werte des akuellen Eintrags zurückgibt
 * @param $formatCallback callback, dem die infos als Array übergeben werden und den formatierten HTML Text zurückgibt
 */
function rex_a62_metaFields($sqlFields, $activeItem, $formatCallback, $epParams)
{
    global $I18N;
    $s = '';
    // Startwert für MEDIABUTTON, MEDIALIST, LINKLIST zähler
    $media_id = 1;
    $mlist_id = 1;
    $link_id = 1;
    $llist_id = 1;
    $sqlFields->reset();
    for ($i = 0; $i < $sqlFields->getRows(); $i++) {
        // Umschliessendes Tag von Label und Formularelement
        $tag = 'p';
        $tag_attr = '';
        $name = $sqlFields->getValue('name');
        $title = $sqlFields->getValue('title');
        $params = $sqlFields->getValue('params');
        $typeLabel = $sqlFields->getValue('label');
        $attr = $sqlFields->getValue('attributes');
        $dblength = $sqlFields->getValue('dblength');
        $dbvalues = array(htmlspecialchars($sqlFields->getValue('default')));
        $dbvalues_esc = $dbvalues;
        if ($activeItem) {
            $itemValue = $activeItem->getValue($name);
            if (strpos($itemValue, '|+|') !== false) {
                // Alte notation mit |+| als Trenner
                $dbvalues = explode('|+|', $activeItem->getValue($name));
            } else {
                // Neue Notation mit | als Trenner
                $dbvalues = explode('|', $activeItem->getValue($name));
            }
            $dbvalues_esc = array_map('htmlspecialchars', $dbvalues);
        }
        if ($title != '') {
            $label = htmlspecialchars(rex_translate($title));
        } else {
            $label = htmlspecialchars($name);
        }
        $id = preg_replace('/[^a-zA-Z\\-0-9_]/', '_', $label);
        $attr .= rex_tabindex();
        $labelIt = true;
        $field = '';
        switch ($typeLabel) {
            case 'text':
                $field = '<input type="' . $typeLabel . '" name="' . $name . '" value="' . $dbvalues_esc[0] . '" id="' . $id . ' "maxlength="' . $dblength . '" ' . $attr . ' />';
                break;
            case 'checkbox':
                $name .= '[]';
            case 'radio':
                $values = array();
                if (rex_sql::getQueryType($params) == 'SELECT') {
                    $sql = new rex_sql();
                    $value_groups = $sql->getDBArray($params, MYSQL_NUM);
                    foreach ($value_groups as $value_group) {
                        if (isset($value_group[1])) {
                            $values[$value_group[1]] = $value_group[0];
                        } else {
                            $values[$value_group[0]] = $value_group[0];
                        }
                    }
                } else {
                    $value_groups = explode('|', $params);
                    foreach ($value_groups as $value_group) {
                        if (strpos($value_group, ':') !== false) {
                            $temp = explode(':', $value_group);
                            $values[$temp[0]] = $temp[1];
                        } else {
                            $values[$value_group] = $value_group;
                        }
                    }
                }
                $class = $typeLabel == 'radio' ? 'rex-rdo' : 'rex-chckbx';
                $oneValue = count($values) == 1;
                if (!$oneValue) {
                    $tag = '';
                    $labelIt = false;
                    $tag = 'div';
                    $tag_attr = ' class="rex-chckbxs rex-ptag"';
                    $field .= '<p>' . $label . '</p>';
                }
                foreach ($values as $key => $value) {
                    $id = preg_replace('/[^a-zA-Z\\-0-9_]/', '_', $id . $key);
                    $key = htmlspecialchars($key);
                    // wenn man keine Werte angibt (Boolean Chkbox/Radio)
                    // Dummy Wert annehmen, damit an/aus unterscheidung funktioniert
                    if ($oneValue && $key == '') {
                        $key = 'true';
                    }
                    $selected = '';
                    if (in_array($key, $dbvalues_esc)) {
                        $selected = ' checked="checked"';
                    }
                    if ($oneValue) {
                        $tag_attr = ' class="' . $class . '"';
                        $field .= '<input type="' . $typeLabel . '" name="' . $name . '" value="' . $key . '" id="' . $id . '" ' . $attr . $selected . ' />' . "\n";
                    } else {
                        $field .= '<p class="' . $class . '">' . "\n";
                        $field .= '<label for="' . $id . '"><span>' . htmlspecialchars($value) . '</span></label>';
                        $field .= '<input type="' . $typeLabel . '" name="' . $name . '" value="' . $key . '" id="' . $id . '" ' . $attr . $selected . ' />' . "\n";
                        $field .= '</p>' . "\n";
                    }
                }
                break;
            case 'select':
                $select = new rex_select();
                $select->setName($name);
                $select->setId($id);
                // hier mit den "raw"-values arbeiten, da die rex_select klasse selbst escaped
                $select->setSelected($dbvalues);
                foreach (rex_split_string($attr) as $attr_name => $attr_value) {
                    if (empty($attr_name)) {
                        continue;
                    }
                    $select->setAttribute($attr_name, $attr_value);
                    if ($attr_name == 'multiple') {
                        $select->setName($name . '[]');
                    }
                }
                if (rex_sql::getQueryType($params) == 'SELECT') {
                    // Werte via SQL Laden
                    $select->addDBSqlOptions($params);
                } else {
                    // Optionen mit | separiert
                    // eine einzelne Option kann mit key:value separiert werden
                    $values = array();
                    $value_groups = explode('|', $params);
                    foreach ($value_groups as $value_group) {
                        if (strpos($value_group, ':') !== false) {
                            $temp = explode(':', $value_group);
                            $values[$temp[0]] = $temp[1];
                        } else {
                            $values[$value_group] = $value_group;
                        }
                    }
                    $select->addOptions($values);
                }
                $field .= $select->get();
                break;
            case 'datetime':
            case 'date':
                if ($dbvalues_esc[0] == '') {
                    $dbvalues_esc[0] = time();
                }
                $style = 'class="rex-fdate"';
                $yearStyle = 'class="rex-fdatey"';
                $yearSelect = new rex_select();
                $yearSelect->addOptions(range(2005, date('Y') + 10), true);
                $yearSelect->setName($name . '[year]');
                $yearSelect->setSize(1);
                $yearSelect->setId($id);
                $yearSelect->setStyle($yearStyle);
                $yearSelect->setSelected(date('Y', $dbvalues_esc[0]));
                $monthSelect = new rex_select();
                $monthSelect->addOptions(range(1, 12), true);
                $monthSelect->setName($name . '[month]');
                $monthSelect->setSize(1);
                $monthSelect->setStyle($style);
                $monthSelect->setSelected(date('m', $dbvalues_esc[0]));
                $daySelect = new rex_select();
                $daySelect->addOptions(range(1, 31), true);
                $daySelect->setName($name . '[day]');
                $daySelect->setSize(1);
                $daySelect->setStyle($style);
                $daySelect->setSelected(date('j', $dbvalues_esc[0]));
                if ($typeLabel == 'datetime') {
                    $hourSelect = new rex_select();
                    $hourSelect->addOptions(range(1, 23), true);
                    $hourSelect->setName($name . '[hour]');
                    $hourSelect->setSize(1);
                    $hourSelect->setStyle($style);
                    $hourSelect->setSelected(date('G', $dbvalues_esc[0]));
                    $minuteSelect = new rex_select();
                    $minuteSelect->addOptions(range(0, 59), true);
                    $minuteSelect->setName($name . '[minute]');
                    $minuteSelect->setSize(1);
                    $minuteSelect->setStyle($style);
                    $minuteSelect->setSelected(date('i', $dbvalues_esc[0]));
                    $field = $daySelect->get() . $monthSelect->get() . $yearSelect->get() . '-' . $hourSelect->get() . $minuteSelect->get();
                } else {
                    $field = $daySelect->get() . $monthSelect->get() . $yearSelect->get();
                }
                break;
            case 'textarea':
                $field = '<textarea name="' . $name . '" id="' . $id . '" cols="50" rows="6" ' . $attr . '>' . $dbvalues_esc[0] . '</textarea>';
                break;
            case 'REX_MEDIA_BUTTON':
                $tag = 'div';
                $tag_attr = ' class="rex-ptag"';
                $field = rex_var_media::getMediaButton($media_id);
                $field = str_replace('REX_MEDIA[' . $media_id . ']', $dbvalues_esc[0], $field);
                $field = str_replace('MEDIA[' . $media_id . ']', $name, $field);
                $id = 'REX_MEDIA_' . $media_id;
                $media_id++;
                break;
            case 'REX_MEDIALIST_BUTTON':
                $tag = 'div';
                $tag_attr = ' class="rex-ptag"';
                $name .= '[]';
                $field = rex_var_media::getMediaListButton($mlist_id, implode(',', $dbvalues_esc));
                $field = str_replace('MEDIALIST[' . $mlist_id . ']', $name, $field);
                $id = 'REX_MEDIALIST_' . $mlist_id;
                $mlist_id++;
                break;
            case 'REX_LINK_BUTTON':
                $tag = 'div';
                $tag_attr = ' class="rex-ptag"';
                $category = '';
                if ($activeItem) {
                    $category = $activeItem->getValue('category_id');
                }
                $field = rex_var_link::getLinkButton($link_id, $dbvalues_esc[0], $category);
                $field = str_replace('LINK[' . $link_id . ']', $name, $field);
                $id = 'LINK_' . $link_id;
                $link_id++;
                break;
            case 'REX_LINKLIST_BUTTON':
                $tag = 'div';
                $tag_attr = ' class="rex-ptag"';
                $category = '';
                if ($activeItem) {
                    $category = $activeItem->getValue('category_id');
                }
                $name .= '[]';
                $field = rex_var_link::getLinklistButton($llist_id, implode(',', $dbvalues), $category);
                $field = str_replace('LINKLIST[' . $llist_id . ']', $name, $field);
                $id = 'REX_LINKLIST_' . $llist_id;
                $llist_id++;
                break;
            default:
                // ----- EXTENSION POINT
                list($field, $tag, $tag_attr, $id, $label, $labelIt) = rex_register_extension_point('A62_CUSTOM_FIELD', array($field, $tag, $tag_attr, $id, $label, $labelIt, 'type' => $typeLabel, 'sql' => $sqlFields));
        }
        $s .= rex_call_func($formatCallback, array($field, $tag, $tag_attr, $id, $label, $labelIt), false);
        $sqlFields->next();
    }
    return $s;
}
/**
 * Erstellt den nötigen HTML Code um ein Formular zu erweitern
 *
 * @param $sqlFields rex_sql-objekt, dass die zu verarbeitenden Felder enthält
 * @param $activeItem objekt, dass mit getValue() die Werte des akuellen Eintrags zurückgibt
 * @param $formatCallback callback, dem die infos als Array übergeben werden und den formatierten HTML Text zurückgibt
 */
function rex_a62_metaFields($sqlFields, $activeItem, $formatCallback, $epParams)
{
    global $I18N;
    $s = '';
    // Startwert für MEDIABUTTON, MEDIALIST, LINKLIST
    $media_id = 1;
    $mlist_id = 1;
    $link_id = 1;
    $sqlFields->reset();
    for ($i = 0; $i < $sqlFields->getRows(); $i++) {
        // Umschliessendes Tag von Label und Formularelement
        $tag = 'p';
        $tag_attr = '';
        $name = $sqlFields->getValue('name');
        $title = $sqlFields->getValue('title');
        $params = $sqlFields->getValue('params');
        $typeLabel = $sqlFields->getValue('label');
        $attr = $sqlFields->getValue('attributes');
        $dbvalues = array('');
        if ($activeItem) {
            $dbvalues = explode('|+|', $activeItem->getValue($name));
        }
        if ($title != '') {
            $label = rex_translate($title);
        } else {
            $label = htmlspecialchars($name);
        }
        $id = preg_replace('/[^a-zA-Z\\-0-9_]/', '_', $label);
        $attr .= rex_tabindex();
        $labelIt = true;
        $field = '';
        switch ($typeLabel) {
            case 'text':
                $field = '<input type="' . $sqlFields->getValue('label') . '" name="' . $name . '" value="' . $dbvalues[0] . '" id="' . $id . '" ' . $attr . ' />';
                break;
            case 'checkbox':
                $name .= '[]';
            case 'radio':
                $values = array();
                if (rex_sql::getQueryType($params) == 'SELECT') {
                    $sql = new rex_sql();
                    $value_groups = $sql->getDBArray($params, MYSQL_NUM);
                    foreach ($value_groups as $value_group) {
                        if (isset($value_group[1])) {
                            $values[$value_group[1]] = $value_group[0];
                        } else {
                            $values[$value_group[0]] = $value_group[0];
                        }
                    }
                } else {
                    $value_groups = explode('|', $params);
                    foreach ($value_groups as $value_group) {
                        if (strpos($value_group, ':') !== false) {
                            $temp = explode(':', $value_group);
                            $values[$temp[0]] = $temp[1];
                        } else {
                            $values[$value_group] = $value_group;
                        }
                    }
                }
                //        if($epParams['extension_point'] != 'CAT_META_FORM_EDIT')
                //          $field .= '<span>'. $label .'</span>';
                $class = $typeLabel == 'radio' ? 'rex-rdo' : 'rex-chckbx';
                $oneValue = count($values) == 1;
                if (!$oneValue) {
                    $tag = '';
                    $labelIt = false;
                    $tag = 'div';
                    $tag_attr = ' class="rex-chckbxs rex-ptag"';
                    $field .= '<p>' . $label . '</p>';
                }
                foreach ($values as $key => $value) {
                    $id = preg_replace('/[^a-zA-Z\\-0-9_]/', '_', $id . $key);
                    // wenn man keine Werte angibt (Boolean Chkbox/Radio)
                    // Dummy Wert annehmen, damit an/aus unterscheidung funktioniert
                    if ($oneValue && $key == '') {
                        $key = 'true';
                    }
                    $selected = '';
                    if (in_array($key, $dbvalues)) {
                        $selected = ' checked="checked"';
                    }
                    if ($oneValue) {
                        $tag_attr = ' class="' . $class . '"';
                        $field .= '<input type="' . $typeLabel . '" name="' . $name . '" value="' . $key . '" id="' . $id . '" ' . $attr . $selected . ' />' . "\n";
                    } else {
                        $field .= '<p class="' . $class . '">' . "\n";
                        $field .= '<label for="' . $id . '"><span>' . htmlspecialchars($value) . '</span></label>';
                        $field .= '<input type="' . $typeLabel . '" name="' . $name . '" value="' . $key . '" id="' . $id . '" ' . $attr . $selected . ' />' . "\n";
                        $field .= '</p>' . "\n";
                    }
                }
                break;
            case 'select':
                $select = new rex_select();
                $select->setName($name);
                $select->setId($id);
                $select->setSelected($dbvalues);
                foreach (explode(' ', $attr) as $pair) {
                    if (strpos($pair, '=') === false) {
                        continue;
                    }
                    $temp = explode('=', $pair);
                    $select->setAttribute($temp[0], str_replace(array('"', "'"), '', $temp[1]));
                    if ($temp[0] == 'multiple') {
                        $select->setName($name . '[]');
                    }
                }
                if (rex_sql::getQueryType($params) == 'SELECT') {
                    $select->addDBSqlOptions($params);
                } else {
                    $values = array();
                    $value_groups = explode('|', $params);
                    foreach ($value_groups as $value_group) {
                        if (strpos($value_group, ':') !== false) {
                            $temp = explode(':', $value_group);
                            $values[$temp[0]] = $temp[1];
                        } else {
                            $values[$value_group] = $value_group;
                        }
                    }
                    $select->addOptions($values);
                }
                $field .= $select->get();
                break;
            case 'datetime':
            case 'date':
                if ($dbvalues[0] == '') {
                    $dbvalues[0] = time();
                }
                $style = 'class="rex-fdate"';
                $yearStyle = 'class="rex-fdatey"';
                $yearSelect = new rex_select();
                $yearSelect->addOptions(range(2005, date('Y') + 2), true);
                $yearSelect->setName($name . '[year]');
                $yearSelect->setSize(1);
                $yearSelect->setId($id);
                $yearSelect->setStyle($yearStyle);
                $yearSelect->setSelected(date('Y', $dbvalues[0]));
                $monthSelect = new rex_select();
                $monthSelect->addOptions(range(1, 12), true);
                $monthSelect->setName($name . '[month]');
                $monthSelect->setSize(1);
                $monthSelect->setStyle($style);
                $monthSelect->setSelected(date('m', $dbvalues[0]));
                $daySelect = new rex_select();
                $daySelect->addOptions(range(1, 31), true);
                $daySelect->setName($name . '[day]');
                $daySelect->setSize(1);
                $daySelect->setStyle($style);
                $daySelect->setSelected(date('j', $dbvalues[0]));
                if ($typeLabel == 'datetime') {
                    $hourSelect = new rex_select();
                    $hourSelect->addOptions(range(1, 23), true);
                    $hourSelect->setName($name . '[hour]');
                    $hourSelect->setSize(1);
                    $hourSelect->setStyle($style);
                    $hourSelect->setSelected(date('G', $dbvalues[0]));
                    $minuteSelect = new rex_select();
                    $minuteSelect->addOptions(range(0, 59), true);
                    $minuteSelect->setName($name . '[minute]');
                    $minuteSelect->setSize(1);
                    $minuteSelect->setStyle($style);
                    $minuteSelect->setSelected(date('i', $dbvalues[0]));
                    $field = $daySelect->get() . $monthSelect->get() . $yearSelect->get() . '-' . $hourSelect->get() . $minuteSelect->get();
                } else {
                    $field = $daySelect->get() . $monthSelect->get() . $yearSelect->get();
                }
                break;
            case 'textarea':
                $field = '<textarea name="' . $name . '" id="' . $id . '" ' . $attr . ' cols="50" rows="6">' . $dbvalues[0] . '</textarea>';
                break;
            case 'REX_MEDIA_BUTTON':
                $tag = 'div';
                $tag_attr = ' class="rex-ptag"';
                $field = rex_var_media::getMediaButton($media_id);
                $field = str_replace('REX_MEDIA[' . $media_id . ']', $dbvalues[0], $field);
                $field = str_replace('MEDIA[' . $media_id . ']', $name, $field);
                $id = 'REX_MEDIA_' . $media_id;
                $media_id++;
                break;
            case 'REX_MEDIALIST_BUTTON':
                $tag = 'div';
                $tag_attr = ' class="rex-ptag"';
                $name .= '[]';
                $field = rex_var_media::getMediaListButton($mlist_id, implode(',', $dbvalues));
                $field = str_replace('MEDIALIST[' . $mlist_id . ']', $name, $field);
                $id = 'REX_MEDIALIST_' . $mlist_id;
                $mlist_id++;
                break;
            case 'REX_LINK_BUTTON':
                $tag = 'div';
                $tag_attr = ' class="rex-ptag"';
                $category = '';
                if ($activeItem) {
                    $category = $activeItem->getValue('category_id');
                }
                $field = rex_var_link::getLinkButton($link_id, $dbvalues[0], $category);
                $field = str_replace('LINK[' . $link_id . ']', $name, $field);
                $id = 'LINK_' . $link_id;
                $link_id++;
                break;
        }
        $s .= rex_call_func($formatCallback, array($field, $tag, $tag_attr, $id, $label, $labelIt), false);
        $sqlFields->next();
    }
    return $s;
}