organizePriorities() public static method

Dies ist z.B. nützlich beim Umgang mit einer Prioritäts-Spalte.
public static organizePriorities ( string $tableName, string $priorColumnName, string $whereCondition = '', string $orderBy = '', integer $startBy = 1 )
$tableName string Name der Datenbanktabelle
$priorColumnName string Name der Spalte in der Tabelle, in der die Priorität (Integer) gespeichert wird
$whereCondition string Where-Bedingung zur Einschränkung des ResultSets
$orderBy string Sortierung des ResultSets
$startBy integer Startpriorität
Exemplo n.º 1
0
 public function organizePriorities(rex_extension_point $ep)
 {
     if ($this->table->equals($ep->getParam('form'))) {
         $name = $this->getFieldName();
         rex_sql_util::organizePriorities($this->table->getTableName(), $name, $this->whereCondition, $name . ', updatedate desc');
     }
 }
Exemplo n.º 2
0
 /**
  * Löscht eine Clang.
  *
  * @param int $id Zu löschende ClangId
  *
  * @throws rex_exception
  */
 public static function deleteCLang($id)
 {
     $startClang = rex_clang::getStartId();
     if ($id == $startClang) {
         throw new rex_functional_exception(rex_i18n::msg('clang_error_startidcanotbedeleted', $startClang));
     }
     if (!rex_clang::exists($id)) {
         throw new rex_functional_exception(rex_i18n::msg('clang_error_idcanotbedeleted', $id));
     }
     $clang = rex_clang::get($id);
     $del = rex_sql::factory();
     $del->setQuery('delete from ' . rex::getTablePrefix() . 'clang where id=?', [$id]);
     rex_sql_util::organizePriorities(rex::getTable('clang'), 'priority', '', 'priority');
     rex_delete_cache();
     // ----- EXTENSION POINT
     rex_extension::registerPoint(new rex_extension_point('CLANG_DELETED', '', ['id' => $clang->getId(), 'name' => $clang->getName(), 'clang' => $clang]));
 }
Exemplo n.º 3
0
/**
 * Fügt ein MetaFeld hinzu und legt dafür eine Spalte in der MetaTable an.
 */
function rex_metainfo_add_field($title, $name, $priority, $attributes, $type, $default, $params = null, $validate = null, $restrictions = '')
{
    $prefix = rex_metainfo_meta_prefix($name);
    $metaTable = rex_metainfo_meta_table($prefix);
    // Prefix korrekt?
    if (!$metaTable) {
        return rex_i18n::msg('minfo_field_error_invalid_prefix');
    }
    // TypeId korrekt?
    $qry = 'SELECT * FROM ' . rex::getTablePrefix() . 'metainfo_type WHERE id=' . $type . ' LIMIT 2';
    $sql = rex_sql::factory();
    $typeInfos = $sql->getArray($qry);
    if ($sql->getRows() != 1) {
        return rex_i18n::msg('minfo_field_error_invalid_type');
    }
    $fieldDbType = $typeInfos[0]['dbtype'];
    $fieldDbLength = $typeInfos[0]['dblength'];
    // Spalte existiert schon?
    $sql->setQuery('SELECT * FROM ' . $metaTable . ' LIMIT 1');
    if (in_array($name, $sql->getFieldnames())) {
        return rex_i18n::msg('minfo_field_error_unique_name');
    }
    // Spalte extiert laut metainfo_field?
    $qry = 'SELECT * FROM ' . rex::getTablePrefix() . 'metainfo_field WHERE name=:name LIMIT 1';
    $sql = rex_sql::factory();
    $sql->setQuery($qry, [':name' => $name]);
    if ($sql->getRows() != 0) {
        return rex_i18n::msg('minfo_field_error_unique_name');
    }
    $sql->setTable(rex::getTablePrefix() . 'metainfo_field');
    $sql->setValue('title', $title);
    $sql->setValue('name', $name);
    $sql->setValue('priority', $priority);
    $sql->setValue('attributes', $attributes);
    $sql->setValue('type_id', $type);
    $sql->setValue('default', $default);
    $sql->setValue('params', $params);
    $sql->setValue('validate', $validate);
    $sql->setValue('restrictions', $restrictions);
    $sql->addGlobalUpdateFields();
    $sql->addGlobalCreateFields();
    $sql->insert();
    // replace LIKE wildcards
    $prefix = str_replace(['_', '%'], ['\\_', '\\%'], $prefix);
    rex_sql_util::organizePriorities(rex::getTablePrefix() . 'metainfo_field', 'priority', 'name LIKE "' . $prefix . '%"', 'priority, updatedate');
    $tableManager = new rex_metainfo_table_manager($metaTable);
    return $tableManager->addColumn($name, $fieldDbType, $fieldDbLength, $default);
}
Exemplo n.º 4
0
 protected function organizePriorities($newPrio, $oldPrio)
 {
     if ($newPrio == $oldPrio) {
         return;
     }
     // replace LIKE wildcards
     $metaPrefix = str_replace(['_', '%'], ['\\_', '\\%'], $this->metaPrefix);
     rex_sql_util::organizePriorities($this->tableName, 'priority', 'name LIKE "' . $metaPrefix . '%"', 'priority, updatedate desc');
 }
Exemplo n.º 5
0
 /**
  * Berechnet die Prios der Kategorien in einer Kategorie neu.
  *
  * @param int $parent_id KategorieId der Kategorie, die erneuert werden soll
  * @param int $clang     ClangId der Kategorie, die erneuert werden soll
  * @param int $new_prio  Neue PrioNr der Kategorie
  * @param int $old_prio  Alte PrioNr der Kategorie
  */
 public static function newCatPrio($parent_id, $clang, $new_prio, $old_prio)
 {
     if ($new_prio != $old_prio) {
         if ($new_prio < $old_prio) {
             $addsql = 'desc';
         } else {
             $addsql = 'asc';
         }
         rex_sql_util::organizePriorities(rex::getTable('article'), 'catpriority', 'clang_id=' . $clang . ' AND parent_id=' . $parent_id . ' AND startarticle=1', 'catpriority,updatedate ' . $addsql);
         rex_article_cache::deleteLists($parent_id);
     }
 }
Exemplo n.º 6
0
 public static function addSlice()
 {
     $article_id = rex_request('article_id', 'int');
     $function = rex_request('page', 'string');
     $cut_slice_id = $slice_id = $_SESSION['slice_ui']['slice_id'];
     $module_id = $_SESSION['slice_ui']['module_id'];
     $clang = rex_get('clang');
     $ctype = rex_get('ctype');
     if (!self::checkPermissions(array('article_id' => $article_id, 'clang' => $clang, 'ctype' => $ctype, 'module_id' => $module_id))) {
         // Alle OBs schließen
         while (@ob_end_clean()) {
         }
         header("Location: " . rex_url::backendController() . '?article_id=' . $article_id . '&clang=' . $clang . '&page=content/edit&ctype=' . $ctype);
         exit;
     }
     $slice_revision = 0;
     $template_attributes = [];
     $newsql = rex_sql::factory();
     // $newsql->setDebug();
     $sliceTable = rex::getTablePrefix() . 'article_slice';
     $newsql->setTable($sliceTable);
     if (strpos($function, 'content/paste') !== false && !empty($_SESSION['slice_ui'])) {
         // determine priority value to get the new slice into the right order
         $priority = '0';
         // $prevSlice->setDebug();
         if ($function === 'content/paste') {
             $priority = 1;
         } else {
             $prevSlice = rex_sql::factory();
             $prevSlice->setQuery('SELECT * FROM ' . $sliceTable . ' WHERE id=' . rex_get('slice_id'));
             $priority = $prevSlice->getValue('priority') + 1;
         }
         $newsql->setValue('article_id', $article_id);
         $newsql->setValue('module_id', $module_id);
         $newsql->setValue('clang_id', $clang);
         $newsql->setValue('ctype_id', $ctype);
         $newsql->setValue('revision', $slice_revision);
         $newsql->setValue('priority', $priority);
         $newsql->addGlobalUpdateFields();
         $newsql->addGlobalCreateFields();
         try {
             $newsql->insert();
             $info = $action_message . rex_i18n::msg('block_added');
             $slice_id = $newsql->getLastId();
             if ($slice_id !== 0) {
                 $_SESSION['slice_ui']['slice_id'] = $slice_id;
             }
             rex_sql_util::organizePriorities(rex::getTable('article_slice'), 'priority', 'article_id=' . $article_id . ' AND clang_id=' . $clang . ' AND ctype_id=' . $ctype . ' AND revision=' . $slice_revision, 'priority, updatedate DESC');
             $function = '';
             // ----- EXTENSION POINT
             rex_extension::registerPoint(new rex_extension_point('SLICE_PASTED', '', ['article_id' => $article_id, 'clang' => $clang, 'function' => $function, 'slice_id' => $slice_id, 'page' => rex_be_controller::getCurrentPage(), 'ctype' => $ctype, 'category_id' => $category_id, 'module_id' => $module_id, 'article_revision' => &$article_revision, 'slice_revision' => &$slice_revision]));
             if ($_SESSION['slice_ui']['cut'] == 1) {
                 $curr = rex_sql::factory();
                 $curr->setDebug();
                 $curr->setTable($sliceTable);
                 $curr->setWhere(array('id' => $cut_slice_id));
                 $curr->delete();
                 rex_sql_util::organizePriorities(rex::getTable('article_slice'), 'priority', 'article_id=' . $_SESSION['slice_ui']['article_id'] . ' AND clang_id=' . $clang . ' AND ctype_id=' . $ctype . ' AND revision=' . $slice_revision, 'priority, updatedate DESC');
             }
         } catch (rex_sql_exception $e) {
             // echo rex_view::warning($e->getMessage());
         }
         // Alle OBs schließen
         while (@ob_end_clean()) {
         }
         header("Location: " . rex_url::backendController() . '?article_id=' . $article_id . '&clang=' . $clang . '&page=content/edit&ctype=' . $ctype);
         exit;
     }
 }
Exemplo n.º 7
0
 /**
  * Kopiert die Inhalte eines Artikels in einen anderen Artikel.
  *
  * @param int $from_id    ArtikelId des Artikels, aus dem kopiert werden (Quell ArtikelId)
  * @param int $to_id      ArtikelId des Artikel, in den kopiert werden sollen (Ziel ArtikelId)
  * @param int $from_clang ClangId des Artikels, aus dem kopiert werden soll (Quell ClangId)
  * @param int $to_clang   ClangId des Artikels, in den kopiert werden soll (Ziel ClangId)
  * @param int $revision
  *
  * @return bool TRUE bei Erfolg, sonst FALSE
  */
 public static function copyContent($from_id, $to_id, $from_clang = 1, $to_clang = 1, $revision = 0)
 {
     if ($from_id == $to_id && $from_clang == $to_clang) {
         return false;
     }
     $gc = rex_sql::factory();
     $gc->setQuery('select * from ' . rex::getTablePrefix() . "article_slice where article_id='{$from_id}' and clang_id='{$from_clang}' and revision='{$revision}'");
     if ($gc->getRows() > 0) {
         $ins = rex_sql::factory();
         //$ins->setDebug();
         $ctypes = [];
         $cols = rex_sql::factory();
         //$cols->setDebug();
         $cols->setquery('SHOW COLUMNS FROM ' . rex::getTablePrefix() . 'article_slice');
         foreach ($gc as $slice) {
             foreach ($cols as $col) {
                 $colname = $col->getValue('Field');
                 if ($colname == 'clang_id') {
                     $value = $to_clang;
                 } elseif ($colname == 'article_id') {
                     $value = $to_id;
                 } else {
                     $value = $slice->getValue($colname);
                 }
                 // collect all affected ctypes
                 if ($colname == 'ctype_id') {
                     $ctypes[$value] = $value;
                 }
                 if ($colname != 'id') {
                     $ins->setValue($colname, $value);
                 }
             }
             $ins->addGlobalUpdateFields();
             $ins->addGlobalCreateFields();
             $ins->setTable(rex::getTablePrefix() . 'article_slice');
             $ins->insert();
         }
         foreach ($ctypes as $ctype) {
             // reorg slices
             rex_sql_util::organizePriorities(rex::getTable('article_slice'), 'priority', 'article_id=' . $to_id . ' AND clang_id=' . $to_clang . ' AND ctype_id=' . $ctype . ' AND revision=' . $revision, 'priority, updatedate');
         }
         rex_article_cache::deleteContent($to_id, $to_clang);
         return true;
     }
     return false;
 }
Exemplo n.º 8
0
     if ($function == 'edit') {
         $newsql->addGlobalUpdateFields();
         try {
             $newsql->update();
             $info = $action_message . rex_i18n::msg('block_updated');
             // ----- EXTENSION POINT
             $info = rex_extension::registerPoint(new rex_extension_point('STRUCTURE_CONTENT_SLICE_UPDATED', $info, ['article_id' => $article_id, 'clang' => $clang, 'function' => $function, 'slice_id' => $slice_id, 'page' => rex_be_controller::getCurrentPage(), 'ctype' => $ctype, 'category_id' => $category_id, 'module_id' => $module_id, 'article_revision' => &$article_revision, 'slice_revision' => &$slice_revision]));
         } catch (rex_sql_exception $e) {
             $warning = $action_message . $e->getMessage();
         }
     } elseif ($function == 'add') {
         $newsql->addGlobalUpdateFields();
         $newsql->addGlobalCreateFields();
         try {
             $newsql->insert();
             rex_sql_util::organizePriorities(rex::getTable('article_slice'), 'priority', 'article_id=' . $article_id . ' AND clang_id=' . $clang . ' AND ctype_id=' . $ctype . ' AND revision=' . $slice_revision, 'priority, updatedate DESC');
             $info = $action_message . rex_i18n::msg('block_added');
             $slice_id = $newsql->getLastId();
             $function = '';
             // ----- EXTENSION POINT
             $info = rex_extension::registerPoint(new rex_extension_point('STRUCTURE_CONTENT_SLICE_ADDED', $info, ['article_id' => $article_id, 'clang' => $clang, 'function' => $function, 'slice_id' => $slice_id, 'page' => rex_be_controller::getCurrentPage(), 'ctype' => $ctype, 'category_id' => $category_id, 'module_id' => $module_id, 'article_revision' => &$article_revision, 'slice_revision' => &$slice_revision]));
         } catch (rex_sql_exception $e) {
             $warning = $action_message . $e->getMessage();
         }
     }
 } else {
     // make delete
     if (rex_content_service::deleteSlice($slice_id)) {
         $global_info = rex_i18n::msg('block_deleted');
         // ----- EXTENSION POINT
         $global_info = rex_extension::registerPoint(new rex_extension_point('STRUCTURE_CONTENT_SLICE_DELETED', $global_info, ['article_id' => $article_id, 'clang' => $clang, 'function' => $function, 'slice_id' => $slice_id, 'page' => rex_be_controller::getCurrentPage(), 'ctype' => $ctype, 'category_id' => $category_id, 'module_id' => $module_id, 'article_revision' => &$article_revision, 'slice_revision' => &$slice_revision]));
Exemplo n.º 9
0
 public static function addSlice()
 {
     $article_id = rex_request('article_id', 'int');
     $function = rex_request('page', 'string');
     $cut_slice_id = $slice_id = $_SESSION['slice_ui']['slice_id'];
     $module_id = $_SESSION['slice_ui']['module_id'];
     $clang = rex_get('clang');
     $ctype = rex_get('ctype');
     $category_id = rex_get('category_id');
     if (!self::checkPermissions(array('article_id' => $article_id, 'clang' => $clang, 'ctype' => $ctype, 'module_id' => $module_id))) {
         // Alle OBs schließen
         while (@ob_end_clean()) {
         }
         header("Location: " . rex_url::backendController() . '?article_id=' . $article_id . '&clang=' . $clang . '&page=content/edit&ctype=' . $ctype);
         exit;
     }
     $slice_revision = 0;
     $template_attributes = [];
     $newsql = rex_sql::factory();
     // $newsql->setDebug();
     $sliceTable = rex::getTablePrefix() . 'article_slice';
     $newsql->setTable($sliceTable);
     if (strpos($function, 'content/paste') !== false && !empty($_SESSION['slice_ui'])) {
         $priority = '0';
         // $prevSlice->setDebug();
         if ($function === 'content/paste') {
             $priority = 1;
         } else {
             $prevSlice = rex_sql::factory();
             $prevSlice->setTable($sliceTable);
             $prevSlice->setWhere(array('id' => rex_get('slice_id')));
             $prevSlice->select();
             $priority = $prevSlice->getValue('priority') + 1;
         }
         $copiedSlice = rex_sql::factory();
         $copiedSlice->setTable($sliceTable);
         $copiedSlice->setWhere(array('id' => $cut_slice_id));
         $copiedSlice->select();
         $exclude = array('id', 'createdate', 'updatedate', 'createuser', 'updateuser', 'priority');
         // print_r($copiedSlice->getRow());
         foreach ($copiedSlice->getRow() as $key => $value) {
             if (empty($value)) {
                 continue;
             }
             $field = end(explode('.', $key));
             if (in_array($field, $exclude)) {
                 continue;
             }
             $newsql->setValue($field, $value);
         }
         $newsql->setValue('article_id', $article_id);
         $newsql->setValue('module_id', $module_id);
         $newsql->setValue('clang_id', $clang);
         $newsql->setValue('ctype_id', $ctype);
         $newsql->setValue('revision', $slice_revision);
         $newsql->setValue('priority', $priority);
         $newsql->addGlobalUpdateFields();
         $newsql->addGlobalCreateFields();
         try {
             $newsql->insert();
             $slice_id = $newsql->getLastId();
             if ($slice_id !== 0) {
                 $_SESSION['slice_ui']['new_slice_id'] = $slice_id;
             }
             rex_sql_util::organizePriorities(rex::getTable('article_slice'), 'priority', 'article_id=' . $article_id . ' AND clang_id=' . $clang . ' AND ctype_id=' . $ctype . ' AND revision=' . $slice_revision, 'priority, updatedate DESC');
             $function = '';
             // ----- EXTENSION POINT
             rex_extension::registerPoint(new rex_extension_point('SLICE_PASTED', '', ['article_id' => $article_id, 'clang' => $clang, 'function' => $function, 'slice_id' => $slice_id, 'page' => rex_be_controller::getCurrentPage(), 'ctype' => $ctype, 'category_id' => $category_id, 'module_id' => $module_id, 'article_revision' => 0, 'slice_revision' => 0]));
             if ($_SESSION['slice_ui']['cut'] == 1) {
                 $curr = rex_sql::factory();
                 $curr->setDebug();
                 $curr->setTable($sliceTable);
                 $curr->setWhere(array('id' => $cut_slice_id));
                 $curr->delete();
                 rex_sql_util::organizePriorities(rex::getTable('article_slice'), 'priority', 'article_id=' . $_SESSION['slice_ui']['article_id'] . ' AND clang_id=' . $clang . ' AND ctype_id=' . $ctype . ' AND revision=' . $slice_revision, 'priority, updatedate DESC');
             }
         } catch (rex_sql_exception $e) {
             echo rex_view::warning($e->getMessage());
         }
         // die();
         // Alle OBs schließen
         while (@ob_end_clean()) {
         }
         header("Location: " . rex_url::backendController() . '?article_id=' . $article_id . '&clang=' . $clang . '&page=content/edit&ctype=' . $ctype);
         exit;
     }
 }