The is_tablet capability

Integrating Tera-WURFL in your applications.

The is_tablet capability

Postby marcguay » Fri Apr 29, 2011 3:39 pm

Is there a way to explore the database by capability, either through the web interface or by searching through MySQL manually? I would like to search for all devices with is_tablet set to 'true' in order to evaluate whether or not it makes sense to have them presented with the mobile or desktop version of the website. I'm tempted to try and come up with a patch that would switch all devices where is_tablet=true to is_wireless_device=false and deal with the consequences of that but I don't think it's possible. The reason I can't simply modify my "which site do you get served?" logic to "if (is_wireless_device && !is_tablet)" is that I've distributed code to clients who now depend on the webservice and redistrubuting that code is not what I would call goodtimes. Any advice would be nice.

Marc
marcguay
 
Posts: 17
Joined: Mon May 31, 2010 11:42 am

Re: The is_tablet capability

Postby kamermans » Fri Apr 29, 2011 4:35 pm

Hi Marc,

You can't easily search the DB because the capabilities are serialized and not expanded through their fallback devices. This question has come up before, so I thought I would post a solution - it's very slow and only works with MySQL, but it will let you search for which devices have which capability.

Code: Select all
<?php
require_once dirname(__FILE__).'/../TeraWurfl.php';

$search = array(
        'product_info.is_tablet' => true,
);

$tw = new TeraWurfl();
$db = new mysqli(TeraWurflConfig::$DB_HOST, TeraWurflConfig::$DB_USER, TeraWurflConfig::$DB_PASS, TeraWurflConfig::$DB_SCHEMA);
$res = $db->query("SELECT * FROM `TeraWurflMerge` WHERE `actual_device_root` = 1");
while($row = $res->fetch_assoc()){
        $caps = unserialize($row['capabilities']);
        $id = $caps['id'];
        $caps = null;
        $tw->getFullCapabilities($id);
        $brand = $tw->capabilities['product_info']['brand_name'];
        $model = $tw->capabilities['product_info']['model_name'];
        $market = $tw->capabilities['product_info']['marketing_name'];
        foreach($search as $key => $val){
                list($group, $name) = explode('.', $key);
                if(!(array_key_exists($group,$tw->capabilities) && array_key_exists($name,$tw->capabilities[$group]))){
                        throw new Exception("Error: group $group or capability $name do not exist in the Tera-WURFL database.\n");
                }
                if($tw->capabilities[$group][$name] == $val){
                        // This is a matching device
                        echo "$id, $brand $model $market\n";
                        last;
                }
        }
}


Here's the output from the script:
Code: Select all
# php search.php
nokia_n810_ver1, Nokia N810
apple_ipad_ver1, Apple iPad
mot_sholest_ver1, Motorola Sholes Tablet
dell_streak_ver1, Dell Streak
samsung_galaxy_tab_ver1, Samsung Galaxy Tab
zte_v9_ver1, ZTE V9
softbank_001dl_ver1, Softbank 001DL
archos_a101it_ver1, Archos A101IT
coby_mid7015_ver1, Coby MID7015 Kyros
viewsonic_viewpad7_ver1, ViewSonic ViewPad7
nextbook_next2_ver1, Nextbook Next2
huawei_ideos_s7_ver1, Huawei IDEOS S7
zenithink_zt180_ver1, Zenithink zt180
motorola_xoom_ver1, Motorola Xoom
lg_v900_ver1, LG V900 Optimus Pad
dell_streak_7_ver1, Dell Streak 7 Streak 7
nextbook_next3_ver1, Nextbook NXM901 Next3
acer_iconia_tab_a500_ver1, Acer Iconia Tab A500 Picasso
acer_iconia_tab_a100_ver1, Acer Iconia Tab A100 Vangogh
toshiba_folio100_ver1, Toshiba Folio 100
rim_playbook_ver1, RIM PlayBook


You can specify whatever capabilities you want to look for in the search array by concatenating the group name and capability name (e.g. $tw->capabilities['display']['resolution_width'] would be "display.resolution_width") and specifying the value you want to search for (e.g. 320):
Code: Select all
$search = array(
        'display.resolution_width' => 320,
        'display.resolution_height' => 320,
);
Thanks,

Steve Kamerman
Tera-WURFL Author
COO of ScientiaMobile

IMPORTANT ANNOUNCEMENT! Tera-WURFL and WURFL have joined forces! We have launched ScientiaMobile to provide commercial support for our device detection solutions.

Tera-WURFL.com | Device Explorer
kamermans
Site Admin
 
Posts: 323
Joined: Wed Mar 10, 2010 12:06 pm
Location: Fort Worth, TX


Return to Using Tera-WURFL

Who is online

Users browsing this forum: No registered users and 2 guests

cron