getObjectsReferencingUser() public static method

finds all objects which hold a reference to a specific user
public static getObjectsReferencingUser ( integer $userId ) : Concrete[]
$userId integer
return Concrete[]
Example #1
0
 public function getAction()
 {
     if (intval($this->getParam("id")) < 1) {
         $this->_helper->json(["success" => false]);
     }
     $user = User::getById(intval($this->getParam("id")));
     if ($user->isAdmin() && !$this->getUser()->isAdmin()) {
         throw new \Exception("Only admin users are allowed to modify admin users");
     }
     // workspaces
     $types = ["asset", "document", "object"];
     foreach ($types as $type) {
         $workspaces = $user->{"getWorkspaces" . ucfirst($type)}();
         foreach ($workspaces as $workspace) {
             $el = Element\Service::getElementById($type, $workspace->getCid());
             if ($el) {
                 // direct injection => not nice but in this case ok ;-)
                 $workspace->path = $el->getRealFullPath();
             }
         }
     }
     // object <=> user dependencies
     $userObjects = Object\Service::getObjectsReferencingUser($user->getId());
     $userObjectData = [];
     foreach ($userObjects as $o) {
         $hasHidden = false;
         if ($o->isAllowed("list")) {
             $userObjectData[] = ["path" => $o->getRealFullPath(), "id" => $o->getId(), "subtype" => $o->getClass()->getName()];
         } else {
             $hasHidden = true;
         }
     }
     // get available permissions
     $availableUserPermissionsList = new User\Permission\Definition\Listing();
     $availableUserPermissions = $availableUserPermissionsList->load();
     // get available roles
     $roles = [];
     $list = new User\Role\Listing();
     $list->setCondition("`type` = ?", ["role"]);
     $list->load();
     $roles = [];
     if (is_array($list->getItems())) {
         foreach ($list->getItems() as $role) {
             $roles[] = [$role->getId(), $role->getName()];
         }
     }
     // unset confidential informations
     $userData = object2array($user);
     $contentLanguages = Tool\Admin::reorderWebsiteLanguages($user, Tool::getValidLanguages());
     $userData["contentLanguages"] = $contentLanguages;
     unset($userData["password"]);
     $availablePerspectives = \Pimcore\Config::getAvailablePerspectives(null);
     $conf = \Pimcore\Config::getSystemConfig();
     $this->_helper->json(["success" => true, "wsenabled" => $conf->webservice->enabled, "user" => $userData, "roles" => $roles, "permissions" => $user->generatePermissionList(), "availablePermissions" => $availableUserPermissions, "availablePerspectives" => $availablePerspectives, "objectDependencies" => ["hasHidden" => $hasHidden, "dependencies" => $userObjectData]]);
 }