public function getPrettyname() { if (isset($this->_prettyname)) { return $this->_prettyname; } /** @var string $fieldName */ $fieldName = $this->_config->getString('entity.prettyname', NULL); $mb = new sspmod_janus_MetadataFieldBuilder($this->_config->getArray('metadatafields.' . $this->_type)); $metadataFields = $mb->getMetadataFields(); if (!is_null($fieldName)) { $rows = $this->loadPrettyNameFromCache($fieldName); if (empty($rows)) { $this->_prettyname = $this->_entityid; } else { if (isset($metadataFields[$fieldName]->default) && $metadataFields[$fieldName]->default == $rows[0]['value']) { $this->_prettyname = $this->_entityid; } else { $this->_prettyname = $rows[0]['value']; } } } else { $this->_prettyname = $this->_entityid; } return $this->_prettyname; }
/** * Retrieve all entities from database * * The method retrieves all entities from the database together with the * newest revision id. * * @param array|string $state States requesting * @param array|string $type Types requesting * * @return bool|array All entities from the database */ public function getEntitiesByStateType($state = null, $type = null, $active = 'yes') { $state = (array) $state; $type = (array) $type; $whereClauses = array('`active` = ?'); $queryData = array($active); if (!empty($state)) { $placeHolders = array_fill(0, count($state), '?'); $whereClauses[] = 'CONNECTION_REVISION.state IN (' . implode(',', $placeHolders) . ')'; $queryData = array_merge($queryData, $state); } if (!empty($type)) { $placeHolders = array_fill(0, count($type), '?'); $whereClauses[] = 'CONNECTION_REVISION.type IN (' . implode(',', $placeHolders) . ')'; $queryData = array_merge($queryData, $type); } // Select entity (only last revision) $selectFields = array('DISTINCT CONNECTION_REVISION.eid', 'CONNECTION_REVISION.revisionid', 'CONNECTION_REVISION.created', 'CONNECTION_REVISION.state', 'CONNECTION_REVISION.type'); $fromTable = $this->getTablePrefix() . "connection AS CONNECTION"; $joins = array("\n INNER JOIN " . $this->getTablePrefix() . "connectionRevision AS CONNECTION_REVISION\n ON CONNECTION_REVISION.eid = CONNECTION.id\n AND CONNECTION_REVISION.revisionid = CONNECTION.revisionNr\n "); $orderFields = array('created ASC'); // Find default value for sort field so it can be excluded /** @var $sortFieldName string */ $sortFieldName = $this->_config->getString('entity.prettyname', NULL); // Try to sort results by pretty name from metadata if ($sortFieldName) { $fieldDefaultValue = ''; if ($sortFieldDefaultValue = $this->_config->getArray('metadatafields.saml20-idp', FALSE)) { if (isset($sortFieldDefaultValue[$sortFieldName])) { $fieldDefaultValue = $sortFieldDefaultValue[$sortFieldName]['default']; } } else { if ($sortFieldDefaultValue = $this->_config->getArray('metadatafields.saml20-sp', FALSE)) { if (isset($sortFieldDefaultValue[$sortFieldName])) { $fieldDefaultValue = $sortFieldDefaultValue[$sortFieldName]['default']; } } } $joins[] = "\n LEFT JOIN " . $this->getTablePrefix() . "metadata AS METADATA\n ON METADATA.key = ?\n AND METADATA.connectionRevisionId = CONNECTION_REVISION.id\n AND METADATA.value != ?"; array_unshift($queryData, $fieldDefaultValue); array_unshift($queryData, $sortFieldName); $selectFields[] = 'IFNULL(METADATA.`value`, CONNECTION_REVISION.`entityid`) AS `orderfield`'; $orderFields = array("orderfield ASC"); } $query = 'SELECT ' . implode(', ', $selectFields); $query .= "\nFROM " . $fromTable; $query .= implode("\n", $joins); $query .= "\nWHERE " . implode(' AND ', $whereClauses); $query .= "\nORDER BY " . implode(', ', $orderFields); $st = self::execute($query, $queryData); if ($st === false) { SimpleSAML_Logger::error('JANUS: Error fetching all entities'); return false; } $rs = $st->fetchAll(PDO::FETCH_ASSOC); return $rs; }
public function findDescriptorsForFilters($filter, $sortBy, $sortOrder) { /** @var $sortFieldDefaultValue string */ $sortFieldName = $this->config->getString('entity.prettyname', NULL); $revisions = $this->connectionRepository->findLatestRevisionsWithFilters($filter, $sortBy, $sortOrder, $sortFieldName); $connectionDescriptors = array(); foreach ($revisions as $revision) { $connectionDescriptors[] = $revision->toDescriptorDto(); } return new ConnectionDtoCollection($connectionDescriptors); }
/** * Subscribe to an address * * @param int $uid Uid of user * @param string $subscriptionAddress The address to subscribe * @param string $type Type of subscription * * @return bool Return true on success and false on error * @throws \Exception */ public function subscribe($uid, $subscriptionAddress, $type = null) { if (is_null($type)) { $type = $this->_config->getString('messenger.default', 'INBOX'); } $subscribingUser = $this->getUserService()->findById($uid); // Check if subscription already exists $entityManager = $this->getEntityManager(); $existingSubscription = $entityManager->getRepository('Janus\\ServiceRegistry\\Entity\\User\\Subscription')->findOneBy(array('user' => $subscribingUser, 'address' => $subscriptionAddress)); if ($existingSubscription instanceof Subscription) { return false; } // Create subscription $subscription = new Subscription($subscribingUser, $subscriptionAddress, $type); $entityManager->persist($subscription); $entityManager->flush(); return $subscription->getId(); }
/** * Create new entity with parsed entityid * * Create a new entity and give the user access to the entity. * * @param string $entityid Entity id for the new entity * @param string $type Entity type * @param string $metadataUrl The -optional- metadata url for the new entity * * @return sspmod_janus_Entity|bool Returns the entity or false on error. * @since Method available since Release 1.0.0 */ public function createNewEntity($entityid, $type, $metadataUrl = null) { assert('is_string($entityid)'); assert('is_string($type)'); if ($this->isEntityIdInUse($entityid, $errorMessage)) { return $errorMessage; } $startstate = $this->_config->getString('workflowstate.default'); // Instantiate a new entity $entity = new sspmod_janus_Entity($this->_config, true); $entity->setEntityid($entityid); $entity->setWorkflow($startstate); $entity->setType($type); $entity->setUser($this->_user->getUid()); $entity->setRevisionnote('Entity created.'); if ($metadataUrl) { $entity->setMetadataURL($metadataUrl); } $entity->save(array()); $adminUtil = new sspmod_janus_AdminUtil(); $adminUtil->addUserToEntity($entity->getEid(), $this->_user->getUid()); $ec = sspmod_janus_DiContainer::getInstance()->getEntityController(); $ec->setEntity($entity); $update = false; // Get metadatafields for new type $nm_mb = new sspmod_janus_MetadataFieldBuilder($this->_config->getArray('metadatafields.' . $type)); $metadatafields = $nm_mb->getMetadataFields(); // Add all required fileds foreach ($metadatafields as $mf) { if (isset($mf->required) && $mf->required === true) { $ec->addMetadata($mf->name, $mf->default); $update = true; } } if ($update === true) { $ec->saveEntity(); } // Reset list of entities $this->_entities = null; $this->_loadEntities(); return $entity->getEid(); }