Code Coverage  | 
      ||||||||||
Lines  | 
       Functions and Methods  | 
       Classes and Traits  | 
      ||||||||
| Total |         | 
       0.00%  | 
       0 / 34  | 
               | 
       0.00%  | 
       0 / 5  | 
       CRAP |         | 
       0.00%  | 
       0 / 1  | 
      
| RequiredActionRedirect |         | 
       0.00%  | 
       0 / 34  | 
               | 
       0.00%  | 
       0 / 5  | 
       56 |         | 
       0.00%  | 
       0 / 1  | 
      
| __construct |         | 
       0.00%  | 
       0 / 2  | 
               | 
       0.00%  | 
       0 / 1  | 
       2 | |||
| execute |         | 
       0.00%  | 
       0 / 14  | 
               | 
       0.00%  | 
       0 / 1  | 
       12 | |||
| __toPhpCode |         | 
       0.00%  | 
       0 / 9  | 
               | 
       0.00%  | 
       0 / 1  | 
       2 | |||
| getUrl |         | 
       0.00%  | 
       0 / 1  | 
               | 
       0.00%  | 
       0 / 1  | 
       2 | |||
| getExcludedRoutes |         | 
       0.00%  | 
       0 / 8  | 
               | 
       0.00%  | 
       0 / 1  | 
       2 | |||
| 1 | <?php | 
| 2 | |
| 3 | /** | 
| 4 | * This program is free software; you can redistribute it and/or | 
| 5 | * modify it under the terms of the GNU General Public License | 
| 6 | * as published by the Free Software Foundation; under version 2 | 
| 7 | * of the License (non-upgradable). | 
| 8 | * | 
| 9 | * This program is distributed in the hope that it will be useful, | 
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 
| 12 | * GNU General Public License for more details. | 
| 13 | * | 
| 14 | * You should have received a copy of the GNU General Public License | 
| 15 | * along with this program; if not, write to the Free Software | 
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 
| 17 | * | 
| 18 | * Copyright (c) 2015 (original work) Open Assessment Technologies SA; | 
| 19 | * | 
| 20 | * | 
| 21 | */ | 
| 22 | |
| 23 | namespace oat\tao\model\requiredAction\implementation; | 
| 24 | |
| 25 | use oat\tao\model\requiredAction\RequiredActionAbstract; | 
| 26 | use Exception; | 
| 27 | use oat\tao\model\requiredAction\RequiredActionRuleInterface; | 
| 28 | use oat\tao\model\routing\FlowController; | 
| 29 | |
| 30 | /** | 
| 31 | * @deprecated use \oat\tao\model\requiredAction\implementation\RequiredActionRedirectUrlPart instead | 
| 32 | * | 
| 33 | * Class RequiredAction | 
| 34 | * | 
| 35 | * RequiredAction is action which should be executed by user before performing any activities in the TAO | 
| 36 | * | 
| 37 | * @package oat\tao\model\requiredAction\implementation | 
| 38 | * @author Aleh Hutnilau <hutnikau@1pt.com> | 
| 39 | */ | 
| 40 | class RequiredActionRedirect extends RequiredActionAbstract | 
| 41 | { | 
| 42 | private $excludedRoutes = [ | 
| 43 | [ | 
| 44 | 'extension' => 'tao', | 
| 45 | 'module' => 'ClientConfig', | 
| 46 | 'action' => 'config', | 
| 47 | ] | 
| 48 | ]; | 
| 49 | |
| 50 | /** | 
| 51 | * @var string | 
| 52 | */ | 
| 53 | private $url; | 
| 54 | |
| 55 | /** | 
| 56 | * @deprecated use \oat\tao\model\requiredAction\implementation\RequiredActionRedirectUrlPart instead | 
| 57 | * | 
| 58 | * RequiredActionRedirect constructor. | 
| 59 | * @param string $name | 
| 60 | * @param RequiredActionRuleInterface[] $rules | 
| 61 | * @param string $url | 
| 62 | * @throws Exception | 
| 63 | */ | 
| 64 | public function __construct($name, array $rules, $url) | 
| 65 | { | 
| 66 | parent::__construct($name, $rules); | 
| 67 | $this->url = $url; | 
| 68 | } | 
| 69 | |
| 70 | /** | 
| 71 | * @deprecated use \oat\tao\model\requiredAction\implementation\RequiredActionRedirectUrlPart instead | 
| 72 | * | 
| 73 | * Execute an action | 
| 74 | * @param array $params | 
| 75 | * @return mixed | 
| 76 | */ | 
| 77 | public function execute(array $params = []) | 
| 78 | { | 
| 79 | $context = \Context::getInstance(); | 
| 80 | $excludedRoutes = $this->getExcludedRoutes(); | 
| 81 | $currentRoute = [ | 
| 82 | 'extension' => $context->getExtensionName(), | 
| 83 | 'module' => $context->getModuleName(), | 
| 84 | 'action' => $context->getActionName(), | 
| 85 | ]; | 
| 86 | |
| 87 | if (!in_array($currentRoute, $excludedRoutes)) { | 
| 88 | $currentUrl = \common_http_Request::currentRequest()->getUrl(); | 
| 89 | $url = $this->url . (parse_url($this->url, PHP_URL_QUERY) ? '&' : '?') . 'return_url=' | 
| 90 | . urlencode($currentUrl); | 
| 91 | |
| 92 | $flowController = new FlowController(); | 
| 93 | $flowController->redirect($url); | 
| 94 | } | 
| 95 | } | 
| 96 | |
| 97 | /** | 
| 98 | * @see \oat\oatbox\PhpSerializable::__toPhpCode() | 
| 99 | */ | 
| 100 | public function __toPhpCode() | 
| 101 | { | 
| 102 | $class = get_class($this); | 
| 103 | $name = $this->name; | 
| 104 | $url = $this->url; | 
| 105 | $rules = \common_Utils::toHumanReadablePhpString($this->getRules()); | 
| 106 | return "new $class( | 
| 107 | '$name', | 
| 108 | $rules, | 
| 109 | '$url' | 
| 110 | )"; | 
| 111 | } | 
| 112 | |
| 113 | /** | 
| 114 | * Return the redirect url | 
| 115 | * @return string | 
| 116 | */ | 
| 117 | public function getUrl() | 
| 118 | { | 
| 119 | return $this->url; | 
| 120 | } | 
| 121 | |
| 122 | /** | 
| 123 | * Some actions should not be redirected (such as retrieving requireJs config) | 
| 124 | * @return array | 
| 125 | */ | 
| 126 | private function getExcludedRoutes() | 
| 127 | { | 
| 128 | $result = $this->excludedRoutes; | 
| 129 | $resolver = new \Resolver($this->url); | 
| 130 | |
| 131 | $result[] = [ | 
| 132 | 'extension' => $resolver->getExtensionFromURL(), | 
| 133 | 'module' => $resolver->getModule(), | 
| 134 | 'action' => $resolver->getAction(), | 
| 135 | ]; | 
| 136 | |
| 137 | return $result; | 
| 138 | } | 
| 139 | } |