Find a location for the name and organization.

@param string $name The name to match against
@param int $organizationId Organization id
@param boolean $create Create a match when it does not exist
@return array location
188578
public function matchLocation($name, $organizationId, $create = true)
    {
        $cacheId = __CLASS__ . '_' . __FUNCTION__;
        $matches = $this->cache->load($cacheId);

        if (! $matches) {
            $matches = array();
            $select     = $this->db->select();
            $select->from('gems__locations')
                    ->order('glo_name');

            $result = $this->db->fetchAll($select);
            foreach ($result as $row) {
                foreach (explode('|', $row['glo_match_to']) as $match) {
                    foreach (explode(':', trim($row['glo_organizations'], ':')) as $subOrg) {
                        $matches[$match][$subOrg] = $row;
                    }
                }
            }
            $this->cache->save($matches, $cacheId, array('locations'));
        }

        if (isset($matches[$name])) {
            if ($organizationId) {
                if (isset($matches[$name][$organizationId])) {
                    return $matches[$name][$organizationId];
                }
                // Not in this organization, if we create we update the record
            } else {
                // Return the first location among the organizations
                return reset($matches[$name]);
            }
        } else {
            $matches[$name] = null;
        }

        if (! $create) {
            return null;
        }

        $result = $this->addLocation($name, $organizationId, $matches[$name]);

        return $result;
    }
84765
public function getFolders($databaseConnectionName = null, $organizationId = null)
  {
    $file = array();

    if(empty($organizationId))
    {
      $organizationId = $this->AuthenticationManager->getCurrentUserOrganizationId();
    }

    $this->File->byTypeAndByOrganization('C', $organizationId, $databaseConnectionName)->each(function($File) use (&$file)
    {
      array_push($file, array('label'=> $File->name , 'value'=>$File->id));
    });

    return $file;
  }
944313
public static function find_or_create($name)
	{
		$hztp = new self();

		if (is_numeric($name))
		{
			$hztp->id = $name;
		}
		else
		{
			$hztp->name = $name;
		}

		if ($hztp->read() == false)
		{
			if ($hztp->create() == false)
			{
				return false;
			}
		}

		return $hztp;
	}
1163274
public function addZone(string $name, bool $jumpStart = false, string $organizationID = ''): \stdClass
    {
        $options = [
            'name' => $name,
            'jump_start' => $jumpStart
        ];

        if (!empty($organizationID)) {
            $options['organization'] = ['id' => $organizationID];
        }

        $user = $this->adapter->post('zones', $options);
        $this->body = json_decode($user->getBody());
        return $this->body->result;
    }
478189
public function findById($name, $id) {
        $this->load();
        $mapper = MapperBuilder::buildFromName($this->mapping, $name);

        $newEntity = NULL;

        $query = "SELECT * FROM `" . $mapper->getTable() . "` WHERE id = :id";

        $result = $this->getDataSource()->query($query, array(":id" => $id));

        if ($result) {
            $newEntity = $mapper->createObject($result[0]);

            /* relations */
            foreach ($mapper->getRelations() as $relation) {

                /* only set relations if not lazy */
                if (!$relation->isLazy()) {
                    $relMapper = MapperBuilder::buildFromName($this->mapping, $relation->getEntity());

                    $queryRel = QueryBuilder::buildSelectRelation($relation, $relMapper);

                    $resRel = $this->getDataSource()->query($queryRel, array(":id" => $newEntity->getId()));

                    $method = "set" . $relation->getName();
                    if ($resRel) {
                        $collection = new Collection($relMapper->getClass(), $resRel, $relMapper);
                    } else {
                        $collection = new Collection($relMapper->getClass(), array(), $relMapper);
                    }
                    $newEntity->$method($collection);
                }
            }
        }
        return $newEntity;
    }
560416
public function getGitRepos($org_id = null, $name = null)
    {
        list($response) = $this->getGitReposWithHttpInfo($org_id, $name);
        return $response;
    }
1153797
public function byParentId($id, $organizationId, $databaseConnectionName = null)
  {
    if(empty($databaseConnectionName))
    {
      $databaseConnectionName = $this->databaseConnectionName;
    }

    return $this->File->setConnection($databaseConnectionName)
      ->where('parent_file_id', '=', $id)
      ->where('organization_id', '=', $organizationId)
      ->get();
  }
1113556
public function get($organizationId, array $parameters = [])
    {
        if (empty($organizationId)) {
            throw new ApiException("Organization ID is empty.");
        }

        return parent::rest_read($organizationId, $parameters);
    }
1001357
public function create($data, $organizationId = null)
    {
        if (isset($organizationId)) {
            return $this->client()->put($data, 'organizations/{organizationId}', ['organizationId' => $organizationId]);
        }

        return $this->client()->post($data, 'organizations');
    }
423687
public function findByName($name, array $locations = [])
    {
        if (empty($locations)) {
            $locations = $this->lookupPaths;
        }

        $finder = new Finder;
        $finder->directories()->depth(0)->name($name)->in($locations);

        $skeletons = iterator_to_array($finder, true);

        return reset($skeletons);
    }
364056
public function create($name, $parentId, $order = null, $partyId = null)
    {
        $params = [
            'name'     => $name,
            'parentid' => $parentId,
            'order'    => $order,
            'id'       => $partyId,
        ];

        return $this->parseJSON('json', [self::API_CREATE, $params]);
    }
27305
public function makeDir($name, $parentID = 0)
    {
        $data = [
            'name'      => $name,
            'parent_id' => $parentID
        ];

        return $this->post('files/create-folder', $data, \false, 'file');
    }
1234935
public function iHaveOrganization($name)
    {
        $user = $this->getUserContext()->getCurrentUser();
        $organization = $this->findOrganizationByName($name,false);
        $repo = $this->getRepository('Organizations/Organization');
        if(!$organization instanceof Organization){

            $organization = new Organization();
            $organizationName = new OrganizationName($name);
            $organization->setOrganizationName($organizationName);
            $organization->setIsDraft(false);
        }
        /* @var OrganizationReference $orgReference */
        $orgReference = $user->getOrganization();
        $parent = $orgReference->getOrganization();
        $organization->setParent($parent);
        $organization->setProfileSetting(Organization::PROFILE_ALWAYS_ENABLE);
        $permissions = $organization->getPermissions();
        $permissions->grant($user,Permissions::PERMISSION_ALL);

        $repo->store($organization);
        $repo->getDocumentManager()->refresh($organization);
        $repo->getDocumentManager()->refresh($user);
    }
102018
public function find( $name )
    {
        if ( ! $this->getEnabledList()
                    ->isEnabled( $name ) )
        {
            return null;
        }

        $data = $this->queryData( $name );

        if ( $data )
        {
            $structure = new Structure( $data );
            $structure->setMapper( $this );
            return $structure;
        }

        return null;
    }
1022586
public function createTeam($organizationUuid, $name)
    {
        $options = [
            'form_params' => [
                'name' => $name,
            ],
        ];

        return new OperationResponse(
            $this->connector->request('post', "/organizations/${organizationUuid}/teams", $this->query, $options)
        );
    }
1261549
public function deleteOrganizationSetting($organizationId, $settingId)
    {
        list($response) = $this->deleteOrganizationSettingWithHttpInfo($organizationId, $settingId);
        return $response;
    }
1320491
public function matchProcedure($name, $organizationId, $create = true)
    {
        $cacheId = __CLASS__ . '_' . __FUNCTION__;
        $matches = $this->cache->load($cacheId);

        if (! $matches) {
            $matches = array();
            $select  = $this->db->select();
            $select->from('gems__agenda_procedures', array(
                'gapr_id_procedure', 'gapr_match_to', 'gapr_id_organization', 'gapr_filter',
                ));

            $result = $this->db->fetchAll($select);
            foreach ($result as $row) {
                if (null === $row['gapr_id_organization']) {
                    $key = 'null';
                } else {
                    $key = $row['gapr_id_organization'];
                }
                foreach (explode('|', $row['gapr_match_to']) as $match) {
                    $matches[$match][$key] = $row['gapr_filter'] ? false : $row['gapr_id_procedure'];
                }
            }
            $this->cache->save($matches, $cacheId, array('procedures'));
        }

        if (isset($matches[$name])) {
            if (isset($matches[$name][$organizationId])) {
                return $matches[$name][$organizationId];
            }
            if (isset($matches[$name]['null'])) {
                return $matches[$name]['null'];
            }
        }

        if (! $create) {
            return null;
        }

        $result = $this->addProcedure($name, $organizationId);

        return $result['gapr_filter'] ? false : $result['gapr_id_procedure'];
    }