|
@@ -0,0 +1,66 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace Base\OAuthClientBundle\Twig;
|
|
|
+
|
|
|
+use WebserviceBundle\Services\Webservice;
|
|
|
+
|
|
|
+class IsGrantedPreviousAdminExtension extends \Twig_Extension
|
|
|
+{
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @var Webservice
|
|
|
+ */
|
|
|
+ protected $webservice;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @var string
|
|
|
+ */
|
|
|
+ protected $urlBase;
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param Webservice $webservice
|
|
|
+ * @param string $urlBase
|
|
|
+ */
|
|
|
+ public function __construct(Webservice $webservice, $urlBase)
|
|
|
+ {
|
|
|
+ $this->webservice = $webservice;
|
|
|
+ $this->urlBase = $urlBase;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function getFunctions()
|
|
|
+ {
|
|
|
+ return array(
|
|
|
+ new \Twig_SimpleFunction('is_granted_previous_admin', array($this, 'isGrantedPreviousAdmin')),
|
|
|
+ new \Twig_SimpleFunction('switch_user_exit', array($this, 'switchUserExit')),
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return boolean
|
|
|
+ */
|
|
|
+ public function isGrantedPreviousAdmin()
|
|
|
+ {
|
|
|
+ return $this->webservice->makeGetRequest($this->urlBase . '/admin/user/is_granted');
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return boolean
|
|
|
+ */
|
|
|
+ public function switchUserExit()
|
|
|
+ {
|
|
|
+ return 'https://' . $this->urlBase . '/?_switch_user=_exit';
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return string
|
|
|
+ */
|
|
|
+ public function getName()
|
|
|
+ {
|
|
|
+ return 'is_granted_previous_admin_extension';
|
|
|
+ }
|
|
|
+
|
|
|
+}
|