/** * PHPDOC * * @param NelioABExperiment $exp PHPDOC * @param object $json PHPDOC * * @return NelioABAltExpGoal PHPDOC * * @since PHPDOC */ public static function decode_from_appengine($exp, $json) { $result = new NelioABAltExpGoal($exp); $result->set_id($json->key->id); $result->set_name($json->name); $result->set_benefit($json->benefit); $result->set_as_main_goal($json->isMainGoal); $ae_actions = array(); if (isset($json->pageAccessedActions)) { foreach ($json->pageAccessedActions as $action) { $action = (array) $action; $action['_type'] = 'page-accessed-action'; $action = (object) $action; array_push($ae_actions, $action); } } if (isset($json->formActions)) { foreach ($json->formActions as $action) { $action = (array) $action; $action['_type'] = 'form-action'; $action = (object) $action; array_push($ae_actions, $action); } } if (isset($json->clickActions)) { foreach ($json->clickActions as $action) { $action = (array) $action; $action['_type'] = 'click-element-action'; $action = (object) $action; array_push($ae_actions, $action); } } if (isset($json->orderCompletedActions)) { foreach ($json->orderCompletedActions as $action) { $action = (array) $action; $action['_type'] = 'order-completed-action'; $action = (object) $action; array_push($ae_actions, $action); } } usort($ae_actions, array('NelioABAltExpGoal', 'sort_goals')); foreach ($ae_actions as $action) { /** @var object $action */ switch ($action->_type) { case 'page-accessed-action': $result->add_action(NelioABPageAccessedAction::decode_from_appengine($action)); break; case 'form-action': $result->add_action(NelioABFormSubmissionAction::decode_from_appengine($action)); break; case 'click-element-action': $result->add_action(NelioABClickElementAction::decode_from_appengine($action)); break; case 'order-completed-action': $result->add_action(NelioABWooCommerceOrderCompletedAction::decode_from_appengine($action)); break; } } return $result; }
/** * Returns a new action object built using the information described in $action. * * @param object $json a JSON action returned by AppEngine. * * @return NelioABClickElementAction the new action containing all the information in `$action`. * * @since PHPDOC * @Override */ public static function decode_from_appengine($json) { $action = new NelioABClickElementAction($json->kind, $json->value); if (isset($json->key->id)) { $action->set_id($json->key->id); } return $action; }
/** * Returns a new action object built using the information described in $action. * * The particular type of the resulting action will depend on * `$action->type`. Note this class is abstract and there are * several concrete classes extending this one. * * @param object $json a JSON action as used in the admin pages of our plugin. * * @return boolean|NelioABAction the new action containing all the information in `$action`. * * @since PHPDOC */ public static function build_action_using_json4js($json) { require_once NELIOAB_MODELS_DIR . '/goals/actions/page-accessed-action.php'; require_once NELIOAB_MODELS_DIR . '/goals/actions/form-submission-action.php'; require_once NELIOAB_MODELS_DIR . '/goals/actions/click-element-action.php'; require_once NELIOAB_MODELS_DIR . '/goals/actions/wc-order-completed-action.php'; switch ($json->type) { case self::PAGE_ACCESSED: case self::POST_ACCESSED: case self::EXTERNAL_PAGE_ACCESSED: return NelioABPageAccessedAction::build_action_using_json4js($json); case self::FORM_SUBMIT: return NelioABFormSubmissionAction::build_action_using_json4js($json); case self::CLICK_ELEMENT: return NelioABClickElementAction::build_action_using_json4js($json); case self::WC_ORDER_COMPLETED: return NelioABWooCommerceOrderCompletedAction::build_action_using_json4js($json); default: return false; } }