(string) $node['name'], 'id' => (string) $node['id'], 'url' => $url, 'binding' => isset($node['binding']) ? (string) $node['binding'] : (isset($node['js']) ? (string) $node['js'] : 'load'), 'context' => (string) $node['context'], 'reload' => isset($node['reload']) ? true : false, 'disabled' => isset($node['disabled']) ? true : false, 'multiple' => isset($node['multiple']) ? (trim(strtolower($node['multiple'])) == 'true') : false, 'group' => isset($node['group']) ? (string) $node['group'] : self::GROUP_DEFAULT, 'extension' => $extension, 'controller' => $controller, 'action' => $action ]; if (isset($node->icon)) { $data['icon'] = Icon::fromSimpleXMLElement($node->icon, $structureExtensionId); } return new static($data); } public function __construct($data, $version = self::SERIAL_VERSION) { $this->data = $data; if (!isset($this->data['icon'])) { $this->data['icon'] = $this->inferLegacyIcon($data); } } public function getName() { return $this->data['name']; } public function getId() { return $this->data['id']; } public function getDisplay() { return $this->data['display']; } public function getUrl() { return _url($this->getAction(), $this->getController(), $this->getExtensionId()); } public function getRelativeUrl() { return $this->data['url']; } public function getBinding() { return $this->data['binding']; } public function getContext() { return $this->data['context']; } public function getReload() { return $this->data['reload']; } public function getDisabled() { return $this->data['disabled']; } public function getGroup() { return $this->data['group']; } /** * @return Icon */ public function getIcon() { return $this->data['icon']; } /** * Is the action available for multiple resources * @return bool */ public function isMultiple() { return $this->data['multiple']; } /** * Get the extension id from the action's URL. * * @return string the extension id */ public function getExtensionId() { return array_key_exists('extension', $this->data) ? $this->data['extension'] : null; } public function getController() { return array_key_exists('controller', $this->data) ? $this->data['controller'] : null; } public function getAction() { return array_key_exists('action', $this->data) ? $this->data['action'] : null; } /** * Try to get the action's icon the old way. * I/O impact (file_exists) is limited as the results can be serialized. * * @return Icon the icon with the src property set to the icon URL. */ private function inferLegacyIcon() { $ext = $this->getExtensionId(); $name = strtolower(\tao_helpers_Display::textCleaner($this->data['name'])); $file = $ext . '/views/img/actions/' . $name . '.png'; $src = 'actions/' . $name . '.png'; if (file_exists(ROOT_PATH . $file)) { return Icon::fromArray(['src' => $src], $ext); } elseif (file_exists(ROOT_PATH . 'tao/views/img/actions/' . $name . '.png')) { return Icon::fromArray(['src' => $src], 'tao'); } else { return Icon::fromArray(['src' => 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAAAAAA6fptVAAAAAnRSTlMA/1uRIrUAAAAKSURBVHjaY/gPAAEBAQAcsIyZAAAAAElFTkSuQmCC'], 'tao'); } } /** * Check whether the current is allowed to see this action (against ACL). * @deprecated Wrong layer. Should be called at the level of the controller * @return bool true if access is granted */ public function hasAccess() { \common_Logger::w('Call to deprecated method ' . __METHOD__ . ' in ' . __CLASS__); $access = true; if (!empty($this->data['url'])) { $access = tao_models_classes_accessControl_AclProxy::hasAccess( $this->data['action'], $this->data['controller'], $this->data['extension'] ); } return $access; } public function getRequiredRights() { return $this->getServiceManager()->get(ActionService::SERVICE_ID)->getRequiredRights($this); } public function __toPhpCode() { return "new " . __CLASS__ . "(" . \common_Utils::toPHPVariableString($this->data) . ',' . \common_Utils::toPHPVariableString(self::SERIAL_VERSION) . ")"; } }