本文整理汇总了PHP中Pimcore\Model\User::getById方法的典型用法代码示例。如果您正苦于以下问题:PHP User::getById方法的具体用法?PHP User::getById怎么用?PHP User::getById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pimcore\Model\User
的用法示例。
在下文中一共展示了User::getById方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: mail
/**
*
*/
public function mail()
{
$conf = Config::getSystemConfig();
if (!empty($conf->general->logrecipient)) {
\Logger::debug(get_class($this) . ": detected log recipient:" . $conf->general->logrecipient);
$user = User::getById($conf->general->logrecipient);
\Logger::debug(get_class($this) . ": detected log recipient:" . $user->getEmail());
if ($user instanceof User && $user->isAdmin()) {
$email = $user->getEmail();
\Logger::debug(get_class($this) . ": user is valid");
if (!empty($email)) {
if (is_dir(PIMCORE_LOG_MAIL_TEMP)) {
\Logger::debug(get_class($this) . ": detected mail log dir");
\Logger::debug(get_class($this) . ": opening dir " . PIMCORE_LOG_MAIL_TEMP);
if ($handle = opendir(PIMCORE_LOG_MAIL_TEMP)) {
\Logger::debug(get_class($this) . ": reading dir " . PIMCORE_LOG_MAIL_TEMP);
while (false !== ($file = readdir($handle))) {
\Logger::debug(get_class($this) . ": detected file " . $file);
if (is_file(PIMCORE_LOG_MAIL_TEMP . "/" . $file) and is_writable(PIMCORE_LOG_MAIL_TEMP . "/" . $file)) {
$now = time();
$threshold = 1 * 60 * 15;
$fileModified = filemtime(PIMCORE_LOG_MAIL_TEMP . "/" . $file);
\Logger::debug(get_class($this) . ": file is writeable and was last modified: " . $fileModified);
if ($fileModified !== FALSE and $fileModified < $now - $threshold) {
$mail = Tool::getMail(array($email), "pimcore log notification - " . $file);
$mail->setIgnoreDebugMode(true);
$mail->setBodyText(file_get_contents(PIMCORE_LOG_MAIL_TEMP . "/" . $file));
$mail->send();
@unlink(PIMCORE_LOG_MAIL_TEMP . "/" . $file);
\Logger::debug(get_class($this) . ": sent mail and deleted temp log file " . $file);
} else {
if ($fileModified > $now - $threshold) {
\Logger::debug(get_class($this) . ": leaving temp log file alone because file [ {$file} ] was written to within the last 15 minutes");
}
}
}
}
}
}
} else {
\Logger::err(get_class($this) . ": Cannot send mail to configured log user [" . $user->getName() . "] because email is empty");
}
} else {
\Logger::err(get_class($this) . ": Cannot send mail to configured log user. User is either null or not an admin");
}
} else {
\Logger::debug(get_class($this) . ": No log recipient configured");
}
}
示例2: authenticateSession
/**
* @static
* @throws Exception
* @return User
*/
public static function authenticateSession()
{
if (!isset($_COOKIE["pimcore_admin_sid"]) && !isset($_REQUEST["pimcore_admin_sid"])) {
// if no session cookie / ID no authentication possible, we don't need to start a session
return null;
}
$session = Session::getReadOnly();
$user = $session->user;
if ($user instanceof User) {
// renew user
$user = User::getById($user->getId());
if (self::isValidUser($user)) {
return $user;
}
}
return null;
}
示例3: getTokenLoginLinkAction
public function getTokenLoginLinkAction()
{
$user = User::getById($this->getParam("id"));
if ($user->isAdmin() && !$this->getUser()->isAdmin()) {
throw new \Exception("Only admin users are allowed to login as an admin user");
}
if ($user) {
$token = Tool\Authentication::generateToken($user->getName(), $user->getPassword());
$r = $this->getRequest();
$link = $r->getScheme() . "://" . $r->getHttpHost() . "/admin/login/login/?username=" . $user->getName() . "&token=" . $token;
$this->_helper->json(["link" => $link]);
}
}
示例4: noteListAction
public function noteListAction()
{
$this->checkPermission("notes_events");
$list = new Element\Note\Listing();
$list->setLimit($this->getParam("limit"));
$list->setOffset($this->getParam("start"));
$sortingSettings = \Pimcore\Admin\Helper\QueryParams::extractSortingSettings($this->getAllParams());
if ($sortingSettings['orderKey'] && $sortingSettings['order']) {
$list->setOrderKey($sortingSettings['orderKey']);
$list->setOrder($sortingSettings['order']);
} else {
$list->setOrderKey(["date", "id"]);
$list->setOrder(["DESC", "DESC"]);
}
$conditions = [];
if ($this->getParam("filter")) {
$conditions[] = "(`title` LIKE " . $list->quote("%" . $this->getParam("filter") . "%") . " OR `description` LIKE " . $list->quote("%" . $this->getParam("filter") . "%") . " OR `type` LIKE " . $list->quote("%" . $this->getParam("filter") . "%") . ")";
}
if ($this->getParam("cid") && $this->getParam("ctype")) {
$conditions[] = "(cid = " . $list->quote($this->getParam("cid")) . " AND ctype = " . $list->quote($this->getParam("ctype")) . ")";
}
if (!empty($conditions)) {
$list->setCondition(implode(" AND ", $conditions));
}
$list->load();
$notes = [];
foreach ($list->getNotes() as $note) {
$cpath = "";
if ($note->getCid() && $note->getCtype()) {
if ($element = Element\Service::getElementById($note->getCtype(), $note->getCid())) {
$cpath = $element->getRealFullPath();
}
}
$e = ["id" => $note->getId(), "type" => $note->getType(), "cid" => $note->getCid(), "ctype" => $note->getCtype(), "cpath" => $cpath, "date" => $note->getDate(), "title" => $note->getTitle(), "description" => $note->getDescription()];
// prepare key-values
$keyValues = [];
if (is_array($note->getData())) {
foreach ($note->getData() as $name => $d) {
$type = $d["type"];
$data = $d["data"];
if ($type == "document" || $type == "object" || $type == "asset") {
if ($d["data"] instanceof Element\ElementInterface) {
$data = ["id" => $d["data"]->getId(), "path" => $d["data"]->getRealFullPath(), "type" => $d["data"]->getType()];
}
} elseif ($type == "date") {
if (is_object($d["data"])) {
$data = $d["data"]->getTimestamp();
}
}
$keyValue = ["type" => $type, "name" => $name, "data" => $data];
$keyValues[] = $keyValue;
}
}
$e["data"] = $keyValues;
// prepare user data
if ($note->getUser()) {
$user = Model\User::getById($note->getUser());
if ($user) {
$e["user"] = ["id" => $user->getId(), "name" => $user->getName()];
} else {
$e["user"] = "";
}
}
$notes[] = $e;
}
$this->_helper->json(["data" => $notes, "success" => true, "total" => $list->getTotalCount()]);
}
示例5: setUserId
/**
* @param integer $userId
* @return void
*/
public function setUserId($userId)
{
if (is_numeric($userId)) {
if ($user = User::getById($userId)) {
$this->userId = (int) $userId;
$this->setUser($user);
}
}
return $this;
}
示例6: getAvailablePerspectives
/** Returns a list of available perspectives for the given user
* @param Model\User $user
* @return array
*/
public static function getAvailablePerspectives($user)
{
$currentConfigName = null;
$masterConfig = self::getPerspectivesConfig()->toArray();
if ($user instanceof Model\User) {
if ($user->isAdmin()) {
$config = self::getPerspectivesConfig()->toArray();
} else {
$config = [];
$roleIds = $user->getRoles();
$userIds = [$user->getId()];
$userIds = array_merge($userIds, $roleIds);
foreach ($userIds as $userId) {
if (in_array($userId, $roleIds)) {
$userOrRoleToCheck = Model\User\Role::getById($userId);
} else {
$userOrRoleToCheck = Model\User::getById($userId);
}
$perspectives = $userOrRoleToCheck->getPerspectives();
if ($perspectives) {
foreach ($perspectives as $perspectiveName) {
$masterDef = $masterConfig[$perspectiveName];
if ($masterDef) {
$config[$perspectiveName] = $masterDef;
}
}
}
}
if (!$config) {
$config = self::getPerspectivesConfig()->toArray();
}
}
if ($config) {
$tmpConfig = [];
$validPerspectiveNames = array_keys($config);
// sort the stuff
foreach ($masterConfig as $masterConfigName => $masterConfiguration) {
if (in_array($masterConfigName, $validPerspectiveNames)) {
$tmpConfig[$masterConfigName] = $masterConfiguration;
}
}
$config = $tmpConfig;
}
$currentConfigName = $user->getActivePerspective();
if ($config && !in_array($currentConfigName, array_keys($config))) {
$currentConfigName = reset(array_keys($config));
}
} else {
$config = self::getPerspectivesConfig()->toArray();
}
$result = [];
foreach ($config as $configName => $configItem) {
$item = ["name" => $configName, "icon" => isset($configItem["icon"]) ? $configItem["icon"] : null, "iconCls" => isset($configItem["iconCls"]) ? $configItem["iconCls"] : null];
if ($user) {
$item["active"] = $configName == $currentConfigName;
}
$result[] = $item;
}
return $result;
}
示例7: initLogger
/**
* @static
*
*/
public static function initLogger()
{
// for forks, etc ...
\Logger::resetLoggers();
// try to load configuration
$conf = Config::getSystemConfig();
if ($conf) {
// redirect php error_log to /website/var/log/php.log
if ($conf->general->custom_php_logfile) {
$phpLog = PIMCORE_LOG_DIRECTORY . "/php.log";
if (!file_exists($phpLog)) {
touch($phpLog);
}
if (is_writable($phpLog)) {
ini_set("error_log", $phpLog);
ini_set("log_errors", "1");
}
}
}
if (!is_file(PIMCORE_LOG_DEBUG)) {
if (is_writable(dirname(PIMCORE_LOG_DEBUG))) {
File::put(PIMCORE_LOG_DEBUG, "AUTOCREATE\n");
}
}
$prioMapping = array("debug" => \Zend_Log::DEBUG, "info" => \Zend_Log::INFO, "notice" => \Zend_Log::NOTICE, "warning" => \Zend_Log::WARN, "error" => \Zend_Log::ERR, "critical" => \Zend_Log::CRIT, "alert" => \Zend_Log::ALERT, "emergency" => \Zend_Log::EMERG);
$prios = array();
if ($conf && $conf->general->debugloglevel) {
$prioMapping = array_reverse($prioMapping);
foreach ($prioMapping as $level => $state) {
$prios[] = $prioMapping[$level];
if ($level == $conf->general->debugloglevel) {
break;
}
}
} else {
// log everything if config isn't loaded (eg. at the installer)
foreach ($prioMapping as $p) {
$prios[] = $p;
}
}
\Logger::setPriorities($prios);
if (is_writable(PIMCORE_LOG_DEBUG)) {
// check for big logfile, empty it if it's bigger than about 200M
if (filesize(PIMCORE_LOG_DEBUG) > 200000000) {
rename(PIMCORE_LOG_DEBUG, PIMCORE_LOG_DEBUG . "-archive-" . date("m-d-Y-H-i"));
// archive log (will be cleaned up by maintenance)
File::put(PIMCORE_LOG_DEBUG, "");
}
if (!empty($prios)) {
$writerFile = new \Zend_Log_Writer_Stream(PIMCORE_LOG_DEBUG);
$loggerFile = new \Zend_Log($writerFile);
\Logger::addLogger($loggerFile);
}
$conf = Config::getSystemConfig();
if ($conf) {
//email logger
if (!empty($conf->general->logrecipient)) {
$user = User::getById($conf->general->logrecipient);
if ($user instanceof User && $user->isAdmin()) {
$email = $user->getEmail();
if (!empty($email)) {
$mail = Tool::getMail(array($email), "pimcore log notification");
$mail->setIgnoreDebugMode(true);
if (!is_dir(PIMCORE_LOG_MAIL_TEMP)) {
File::mkdir(PIMCORE_LOG_MAIL_TEMP);
}
$tempfile = PIMCORE_LOG_MAIL_TEMP . "/log-" . uniqid() . ".log";
$writerEmail = new \Pimcore\Log\Writer\Mail($tempfile, $mail);
$loggerEmail = new \Zend_Log($writerEmail);
\Logger::addLogger($loggerEmail);
}
}
}
}
} else {
// try to use syslog instead
try {
$writerSyslog = new \Zend_Log_Writer_Syslog(array('application' => 'pimcore'));
$loggerSyslog = new \Zend_Log($writerSyslog);
\Logger::addLogger($loggerSyslog);
} catch (\Exception $e) {
}
}
if (array_key_exists("pimcore_log", $_REQUEST) && self::inDebugMode()) {
if (empty($_REQUEST["pimcore_log"])) {
$requestLogName = date("Y-m-d_H-i-s");
} else {
$requestLogName = $_REQUEST["pimcore_log"];
}
$requestLogFile = dirname(PIMCORE_LOG_DEBUG) . "/request-" . $requestLogName . ".log";
if (!file_exists($requestLogFile)) {
File::put($requestLogFile, "");
}
$writerRequestLog = new \Zend_Log_Writer_Stream($requestLogFile);
$loggerRequest = new \Zend_Log($writerRequestLog);
\Logger::addLogger($loggerRequest);
//.........这里部分代码省略.........
示例8: save
/**
* @throws \Exception
*/
public function save()
{
$isUpdate = false;
if ($this->getId()) {
$isUpdate = true;
\Pimcore::getEventManager()->trigger("object.class.preUpdate", $this);
} else {
\Pimcore::getEventManager()->trigger("object.class.preAdd", $this);
}
$this->setModificationDate(time());
$this->getDao()->save();
// create class for object
$extendClass = "Concrete";
if ($this->getParentClass()) {
$extendClass = $this->getParentClass();
$extendClass = "\\" . ltrim($extendClass, "\\");
}
// creaste directory if not exists
if (!is_dir(PIMCORE_CLASS_DIRECTORY . "/Object")) {
File::mkdir(PIMCORE_CLASS_DIRECTORY . "/Object");
}
$cd = '<?php ';
$cd .= "\n\n";
$cd .= "/** Generated at " . date('c') . " */";
$cd .= "\n\n";
$cd .= "/**\n";
if ($this->getDescription()) {
$description = str_replace(array("/**", "*/", "//"), "", $this->getDescription());
$description = str_replace("\n", "\n* ", $description);
$cd .= "* " . $description . "\n";
}
$cd .= "* Inheritance: " . ($this->getAllowInherit() ? "yes" : "no") . "\n";
$cd .= "* Variants : " . ($this->getAllowVariants() ? "yes" : "no") . "\n";
$user = Model\User::getById($this->getUserModification());
if ($user) {
$cd .= "* Changed by : " . $user->getName() . " (" . $user->getId() . ")" . "\n";
}
if ($_SERVER["REMOTE_ADDR"]) {
$cd .= "* IP: " . $_SERVER["REMOTE_ADDR"] . "\n";
}
$cd .= "*/\n";
$cd .= "\n\n";
$cd .= "namespace Pimcore\\Model\\Object;";
$cd .= "\n\n";
$cd .= "\n\n";
$cd .= "/**\n";
if (is_array($this->getFieldDefinitions()) && count($this->getFieldDefinitions())) {
foreach ($this->getFieldDefinitions() as $key => $def) {
if (!(method_exists($def, "isRemoteOwner") and $def->isRemoteOwner())) {
$cd .= "* @method static \\Pimcore\\Model\\Object\\" . ucfirst($this->getName()) . '\\Listing getBy' . ucfirst($def->getName()) . ' ($value, $limit = 0) ' . "\n";
}
}
}
$cd .= "*/\n\n";
$cd .= "class " . ucfirst($this->getName()) . " extends " . $extendClass . " {";
$cd .= "\n\n";
if ($this->getUseTraits()) {
$cd .= 'use ' . $this->getUseTraits() . ";\n";
$cd .= "\n";
}
$cd .= 'public $o_classId = ' . $this->getId() . ";\n";
$cd .= 'public $o_className = "' . $this->getName() . '"' . ";\n";
if (is_array($this->getFieldDefinitions()) && count($this->getFieldDefinitions())) {
foreach ($this->getFieldDefinitions() as $key => $def) {
if (!(method_exists($def, "isRemoteOwner") && $def->isRemoteOwner()) && !$def instanceof Object\ClassDefinition\Data\CalculatedValue) {
$cd .= "public \$" . $key . ";\n";
}
}
}
$cd .= "\n\n";
$cd .= '/**' . "\n";
$cd .= '* @param array $values' . "\n";
$cd .= '* @return \\Pimcore\\Model\\Object\\' . ucfirst($this->getName()) . "\n";
$cd .= '*/' . "\n";
$cd .= 'public static function create($values = array()) {';
$cd .= "\n";
$cd .= "\t" . '$object = new static();' . "\n";
$cd .= "\t" . '$object->setValues($values);' . "\n";
$cd .= "\t" . 'return $object;' . "\n";
$cd .= "}";
$cd .= "\n\n";
if (is_array($this->getFieldDefinitions()) && count($this->getFieldDefinitions())) {
$relationTypes = array();
foreach ($this->getFieldDefinitions() as $key => $def) {
if (method_exists($def, "isRemoteOwner") and $def->isRemoteOwner()) {
continue;
}
// get setter and getter code
$cd .= $def->getGetterCode($this);
$cd .= $def->getSetterCode($this);
// call the method "classSaved" if exists, this is used to create additional data tables or whatever which depends on the field definition, for example for localizedfields
if (method_exists($def, "classSaved")) {
$def->classSaved($this);
}
if ($def->isRelationType()) {
$relationTypes[$key] = array("type" => $def->getFieldType());
}
//.........这里部分代码省略.........
示例9: checkValidity
/**
* Checks if data is valid for current data field
*
* @param mixed $data
* @param boolean $omitMandatoryCheck
* @throws \Exception
*/
public function checkValidity($data, $omitMandatoryCheck = false)
{
if (!$omitMandatoryCheck and $this->getMandatory() and empty($data)) {
throw new \Exception("Empty mandatory field [ " . $this->getName() . " ]");
}
if (!empty($data)) {
$user = Model\User::getById($data);
if (!$user instanceof Model\User) {
throw new \Exception("invalid user reference");
}
}
}
示例10: initLogger
/**
* @static
*
*/
public static function initLogger()
{
// for forks, etc ...
\Logger::resetLoggers();
// try to load configuration
$conf = Config::getSystemConfig();
if ($conf) {
// redirect php error_log to /website/var/log/php.log
if ($conf->general->custom_php_logfile) {
$phpLog = PIMCORE_LOG_DIRECTORY . "/php.log";
if (!file_exists($phpLog)) {
touch($phpLog);
}
if (is_writable($phpLog)) {
ini_set("error_log", $phpLog);
ini_set("log_errors", "1");
}
}
}
if (!is_file(PIMCORE_LOG_DEBUG)) {
if (is_writable(dirname(PIMCORE_LOG_DEBUG))) {
File::put(PIMCORE_LOG_DEBUG, "AUTOCREATE\n");
}
}
$prios = [];
$availablePrios = \Logger::getAvailablePriorities();
if ($conf && $conf->general->debugloglevel) {
foreach ($availablePrios as $level) {
$prios[] = $level;
if ($level == $conf->general->debugloglevel) {
break;
}
}
\Logger::setPriorities($prios);
} else {
\Logger::setVerbosePriorities();
}
if (is_writable(PIMCORE_LOG_DEBUG)) {
// check for big logfile, empty it if it's bigger than about 200M
if (filesize(PIMCORE_LOG_DEBUG) > 200000000) {
rename(PIMCORE_LOG_DEBUG, PIMCORE_LOG_DEBUG . "-archive-" . date("m-d-Y-H-i"));
// archive log (will be cleaned up by maintenance)
File::put(PIMCORE_LOG_DEBUG, "");
}
// set default core logger (debug.log)
if (!empty($prios)) {
$loggerFile = new \Monolog\Logger('core');
$loggerFile->pushHandler(new \Monolog\Handler\StreamHandler(PIMCORE_LOG_DEBUG));
\Logger::addLogger($loggerFile);
}
$conf = Config::getSystemConfig();
if ($conf) {
//email logger
if (!empty($conf->general->logrecipient)) {
$user = User::getById($conf->general->logrecipient);
if ($user instanceof User && $user->isAdmin()) {
$email = $user->getEmail();
if (!empty($email)) {
$loggerMail = new \Monolog\Logger('email');
$mailHandler = new \Pimcore\Log\Handler\Mail($email);
$loggerMail->pushHandler(new \Monolog\Handler\BufferHandler($mailHandler));
\Logger::addLogger($loggerMail);
}
}
}
}
} else {
// try to use syslog instead
try {
$loggerSyslog = new \Monolog\Logger('core');
$loggerSyslog->pushHandler(new \Monolog\Handler\SyslogHandler("pimcore"));
\Logger::addLogger($loggerSyslog);
} catch (\Exception $e) {
// nothing to do here
}
}
// special request log -> if parameter pimcore_log is set
if (array_key_exists("pimcore_log", $_REQUEST) && self::inDebugMode()) {
if (empty($_REQUEST["pimcore_log"])) {
$requestLogName = date("Y-m-d_H-i-s");
} else {
$requestLogName = $_REQUEST["pimcore_log"];
}
$requestLogFile = dirname(PIMCORE_LOG_DEBUG) . "/request-" . $requestLogName . ".log";
if (!file_exists($requestLogFile)) {
File::put($requestLogFile, "");
}
$loggerRequest = new \Monolog\Logger('request');
$loggerRequest->pushHandler(new \Monolog\Handler\StreamHandler($requestLogFile));
\Logger::addLogger($loggerRequest);
\Logger::setVerbosePriorities();
}
}
示例11: setUserId
/**
* @param integer $userId
* @return void
*/
public function setUserId($userId)
{
if ($userId) {
if ($user = Model\User::getById($userId)) {
$this->userId = (int) $userId;
$this->setUser($user);
}
}
return $this;
}
示例12: getInfoDocBlock
/**
* @return string
*/
protected function getInfoDocBlock()
{
$cd = "";
$cd .= "/** ";
$cd .= "\n";
$cd .= "* Generated at: " . date('c') . "\n";
$cd .= "* Inheritance: " . ($this->getAllowInherit() ? "yes" : "no") . "\n";
$cd .= "* Variants: " . ($this->getAllowVariants() ? "yes" : "no") . "\n";
$user = Model\User::getById($this->getUserModification());
if ($user) {
$cd .= "* Changed by: " . $user->getName() . " (" . $user->getId() . ")" . "\n";
}
if (isset($_SERVER["REMOTE_ADDR"])) {
$cd .= "* IP: " . $_SERVER["REMOTE_ADDR"] . "\n";
}
if ($this->getDescription()) {
$description = str_replace(["/**", "*/", "//"], "", $this->getDescription());
$description = str_replace("\n", "\n* ", $description);
$cd .= "* " . $description . "\n";
}
$cd .= "\n\n";
$cd .= "Fields Summary: \n";
$cd = $this->getInfoDocBlockForFields($this, $cd, 1);
$cd .= "*/ ";
return $cd;
}