1. REGISTRATION REQUIREMENTS:

    Your username here MUST MATCH your XenForo username (connected to your XF license).

    Once you have registered here, then you need to start a conversation at xenforo.com w/Bob and provide the following:
    1. Your XenForo License Validation Token
    2. The Domain Name associated with the License
    NOTE: Your account will be validated once ALL requirements are verified/met. Thank you for your patience.

Quick Default Option Query

Discussion in 'Showcase Support' started by DeviateDefiant, Nov 22, 2014.

  1. DeviateDefiant

    DeviateDefiant Member SC Premium

    Is there a simple way for me to by default have all new items featured? I know it's against the premise behind the "feature" feature, but I use it with the XenPorta block on the homepage which randomly displays a selection of featured vehicles.
     
  2. BT012SS

    BT012SS Active Member AMS Premium Showcase Pickem

    Hi,
    what is with the block "ShowcaseImages"
    Data Type "Most Recent" an "Images to display"
    With it you see always the newest items, or what do you want?
     
  3. DeviateDefiant

    DeviateDefiant Member SC Premium

    I display a random selection from all the items in the showcase using the featured option, as Bob doesn't want to add a feature that does this natively because of the potential performance hit from doing so.

    I have no issue with the load so made a pseudo-random by using the block with 'featured cars' from which it selects randomly anyway. The only pitfall in doing so is that each new addition needs to be manually featured.
     
  4. BT012SS

    BT012SS Active Member AMS Premium Showcase Pickem

    Yes, i understand.
    But i don“t understand why the cars must be featured to be displayed in the slider.
     
  5. Bob

    Bob Developer Staff Member

    I'd just create a CRON that will run a update statement daily. If you need me to, I can add code to the model that will allow you to pull items randomly, then you can modify the xenporta block (php file) to fetch random items.
     
  6. DeviateDefiant

    DeviateDefiant Member SC Premium

    Thanks @Bob, I'd much rather go that route, I'd rather a native "random" implementation than my hacky solution. I have everything cached for a minute anyway so the load effect shouldn't be a concern. If you can get me started, I'm sure I can figure out the rest :)
     
  7. Bob

    Bob Developer Staff Member

    Edit the item model: /library/NFLJ/Showcase/Model/Item.php

    find the prepareItemOrderOptions method and add a new choice to the end of the choices array as shown below.
    PHP:
        /**
         * Construct 'ORDER BY' clause
         *
         * @param array $fetchOptions (uses 'order' key)
         * @param string $defaultOrderSql Default order SQL
         *
         * @return string
         */
        
    public function prepareItemOrderOptions(array &$fetchOptions$defaultOrderSql '')
        {
            
    $choices = array(
                
    'recent' => 'item.date_added',
                
    'rated' => 'item.rating_avg %s, item.rating_count DESC, item.likes DESC, item.view_count DESC',
                
    'reviewed' => 'item.review_count %s, item.rating_avg DESC, item.likes DESC, item.view_count DESC',
                
    'popular' => 'item.view_count %s, item.rating_avg DESC',
                
    'liked' => 'item.likes %s, item.rating_avg DESC, item.view_count DESC',          
                
    'updated' => 'item.last_update',              
                
    'featured' => 'rand() %s, item.last_update DESC',
                
    'atoz' => 'item.item_name',
                
    'random' => 'rand()',
            );
            return 
    $this->getOrderByClause($choices$fetchOptions$defaultOrderSql);
        }

    The edit the XenPortaPotty Block file: /library/EWRporta/Block/ShowcaseFeaturedItems.php

    Find this:
    PHP:
            $conditions = array(
                
    'category_id' => $catIds,
                
    'image' => ($imageRequired == 1) ? true false,
                
    'featured' => true  
            
    );    
    Set featured to: false


    Find this:
    PHP:
            if ($featuredItems $scItemModel->getItems($conditions, array(
                
    'join' => NFLJ_Showcase_Model_Item::FETCH_CATEGORY
                    
    NFLJ_Showcase_Model_Item::FETCH_USER,
                
    'limit' => $options['scFI_numItems'],
                
    'order' => 'featured',
                
    'direction' => 'DESC')))
            {
    set order to: 'random'
     
  8. DeviateDefiant

    DeviateDefiant Member SC Premium

    Thank you mate. Done, I then updated all the items not to be featured any more:
    Code:
    UPDATE `xf_nflj_showcase_item`
    SET featured=0
    But I'm not getting any of them show, tinkering still now to find a solution.
     
  9. DeviateDefiant

    DeviateDefiant Member SC Premium

    Two thoughts, either there's an additional "featured" check somewhere, or the scripts I've been modifying are cached somewhere?
     
  10. Bob

    Bob Developer Staff Member

    working fine for me...

    Selection_432.png

    Selection_433.png
     
  11. Bob

    Bob Developer Staff Member

    All XenPorta blocks have built in cache by default. For testing, you need to disable the block cache (uncheck the "Enable caching of data every" option.

    Selection_434.png
     
  12. DeviateDefiant

    DeviateDefiant Member SC Premium

    Oopsie, well that explains it, I was talking about the "Showcase Images" block set to "Featured" and not the "Showcase Featured" block, just trying to replicate the modifications in that file now.
     
  13. Bob

    Bob Developer Staff Member

    Just set featured option to false : false and still check "featured" in the options
    PHP:
    'featured' => ($options['scI_sortOrder'] == 'featured') ? false false,
    Also still need to change the ORDER
    change this:
    PHP:
                'order' => $options['scI_sortOrder'],
    to this:
    PHP:
                'order' =>'random',
     
  14. DeviateDefiant

    DeviateDefiant Member SC Premium

    Boom, that's working fine - thank you bud!
     
    Bob likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.