rex_sql_util::organizePriorities PHP Method

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
    public static function organizePriorities($tableName, $priorColumnName, $whereCondition = '', $orderBy = '', $startBy = 1)
    {
        // Datenbankvariable initialisieren
        $qry = 'SET @count=' . ($startBy - 1);
        $sql = rex_sql::factory();
        $sql->setQuery($qry);
        // Spalte updaten
        $qry = 'UPDATE ' . $tableName . ' SET ' . $priorColumnName . ' = ( SELECT @count := @count +1 )';
        if ($whereCondition != '') {
            $qry .= ' WHERE ' . $whereCondition;
        }
        if ($orderBy != '') {
            $qry .= ' ORDER BY ' . $orderBy;
        }
        $sql->setQuery($qry);
    }

Usage Example

Example #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');
     }
 }
All Usage Examples Of rex_sql_util::organizePriorities