コード例 #1
0
ファイル: FilesModel.php プロジェクト: osmcz/website
    public static function sort($data)
    {
        if (isset($data['changedId']) and $f = self::getFile($data['changedId'])) {
            //update position DOWN of removed gallery
            dibi::query('UPDATE pages_files
				SET ord = ord-1
				WHERE id_page = %i', $f->id_page, '
					AND gallerynum = %i', $f->gallerynum, '
					AND ord > %i', $f->ord);
            //insert into new gallery
            $f->gallerynum = (int) $data['num'];
            $f->save();
            //update position UP of new gallery (hidden files not influenced by the bottom one)
            dibi::query('UPDATE pages_files
				SET ord = ord+1
				WHERE id_page = %i', $f->id_page, '
					AND gallerynum = %i', $f->gallerynum, '
					AND ord > %i', $f->ord);
        }
        //TODO maybe? SET ord = CASE id WHEN 10 THEN 1 END CASE
        $order = 0;
        foreach ($data['fileid'] as $id) {
            dibi::query('UPDATE pages_files SET ord=%i', $order++, ' WHERE id=%i', $id);
        }
        self::$cache = array();
        self::$cacheByPage = array();
    }