Ejemplo n.º 1
0
function addItemToDB($filename, $categories)
{
    $itemData = json_decode(file_get_contents(__DIR__ . "/../data/items/{$filename}"), true);
    $itemData = array_map(function ($x) use($categories) {
        $x['_type'] = 'item';
        $x['shop'] = R::findOne('shop', 'reference = ?', [$x['shopReference']]);
        unset($x['shopReference']);
        foreach ($categories as $cat) {
            if (strtolower($x['category']) === strtolower($cat['name'])) {
                $x['category'] = $cat;
                break;
            }
        }
        return $x;
    }, $itemData);
    $items = R::dispense($itemData);
    foreach ($items as $item) {
        R::storeAll($items);
    }
}
Ejemplo n.º 2
0
        exit;
    }
} else {
    if (isset($_POST) && count($_POST) > 0) {
        // push 模式 part 2:從手機上傳送資料給伺服器
        if (isset($_POST["logs"]) && isset($_POST["uuid"])) {
            $uuid = $_POST["uuid"];
            $logs_ary = json_decode($_POST["logs"]);
        } else {
            exit;
        }
        //print_r($logs_ary);
        if (count($logs_ary) > 1) {
            $log_beans = R::dispense("log", count($logs_ary));
            foreach ($logs_ary as $i => $log) {
                $log_beans[$i]->uuid = $uuid;
                $log_beans[$i]->import($log);
            }
            R::storeAll($log_beans);
        } else {
            if (count($logs_ary) === 1) {
                $log_bean = R::dispense("log");
                $log_bean->uuid = $uuid;
                $log_bean->import($logs_ary);
                R::store($log_bean);
            }
        }
        //sync_complete($uuid, "push");
        jsonp_callback(true);
    }
}
Ejemplo n.º 3
0
 /**
  * Test limited support for 1-to-1 associations.
  * 
  * @return void
  */
 public function testOneToOne()
 {
     testpack('Testing one-to-ones');
     $author = R::dispense('author')->setAttr('name', 'a');
     $bio = R::dispense('bio')->setAttr('name', 'a');
     R::storeAll(array($author, $bio));
     $id1 = $author->id;
     $author = R::dispense('author')->setAttr('name', 'b');
     $bio = R::dispense('bio')->setAttr('name', 'b');
     R::storeAll(array($author, $bio));
     $id2 = $author->id;
     list($a, $b) = R::loadMulti('author,bio', $id1);
     asrt($a->name, $b->name);
     asrt($a->name, 'a');
     list($a, $b) = R::loadMulti('author,bio', $id2);
     asrt($a->name, $b->name);
     asrt($a->name, 'b');
     list($a, $b) = R::loadMulti(array('author', 'bio'), $id1);
     asrt($a->name, $b->name);
     asrt($a->name, 'a');
     list($a, $b) = R::loadMulti(array('author', 'bio'), $id2);
     asrt($a->name, $b->name);
     asrt($a->name, 'b');
     asrt(is_array(R::loadMulti(NULL, 1)), TRUE);
     asrt(count(R::loadMulti(NULL, 1)) === 0, TRUE);
 }
Ejemplo n.º 4
0
    public function install($debug = false)
    {
        /**
         * Load models
         */
        $this->load->model('account/account_model');
        $this->load->model('account/group_model');
        $this->load->model('account/uriresource_model');
        $this->load->model('layout/layout_model');
        $this->load->model('admin/modmenu_model');
        $this->load->model('map_model');
        $this->load->model('layer_model');
        $this->load->model('mapserver/mapserver_model');
        $this->load->model('googleearth/googleearth_model');
        $this->load->model('openlayers/openlayers_model');
        $this->load->model('admin/dataexplorer_model');
        // Debug SQL
        R::debug($debug);
        // EMPTY DATABASE
        R::nuke();
        // Create admin account
        $account_admin = $this->account_model->create('*****@*****.**', 'admin', 'admin');
        R::store($account_admin);
        // Create guest account
        $account_guest = $this->account_model->create('*****@*****.**', 'guest', '');
        R::store($account_guest);
        // Create geo account
        $account_geo = $this->account_model->create('*****@*****.**', 'geo', 'geo');
        R::store($account_geo);
        // Create admin group
        $group_admin = $this->group_model->create('admin');
        R::store($group_admin);
        // Create guest group
        $group_guest = $this->group_model->create('guest');
        R::store($group_admin);
        // Create geo group
        $group_geo = $this->group_model->create('geo');
        R::store($group_geo);
        // Add admin account to admin group
        $group_admin->sharedAccount[] = $account_admin;
        R::store($group_admin);
        // Add guest account to guest group
        $group_guest->sharedAccount[] = $account_guest;
        R::store($group_guest);
        // Add geo account to geo group
        $group_geo->sharedAccount[] = $account_geo;
        R::store($group_geo);
        // Create Uri Resources
        $uriresource_admin = $this->uriresource_model->create('/^admin/i');
        R::store($uriresource_admin);
        $uriresource_user = $this->uriresource_model->create('/^user/i');
        R::store($uriresource_user);
        // Add permission to guest group
        $this->group_model->addPermission($group_guest, $uriresource_user, 'deny', 0);
        $this->group_model->addPermission($group_guest, $uriresource_admin, 'deny', 0);
        R::store($group_guest);
        // Register authentication module block
        $previewimg = 'web/images/module/simpleauth.png';
        $authblock = $this->layout_model->createModule('Simple Authentication', 'account/modauth_lblock', NULL, $previewimg);
        $authblock->owner = $account_admin;
        R::store($authblock);
        // Register tickets block
        $previewimg = 'web/images/module/tickets.png';
        $ticketsblock = $this->layout_model->createModule('Tickets', 'crm/tickets_lblock', NULL, $previewimg);
        $ticketsblock->owner = $account_admin;
        R::store($ticketsblock);
        // Register layerswitcher block
        $previewimg = 'web/images/module/layerswitcher.png';
        $layerswitcherblock = $this->layout_model->createModule('Layer Switcher', 'openlayers/layerswitcher_lblock', 'olmap', $previewimg);
        $layerswitcherblock->owner = $account_admin;
        R::store($layerswitcherblock);
        // Register Footer Module
        $footermod = $this->layout_model->createModule('Footer', 'admin/footer_lblock');
        $footermod->owner = $account_admin;
        R::store($footermod);
        // Register Credits Module
        $creditsmod = $this->layout_model->createModule('Credits', 'admin/credits_lblock');
        $creditsmod->owner = $account_admin;
        R::store($creditsmod);
        // Register language switcher module block
        $previewimg = 'web/images/module/idiomswitcher.png';
        $langblock = $this->layout_model->createModule('Language Selection', 'crm/lang_lblock', NULL, $previewimg);
        $langblock->owner = $account_admin;
        R::store($langblock);
        // Register featuresearch block
        $previewimg = 'web/images/module/featuresearch.png';
        $searchblock = $this->layout_model->createModule('Feature Search', 'openlayers/featuresearch_lblock', 'olmap', $previewimg);
        $searchblock->owner = $account_admin;
        R::store($searchblock);
        // Register Google Maps Api module
        $modgmapsapi = $this->layout_model->createModule('Load Google Maps API', 'openlayers/modgmapsapiv3_lblock');
        $modgmapsapi->owner = $account_admin;
        R::store($modgmapsapi);
        // Register gefeaturesearch block
        $previewimg = 'web/images/module/gefeaturesearch.png';
        $gesearchblock = $this->layout_model->createModule('Google Earth Search', 'googleearth/gefeaturesearch_lblock', 'gemap', $previewimg);
        $gesearchblock->owner = $account_admin;
        R::store($gesearchblock);
        // Create layout
        $layout_public = $this->layout_model->create('public', 'layout/publicfullscreen2');
        $layout_public->owner = $account_admin;
        R::store($layout_public);
        // Create public layout slots
        $pslot1 = $this->layout_model->createSlot('slot1', $layout_public);
        $pslot2 = $this->layout_model->createSlot('slot2', $layout_public);
        $pslot3 = $this->layout_model->createSlot('slot3', $layout_public);
        $pslot4 = $this->layout_model->createSlot('slot4', $layout_public);
        $pslot5 = $this->layout_model->createSlot('slot5', $layout_public);
        $pslot1->owner = $account_admin;
        $pslot2->owner = $account_admin;
        $pslot3->owner = $account_admin;
        $pslot4->owner = $account_admin;
        $pslot5->owner = $account_admin;
        R::storeAll(array($pslot1, $pslot2, $pslot3, $pslot4, $pslot5));
        // Create module layout
        $layout_mod = $this->layout_model->create('module', 'layout/module');
        $layout_mod->owner = $account_admin;
        R::store($layout_mod);
        // Create module layout slots
        $mslot1 = $this->layout_model->createSlot('slot1', $layout_mod);
        $mslot2 = $this->layout_model->createSlot('slot2', $layout_mod);
        $mslot3 = $this->layout_model->createSlot('slot3', $layout_mod);
        $mslot1->owner = $account_admin;
        $mslot2->owner = $account_admin;
        $mslot3->owner = $account_admin;
        R::storeAll(array($mslot1, $mslot2, $mslot3));
        // Create layout blocks
        $lblock2 = $this->layout_model->createBlock('authblock', $authblock, 1);
        $lblock2->owner = $account_admin;
        R::storeAll(array($lblock2));
        // Create tickets layout block
        $lblock3 = $this->layout_model->createBlock('tickets', $ticketsblock, 2);
        $lblock3->owner = $account_admin;
        R::storeAll(array($lblock3));
        // Create layerswitcher layout block
        $lblock4 = $this->layout_model->createBlock('layerswitcher1', $layerswitcherblock, 3, '', 1);
        $lblock4->owner = $account_admin;
        R::storeAll(array($lblock4));
        // Create layout blocks
        $footerblock = $this->layout_model->createBlock('footerblock', $footermod, 1);
        $footerblock->owner = $account_admin;
        $creditsblock = $this->layout_model->createBlock('creditsblock', $creditsmod, 2);
        $creditsblock->owner = $account_admin;
        R::storeAll(array($footerblock, $creditsblock));
        // Create language blocks
        $lblock5 = $this->layout_model->createBlock('langblock', $langblock, 3);
        $lblock5->owner = $account_admin;
        R::storeAll(array($lblock5));
        // Assign layout blocks to slots
        $this->layout_model->slotAddBlock($pslot2, $lblock3);
        $this->layout_model->slotAddBlock($pslot2, $lblock2);
        $this->layout_model->slotAddBlock($pslot4, $footerblock);
        $this->layout_model->slotAddBlock($pslot5, $creditsblock);
        $this->layout_model->slotAddBlock($pslot2, $lblock5);
        // Create registered layout
        $layout_reg = $this->layout_model->create('registered', 'layout/registered');
        $layout_reg->owner = $account_admin;
        R::store($layout_reg);
        // Create registered layout slots
        $rslot1 = $this->layout_model->createSlot('slot1', $layout_reg);
        $rslot2 = $this->layout_model->createSlot('slot2', $layout_reg);
        $rslot3 = $this->layout_model->createSlot('slot3', $layout_reg);
        $rslot4 = $this->layout_model->createSlot('slot4', $layout_reg);
        $rslot5 = $this->layout_model->createSlot('slot5', $layout_reg);
        $rslot1->owner = $account_admin;
        $rslot2->owner = $account_admin;
        $rslot3->owner = $account_admin;
        $rslot4->owner = $account_admin;
        $rslot5->owner = $account_admin;
        R::storeAll(array($rslot1, $rslot2, $rslot3, $rslot4, $rslot5));
        // Create layout blocks
        $rlblock2 = $this->layout_model->createBlock('userauthblock', $authblock, 1);
        $rlblock2->owner = $account_admin;
        R::storeAll(array($rlblock2));
        // Assign layout blocks to slots
        $this->layout_model->slotAddBlock($rslot2, $rlblock2);
        // Create Admin Menu
        $menu1 = $this->modmenu_model->create('admin');
        $menu1->owner = $account_admin;
        $this->modmenu_model->save($menu1);
        // Register admin menu block
        $previewimg = 'web/images/module/menu.png';
        $menublock1 = $this->layout_model->createModule('Menu', 'admin/modmenu_lblock', 'modmenu', $previewimg);
        $menublock1->owner = $account_admin;
        R::store($menublock1);
        // Register WFS get feature popup module
        $previewimg = 'web/images/module/wfsgetfeature.png';
        $wfsgetfeature1 = $this->layout_model->createModule('WFSGetFeature Popup', 'openlayers/mapwfsgetfeaturepopup_lblock', 'layer', $previewimg);
        $wfsgetfeature1->owner = $account_admin;
        R::store($wfsgetfeature1);
        // Register WFS get feature module
        $previewimg = 'web/images/module/wfsgetfeature.png';
        $wfsgetfeature2 = $this->layout_model->createModule('WFSGetFeature', 'openlayers/mapwfsgetfeaturecontent_lblock', 'layer', $previewimg);
        $wfsgetfeature2->owner = $account_admin;
        R::store($wfsgetfeature2);
        // Register CKEditor module
        $previewimg = 'web/images/module/ckeditor.png';
        $ckeditor1 = $this->layout_model->createModule('CKEditor', 'layout/ckeditor_lblock', NULL, $previewimg);
        $ckeditor1->owner = $account_admin;
        R::store($ckeditor1);
        // Register rating module
        $previewimg = 'web/images/module/rating.png';
        $ratingmod1 = $this->layout_model->createModule('Rating', 'rating/rating_lblock', NULL, $previewimg);
        $ratingmod1->owner = $account_admin;
        R::store($ratingmod1);
        // Create rating blocks
        $ratingblock = $this->layout_model->createBlock('ratingblock', $ratingmod1, 2);
        $ratingblock->owner = $account_admin;
        R::storeAll(array($ratingblock));
        // Assign layout blocks to slots
        $this->layout_model->slotAddBlock($pslot3, $ratingblock);
        // Create admin layout
        $layout_adm = $this->layout_model->create('admin', 'layout/admin');
        $layout_adm->owner = $account_admin;
        R::store($layout_adm);
        // Create registered layout slots
        $aslot1 = $this->layout_model->createSlot('slot1', $layout_adm);
        $aslot2 = $this->layout_model->createSlot('slot2', $layout_adm);
        $aslot3 = $this->layout_model->createSlot('slot3', $layout_adm);
        $aslot4 = $this->layout_model->createSlot('slot4', $layout_adm);
        $aslot5 = $this->layout_model->createSlot('slot5', $layout_adm);
        $aslot1->owner = $account_admin;
        $aslot2->owner = $account_admin;
        $aslot3->owner = $account_admin;
        $aslot4->owner = $account_admin;
        $aslot5->owner = $account_admin;
        R::storeAll(array($aslot1, $aslot2, $aslot3, $aslot4, $aslot5));
        // Create layout blocks
        $alblock1 = $this->layout_model->createBlock('menu1', $menublock1, 1, '', $menu1->id);
        $alblock1->owner = $account_admin;
        $alblock2 = $this->layout_model->createBlock('adminauthblock', $authblock, 2);
        $alblock2->owner = $account_admin;
        R::storeAll(array($alblock1, $alblock2));
        // Assign layout blocks to slots
        $this->layout_model->slotAddBlock($aslot2, $alblock1);
        $this->layout_model->slotAddBlock($aslot1, $alblock2);
        // Create CKEditor Admin block
        $alblock3 = $this->layout_model->createBlock('ckeditorblock', $ckeditor1, 1);
        $alblock3->owner = $account_admin;
        R::storeAll(array($alblock3));
        // Assign CKEditor block to admin layout slot
        $this->layout_model->slotAddBlock($aslot1, $alblock3);
        // Create CKEditor User block
        $rlblock3 = $this->layout_model->createBlock('ckeditorblock', $ckeditor1, 1);
        $rlblock3->owner = $account_admin;
        R::storeAll(array($rlblock3));
        // Assign CKEditor block to user layout slot
        $this->layout_model->slotAddBlock($rslot1, $rlblock3);
        // Add admin menu items
        $menuitems[] = $this->modmenu_model->addItem('Admin Home', 'admin/admin', 1, $menu1, 1);
        $menuitems[] = $this->modmenu_model->addItem('Frontpage', '', 1, $menu1, 2);
        $menuitems[] = $this->modmenu_model->addItem('User Home', 'user/user', 1, $menu1, 3);
        $menuitems[] = $this->modmenu_model->addItem('System', 'admin/adminsystem', 1, $menu1, 4);
        foreach ($menuitems as $menuitem) {
            $menuitem->owner = $account_admin;
        }
        R::storeAll($menuitems);
        // Mapserver
        // Create metadata
        $msmetadata[] = $this->mapserver_model->createMetadata('wms_encoding');
        $msmetadata[] = $this->mapserver_model->createMetadata('wms_title');
        $msmetadata[] = $this->mapserver_model->createMetadata('wms_abstract');
        $msmetadata[] = $this->mapserver_model->createMetadata('wms_srs');
        $msmetadata[] = $this->mapserver_model->createMetadata('wms_onlineresource');
        $msmetadata[] = $this->mapserver_model->createMetadata('gml_include_items');
        $msmetadata[] = $this->mapserver_model->createMetadata('wms_extent');
        $msmetadata[] = $this->mapserver_model->createMetadata('ows_srs');
        $msmetadata[] = $this->mapserver_model->createMetadata('ows_enable_request');
        $msmetadata[] = $this->mapserver_model->createMetadata('wms_feature_info_mime_type');
        $msmetadata[] = $this->mapserver_model->createMetadata('wfs_title');
        $msmetadata[] = $this->mapserver_model->createMetadata('wfs_onlineresource');
        $msmetadata[] = $this->mapserver_model->createMetadata('wfs_abstract');
        $msmetadata[] = $this->mapserver_model->createMetadata('wfs_srs');
        $msmetadata[] = $this->mapserver_model->createMetadata('wfs_enable_request');
        $msmetadata[] = $this->mapserver_model->createMetadata('gml_featureid');
        foreach ($msmetadata as &$item) {
            $item->owner = $account_admin;
        }
        R::storeAll($msmetadata);
        // Create units
        $msunits[] = $this->mapserver_model->createUnits('dd');
        $msunits[] = $this->mapserver_model->createUnits('feet');
        $msunits[] = $this->mapserver_model->createUnits('inches');
        $msunits[] = $this->mapserver_model->createUnits('kilometers');
        $msunits[] = $this->mapserver_model->createUnits('meters');
        $msunits[] = $this->mapserver_model->createUnits('miles');
        $msunits[] = $this->mapserver_model->createUnits('nauticalmiles');
        $msunits[] = $this->mapserver_model->createUnits('percentages');
        $msunits[] = $this->mapserver_model->createUnits('pixels');
        foreach ($msunits as &$item) {
            $item->owner = $account_admin;
        }
        R::storeAll($msunits);
        // Create Layer Types
        $mslayertype[] = $this->mapserver_model->createLayerType('annotation');
        $mslayertype[] = $this->mapserver_model->createLayerType('chart');
        $mslayertype[] = $this->mapserver_model->createLayerType('circle');
        $mslayertype[] = $this->mapserver_model->createLayerType('line');
        $mslayertype[] = $this->mapserver_model->createLayerType('point');
        $mslayertype[] = $this->mapserver_model->createLayerType('polygon');
        $mslayertype[] = $this->mapserver_model->createLayerType('raster');
        $mslayertype[] = $this->mapserver_model->createLayerType('query');
        foreach ($mslayertype as &$item) {
            $item->owner = $account_admin;
        }
        R::storeAll($mslayertype);
        // Create Layer Connection Types
        $mslayerconntype[] = $this->mapserver_model->createLayerConnectionType('local');
        $mslayerconntype[] = $this->mapserver_model->createLayerConnectionType('ogr');
        $mslayerconntype[] = $this->mapserver_model->createLayerConnectionType('oraclespatial');
        $mslayerconntype[] = $this->mapserver_model->createLayerConnectionType('plugin');
        $mslayerconntype[] = $this->mapserver_model->createLayerConnectionType('postgis');
        $mslayerconntype[] = $this->mapserver_model->createLayerConnectionType('sde');
        $mslayerconntype[] = $this->mapserver_model->createLayerConnectionType('wfs');
        $mslayerconntype[] = $this->mapserver_model->createLayerConnectionType('wms');
        foreach ($mslayerconntype as &$item) {
            $item->owner = $account_admin;
        }
        R::storeAll($mslayerconntype);
        // Create a new map
        $map = $this->map_model->create('Demo Map', 'Simple map with OSM + WMS', 'demo');
        $map->owner = $account_admin;
        $this->map_model->save($map);
        // Create layer
        $layer = $this->layer_model->create('Demo Layer', 'Data from shapefile', 'layer1');
        $layer->owner = $account_admin;
        $this->layer_model->save($layer);
        // Add Layer to Map
        $this->map_model->addMapLayer($map, $layer);
        // Create wfsgetfeature block
        $wfsgetfeaturelblockconfig = '{
"popupfunction":"popupfeature",
"htmlurl":null
}';
        $wfsgetfeaturelblock = $this->layout_model->createBlock('wfsgetfeature1', $wfsgetfeature2, 1, $wfsgetfeaturelblockconfig, $layer->id);
        $wfsgetfeaturelblock->owner = $account_admin;
        R::storeAll(array($wfsgetfeaturelblock));
        // assignwfsgetfeature block
        $this->layout_model->slotAddBlock($pslot3, $wfsgetfeaturelblock);
        // Create mapfile
        $extent = '-20037508.34 -20037508.34 20037508.34 20037508.34';
        $projection = "init=epsg:3857";
        $mapfile = $this->mapserver_model->createMapfile($map, $extent, $projection);
        $mapfile->msunits = $msunits[4];
        $mapfile->debug = 'off';
        $mapfile->fontset = './mapfile/fonts/fonts.list';
        $mapfile->symbolset = './mapfile/symbols/symbols.txt';
        $mapfile->owner = $account_admin;
        $this->mapserver_model->save($mapfile);
        // Add metadata
        $this->mapserver_model->addMapfileMetadata($mapfile, $msmetadata[0], 'UTF8');
        $this->mapserver_model->addMapfileMetadata($mapfile, $msmetadata[1], 'Cities');
        $this->mapserver_model->addMapfileMetadata($mapfile, $msmetadata[2], 'No info');
        $this->mapserver_model->addMapfileMetadata($mapfile, $msmetadata[3], 'EPSG:20790 EPSG:3857 EPSG:4326');
        $this->mapserver_model->addMapfileMetadata($mapfile, $msmetadata[4], 'mapserver?map=' . $map->alias . '.map');
        $this->mapserver_model->addMapfileMetadata($mapfile, $msmetadata[8], '*');
        $this->mapserver_model->addMapfileMetadata($mapfile, $msmetadata[9], 'text/html');
        // Create Mapserver Layer
        $extent = '-13207.017577 49518.222243 452964.525460 291327.263653';
        $projection = "proj=tmerc lat_0=39.66666666666666 lon_0=1 k=1 x_0=200000 y_0=300000 ellps=intl towgs84=-304.046,-60.576,103.64,0,0,0,0 pm=lisbon units=m no_defs";
        $mslayer = $this->mapserver_model->createLayer($layer, $extent, $projection);
        $mslayer->mslayertype = $mslayertype[4];
        $mslayer->template = './mapfile/template/shape_feature_body.html';
        $mslayer->data = './mapfile/shapefile/map1.shp';
        $mslayer->labelitem = 'concelho';
        $mslayer->owner = $account_admin;
        // Add Layer Metadata
        $this->mapserver_model->addLayerMetadata($mslayer, $msmetadata[5], 'all');
        $this->mapserver_model->addLayerMetadata($mslayer, $msmetadata[7], 'EPSG:3857');
        $this->mapserver_model->save($mslayer);
        $this->mapserver_model->addMapfileLayer($mapfile, $mslayer);
        // Create Layer Class
        $msclass = $this->mapserver_model->createClass($mslayer, 'Cities');
        $msclass->owner = $account_admin;
        $this->mapserver_model->save($msclass);
        // Create MapIcons Point Style
        $msstyle1 = $this->mapserver_model->createStyle('Simple Map Icon');
        $msstyle1->symbol = './mapfile/symbols/mapiconscollection-tourism/bigcity.png';
        $msstyle1->size = 32;
        $msstyle1->color = '0 255 0';
        $msstyle1->owner = $account_admin;
        $this->mapserver_model->save($msstyle1);
        // Add Style to Class
        $this->mapserver_model->addClassStyle($msclass, $msstyle1);
        // Create Default Point Style
        $msstyle3 = $this->mapserver_model->createStyle('Simple Icon');
        $msstyle3->symbol = './mapfile/symbols/google-marker-small.png';
        $msstyle3->size = 30;
        $msstyle3->color = '0 255 0';
        $msstyle3->owner = $account_admin;
        $this->mapserver_model->save($msstyle3);
        // Create Default Area Style
        $msstyle2 = $this->mapserver_model->createStyle('Simple Area');
        $msstyle2->symbol = '';
        $msstyle2->owner = $account_admin;
        $this->mapserver_model->save($msstyle2);
        // Create Label
        $mslabel = $this->mapserver_model->createLabel('Simple Label');
        $mslabel->owner = $account_admin;
        $this->mapserver_model->save($mslabel);
        // Add Label to Class
        $this->mapserver_model->addClassLabel($msclass, $mslabel);
        // Create Map Legend
        $mslegend = $this->mapserver_model->createLegend($mapfile);
        $mslegend->template = './mapfile/template/shape_legend_body.html';
        $mslegend->owner = $account_admin;
        $this->mapserver_model->save($mslegend);
        // Update mapfile AFTER all mapfile is set
        $this->mapserver_model->updateMapfile($mapfile->id);
        // Add Label to Map Legend
        $this->mapserver_model->addLegendLabel($mslegend, $mslabel);
        // Register openlayers map block
        $previewimg = 'web/images/module/openlayersmap.png';
        $olmapblock = $this->layout_model->createModule('OpenLayers Map', 'openlayers/modmap_lblock', 'olmap', $previewimg);
        $olmapblock->owner = $account_admin;
        R::store($olmapblock);
        // Create Openlayers Layers Type
        $ollayertype[] = $this->openlayers_model->createLayerType('OSM', 'OpenLayers.Layer.OSM');
        $ollayertype[] = $this->openlayers_model->createLayerType('Google', 'OpenLayers.Layer.Google');
        $ollayertype[] = $this->openlayers_model->createLayerType('Bing', 'OpenLayers.Layer.Bing');
        $ollayertype[] = $this->openlayers_model->createLayerType('Internal WMS', 'OpenLayers.Layer.WMS');
        $ollayertype[] = $this->openlayers_model->createLayerType('External WMS', 'OpenLayers.Layer.WMS');
        foreach ($ollayertype as &$item) {
            $item->owner = $account_admin;
        }
        R::storeAll($ollayertype);
        // Create Abstract Layers
        $osmlayer = $this->layer_model->create('OSM', 'OpenStreetMap Layer', 'osm1');
        $osmlayer->owner = $account_admin;
        $this->layer_model->save($osmlayer);
        $googlelayer = $this->layer_model->create('Google', 'Google Layer', 'google1');
        $googlelayer->owner = $account_admin;
        $this->layer_model->save($googlelayer);
        $binglayer = $this->layer_model->create('Bing', 'Bing Layer', 'bing1');
        $binglayer->owner = $account_admin;
        $this->layer_model->save($binglayer);
        // Add Layers to Map
        $this->map_model->addMapLayer($map, $osmlayer);
        $this->map_model->addMapLayer($map, $googlelayer);
        $this->map_model->addMapLayer($map, $binglayer);
        // Create Specific OL Layers
        // Create OSM Layer
        $opts = "{\n\"isBaseLayer\": true\n}";
        $olosmlayer = $this->openlayers_model->createLayer($osmlayer, $ollayertype[0], '', $opts);
        $olosmlayer->owner = $account_admin;
        $this->openlayers_model->save($olosmlayer);
        // Create Google Layer
        $opts = "{\n\"isBaseLayer\": true\n}";
        $vendoropts = "{\n\"type\":\"satellite\",\n\"numZoomLevels\":22\n}";
        $olgooglelayer = $this->openlayers_model->createLayer($googlelayer, $ollayertype[1], '', $opts, $vendoropts);
        $olgooglelayer->owner = $account_admin;
        $this->openlayers_model->save($olgooglelayer);
        // Create Bing Layer
        $opts = "{\n\"isBaseLayer\": true\n}";
        $vendoropts = "{\n\"name\": \"" . $binglayer->title . "\",\n\"key\":\"AqTGBsziZHIJYYxgivLBf0hVdrAk9mWO5cQcb8Yux8sW5M8c8opEC2lZqKR1ZZXf\",\n\"type\":\"Aerial\"\n}";
        $olbinglayer = $this->openlayers_model->createLayer($binglayer, $ollayertype[2], '', $opts, $vendoropts);
        $olbinglayer->owner = $account_admin;
        $this->openlayers_model->save($olbinglayer);
        // Create WMS Mapserver Layer defined above
        $opts = "{\n\"isBaseLayer\": false,\n\"gutter\": 15\n}";
        $vendoropts = "{\n\"layers\":\"" . $layer->alias . "\",\n\"transparent\": true,\n\"projection\":\"EPSG:20790\"\n}";
        $url = $map->alias;
        $olwmslayer = $this->openlayers_model->createLayer($layer, $ollayertype[3], $url, $opts, $vendoropts);
        $olwmslayer->owner = $account_admin;
        $this->openlayers_model->save($olwmslayer);
        // Create Openlayers Map
        $olmap = $this->openlayers_model->createMap($map);
        $olmap->projection = 'EPSG:3857';
        $olmap->owner = $account_admin;
        $this->openlayers_model->save($olmap);
        // Create feature search block
        $lblock6 = $this->layout_model->createBlock('searchblock', $searchblock, 1, '[]', $olmap->id);
        $lblock6->owner = $account_admin;
        R::storeAll(array($lblock6));
        // Add OL Layers to OL Map
        $this->openlayers_model->addMapLayer($olmap, $olosmlayer);
        //$this->openlayers_model->addMapLayer($olmap, $olgooglelayer);
        //$this->openlayers_model->addMapLayer($olmap, $olbinglayer);
        $this->openlayers_model->addMapLayer($olmap, $olwmslayer);
        // Create publicmap layout block
        $olmapblockconfig = '{
"run":["layerswitcher1","wfsgetfeature1","searchblock"],
"center":[-8.5,38.58],
"zoom":8
}';
        $lblock5 = $this->layout_model->createBlock('publicmap1', $olmapblock, 1, $olmapblockconfig, $olmap->id);
        $lblock5->owner = $account_admin;
        R::storeAll(array($lblock5));
        // Add publicmap block to public layout slot
        $this->layout_model->slotAddBlock($pslot1, $lblock5);
        // Add Links to Mapserver Administration
        $menuitems[] = $this->modmenu_model->addItem("Explorer", 'admin/dataexplorer', 1, $menu1, 5);
        $menuitems[] = $this->modmenu_model->addItem("Tickets", 'admin/adminticket', 1, $menu1, 6);
        $menuitems[] = $this->modmenu_model->addItem("Maps", 'admin/adminmap', 1, $menu1, 7);
        $menuitems[] = $this->modmenu_model->addItem("Layers", 'admin/adminlayer', 1, $menu1, 8);
        $menuitems[] = $this->modmenu_model->addItem("Places", 'admin/adminpgplace', 1, $menu1, 9);
        $menuitems[] = $this->modmenu_model->addItem("MapServer Options", 'admin/adminmapserver', 1, $menu1, 10);
        $menuitems[] = $this->modmenu_model->addItem("OpenLayers Options", 'admin/adminopenlayers', 1, $menu1, 11);
        $menuitems[] = $this->modmenu_model->addItem("Google Earth Options", 'admin/admingoogleearth', 1, $menu1, 12);
        $menuitems[] = $this->modmenu_model->addItem("Import", 'admin/import', 1, $menu1, 13);
        foreach ($menuitems as &$item) {
            $item->owner = $account_admin;
        }
        R::storeAll($menuitems);
        // Register default files
        $this->dataexplorer_model->registerpath('./mapfile', 'private', $account_admin);
        // Create User Menu
        $menu2 = $this->modmenu_model->create('usermenu');
        $menu2->owner = $account_admin;
        $this->modmenu_model->save($menu2);
        // Add user menu items
        $menu2items[] = $this->modmenu_model->addItem('Home', 'user/user', 1, $menu2, 1);
        $menu2items[] = $this->modmenu_model->addItem('Frontpage', '', 1, $menu2, 2);
        $menu2items[] = $this->modmenu_model->addItem('My Maps', 'user/managemap', 1, $menu2, 3);
        $menu2items[] = $this->modmenu_model->addItem('My Layers', 'user/managelayer', 1, $menu2, 4);
        $menu2items[] = $this->modmenu_model->addItem('My Places', 'user/managepgplace', 1, $menu2, 5);
        $menu2items[] = $this->modmenu_model->addItem('My Styles', 'user/managemsstyle', 1, $menu2, 6);
        $menu2items[] = $this->modmenu_model->addItem('My Tickets', 'user/manageticket', 1, $menu2, 7);
        $menu2items[] = $this->modmenu_model->addItem("Import", 'user/userimport', 1, $menu2, 8);
        foreach ($menu2items as &$item) {
            $item->owner = $account_admin;
        }
        R::storeAll($menu2items);
        // Create user menu block
        $rlblock3 = $this->layout_model->createBlock('usermenu1', $menublock1, 1, '', $menu2->id);
        $rlblock3->owner = $account_admin;
        R::storeAll(array($rlblock3));
        // Assign layout blocks to slots
        $this->layout_model->slotAddBlock($rslot3, $rlblock3);
        // Create full screen layout
        $fullscreenedit_public = $this->layout_model->create('fullscreenedit', 'admin/fullscreenedit');
        $fullscreenedit_public->owner = $account_admin;
        R::store($fullscreenedit_public);
        // Assign blocks to public layout
        $this->layout_model->slotAddBlock($pslot3, $lblock6);
        $this->layout_model->slotAddBlock($pslot3, $lblock4);
        // Register public controllers
        $ctl = $this->create('controller');
        $ctl->path = 'publicmap';
        $ctl->layout = $layout_public;
        $this->save($ctl);
        $ctl = $this->create('controller');
        $ctl->path = 'auth';
        $ctl->layout = $layout_mod;
        $this->save($ctl);
        $ctl = $this->create('controller');
        $ctl->path = 'tickets';
        $ctl->layout = $layout_mod;
        $this->save($ctl);
        // Register Google Earth map moduke
        $previewimg = 'web/images/module/openlayersmap.png';
        $gemapmod = $this->layout_model->createModule('Google Earth Map', 'googleearth/modgemap_lblock', 'gemap', $previewimg);
        $gemapmod->owner = $account_admin;
        R::store($gemapmod);
        // Create Google Earth Layer Type
        $gelayertype[] = $this->googleearth_model->createLayerType('KML');
        foreach ($gelayertype as &$item) {
            $item->owner = $account_admin;
        }
        R::storeAll($gelayertype);
        // Set Application version (should be last instruction)
        $this->database_model->setVersion($this->config->item('_version'));
        // Return success
        return true;
    }
Ejemplo n.º 5
0
 /**
  * More variations...
  * 
  * @return void
  */
 public function testEmbeddedSQLPart2()
 {
     list($book1, $book2, $book3) = R::dispense('book', 3);
     $book1->position = 1;
     $book2->position = 2;
     $book3->position = 3;
     $shelf = R::dispense('shelf');
     $shelf->ownBook = array($book1, $book2, $book3);
     $id = R::store($shelf);
     $shelf = R::load('shelf', $id);
     $books = $shelf->with(' ORDER BY position ASC ')->ownBook;
     $book1 = array_shift($books);
     asrt((int) $book1->position, 1);
     $book2 = array_shift($books);
     asrt((int) $book2->position, 2);
     $book3 = array_shift($books);
     asrt((int) $book3->position, 3);
     $books = $shelf->with(' ORDER BY position DESC ')->ownBook;
     $book1 = array_shift($books);
     asrt((int) $book1->position, 3);
     $book2 = array_shift($books);
     asrt((int) $book2->position, 2);
     $book3 = array_shift($books);
     asrt((int) $book3->position, 1);
     //R::debug(1);
     $shelf = R::load('shelf', $id);
     $books = $shelf->with(' AND position > 2 ')->ownBook;
     asrt(count($books), 1);
     $shelf = R::load('shelf', $id);
     $books = $shelf->with(' AND position < ? ', array(3))->ownBook;
     asrt(count($books), 2);
     $shelf = R::load('shelf', $id);
     $books = $shelf->with(' AND position = 1 ')->ownBook;
     asrt(count($books), 1);
     $shelf = R::load('shelf', $id);
     $books = $shelf->withCondition(' position > -1 ')->ownBook;
     asrt(count($books), 3);
     // With-condition should not affect storing
     $shelf = R::load('shelf', $id);
     $books = $shelf->with(' AND position = 1 ')->ownBook;
     asrt(count($books), 1);
     asrt(count($shelf->ownBook), 1);
     $book = reset($shelf->ownBook);
     $book->title = 'Trees and other Poems';
     R::store($shelf);
     $books = $shelf->withCondition(' position > -1 ')->ownBook;
     asrt(count($books), 3);
     asrt(count($shelf->ownBook), 3);
     $shelf = R::load('shelf', $id);
     $books = $shelf->with(' AND position = 1 ')->ownBook;
     // Also with trashing -- just trash one!
     $shelf->ownBook = array();
     R::store($shelf);
     $books = $shelf->withCondition(' position > -1 ')->ownBook;
     asrt(count($books), 2);
     // With should cause a reload of a list
     $shelf = R::load('shelf', $id);
     $books = $shelf->with(' AND position = 2 ')->ownBook;
     asrt(count($books), 1);
     $books = $shelf->withCondition(' position > -1 ')->ownBook;
     asrt(count($books), 2);
     $book = reset($books);
     $book->title = 'Venetian Music';
     // Should not affect storage (fact that we used with twice, unsetting prop)
     R::store($shelf);
     $shelf = R::load('shelf', $id);
     asrt(count($shelf->ownBook), 2);
     // Alias
     list($game1, $game2, $game3) = R::dispense('game', 3);
     list($t1, $t2, $t3) = R::dispense('team', 3);
     $t1->name = 'Bats';
     $t2->name = 'Tigers';
     $t3->name = 'Eagles';
     $game1->name = 'a';
     $game1->team1 = $t1;
     $game1->team2 = $t2;
     $game2->name = 'b';
     $game2->team1 = $t1;
     $game2->team2 = $t3;
     $game3->name = 'c';
     $game3->team1 = $t2;
     $game3->team2 = $t3;
     R::storeAll(array($game1, $game2, $game3));
     $team1 = R::load('team', $t1->id);
     $team2 = R::load('team', $t2->id);
     $team3 = R::load('team', $t3->id);
     asrt(count($team1->alias('team1')->ownGame), 2);
     asrt(count($team2->alias('team1')->ownGame), 1);
     $team1 = R::load('team', $t1->id);
     $team2 = R::load('team', $t2->id);
     asrt(count($team1->alias('team2')->ownGame), 0);
     asrt(count($team2->alias('team2')->ownGame), 1);
     asrt(count($team3->alias('team1')->ownGame), 0);
     $team3 = R::load('team', $t3->id);
     asrt(count($team3->alias('team2')->ownGame), 2);
     $team1 = R::load('team', $t1->id);
     $games = $team1->alias('team1')->ownGame;
     $game4 = R::dispense('game');
     $game4->name = 'd';
     $game4->team2 = $t3;
     $team1->alias('team1')->ownGame[] = $game4;
     R::store($team1);
     $team1 = R::load('team', $t1->id);
     asrt(count($team1->alias('team1')->ownGame), 3);
     foreach ($team1->ownGame as $g) {
         if ($g->name == 'a') {
             $game = $g;
         }
     }
     $game->name = 'match';
     R::store($team1);
     $team1 = R::load('team', $t1->id);
     asrt(count($team1->alias('team1')->ownGame), 3);
     $found = 0;
     foreach ($team1->ownGame as $g) {
         if ($g->name == 'match') {
             $found = 1;
         }
     }
     if ($found) {
         pass();
     }
     $team1->ownGame = array();
     R::store($team1);
     $team1 = R::load('team', $t1->id);
     asrt(count($team1->alias('team1')->ownGame), 0);
     $team1->ownBook[] = $book1;
     R::store($team1);
     $team1 = R::load('team', $t1->id);
     asrt(count($team1->alias('team1')->ownGame), 0);
     asrt(count($team1->ownBook), 1);
 }
Ejemplo n.º 6
0
    echo json_encode(['result' => 'failed', 'error' => 'invalid post data']);
    die;
}
// Insert
R::addDatabase('wechat_csc', $GLOBALS['db_wechat_csc_url'], $GLOBALS['db_wechat_csc_user'], $GLOBALS['db_wechat_csc_pass']);
R::selectDatabase('wechat_csc');
if (!R::testConnection()) {
    exit('DB failed' . PHP_EOL);
}
R::freeze(true);
// Insert
try {
    $surveys = R::getRedBean()->dispense('wxcsc_survey', count($answers));
    for ($i = 0; $i < count($answers); $i++) {
        list($q, $a) = explode(':', $answers[$i]);
        $surveys[$i]->survey_id = $survey_id;
        $surveys[$i]->username = $user_name;
        $surveys[$i]->question_id = $q;
        $surveys[$i]->answer = $a;
    }
    $ids = R::storeAll($surveys);
} catch (Exception $e) {
    header('Content-type:text/json;charset=utf-8');
    echo json_encode(['result' => 'failed', 'error' => 'db error wechat', 'details' => $e->getMessage()]);
    die;
}
R::close();
// Return
header('Content-type:text/json;charset=utf-8');
echo json_encode(['result' => 'true']);
die;
Ejemplo n.º 7
0
 /**
  * Test the database driver and low level functions.
  * 
  * @return void
  */
 public function testDriver()
 {
     $currentDriver = $this->currentlyActiveDriverID;
     R::store(R::dispense('justabean'));
     $adapter = new TroubleDapter(R::$toolbox->getDatabaseAdapter()->getDatabase());
     $adapter->setSQLState('HY000');
     $writer = new RedBean_QueryWriter_SQLiteT($adapter);
     $redbean = new RedBean_OODB($writer);
     $toolbox = new RedBean_ToolBox($redbean, $adapter, $writer);
     // We can only test this for a known driver...
     if ($currentDriver === 'sqlite') {
         try {
             $redbean->find('bean');
             pass();
         } catch (Exception $e) {
             var_dump($e->getSQLState());
             fail();
         }
     }
     $adapter->setSQLState(-999);
     try {
         $redbean->find('bean');
         fail();
     } catch (Exception $e) {
         pass();
     }
     $beanA = R::dispense('bean');
     $beanB = R::dispense('bean');
     R::storeAll(array($beanA, $beanB));
     $associationManager = new RedBean_AssociationManager($toolbox);
     $adapter->setSQLState('HY000');
     // We can only test this for a known driver...
     if ($currentDriver === 'sqlite') {
         try {
             $associationManager->areRelated($beanA, $beanB);
             pass();
         } catch (Exception $e) {
             fail();
         }
     }
     $adapter->setSQLState(-999);
     try {
         $associationManager->areRelated($beanA, $beanA);
         fail();
     } catch (Exception $e) {
         pass();
     }
     try {
         $redbean->wipe('justabean');
         fail();
     } catch (Exception $e) {
         pass();
     }
     $toolbox = R::$toolbox;
     $adapter = $toolbox->getDatabaseAdapter();
     $writer = $toolbox->getWriter();
     $redbean = $toolbox->getRedBean();
     $pdo = $adapter->getDatabase();
     $page = $redbean->dispense("page");
     try {
         $adapter->exec("an invalid query");
         fail();
     } catch (RedBean_Exception_SQL $e) {
         pass();
     }
     // Special data type description should result in magic number 99 (specified)
     if ($currentDriver == 'mysql') {
         asrt($writer->code(RedBean_QueryWriter_MySQL::C_DATATYPE_SPECIAL_DATE), 99);
     }
     if ($currentDriver == 'pgsql') {
         asrt($writer->code(RedBean_QueryWriter_PostgreSQL::C_DATATYPE_SPECIAL_DATE), 99);
     }
     if ($currentDriver == 'CUBRID') {
         asrt($writer->code(RedBean_QueryWriter_CUBRID::C_DATATYPE_SPECIAL_DATE), 99);
     }
     asrt((int) $adapter->getCell("SELECT 123"), 123);
     $page->aname = "my page";
     $id = (int) $redbean->store($page);
     asrt((int) $page->id, 1);
     asrt((int) $pdo->GetCell("SELECT count(*) FROM page"), 1);
     asrt($pdo->GetCell("SELECT aname FROM page LIMIT 1"), "my page");
     asrt((int) $id, 1);
     $page = $redbean->load("page", 1);
     asrt($page->aname, "my page");
     asrt((bool) $page->getMeta("type"), TRUE);
     asrt(isset($page->id), TRUE);
     asrt($page->getMeta("type"), "page");
     asrt((int) $page->id, $id);
 }
Ejemplo n.º 8
0
 /**
  * Test batch alias loadAll.
  * 
  * @return void
  */
 public function testBatchAliasLoadAll()
 {
     $ids = R::storeAll(R::dispense('page', 2));
     $pages = R::loadAll('page', $ids);
     asrt(is_array($pages), true);
     asrt(count($pages), 2);
     asrt($pages[$ids[0]] instanceof RedBean_OODBBean, true);
 }
Ejemplo n.º 9
0
 /**
  * Test variations and cache 2.
  * 
  * @return void
  */
 public function testPreloadingVariationsAndCache2()
 {
     R::$writer->setUseCache(FALSE);
     $villages = R::dispense('village', 3);
     foreach ($villages as $v) {
         $v->ownBuilding = R::dispense('building', 3);
     }
     foreach ($villages as $v) {
         foreach ($v->ownBuilding as $b) {
             $b->ownFurniture = R::dispense('furniture', 2);
         }
     }
     $armies = R::dispense('army', 3);
     $villages[0]->sharedArmy = array($armies[1], $armies[2]);
     $villages[1]->sharedArmy = array($armies[0], $armies[1]);
     $villages[2]->sharedArmy = array($armies[2]);
     $soldiers = R::dispense('soldier', 4);
     $armies[0]->sharedSoldier = array($soldiers[0], $soldiers[1], $soldiers[2]);
     $armies[1]->sharedSoldier = array($soldiers[2], $soldiers[1]);
     $armies[2]->sharedSoldier = array($soldiers[2]);
     $counter = 0;
     foreach ($villages as $v) {
         $v->name = $counter++;
     }
     $counter = 0;
     foreach ($armies as $a) {
         $a->name = $counter++;
     }
     $counter = 0;
     foreach ($soldiers as $s) {
         $s->name = $counter++;
     }
     $buildings = R::dispense('building', 4);
     $villages[0]->ownBuilding = array($buildings[0]);
     $villages[1]->ownBuilding = array($buildings[1], $buildings[2]);
     $villages[2]->ownBuilding = array($buildings[3]);
     $counter = 0;
     foreach ($buildings as $b) {
         $b->name = $counter++;
     }
     $books = R::dispense('book', 5);
     $counter = 0;
     foreach ($books as $b) {
         $b->name = $counter++;
     }
     $buildings[0]->ownBook = array($books[0], $books[1]);
     $buildings[1]->ownBook = array($books[2]);
     $buildings[2]->ownBook = array($books[3], $books[4]);
     $world = R::dispense('world');
     $world->name = 'w1';
     $villages[1]->world = $world;
     R::storeAll($villages);
     $towns = R::find('village');
     $counter = 0;
     R::each($towns, array('sharedArmy' => 'army', 'sharedArmy.sharedSoldier' => array('soldier', array(' ORDER BY soldier.name DESC ', array())), 'ownBuilding' => array('building', array(' ORDER BY building.name DESC ', array())), 'ownBuilding.ownBook' => 'book', 'world'), function ($t, $a, $s, $b, $x, $w) use(&$counter) {
         if ($counter === 0) {
             asrt($w, NULL);
             asrt((string) $t->name, '0');
             asrt(count($t->sharedArmy), 2);
             $list = array();
             foreach ($a as $item) {
                 $list[] = $item->name;
             }
             sort($list);
             asrt(implode(',', $list), '1,2');
             $list = array();
             foreach ($s as $item) {
                 $list[] = $item->name;
             }
             asrt(implode(',', $list), '2,1');
             $list = array();
             foreach ($b as $item) {
                 $list[] = $item->name;
             }
             sort($list);
             asrt(implode(',', $list), '0');
             $list = array();
             foreach ($x as $item) {
                 $list[] = $item->name;
             }
             sort($list);
             asrt(implode(',', $list), '0,1');
             $first = reset($a);
             asrt($first->getMeta('type'), 'army');
             $first = reset($s);
             asrt($first->getMeta('type'), 'soldier');
             $first = reset($b);
             asrt($first->getMeta('type'), 'building');
             $first = reset($x);
             asrt($first->getMeta('type'), 'book');
         } elseif ($counter === 1) {
             asrt($w->name, 'w1');
             asrt((string) $t->name, '1');
             asrt(count($t->sharedArmy), 2);
             $list = array();
             foreach ($a as $item) {
                 $list[] = $item->name;
             }
             sort($list);
             asrt(implode(',', $list), '0,1');
             $list = array();
             foreach ($s as $item) {
                 $list[] = $item->name;
             }
             sort($list);
             asrt(implode(',', $list), '0,1,2');
             $list = array();
             foreach ($b as $item) {
                 $list[] = $item->name;
             }
             asrt(implode(',', $list), '2,1');
             $list = array();
             foreach ($x as $item) {
                 $list[] = $item->name;
             }
             sort($list);
             asrt(implode(',', $list), '2,3,4');
             $first = reset($a);
             asrt($first->getMeta('type'), 'army');
             $first = reset($s);
             asrt($first->getMeta('type'), 'soldier');
             $first = reset($b);
             asrt($first->getMeta('type'), 'building');
             $first = reset($x);
             asrt($first->getMeta('type'), 'book');
         } elseif ($counter === 2) {
             asrt($w, NULL);
             asrt((string) $t->name, '2');
             asrt(count($t->sharedArmy), 1);
             $list = array();
             foreach ($a as $item) {
                 $list[] = $item->name;
             }
             sort($list);
             asrt(implode(',', $list), '2');
             $list = array();
             foreach ($s as $item) {
                 $list[] = $item->name;
             }
             sort($list);
             asrt(implode(',', $list), '2');
             $list = array();
             foreach ($b as $item) {
                 $list[] = $item->name;
             }
             sort($list);
             asrt(implode(',', $list), '3');
             asrt(count($x), 0);
             $first = reset($a);
             asrt($first->getMeta('type'), 'army');
             $first = reset($s);
             asrt($first->getMeta('type'), 'soldier');
             $first = reset($b);
             asrt($first->getMeta('type'), 'building');
         }
         $counter++;
     });
 }
Ejemplo n.º 10
0
 /**
  * Test trashAll().
  */
 public function testMultiDeleteUpdate()
 {
     testpack('test multi delete and multi update');
     $beans = R::dispenseLabels('bean', array('a', 'b'));
     $ids = R::storeAll($beans);
     asrt((int) R::count('bean'), 2);
     R::trashAll(R::batch('bean', $ids));
     asrt((int) R::count('bean'), 0);
     testpack('test assocManager check');
     $rb = new RedBean_OODB(R::$writer);
     try {
         $rb->getAssociationManager();
         fail();
     } catch (RedBean_Exception_Security $e) {
         pass();
     }
 }
Ejemplo n.º 11
0
 /**
  * Switching aliases (->alias) should not change other list during
  * storage.
  * 
  * @return void
  */
 public function testShadow()
 {
     list($project1, $project2) = R::dispense('project', 2);
     list($irene, $ilse) = R::dispense('person', 2);
     $project1->developer = $ilse;
     $project1->designer = $irene;
     $project2->developer = $ilse;
     R::storeAll(array($project1, $project2));
     $ilse = R::load('person', $ilse->id);
     $irene = R::load('person', $irene->id);
     asrt(count($ilse->alias('developer')->ownProject), 2);
     asrt(count($ilse->alias('designer')->ownProject), 0);
     R::store($ilse);
     $ilse = R::load('person', $ilse->id);
     $irene = R::load('person', $irene->id);
     asrt(count($ilse->alias('designer')->ownProject), 0);
     asrt(count($ilse->alias('developer')->ownProject), 2);
     R::storeAll(array($ilse, $irene));
     $ilse = R::load('person', $ilse->id);
     $irene = R::load('person', $irene->id);
     asrt(count($ilse->alias('designer')->ownProject), 0);
     asrt(count($ilse->alias('developer')->ownProject), 2);
     asrt(count($irene->alias('designer')->ownProject), 1);
     asrt(count($irene->alias('developer')->ownProject), 0);
     R::storeAll(array($ilse, $irene));
     $ilse = R::load('person', $ilse->id);
     $irene = R::load('person', $irene->id);
     asrt(count($ilse->alias('designer')->ownProject), 0);
     asrt(count($ilse->alias('developer')->ownProject), 2);
     asrt(count($irene->alias('designer')->ownProject), 1);
     asrt(count($irene->alias('developer')->ownProject), 0);
 }
Ejemplo n.º 12
0
 /**
  * test emulation via association renaming
  * 
  * @return void
  */
 public function testAssociationRenaming()
 {
     list($p1, $p2, $p3) = R::dispense('painting', 3);
     list($m1, $m2, $m3) = R::dispense('museum', 3);
     $p1->name = 'painting1';
     $p2->name = 'painting2';
     $p3->name = 'painting3';
     $m1->thename = 'a';
     $m2->thename = 'b';
     $m3->thename = 'c';
     R::renameAssociation('museum_painting', 'exhibited');
     // Also test array syntax
     R::renameAssociation(array('museum_museum' => 'center'));
     $m1->link('center', array('name' => 'History Center'))->museum2 = $m2;
     $m1->link('exhibited', '{"from":"2014-02-01","til":"2014-07-02"}')->painting = $p3;
     $m2->link('exhibited', '{"from":"2014-07-03","til":"2014-10-02"}')->painting = $p3;
     $m3->link('exhibited', '{"from":"2014-02-01","til":"2014-07-02"}')->painting = $p1;
     $m2->link('exhibited', '{"from":"2014-02-01","til":"2014-07-02"}')->painting = $p2;
     R::storeAll(array($m1, $m2, $m3));
     list($m1, $m2, $m3) = array_values(R::findAll('museum', ' ORDER BY thename ASC'));
     asrt(count($m1->sharedMuseum), 1);
     asrt(count($m1->sharedPainting), 1);
     asrt(count($m2->sharedPainting), 2);
     asrt(count($m3->sharedPainting), 1);
     $p3 = reset($m1->sharedPainting);
     asrt(count($p3->ownExhibited), 2);
     asrt(count($m2->ownExhibited), 2);
     R::storeAll(array($m1, $m2, $m3));
     list($m1, $m2, $m3) = array_values(R::findAll('museum', ' ORDER BY thename ASC'));
     asrt(count($m1->sharedPainting), 1);
     asrt(count($m2->sharedPainting), 2);
     asrt(count($m3->sharedPainting), 1);
     $p3 = reset($m1->sharedPainting);
     asrt(count($p3->ownExhibited), 2);
     $paintings = $m2->sharedPainting;
     foreach ($paintings as $painting) {
         if ($painting->name === 'painting2') {
             pass();
             $paintingX = $painting;
         }
     }
     unset($m2->sharedPainting[$paintingX->id]);
     R::store($m2);
     $m2 = R::load('museum', $m2->id);
     asrt(count($m2->sharedPainting), 1);
     $left = reset($m2->sharedPainting);
     asrt($left->name, 'painting3');
     asrt(count($m2->ownExhibited), 1);
     $exhibition = reset($m2->ownExhibited);
     asrt($exhibition->from, '2014-07-03');
     asrt($exhibition->til, '2014-10-02');
 }