Skip to content

Commit

Permalink
Add new ecom_active() function for a universal way to see if ecom is …
Browse files Browse the repository at this point in the history
…active before ECOM is set in main index.php (e.g. install/upgrade), and updates renderAction() comments
  • Loading branch information
dleffler committed Nov 17, 2014
1 parent 08d25d6 commit 9f3b02a
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 28 deletions.
36 changes: 20 additions & 16 deletions framework/core/expFramework.php
Expand Up @@ -240,7 +240,7 @@
$order = null;

/**
* Main module display logic/routine for MVC modules
* Main module action/display logic/routine; initializes/checks controller before calling action/method
*
* @param array $parms
* @return bool|mixed|string
Expand All @@ -258,15 +258,12 @@ function renderAction(array $parms=array()) {
}

if (isset($parms['view'])) $parms['view'] = urldecode($parms['view']);
// Figure out the action to use...if the specified action doesn't exist then
// we look for the index action.
// Figure out the action to use...if the specified action doesn't exist then we look for the showall action.
if ($controllerClass->hasMethod($parms['action'])) {
$action = $parms['action'];
/* TODO: Not sure if this needs to be here. FJD
/* TODO: Not sure if we need to check for private methods to be here. FJD
$meth = $controllerClass->getMethod($action);
if ($meth->isPrivate()) expQueue::flashAndFlow('error', gt('The requested action could not be performed: Action not found'));*/
// } elseif ($controllerClass->hasMethod('index')) {
// $action = 'index';
} elseif ($controllerClass->hasMethod('showall')) {
$parms['action'] = 'showall';
$action = 'showall';
Expand All @@ -278,12 +275,12 @@ function renderAction(array $parms=array()) {
$src = isset($parms['src']) ? $parms['src'] : null;
$controller = new $fullControllerName($src, $parms);

//Set up the template to use for this action
//Set up the correct template to use for this action
global $template;
$view = !empty($parms['view']) ? $parms['view'] : $action;
$template = expTemplate::get_template_for_action($controller, $view, $controller->loc);

//setup some default models for this controller's actions to use
//setup default model(s) for this controller's actions to use
foreach ($controller->getModels() as $model) {
$controller->$model = new $model(null,false,false); //added null,false,false to reduce unnecessary queries. FJD
// flag for needing approval check
Expand All @@ -298,9 +295,10 @@ function renderAction(array $parms=array()) {
}
}

// FIXME this is now handled by the template class during get_template_for_action since it only sets template variables
// have the controller assign knowledge about itself to the template.
// this has to be done after the controller gets the template for its actions
// $controller->moduleSelfAwareness(); // FIXME this is now handled by the template class during get_template_for_action
// $controller->moduleSelfAwareness();

//if this controller is being called by a container then we should have a module title.
if (isset($parms['moduletitle'])) {
Expand All @@ -313,8 +311,6 @@ function renderAction(array $parms=array()) {
$template->assign('moduletitle', $db->selectValue('container', 'title', "internal='".serialize($title)."'"));
}

// add the $_REQUEST values to the controller <- pb: took this out and passed in the params to the controller constructor above
//$controller->params = $parms;
// check the perms for this action
$perms = $controller->permissions();

Expand All @@ -324,6 +320,7 @@ function renderAction(array $parms=array()) {
// the action. To safeguard, we'll catch if the action is update and change it either to create or
// edit depending on whether an id param is passed to. that should be sufficient.
$common_action = null;
//FIXME do we also need to account for actions with camelcase action/perm such as editItem ???
if ($parms['action'] == 'update') {
$perm_action = (!isset($parms['id']) || $parms['id'] == 0) ? 'create' : 'edit';
} elseif ($parms['action'] == 'edit' && (!isset($parms['id']) || $parms['id'] == 0)) {
Expand Down Expand Up @@ -391,6 +388,7 @@ function renderAction(array $parms=array()) {
}
}

//FIXME? if the assoc $perm doesn't exist, the 'action' will ALWAYS be allowed, e.g., default is to allow action
if (array_key_exists($perm_action, $perms)) {
if (!expPermissions::check($perm_action, $controller->loc)) {
if (expTheme::inAction()) {
Expand Down Expand Up @@ -432,11 +430,6 @@ function renderAction(array $parms=array()) {
// register this controllers permissions to the view for in view perm checks
$template->register_permissions(array_keys($perms), $controller->loc);

// pass this controllers config to the view
// $template->assign('config', $controller->config);
// assign the controllers basemodel to the view
// $template->assign('modelname', $controller->basemodel_name);

// globalizing $user inside all templates
$template->assign('user', $user);

Expand Down Expand Up @@ -887,6 +880,17 @@ function curPageURL() {
return $pageURL;
}

/**
* Return status of e-commerce
*/
function ecom_active() {
global $db;

return ($db->selectValue('modstate', 'active', 'module="store"') ||
$db->selectValue('modstate', 'active', 'module="eventregistration"') ||
$db->selectValue('modstate', 'active', 'module="donation"') || FORCE_ECOM);
}

/**
* Return the current framework
*
Expand Down
1 change: 0 additions & 1 deletion framework/core/forms/basetemplate.php
Expand Up @@ -125,7 +125,6 @@ function __construct($item_type, $item_dir, $view = "Default")
$this->tpl->setTemplateDir($this->viewdir);

$this->tpl->setCompileDir(BASE . 'tmp/views_c');
// $this->tpl->compile_id = md5($this->viewfile);
$this->tpl->compile_id = framework() . '_' . md5($this->viewfile);

$this->tpl->assign("__view", $this->view);
Expand Down
1 change: 0 additions & 1 deletion framework/core/forms/controllertemplate.php
Expand Up @@ -104,7 +104,6 @@ function __construct($controller, $viewfile) {
$this->tpl->setTemplateDir($this->viewdir);

$this->tpl->setCompileDir(BASE . 'tmp/views_c');
// $this->tpl->compile_id = md5($this->viewfile);
$this->tpl->compile_id = framework() . '_' . md5($this->viewfile);

$this->tpl->assign("__view", $this->view);
Expand Down
4 changes: 4 additions & 0 deletions framework/modules/administration/menus/upcomingevents.php
Expand Up @@ -22,6 +22,10 @@

global $db, $user, $router;

$active = ECOM;
if (empty($active))
return false;

if (!$user->isAdmin()) {
$viewregperms = $db->selectValue(
'userpermission',
Expand Down
4 changes: 1 addition & 3 deletions index.php
Expand Up @@ -51,9 +51,7 @@ function epb($buffer, $mode) {
//if ($db->selectValue('modstate', 'active', 'module="storeController"') ||
// $db->selectValue('modstate', 'active', 'module="eventregistrationController"') ||
// $db->selectValue('modstate', 'active', 'module="donationController"') || FORCE_ECOM) {
if ($db->selectValue('modstate', 'active', 'module="store"') ||
$db->selectValue('modstate', 'active', 'module="eventregistration"') ||
$db->selectValue('modstate', 'active', 'module="donation"') || FORCE_ECOM) {
if (ecom_active()) {
define('ECOM',1);
$order = order::getUserCart(); // set global store $order
// global store config
Expand Down
2 changes: 1 addition & 1 deletion install/upgrades/update_ecom.php
Expand Up @@ -46,7 +46,7 @@ function description() { return "In v2.0.9, the e-Commerce header/footer configu
*/
function needed() {
$config = new expConfig(expCore::makeLocation("ecomconfig","@globalstoresettings",""));
if (defined('ECOM') && (!empty($config->config['header']) || !empty($config->config['footer']))) {
if (ecom_active() && (!empty($config->config['header']) || !empty($config->config['footer']))) {
return true;
} else return false;
}
Expand Down
2 changes: 1 addition & 1 deletion install/upgrades/update_ecom2.php
Expand Up @@ -49,7 +49,7 @@ function needed() {
// if (!empty($config)) {
// return true;
// } else return false;
if (defined('ECOM')) return true;
if (ecom_active()) return true;
else return false;
}

Expand Down
6 changes: 1 addition & 5 deletions install/upgrades/update_shipping_billing_calcs.php
Expand Up @@ -45,11 +45,7 @@ function description() { return "Some e-Commerce calculators were revised. This
* @return bool
*/
function needed() {
global $db;

if ($db->selectValue('modstate', 'active', 'module="store"') ||
$db->selectValue('modstate', 'active', 'module="eventregistration"') ||
$db->selectValue('modstate', 'active', 'module="donation"') || FORCE_ECOM) {
if (ecom_active()) {
return true;
} else {
return false;
Expand Down

0 comments on commit 9f3b02a

Please sign in to comment.