PHP:
class Car_Installer extends Engine_Package_Installer_Module
{
public function onInstall()
{
$this->_addUserProfileContent();
$this->_addCarViewPage();
$this->_addCarBrowsePage();
parent::onInstall();
}
protected function _addCarBrowsePage()
{
$db = $this->getDb();
// profile page
$page_id = $db->select()
->from('engine4_core_pages', 'page_id')
->where('name = ?', 'car_index_browse')
->limit(1)
->query()
->fetchColumn();
// insert if it doesn't exist yet
if( !$page_id ) {
// Insert page
$db->insert('engine4_core_pages', array(
'name' => 'car_index_browse',
'displayname' => 'Car Browse Page',
'title' => 'Car Browse',
'description' => 'This page lists cars.',
'custom' => 0,
));
$page_id = $db->lastInsertId();
// Insert top
$db->insert('engine4_core_content', array(
'type' => 'container',
'name' => 'top',
'page_id' => $page_id,
'order' => 1,
));
$top_id = $db->lastInsertId();
// Insert main
$db->insert('engine4_core_content', array(
'type' => 'container',
'name' => 'main',
'page_id' => $page_id,
'order' => 2,
));
$main_id = $db->lastInsertId();
// Insert top-middle
$db->insert('engine4_core_content', array(
'type' => 'container',
'name' => 'middle',
'page_id' => $page_id,
'parent_content_id' => $top_id,
));
$top_middle_id = $db->lastInsertId();
// Insert main-middle
$db->insert('engine4_core_content', array(
'type' => 'container',
'name' => 'middle',
'page_id' => $page_id,
'parent_content_id' => $main_id,
'order' => 2,
));
$main_middle_id = $db->lastInsertId();
// Insert main-right
$db->insert('engine4_core_content', array(
'type' => 'container',
'name' => 'right',
'page_id' => $page_id,
'parent_content_id' => $main_id,
'order' => 1,
));
$main_right_id = $db->lastInsertId();
// Insert menu
$db->insert('engine4_core_content', array(
'type' => 'widget',
'name' => 'car.browse-menu',
'page_id' => $page_id,
'parent_content_id' => $top_middle_id,
'order' => 1,
));
// Insert content
$db->insert('engine4_core_content', array(
'type' => 'widget',
'name' => 'core.content',
'page_id' => $page_id,
'parent_content_id' => $main_middle_id,
'order' => 1,
));
// Insert search
$db->insert('engine4_core_content', array(
'type' => 'widget',
'name' => 'car.browse-search',
'page_id' => $page_id,
'parent_content_id' => $main_right_id,
'order' => 1,
));
// Insert gutter menu
$db->insert('engine4_core_content', array(
'type' => 'widget',
'name' => 'car.browse-menu-quick',
'page_id' => $page_id,
'parent_content_id' => $main_right_id,
'order' => 2,
));
}
}
protected function _addUserProfileContent()
{
$db = $this->getDb();
$select = new Zend_Db_Select($db);
// profile page
$select
->from('engine4_core_pages')
->where('name = ?', 'user_profile_index')
->limit(1);
$page_id = $select->query()->fetchObject()->page_id;
// car.profile-cars
// Check if it's already been placed
$select = new Zend_Db_Select($db);
$select
->from('engine4_core_content')
->where('page_id = ?', $page_id)
->where('type = ?', 'widget')
->where('name = ?', 'car.profile-cars')
;
$info = $select->query()->fetch();
if( empty($info) ) {
// container_id (will always be there)
$select = new Zend_Db_Select($db);
$select
->from('engine4_core_content')
->where('page_id = ?', $page_id)
->where('type = ?', 'container')
->limit(1);
$container_id = $select->query()->fetchObject()->content_id;
// middle_id (will always be there)
$select = new Zend_Db_Select($db);
$select
->from('engine4_core_content')
->where('parent_content_id = ?', $container_id)
->where('type = ?', 'container')
->where('name = ?', 'middle')
->limit(1);
$middle_id = $select->query()->fetchObject()->content_id;
// tab_id (tab container) may not always be there
$select
->reset('where')
->where('type = ?', 'widget')
->where('name = ?', 'core.container-tabs')
->where('page_id = ?', $page_id)
->limit(1);
$tab_id = $select->query()->fetchObject();
if( $tab_id && @$tab_id->content_id ) {
$tab_id = $tab_id->content_id;
} else {
$tab_id = null;
}
// tab on profile
$db->insert('engine4_core_content', array(
'page_id' => $page_id,
'type' => 'widget',
'name' => 'car.profile-cars',
'parent_content_id' => ($tab_id ? $tab_id : $middle_id),
'order' => 12,
'params' => '{"title":"Cars","titleCount":true}',
));
}
}
protected function _addCarViewPage()
{
$db = $this->getDb();
$select = new Zend_Db_Select($db);
// Check if it's already been placed
$select = new Zend_Db_Select($db);
$select
->from('engine4_core_pages')
->where('name = ?', 'car_index_view')
->limit(1);
;
$info = $select->query()->fetch();
if( empty($info) ) {
$db->insert('engine4_core_pages', array(
'name' => 'car_index_view',
'displayname' => 'Car View Page',
'title' => 'View Car',
'description' => 'This is the view page for a car.',
'custom' => 0,
'provides' => 'subject=car',
));
$page_id = $db->lastInsertId('engine4_core_pages');
// containers
$db->insert('engine4_core_content', array(
'page_id' => $page_id,
'type' => 'container',
'name' => 'main',
'parent_content_id' => null,
'order' => 1,
'params' => '',
));
$container_id = $db->lastInsertId('engine4_core_content');
$db->insert('engine4_core_content', array(
'page_id' => $page_id,
'type' => 'container',
'name' => 'left',
'parent_content_id' => $container_id,
'order' => 1,
'params' => '',
));
$left_id = $db->lastInsertId('engine4_core_content');
$db->insert('engine4_core_content', array(
'page_id' => $page_id,
'type' => 'container',
'name' => 'right',
'parent_content_id' => $container_id,
'order' => 1,
'params' => '',
));
$right_id = $db->lastInsertId('engine4_core_content');
$db->insert('engine4_core_content', array(
'page_id' => $page_id,
'type' => 'container',
'name' => 'middle',
'parent_content_id' => $container_id,
'order' => 3,
'params' => '',
));
$middle_id = $db->lastInsertId('engine4_core_content');
// middle column content
$db->insert('engine4_core_content', array(
'page_id' => $page_id,
'type' => 'widget',
'name' => 'core.container-tabs',
'parent_content_id' => $middle_id,
'order' => 1,
'params' => '{"max":6}'
));
$container_tabs_id = $db->lastInsertId('engine4_core_content');
$db->insert('engine4_core_content', array(
'page_id' => $page_id,
'type' => 'widget',
'name' => 'activity.feed',
'parent_content_id' => $container_tabs_id,
'order' => 1,
'params' => '{"title":"Activity"}',
));
$db->insert('engine4_core_content', array(
'page_id' => $page_id,
'type' => 'widget',
'name' => 'car.profile-fields',
'parent_content_id' => $container_tabs_id,
'order' => 2,
'params' => '{"title":"Info"}',
));
$db->insert('engine4_core_content', array(
'page_id' => $page_id,
'type' => 'widget',
'name' => 'car.profile-albums',
'parent_content_id' => $container_tabs_id,
'order' => 3,
'params' => '{"title":"Albums","titleCount":true}',
));
$db->insert('engine4_core_content', array(
'page_id' => $page_id,
'type' => 'widget',
'name' => 'car.profile-videos',
'parent_content_id' => $container_tabs_id,
'order' => 4,
'params' => '{"title":"Videos","titleCount":true}',
));
// right column
$db->insert('engine4_core_content', array(
'page_id' => $page_id,
'type' => 'widget',
'name' => 'car.show-same-tags',
'parent_content_id' => $right_id,
'order' => 1,
'params' => '',
));
$db->insert('engine4_core_content', array(
'page_id' => $page_id,
'type' => 'widget',
'name' => 'car.show-also-liked',
'parent_content_id' => $right_id,
'order' => 2,
'params' => '',
));
$db->insert('engine4_core_content', array(
'page_id' => $page_id,
'type' => 'widget',
'name' => 'car.show-same-poster',
'parent_content_id' => $right_id,
'order' => 3,
'params' => '',
));
// left column
$db->insert('engine4_core_content', array(
'page_id' => $page_id,
'type' => 'widget',
'name' => 'car.profile-photo',
'parent_content_id' => $left_id,
'order' => 1,
'params' => '',
));
$db->insert('engine4_core_content', array(
'page_id' => $page_id,
'type' => 'widget',
'name' => 'car.profile-ratings',
'parent_content_id' => $left_id,
'order' => 2,
'params' => '',
));
$db->insert('engine4_core_content', array(
'page_id' => $page_id,
'type' => 'widget',
'name' => 'car.profile-options',
'parent_content_id' => $left_id,
'order' => 3,
'params' => '',
));
$db->insert('engine4_core_content', array(
'page_id' => $page_id,
'type' => 'widget',
'name' => 'car.profile-info',
'parent_content_id' => $left_id,
'order' => 4,
'params' => '',
));
}
}
}
This class' onInstall method runs when the module is install and construct the pages that we need to be editable in the layout editor.
Code:
INSERT IGNORE INTO engine4_core_menus (`name`, `type`, `title`, `order`) VALUES ('car_main', 'standard', 'Car Main Navigation Menu', 999);
INSERT IGNORE INTO engine4_core_menuitems (`name`, `module`, `label`, `plugin`, `params`, `menu`, `submenu`, `enabled`, `custom`, `order`) VALUES
('car_main_browse', 'car', 'Browse Cars', 'Car_Plugin_Menus::canViewCars', '{"route":"car_general","action":"browse"}', 'car_main', '', 1, 0, 1),
('car_main_manage', 'car', 'My Cars', 'Car_Plugin_Menus::canCreateCars', '{"route":"car_general","action":"manage"}', 'car_main', '', 1, 0, 2),
('car_main_create', 'car', 'Create Car', 'Car_Plugin_Menus::canCreateCars', '{"route":"car_general","action":"create"}', 'car_main', '', 1, 0, 3);
Now we can discuss the plugin field. The field comes in two formats: <ClassName> and <ClassName>::<Method>. Using the latter we can control whether the menu item is