function addUserToEntity($params)
{
    if (!isset($params['eid']) || !isset($params['uid'])) {
        return FALSE;
    }
    $eid = $params['eid'];
    $uid = $params['uid'];
    $util = new sspmod_janus_AdminUtil();
    if (!($userid = $util->addUserToEntity($eid, $uid))) {
        return FALSE;
    }
    return array('eid' => $eid, 'uid' => $uid, 'userid' => $userid);
}
示例#2
0
function addUserToEntity($params)
{
    if (!isset($params['eid']) || !isset($params['uid'])) {
        return FALSE;
    }
    $eid = $params['eid'];
    $uid = $params['uid'];
    # security hack - uid is actually userid ie. user@example.com - convert it to a janus uid as expected for further processing
    $janus_config = sspmod_janus_DiContainer::getInstance()->getConfig();
    $user = new sspmod_janus_User();
    $user->setUserid($uid);
    if ($user->load(sspmod_janus_User::USERID_LOAD) === false) {
        echo json_encode(array('status' => 'Unknown user'));
        exit;
    }
    $actual_uid = $user->getUid();
    $util = new sspmod_janus_AdminUtil();
    try {
        if (!($userid = $util->addUserToEntity($eid, $actual_uid))) {
            return FALSE;
        }
    } catch (Exception $e) {
        echo json_encode(array('status' => 'An unspecified error occurred'));
        exit;
    }
    return array('eid' => $eid, 'uid' => $actual_uid, 'userid' => $userid);
}
示例#3
0
 /**
  * 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();
 }