本文整理汇总了PHP中Pimcore\Tool\Admin类的典型用法代码示例。如果您正苦于以下问题:PHP Admin类的具体用法?PHP Admin怎么用?PHP Admin使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Admin类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getUser
/**
* @return Tool\User
* @throws \Exception
*/
public function getUser()
{
if ($user = Tool\Admin::getCurrentUser()) {
return $user;
}
throw new \Exception("Webservice instantiated, but no user present");
}
示例2: importClassDefinitionFromJson
/**
* @param $class
* @param $json
* @return bool
*/
public static function importClassDefinitionFromJson($class, $json, $throwException = false)
{
$userId = 0;
$user = \Pimcore\Tool\Admin::getCurrentUser();
if ($user) {
$userId = $user->getId();
}
$importData = \Zend_Json::decode($json);
// set layout-definition
$layout = self::generateLayoutTreeFromArray($importData["layoutDefinitions"], $throwException);
if ($layout === false) {
return false;
}
$class->setLayoutDefinitions($layout);
// set properties of class
$class->setModificationDate(time());
$class->setUserModification($userId);
$class->setIcon($importData["icon"]);
$class->setAllowInherit($importData["allowInherit"]);
$class->setAllowVariants($importData["allowVariants"]);
$class->setShowVariants($importData["showVariants"]);
$class->setParentClass($importData["parentClass"]);
$class->setUseTraits($importData["useTraits"]);
$class->setPreviewUrl($importData["previewUrl"]);
$class->setPropertyVisibility($importData["propertyVisibility"]);
$class->save();
return true;
}
示例3: correctClasses
/**
* this is a hack for import see: http://www.pimcore.org/issues/browse/PIMCORE-790
* @param array
* @return array
*/
protected function correctClasses($classes)
{
// this is the new method with Ext.form.MultiSelect
/**
* @extjs6
* @todo this need to be refactored when extjs3 support is removed
*/
if (is_string($classes) && !empty($classes) || \Pimcore\Tool\Admin::isExtJS6() && is_array($classes)) {
if (!\Pimcore\Tool\Admin::isExtJS6()) {
$classParts = explode(",", $classes);
} else {
$classParts = $classes;
}
$classes = array();
foreach ($classParts as $class) {
if (is_array($class)) {
$classes[] = $class;
} else {
if ($class) {
$classes[] = array("classes" => $class);
}
}
}
}
// this was the legacy method with Ext.SuperField
if (is_array($classes) && array_key_exists("classes", $classes)) {
$classes = array($classes);
}
if (!is_array($classes)) {
$classes = array();
}
return $classes;
}
示例4: routeStartup
/**
* @param \Zend_Controller_Request_Abstract $request
*/
public function routeStartup(\Zend_Controller_Request_Abstract $request)
{
$maintenance = false;
$file = \Pimcore\Tool\Admin::getMaintenanceModeFile();
if (is_file($file)) {
$conf = (include $file);
if (isset($conf["sessionId"])) {
if ($conf["sessionId"] != $_COOKIE["pimcore_admin_sid"]) {
$maintenance = true;
}
} else {
@unlink($file);
}
}
// do not activate the maintenance for the server itself
// this is to avoid problems with monitoring agents
$serverIps = ["127.0.0.1"];
if ($maintenance && !in_array(\Pimcore\Tool::getClientIp(), $serverIps)) {
header("HTTP/1.1 503 Service Temporarily Unavailable", 503);
$file = PIMCORE_PATH . "/static/html/maintenance.html";
$customFile = PIMCORE_CUSTOM_CONFIGURATION_DIRECTORY . "/maintenance.html";
if (file_exists($customFile)) {
$file = $customFile;
}
echo file_get_contents($file);
exit;
}
}
示例5: saveAction
public function saveAction()
{
try {
if ($this->getParam("id")) {
$link = Document\Hardlink::getById($this->getParam("id"));
$this->setValuesToDocument($link);
$link->setModificationDate(time());
$link->setUserModification($this->getUser()->getId());
if ($this->getParam("task") == "unpublish") {
$link->setPublished(false);
}
if ($this->getParam("task") == "publish") {
$link->setPublished(true);
}
// only save when publish or unpublish
if ($this->getParam("task") == "publish" && $link->isAllowed("publish") || $this->getParam("task") == "unpublish" && $link->isAllowed("unpublish")) {
$link->save();
$this->_helper->json(["success" => true]);
}
}
} catch (\Exception $e) {
\Logger::log($e);
if (\Pimcore\Tool\Admin::isExtJS6() && $e instanceof Element\ValidationException) {
$this->_helper->json(["success" => false, "type" => "ValidationException", "message" => $e->getMessage(), "stack" => $e->getTraceAsString(), "code" => $e->getCode()]);
}
throw $e;
}
$this->_helper->json(false);
}
示例6: getRecordIdForGridRequest
public static function getRecordIdForGridRequest($param)
{
if (!\Pimcore\Tool\Admin::isExtJS6() && is_numeric($param)) {
return intval($param);
} else {
$param = json_decode($param, true);
return $param['id'];
}
}
示例7: checkUserPermission
private function checkUserPermission($permission)
{
if ($user = Tool\Admin::getCurrentUser()) {
if ($user->isAllowed($permission)) {
return;
}
}
$this->getResponse()->setHttpResponseCode(403);
$this->encoder->encode(["success" => false, "msg" => "not allowed"]);
}
示例8: initialize
/**
* @param InputInterface $input
* @param OutputInterface $output
*/
protected function initialize(InputInterface $input, OutputInterface $output)
{
parent::initialize($input, $output);
$this->input = $input;
$this->output = $output;
// use Console\Dumper for nice debug output
$this->dumper = new Dumper($this->output);
// skip if maintenance mode is on and the flag is not set
if (Admin::isInMaintenanceMode() && !$input->getOption('ignore-maintenance-mode')) {
throw new \RuntimeException('In maintenance mode - set the flag --ignore-maintenance-mode to force execution!');
}
}
示例9: getByKeyLocalized
/**
* @param $id
* @param bool $create
* @param bool $returnIdIfEmpty
* @param null $language
* @return array
* @throws \Exception
* @throws \Zend_Exception
*/
public static function getByKeyLocalized($id, $create = false, $returnIdIfEmpty = false, $language = null)
{
if ($user = Tool\Admin::getCurrentUser()) {
$language = $user->getLanguage();
} elseif ($user = Tool\Authentication::authenticateSession()) {
$language = $user->getLanguage();
} elseif (\Zend_Registry::isRegistered("Zend_Locale")) {
$language = (string) \Zend_Registry::get("Zend_Locale");
}
if (!in_array($language, Tool\Admin::getLanguages())) {
$config = \Pimcore\Config::getSystemConfig();
$language = $config->general->language;
}
return self::getByKey($id, $create, $returnIdIfEmpty)->getTranslation($language);
}
示例10: updateAction
public function updateAction()
{
$report = CustomReport\Config::getByName($this->getParam("name"));
$data = \Zend_Json::decode($this->getParam("configuration"));
if (\Pimcore\Tool\Admin::isExtJS6() && !is_array($data["yAxis"])) {
$data["yAxis"] = strlen($data["yAxis"]) ? [$data["yAxis"]] : [];
}
foreach ($data as $key => $value) {
$setter = "set" . ucfirst($key);
if (method_exists($report, $setter)) {
$report->{$setter}($value);
}
}
$report->save();
$this->_helper->json(["success" => true]);
}
示例11: init
public function init()
{
parent::init();
$pimUser = false;
if (\Pimcore\Tool::isFrontentRequestByAdmin()) {
$pimUser = \Pimcore\Tool\Admin::getCurrentUser();
if ($pimUser) {
//echo "IS ADMIN";
}
}
$identity = \Zend_Auth::getInstance()->getIdentity();
if (!$identity && !$pimUser or $this->getParam('oid') != $identity['oid']) {
$this->redirect("/");
} else {
// login ok
}
}
示例12: move
/**
* Moves a file/directory
*
* @param string $sourcePath
* @param string $destinationPath
* @return void
*/
public function move($sourcePath, $destinationPath)
{
$nameParts = explode("/", $sourcePath);
$nameParts[count($nameParts) - 1] = File::getValidFilename($nameParts[count($nameParts) - 1]);
$sourcePath = implode("/", $nameParts);
$nameParts = explode("/", $destinationPath);
$nameParts[count($nameParts) - 1] = File::getValidFilename($nameParts[count($nameParts) - 1]);
$destinationPath = implode("/", $nameParts);
try {
if (dirname($sourcePath) == dirname($destinationPath)) {
$asset = null;
if ($asset = Asset::getByPath("/" . $destinationPath)) {
// If we got here, this means the destination exists, and needs to be overwritten
$sourceAsset = Asset::getByPath("/" . $sourcePath);
$asset->setData($sourceAsset->getData());
$sourceAsset->delete();
}
// see: Asset\WebDAV\File::delete() why this is necessary
$log = Asset\WebDAV\Service::getDeleteLog();
if (!$asset && array_key_exists("/" . $destinationPath, $log)) {
$asset = \Pimcore\Tool\Serialize::unserialize($log["/" . $destinationPath]["data"]);
if ($asset) {
$sourceAsset = Asset::getByPath("/" . $sourcePath);
$asset->setData($sourceAsset->getData());
$sourceAsset->delete();
}
}
if (!$asset) {
$asset = Asset::getByPath("/" . $sourcePath);
}
$asset->setFilename(basename($destinationPath));
} else {
$asset = Asset::getByPath("/" . $sourcePath);
$parent = Asset::getByPath("/" . dirname($destinationPath));
$asset->setPath($parent->getFullPath() . "/");
$asset->setParentId($parent->getId());
}
$user = \Pimcore\Tool\Admin::getCurrentUser();
$asset->setUserModification($user->getId());
$asset->save();
} catch (\Exception $e) {
\Logger::error($e);
}
}
示例13: createActionNote
/**
* Creates a note for an action with a transition
* @param Element\AbstractElement $element
* @param string $type
* @param string $title
* @param string $description
* @param array $noteData
* @return Element\Note $note
*/
public static function createActionNote($element, $type, $title, $description, $noteData, $user = null)
{
//prepare some vars for creating the note
if (!$user) {
$user = \Pimcore\Tool\Admin::getCurrentUser();
}
$note = new Element\Note();
$note->setElement($element);
$note->setDate(time());
$note->setType($type);
$note->setTitle($title);
$note->setDescription($description);
$note->setUser($user->getId());
if (is_array($noteData)) {
foreach ($noteData as $row) {
$note->addData($row['key'], $row['type'], $row['value']);
}
}
$note->save();
return $note;
}
示例14: adminElementGetPreSendData
/**
* Fired before information is sent back to the admin UI about an element
* @param \Zend_EventManager_Event $e
* @throws \Exception
*/
public static function adminElementGetPreSendData($e)
{
$element = self::extractElementFromEvent($e);
$returnValueContainer = $e->getParam('returnValueContainer');
$data = $returnValueContainer->getData();
//create a new namespace for WorkflowManagement
//set some defaults
$data['workflowManagement'] = ['hasWorkflowManagement' => false];
if (Workflow\Manager::elementCanAction($element)) {
$data['workflowManagement']['hasWorkflowManagement'] = true;
//see if we can change the layout
$currentUser = Admin::getCurrentUser();
$manager = Workflow\Manager\Factory::getManager($element, $currentUser);
$data['workflowManagement']['workflowName'] = $manager->getWorkflow()->getName();
//get the state and status
$state = $manager->getElementState();
$data['workflowManagement']['state'] = $manager->getWorkflow()->getStateConfig($state);
$status = $manager->getElementStatus();
$data['workflowManagement']['status'] = $manager->getWorkflow()->getStatusConfig($status);
if ($element instanceof ConcreteObject) {
$workflowLayoutId = $manager->getObjectLayout();
//check for !is_null here as we might want to specify 0 in the workflow config
if (!is_null($workflowLayoutId)) {
//load the new layout into the object container
$validLayouts = Object\Service::getValidLayouts($element);
//check that the layout id is valid before trying to load
if (!empty($validLayouts)) {
//todo check user permissions again
if ($validLayouts && $validLayouts[$workflowLayoutId]) {
$customLayout = ClassDefinition\CustomLayout::getById($workflowLayoutId);
$customLayoutDefinition = $customLayout->getLayoutDefinitions();
Object\Service::enrichLayoutDefinition($customLayoutDefinition, $e->getParam('object'));
$data["layout"] = $customLayoutDefinition;
}
}
}
}
}
$returnValueContainer->setData($data);
}
示例15: correctClasses
/**
* this is a hack for import see: http://www.pimcore.org/issues/browse/PIMCORE-790
* @param array
* @return array
*/
protected function correctClasses($classes)
{
// this is the new method with Ext.form.MultiSelect
if (is_string($classes) && !empty($classes) || \Pimcore\Tool\Admin::isExtJS5() && is_array($classes)) {
if (!\Pimcore\Tool\Admin::isExtJS5()) {
$classParts = explode(",", $classes);
} else {
$classParts = $classes;
}
$classes = array();
foreach ($classParts as $class) {
$classes[] = array("classes" => $class);
}
}
// this was the legacy method with Ext.SuperField
if (is_array($classes) && array_key_exists("classes", $classes)) {
$classes = array($classes);
}
if (!is_array($classes)) {
$classes = array();
}
return $classes;
}