Autor Zpráva
Konkor
Profil *
Pro výpis dat z databáze používám toto:
{if !empty($side->categories[2])}
                                {foreach $side->categories[2] as $_}
                                    <li class=" ">
                                        <a href="{link Show:default, $_['nice_name']}">{=$_['meta_name']}</a>
                                    </li>
                                {/foreach}
                            {/if}

Vše se vypíše dobře, ale není to podle abecedy. Hledal jsem a mělo by to jít nějak pomocí ORDER BY, ale nepřišel jsem jak na to..
Tak prosím o rady.
juriad
Profil
Toto je nějaká šablona. Někde dříve pokládáš dotaz (hledej slovo SELECT). Tam přidej na konec ORDER BY název-sloupce.
Případně, až ten dotaz do databáze najdeš, tak se ozvi.
Konkor
Profil *
A poznám z té šablony, co bych měl kde hledat?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>{if isset($page) && $page !== NULL && $page->getMetaKeywords() !== NULL}{$page->getMetaKeywords()}{else}{=Environment::expand('%metaKeywords%')}{/if} online | {=$server->name}</title>
        <meta name="description" content="{if isset($page) && $page !== NULL && $page->getMetaDescription() !== NULL}{$page->getMetaDescription()}{else}{=Environment::expand('%metaDescription%')}{/if}">
        <link rel="stylesheet" type="text/css" href="{=Environment::expand('%themeBaseUri%/style.css')}">
        <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
        <script type="text/javascript" src="/misc/base.js"></script>
        <script src="/sorttable.js"></script>
        <link href="/favicon.png" rel="icon" type="image/png" />
    </head>
    <body>
    
    <div id="content">
        
            <a id="logo" href="http://web.cz/" ></a>
        
        <div id="search">
        
        <?php $searchform = $presenter->getComponent('searchForm'); $searchform->render('begin'); ?>
            <?php echo $searchform['q']->control; ?>
            <input type="submit" class="btn_search" value="" />
            <?php $searchform->render('end'); ?>
        </div>
        <div class="clr"></div>
        <div id="big_content">
            <ul id="menu">
                {foreach $side->pages as $_}
                    <li><a href="{link Show:default, $_->getNiceName()}">{=$_->getName()}</a></li>
                {/foreach}
            </ul>
            <div class="clr"></div>
            <div id="big_content_2">
                <div class="boxes_big" >
                    <a href="http://web.cz/ceske/" id="link1">České</a>
                    <a href="http://web.cz/ceskej/" id="link2">Slovenské</a>
                    <a href="/icq-online/" id="link3">ICQ online</a>
                    <a id="bb1" href="http://web.cz/ceske/" >CZ</a>
                    <a id="bb2" href="http://web.cz/ceskej/" >SK</a>
                </div>
                    <div id="login" {if !is_null($udata)}style="position: relative;left: 0px;border: 1px solid #CCD4D7; background: none repeat scroll 0 0 #E2EBEF; padding: 10px; height: 150px; border-radius: 10px; "{/if}>
                        {if is_null($udata)}
                            <div id="loginpr" >Přihlášení</div>
                            {$form_1->render('begin')}
                            {$form_1->render('errors')}
                                {$form_1['email']->control}
                                <div id="loginpj" >Přihlašovací email: </div>
                                {$form_1['pwd']->control}
                                <div id="loginpw" >Heslo:</div>
                                <input type="submit" class="button" name="ok" id="frmloginForm-ok" value="Přihlásit se">
                                <a id="loginreg" href="{link User:registration}" >Registrovat</a>
                                {$form_1->render('end')}
                        {else}
                            <h2>{$udata->payer_company}</h2>
                            <ul>
                                {if $udata->role_id == 1}
                                    <li>
                                        <a href="/admin/">Administrace</a>
                                    </li>
                                {/if}
                                <li>
                                    <a href="{link User:setting}">Nastavení profilu</a>
                                </li>
                                <li>
                                    <a href="{link User:favourites}">Oblíbená videa</a>
                                </li>
                                <li>
                                    <a href="{link User:logout}">Odhlášení</a>
                                </li>
                            </ul>
                        {/if}
                    </div>  
                <div class="clr"></div>
                <div id="full_left">
                    {if !empty($side->items_2)}
                        <div class="left_kat">
                        <div class="box_l_1">
                            <div class="box_l_2">{!$server->prvni_kat2}</div>
                        </div>
                        <div class="clr"></div>
                        <div class="box_l_3">
                            <ul>
                            {if !empty($side->items_2)}
                                {foreach $side->items_2 as $_}
                                    <li class=" ">
                                        <a href="{link Show:default, $_->getNiceName()}">{=$_->getMetaKeywords()}</a>
                                    </li>
                                {/foreach}
                            {/if}
                            </ul>
                            <div class="clr"></div>
                        </div>
                        </div>
                    {/if}   
                    <div class="left_kat">
                    <div class="box_l_1">
                        <div class="box_l_2">Podle státu </div>
                    </div>
                    <div class="clr"></div>
                    <div class="box_l_3">
                        <ul>
                        {if !empty($side->categories[1])}
                            {foreach $side->categories[1] as $_}
                                <li class=" ">
                                    <a href="{link Show:default, $_['nice_name']}">{=$_['meta_keywords']}</a>
                                </li>
                            {/foreach}
                        {/if}
                        </ul>
                        <div class="clr"></div>
                    </div>
                    </div>
                    {if !empty($side->categories[2])}
                        <div class="left_kat">
                        <div class="box_l_1">
                            <div class="box_l_2">Podle druhu</div>
                        </div>
                        <div class="clr"></div>
                        <div class="box_l_3">
                            <ul>
                            {if !empty($side->categories[2])}
                                {foreach $side->categories[2] as $_}
                                    <li class=" ">
                                        <a href="{link Show:default, $_['nice_name']}">{=$_['meta_keywords']}</a>
                                    </li>
                                {/foreach}
                            {/if}
                            </ul>
                            <div class="clr"></div>
                        </div>
                        </div>
                    {/if}
                </div>
            
                <div id="right_cat">
                    <?php echo $content->render(); ?>
                </div>
                <div class="clr"></div>
                <div id="footer">
                    Copyright © 2009 - 2013
                </div>
            </div>
        </div>
    </div>
    </body>
</html>
Rfilip
Profil
Tohle vypadá na šablonu něčeho, pravděpodobně nějakého mvc/mvp frameworku, zkus sem dát link na stránku, frameworky se občas podepisují v http hlavičkách, či v výsledném html kodu nebo adresářové struktuře.
Konkor
Profil *
Web http://televizka.cz/
Rfilip
Profil
Jedná se o ne moc dobře udělanou šablonu nette frameworku, viz http hlavička "X-Powered-By:Nette Framework".
Za předpokladu standartní adresářové struktury, se podívej do souboru app/presenters/HomepagePresenter.php do metody renderDefault
Konkor
Profil *
Struktura není zachována, ale myslím, že jsem ten soubor našel, nicméně mi tam to ORDER nejde nikam dát:
<?php
abstract class Front_BasePresenter extends /*Nette\Application\*/Presenter
{
    public $lang;
    public $server;
    public function startup()
    {
        // preload
        mapper::manufacturers()->findAll();
        mapper::categories()->findMain();
        mapper::pages()->findNotRef();

        if (Environment::getUser()->isAuthenticated()) {
            $this->template->udata = Common::getUserData(Environment::getUser()->getIdentity()->id);
        
            $form = dibi::query('SELECT * FROM favourites WHERE uid = %i',Environment::getUser()->getIdentity()->id)->fetchAll();
            if($form){
                foreach($form as $_form){
                    $prod[] = mapper::products()->findById($_form->vid);
                }
                $this->template->prods = $prod;
            }
        }
        
        $_SERVER['SERVER_NAME'] = str_replace("www.", "", $_SERVER['SERVER_NAME']);
        $server = dibi::query('SELECT * FROM shopaholic_weby WHERE adresa = %s', $_SERVER['SERVER_NAME'])->fetch();
        if(!$server){
            die('Web není přidán v administraci');
        }
        
        $this->server = $server;
        $this->template->server = $server;
        // visited products
        if (!isset(Environment::getSession(SESSION_ORDER_NS)->visited)) {
            Environment::getSession(SESSION_ORDER_NS)->visited = array();
        }
        
    }

    public function beforeRender()
    {
        // curly brackets
        $this->template->registerFilter('Nette\Templates\CurlyBracketsFilter::invoke');

        // texy
        $texy = new Texy;
        $this->template->registerHelper('texy', array($texy, 'process'));

        // side
        $side = array();
        $i = 1; 
        foreach (mapper::categories()->findAll2($this->server->zkratka) as $_) {
            $items[$_['type']][] = $_;
        }
        
        $q = dibi::query('SELECT ref_id FROM shopaholic_pages WHERE nice_name = %s', $this->server->prvni_kat)->fetchSingle();
        if($q){
            $q = dibi::query('SELECT id FROM shopaholic_products WHERE lang = %s',$this->server->zkratka,' AND category_id1 = '.$q.' OR category_id2 = '.$q)->fetchAll();
            foreach($q as $_q){
                $b[] = mapper::products()->findById($_q->id);
            }
            $side['items_2'] = $b;
        }
        
        $side['manufacturers'] = mapper::manufacturers()->findAll();
        $side['categories'] = $items;
        $side['pages'] = mapper::pages()->findNotRef2($this->server->zkratka);
        $side['cart'] = Environment::getSession(SESSION_ORDER_NS);
        $side['recent_products'] = Environment::getSession(SESSION_RECENTPRODUCTS_NS)->recent;

        $this->template->side = (object) $side;
        $this->template->vars = Environment::getVariables();
        $this->template->form_1 = $this->getComponent('loginForm');
    }

    public function createComponent($name)
    {
        switch ($name) {
            case 'searchForm':
                $form = new AppForm($this, $name);
                $form->addText('q', __('Query:'));
                $form['q']->getControlPrototype()->onclick(
                    'if (this.value === "' . __('Input search keywords') . '") {
                        this._default = this.value;
                        this.value = "";
                    }');
                $form['q']->getControlPrototype()->onblur(
                    'if (this.value === "" && this._default !== undefined) {
                        this.value = this._default;
                    }');
                $form->setAction($this->link('Search:default'));
                $form->setMethod('get');
                
                if ($this->getParam('q')) {
                    $form->setDefaults(array('q' => $this->getParam('q')));
                } else {
                    $form->setDefaults(array('q' => __('Input search keywords')));
                }
            break;
            case 'loginForm':
                $form = new AppForm($this, $name);
                $form->addText('email', __('E-mail:'))
                    ->setEmptyValue('@')
                    ->addRule(Form::FILLED, __('You have to enter your e-mail.'))
                    ->addRule(Form::EMAIL, __('This is not an e-mail address.'));
                $form->addPassword('pwd', __('Password:'))
                    ->addRule(Form::FILLED, __('You have to enter your password'));
                    
                $form->addSubmit('ok', __(''));
                $form['ok']->setRendered(TRUE);
                $form->onSubmit[] = array($this, 'onloginFormSubmit');
            break;

            default:
                return parent::createComponent($name);
        }
    }

    public function onloginFormSubmit(Form $form)
    {
        $user = Environment::getUser();
        $user->setAuthenticationHandler(new Authenticator());

        $values = $form->getValues();
        try {
            $user->authenticate($values['email'], $values['pwd']);
            adminlog::log(__('Successfully logged in as "%s"'), Environment::getUser()->getIdentity()->getName());

            $this->redirect('default');
            $this->terminate();
        } catch (AuthenticationException $e) {
            adminlog::log(__('Unsuccessful log in (username: "%s", password: "%s")'), $values['username'], $values['password']);
            $form->addError($e->getMessage());
        }
    }
}
Rfilip
Profil
Takže musíme najít třídu mapper, ta by měla být standardně v app/Model.
Konkor
Profil *
Teď bohužel nevim co přesně myslíš, tady je soubor mapper.php
<?php
/**
 * Mapper
 */
abstract class mapper extends /*Nette\*/Object
{
    /**
     * @var array Mapper objects
     */
    private static $mappers = array();

    /**
     * @var array Mappers' domain objects
     */
    private static $domains = array();

    /**
     * @var array Pool of fetched objects
     */
    protected $pool = array();

    /**
     * Get mapper
     * @param string
     * @return mixed
     */
    public static function object($name)
    {
        if (!isset(self::$mappers[$name])) {
            self::$mappers[$name] = new $name;
        }

        return self::$mappers[$name];
    }

    /**
     * Convert mapper to domain name
     * @param string
     * @return string
     */
    private static function domainize($mapper)
    {
        if (isset(self::$domains[$mapper])) {
            return self::$domains[$mapper];
        }

        if ($mapper[strlen($mapper) - 1] === 's') {
            return substr($mapper, 0, strlen($mapper) - 1);
        }

        throw new /*\*/Exception("Cannot find domain for $mapper.");
    }

    /**
     * Add/change mappers' domain
     * @param string
     * @param string
     */
    private static function mapperDomain($mapper, $domain)
    {
        self::$domains[$mapper] = $domain;
    }

    /**
     * Call to undefined static method
     * @param string
     * @param array
     * @return mapper
     */
    public static function __callStatic($name, $args)
    {
        return self::object($name);
    }

    /**
     * product_availabilities mapper
     * @return product_availabilities
     */
    public static function product_availabilities()
    {
        return self::object('product_availabilities');
    }

    /**
     * categories mapper
     * @return categories
     */
    public static function categories()
    {
        return self::object('categories');
    }

    /**
     * manufacturers mapper
     * @return manufacturers
     */
    public static function manufacturers()
    {
        return self::object('manufacturers');
    }

    /**
     * order_delivery_types mapper
     * @return order_delivery_types
     */
    public static function order_delivery_types()
    {
        return self::object('order_delivery_types');
    }

    /**
     * order_emails mapper
     * @return order_emails
     */
    public static function order_emails()
    {
        return self::object('order_emails');
    }

    /**
     * order_payment_types mapper
     * @return order_payment_types
     */
    public static function order_payment_types()
    {
        return self::object('order_payment_types');
    }

    /**
     * order_statuses mapper
     * @return order_statuses
     */
    public static function order_statuses()
    {
        return self::object('order_statuses');
    }

    /**
     * orders mapper
     * @return orders
     */
    public static function orders()
    {
        return self::object('orders');
    }

    /**
     * pages mapper
     * @return pages
     */
    public static function pages()
    {
        return self::object('pages');
    }

    /**
     * pictures mapper
     * @return pictures
     */
    public static function pictures()
    {
        return self::object('pictures');
    }

    /**
     * products mapper
     * @return products
     */
    public static function products()
    {
        return self::object('products');
    }

    /**
     * actualities mapper
     * @return actualities
     */
    public static function actualities()
    {
        return self::object('actualities');
    }

    /**
     * Should not be constructed outside of mapper
     */
    protected function __construct()
    {
    }

    /**
     * Primary key getter
     * @return string
     */
    public function getPK()
    {
        return 'id';
    }

    /**
     * Table name getter
     * @return string
     */
    public function getTable()
    {
        return get_class($this);
    }

    /**
     * Domain object class getter
     * @return string
     */
    public function getDomain()
    {
        return self::domainize(get_class($this));
    }

    /**
     * Reset pool
     */
    public function resetPool()
    {
        $this->pool = array();
    }

    /**
     * Update data in DB
     * @param array
     */
    protected function update(array $data)
    {
        $pk = $data[$this->getPK()];
        unset($data[$this->getPK()]);

        return dibi::query(
            'UPDATE %n', ':prefix:' . $this->getTable(),
            'SET', $data,
            'WHERE %n=%i', $this->getPK(), $pk
        );
    }

    /**
     * Insert data into DB
     * @param array
     */
    protected function insert(array $data)
    {
        return dibi::query(
            'INSERT INTO %n', ':prefix:' . $this->getTable(), $data
        );
    }

    /**
     * Delete from DB
     * @param array
     */
    protected function delete(array $where)
    {
        return dibi::query(
            'DELETE FROM %n', ':prefix:' . $this->getTable(),
            'WHERE', $where
        );
    }
}
Rfilip
Profil
Ano,to je přesně ono, ale v tom souboru je odkázané dál, není v stejné složce třída categories? Pokud ano dej ji sem to už by měl být poslední soubor. Tam by měla být metoda findAll2 kterou potřebujeme upravit.
Konkor
Profil *
Tak snad toto:
[pre]<?php
final class categories extends mapper
{
/**
* @var string Base query
*/
private $query;

/**
* @var array Main categories (depth = 0)
*/
private $main = NULL;

/**
* @var array All categories
*/
private $all = NULL;

/**
* Constructor
*/
protected function __construct()
{
$this->query = '
SELECT
[categories].[id] AS [id],
[pages].[name] AS [name],
[pages].[nice_name] AS [nice_name],
[pages].[content] AS [description],
[pages].[meta_keywords] AS [meta_keywords],
[pages].[meta_description] AS [meta_description],
[pictures].[id] AS [picture_id],
[pictures].[file] AS [picture_file],
[pictures].[description] AS [picture_description],
[pictures].[thumbnail_id] AS [thumbnail_id],
[thumbnails].[file] AS [thumbnail_file],
[thumbnails].[description] AS [thumbnail_description]
FROM [:prefix:categories] AS [categories]
LEFT JOIN [:prefix:pages] AS [pages]
ON [pages].[ref_id] = [categories].[id] AND
[pages].[ref_type] = \'' . pages::CATEGORY . '\'
LEFT JOIN [:prefix:pictures] AS [pictures]
ON [pages].[picture_id] = [pictures].[id]
LEFT JOIN [:prefix:pictures] AS [thumbnails]
ON [pictures].[thumbnail_id] = [thumbnails].[id]';
}

/**
* Converts list of categories with depths to tree
* @param array
* @return array
*/
public function treeize(array $categories)
{
$root = array(NULL, array());
$indexes = array(0 => 0);
foreach ($categories as $_) {
list($depth, $category) = $_;
$indexes[$depth]++;
$add =& $root;
for ($i = 0; $i < $depth; $i++) $add =& $add[1][$indexes[$i] - 1];
$add[1][] = array($category, array());
$indexes[$depth + 1] = 0;
}
return $root[1];
}

/**
* Find all categories
* @return array
*/
public function findAll2($lang)
{
if ($this->all === NULL) {
$this->all = array();
$res = dibi::query('
SELECT
[categories].[type] AS [type],
[categories].[lang] AS [lang],
[node].[id] AS [id],
[pages].[name] AS [name],
[pages].[nice_name] AS [nice_name],
[pages].[content] AS [description],
[pages].[meta_keywords] AS [meta_keywords],
[pages].[meta_description] AS [meta_description],
[pictures].[id] AS [picture_id],
[pictures].[file] AS [picture_file],
[pictures].[description] AS [picture_description],
[pictures].[thumbnail_id] AS [thumbnail_id],
[thumbnails].[file] AS [thumbnail_file],
[thumbnails].[description] AS [thumbnail_description],
(COUNT([parent].[id]) - 1) AS [depth]
FROM [:prefix:categories] AS [node], [:prefix:categories] AS [parent],
[:prefix:pages] AS [pages]
LEFT JOIN [:prefix:pictures] AS [pictures]
ON [pages].[picture_id] = [pictures].[id]
LEFT JOIN [:prefix:categories] AS [categories]
ON [categories].[id] = [pages].[ref_id]
LEFT JOIN [:prefix:pictures] AS [thumbnails]
ON [pictures].[thumbnail_id] = [thumbnails].[id]
WHERE ([node].[lft] BETWEEN [parent].[lft] AND [parent].[rgt]) AND
[pages].[ref_id] = [node].[id] AND [pages].[ref_type] = %s', pages::CATEGORY, '
AND [categories].[lang] = %s',$lang,'
GROUP BY [node].[id]
ORDER BY [node].[lft]');
foreach ($res as $row) {
$this->all[] = (array) $row;
}
}

return $this->all;
}
public function findAll3($lang)
{
if ($this->all === NULL) {
$this->all = array();
$res = dibi::query('
SELECT
[categories].[type] AS [type],
[categories].[lang] AS [lang],
[node].[id] AS [id],
[pages].[name] AS [name],
[pages].[nice_name] AS [nice_name],
[pages].[content] AS [description],
[pages].[meta_keywords] AS [meta_keywords],
[pages].[meta_description] AS [meta_description],
[pictures].[id] AS [picture_id],
[pictures].[file] AS [picture_file],
[pictures].[description] AS [picture_description],
[pictures].[thumbnail_id] AS [thumbnail_id],
[thumbnails].[file] AS [thumbnail_file],
[thumbnails].[description] AS [thumbnail_description],
(COUNT([parent].[id]) - 1) AS [depth]
FROM [:prefix:categories] AS [node], [:prefix:categories] AS [parent],
[:prefix:pages] AS [pages]
LEFT JOIN [:prefix:pictures] AS [pictures]
ON [pages].[picture_id] = [pictures].[id]
LEFT JOIN [:prefix:categories] AS [categories]
ON [categories].[id] = [pages].[ref_id]
LEFT JOIN [:prefix:pictures] AS [thumbnails]
ON [pictures].[thumbnail_id] = [thumbnails].[id]
WHERE ([node].[lft] BETWEEN [parent].[lft] AND [parent].[rgt]) AND
[pages].[ref_id] = [node].[id] AND [pages].[ref_type] = %s', pages::CATEGORY, '
GROUP BY [node].[id]
ORDER BY [node].[lft]');
foreach ($res as $row) {
$this->all[] = (array) $row;
}
}

return $this->all;
}
public function findAll()
{
if ($this->all === NULL) {
$this->all = array();
$res = dibi::query('
SELECT
[node].[id] AS [id],
[pages].[name] AS [name],
[pages].[nice_name] AS [nice_name],
[pages].[content] AS [description],
[pages].[meta_keywords] AS [meta_keywords],
[pages].[meta_description] AS [meta_description],
[pictures].[id] AS [picture_id],
[pictures].[file] AS [picture_file],
[pictures].[description] AS [picture_description],
[pictures].[thumbnail_id] AS [thumbnail_id],
[thumbnails].[file] AS [thumbnail_file],
[thumbnails].[description] AS [thumbnail_description],
(COUNT([parent].[id]) - 1) AS [depth]
FROM [:prefix:categories] AS [node], [:prefix:categories] AS [parent],
[:prefix:pages] AS [pages]
LEFT JOIN [:prefix:pictures] AS [pictures]
ON [pages].[picture_id] = [pictures].[id]
LEFT JOIN [:prefix:pictures] AS [thumbnails]
ON [pictures].[thumbnail_id] = [thumbnails].[id]
WHERE ([node].[lft] BETWEEN [parent].[lft] AND [parent].[rgt]) AND
[pages].[ref_id] = [node].[id] AND [pages].[ref_type] = %s', pages::CATEGORY, '
GROUP BY [node].[id]
ORDER BY [node].[lft]');

foreach ($res as $row) {
$arr = (array) $row;

$thumbnail = array();
$thumbnail['id'] = $row->thumbnail_id;
$thumbnail['file'] = $row->thumbnail_file;
$thumbnail['description'] = $row->thumbnail_description;
$thumbnail['thumbnail'] = NULL;
unset($arr['thumbnail_id'], $arr['thumbnail_file'], $arr['thumbnail_description']);

$picture = array();
$picture['id'] = $row->picture_id;
$picture['file'] = $row->picture_file;
$picture['description'] = $row->picture_description;
$picture['thumbnail'] = is_null($row->thumbnail_id) ? NULL :
new picture($thumbnail);
unset($arr['picture_id'], $arr['picture_file'], $arr['picture_description']);

$arr['picture'] = is_null($row->picture_id) ? NULL :
new picture($picture);

$depth = intval($arr['depth']);
unset($arr['depth']); // for finding subcategories

$this->pool[$row->id] = new category($arr);
$this->all[] = array($row->depth, $this->pool[$row->id]);
}
}

return $this->all;
}

/**
* Find main categories
* @return array
*/
public function findMain()
{
if ($this->main === NULL) {
$this->main = $this->poolResults(dibi::query('
SELECT
[node].[id] AS [id],
[pages].[name] AS [name],
[pages].[nice_name] AS [nice_name],
[pages].[content] AS [description],
[pages].[meta_keywords] AS [meta_keywords],
[pages].[meta_description] AS [meta_description],
[pictures].[id] AS [picture_id],
[pictures].[file] AS [picture_file],
[pictures].[description] AS [picture_description],
[pictures].[thumbnail_id] AS [thumbnail_id],
[thumbnails].[file] AS [thumbnail_file],
[thumbnails].[description] AS [thumbnail_description
Rfilip
Profil
Jo to je ono jde o upravu tohoto SQL (metoda findAll2):
SELECT 
[categories].[type] AS [type], 
[categories].[lang] AS [lang], 
[node].[id] AS [id], 
[pages].[name] AS [name], 
[pages].[nice_name] AS [nice_name], 
[pages].[content] AS [description], 
[pages].[meta_keywords] AS [meta_keywords], 
[pages].[meta_description] AS [meta_description], 
[pictures].[id] AS [picture_id], 
[pictures].[file] AS [picture_file], 
[pictures].[description] AS [picture_description], 
[pictures].[thumbnail_id] AS [thumbnail_id], 
[thumbnails].[file] AS [thumbnail_file], 
[thumbnails].[description] AS [thumbnail_description], 
(COUNT([parent].[id]) - 1) AS [depth] 
FROM [:prefix:categories] AS [node], [:prefix:categories] AS [parent], 
[:prefix:pages] AS [pages] 
LEFT JOIN [:prefix:pictures] AS [pictures] 
ON [pages].[picture_id] = [pictures].[id] 
LEFT JOIN [:prefix:categories] AS [categories] 
ON [categories].[id] = [pages].[ref_id] 
LEFT JOIN [:prefix:pictures] AS [thumbnails] 
ON [pictures].[thumbnail_id] = [thumbnails].[id] 
WHERE ([node].[lft] BETWEEN [parent].[lft] AND [parent].[rgt]) AND 
[pages].[ref_id] = [node].[id] AND [pages].[ref_type] = %s', pages::CATEGORY, ' 
AND [categories].[lang] = %s',$lang,' 
GROUP BY [node].[id] 
ORDER BY [node].[lft]
Ted se řadí dle sloupce lft z tabulky ...categories. ... je někde (u vás netuším kde) definováno ale standartně v app/config/config.neon v sekci dibi položka prefix. Pozor v souboru je definováno připojení do db (i hesla) a další citlivé udaje
Podle čeho chcete řadit?
Konkor
Profil *
prefix používám shopaholic_ a chtěl bych to řadit podle meta_keywords
Snad je to to co potřebuješ.
Rfilip
Profil
Takže v kodu z [#11] v metodě findAll2 nahrad řádek ORDER BY [node].[lft] tímto ORDER BY [node].[meta_keywords]
Konkor
Profil *
Nahradil, jsem to ORDER BY [pages].[meta_keywords] , ještě jsem změnil to pages, nebude to dělat neplechu? Když sem to udělal jak si psal, tak se stránka nenačetla...


Vypadá, že vše je ok. Tak moc díky :)
Konkor
Profil *
Omlovám se že znovu otrvuji, ale ještě bych chtěl opravit řazení tohoto:
{foreach $products as $product}
            <?
             
                $cat1 = mapper::categories()->findById(common::getProdData($product->getId())->category_id1); 
                $cat2 = mapper::categories()->findById(common::getProdData($product->getId())->category_id2);
                $count = dibi::query('SELECT COUNT(*) FROM shopaholic_views WHERE product_id = %i', $product->getId(), ' AND date = %s', date("Y-m-d"))->fetchSingle();
                $name = $product->getName();
                if(empty($q)){$porovnat = $category->getMetaKeywords(); }
                if(!empty($name)){ 
            ?>
            <tr>
                <td id="tab1d" valign="top">
                    <a href="{link Show:default, $product->getNiceName()}">{$product->getMetaKeywords()}</a>
                </td>
                <td id="tab2d" valign="top">
                    {if ($cat1->getMetaKeywords())!=($porovnat)}{!$cat1->getMetaKeywords()}{/if} {if ($cat2->getMetaKeywords())!=($porovnat)}{!$cat2->getMetaKeywords()}{/if}
                </td>
                <td id="tab3d" valign="top">
                    {!$count}
                </td>
            </tr>
            <?
                }
            ?>
        {/foreach}

Myslel jsem si že to bude tento soubor, ale nevím jak to kde upravit, chci aby se to řadilo stejně jako minule.
Snad by to mělo jít upravit v tomto souboru nějak:
[pre]<?php
final class products extends mapper
{
/**
* @var string Base query
*/
private $query;

/**
* Constructor
*/
protected function __construct()
{
$this->query ='
SELECT [products].[id] AS [id],
[products].[code] AS [code],
[products].[price] AS [price],
[products].[tags_id] AS [tags_id],
[pages].[name] AS [name],
[pages].[nice_name] AS [nice_name],
[pages].[content] AS [description],
[pages].[meta_keywords] AS [meta_keywords],
[pages].[meta_description] AS [meta_description],
[products].[price] AS [price],
[pictures].[id] AS [picture_id],
[pictures].[file] AS [picture_file],
[pictures].[description] AS [picture_description],
[pictures].[thumbnail_id] AS [thumbnail_id],
[thumbnails].[file] AS [thumbnail_file],
[thumbnails].[description] AS [thumbnail_description],
[product_availabilities].[id] AS [availability_id],
[product_availabilities].[name] AS [availability_name]
FROM [:prefix:products] AS [products]
LEFT JOIN [:prefix:pages] AS [pages]
ON [pages].[ref_id] = [products].[id] AND
[pages].[ref_type] = \'' . pages::PRODUCT . '\'
LEFT JOIN [:prefix:product_availabilities] AS [product_availabilities]
ON [products].[availability_id] = [product_availabilities].[id]
LEFT JOIN [:prefix:pictures] AS [pictures]
ON [pages].[picture_id] = [pictures].[id]
LEFT JOIN [:prefix:pictures] AS [thumbnails]
ON [pictures].[thumbnail_id] = [thumbnails].[id]';
}

/**
* Find all
* @return array
*/
public function findAll($limit = NULL, $offset = NULL)
{
$query = array(
$this->query,
'ORDER BY [pages].[nice_name]'
);

if ($limit !== NULL) {
$query[] = 'LIMIT %i';
$query[] = intval($limit);
}

if ($offset !== NULL) {
$query[] = 'OFFSET %i';
$query[] = intval($offset);
}

return $this->poolResults(dibi::query($query));
}

/**
* Find by ids
* @param int
* @return product[]
*/
public function findByIds($ids = array())
{
if (!is_array($ids)) {
$ids = func_get_args();
}

if (empty($ids)) {
return array();
}

$ret = $this->poolResults(dibi::query($this->query,
'WHERE [products].[id] IN %l', $ids));
return $ret;
}

/**
* Find by codes
* @param int
* @return products[]
*/
public function findByCodes($codes = array())
{
if (!is_array($codes)) {
$codes = func_get_args();
}

if (empty($codes)) {
return array();
}

return $this->poolResults(dibi::query($this->query,
'WHERE [products].[code] IN %l', $codes));
}

/**
* Find by id
* @param int
* @return product
*/
public function findById($id)
{
$ret = $this->poolResults(dibi::query($this->query,
'WHERE [products].[id] = %i', $id,
'LIMIT 1'));
return isset($ret[0]) ? $ret[0] : NULL;
}

/**
* Find by nice name
* @param string
* @return product
*/
public function findByNiceName($nice_name)
{
$ret = $this->poolResults(dibi::query($this->query,
'WHERE [pages].[nice_name] = %s', $nice_name,
'LIMIT 1'));
return isset($ret[0]) ? $ret[0] : NULL;
}

/**
* Find by category
* @param category
* @return array
*/
public function findByCategory(category $category, $limit = NULL, $offset = NULL, $letter = NULL, $sort = NULL)
{
try {
$arrs[$category->getId()] = $category->getId();
$cats = mapper::categories()->findSubcategories($category);
if($cats){
foreach($cats as $_cats){
$arrs[$_cats->getId()] = $_cats->getId();
}
}
$_SERVER['SERVER_NAME'] = str_replace("www.", "", $_SERVER['SERVER_NAME']);
$server = dibi::query('SELECT * FROM shopaholic_weby WHERE adresa = %s', $_SERVER['SERVER_NAME'])->fetch();
$query = array(
$this->query,
'LEFT JOIN [:prefix:categories] AS [categories]
ON ([categories].[id] = [products].[category_id1] OR [categories].[id] = [products].[category_id2])',
'WHERE [categories].[id] IN ( %s )', $arrs, ' AND [products].`lang` = %s', $server->zkratka);
if ($sort !== NULL) {
switch($sort){
case 1:
$query[] = 'ORDER BY [products].[price] ASC';
break;
case 2:
$query[] = 'ORDER BY [products].[price] DESC';
break;
case 3:
$query[] = 'ORDER BY [pages].[name] ASC';
break;
case 4:
$query[] = 'ORDER BY [pages].[name] DESC';
break;
}
}

if ($limit !== NULL) {
$query[] = 'LIMIT %i';
$query[] = intval($limit);
}

if ($offset !== NULL) {
$query[] = 'OFFSET %i';
$query[] = intval($offset);
}
$ret = $this->poolResults(dibi::query($query));
return $ret;
} catch (Exception $e) {
return array();
}
}

/**
* Find by manufacturer
* @param manufacturer
* @return array
*/
public function findByManufacturer(manufacturer $manufacturer, $limit = NULL, $offset = NULL, $letter = NULL)
{
try {
$query = array(
$this->query,
'WHERE [products].[manufacturer_id] = %i', $manufacturer->getId()
);

if ($letter !== NULL) {
$query = array_merge($query, (array) 'AND', $this->whereLetter($letter));
}

$query[] = 'ORDER BY [pages].[nice_name]';

if ($limit !== NULL) {
$query[] = 'LIMIT %i';
$query[] = intval($limit);
}

if ($offset !== NULL) {
$query[] = 'OFFSET %i';
$query[] = intval($offset);
}

$ret = $this->poolResults(dibi::query($query));
return $ret;
} catch (Exception $e) {
return array();
}
}

/**
* Find category of some product
* @param int
* @return category
*/
public function findCategoryOf($id)
{
return self::categories()->findById(
dibi::query('SELECT [category_id] FROM [:prefix:products] WHERE [id] = %i',
$id)->fetchSingle());
}

/**
* Find manufacturer of some product
* @param int
* @return manufacturer
*/
public function findManufacturerOf($id)
{
return self::manufacturers()->findById(
dibi::query('SELECT [manufacturer_id] FROM [:prefix:products] WHERE [id] = %i',
$id)->fetchSingle());
}

/**
* Find random
* @param int
* @return products[]
*/
public function findDoporucujeme($count)
{
return $this->poolResults(dibi::query($this->query,
'WHERE tags_id = 2',
'ORDER BY RAND()',
'LIMIT %i', $count));
}
public function findRandom($count)
{
return $this->poolResults(dibi::query($this->query,
'ORDER BY RAND()',
'LIMIT %i', $count));
}
public function findNews($count)
{
return $this->poolResults(dibi::query($this->query,
'ORDER BY [products].[id] DESC',
'LIMIT %i', $count));
}
public function findSort($count)
{
return $this->poolResults(dibi::query($this->query,
'ORDER BY RAND()',
Tori
Profil
Chcete seřadit ty produkty? A kde a jak se v kontroleru plní proměnná $this->template->products?
Konkor
Profil *
Bohužel nechápu


Myslíš $product->getMetaKeywords() (podle tehle proměnné to chci seřadit, podle prvních písmen v abecedě)
Konkor
Profil *
Nebo něco jiného?

Vaše odpověď

Mohlo by se hodit


Prosím používejte diakritiku a interpunkci.

Ochrana proti spamu. Napište prosím číslo dvě-sta čtyřicet-sedm: