sentence1 stringlengths 52 3.87M | sentence2 stringlengths 1 47.2k | label stringclasses 1
value |
|---|---|---|
protected function escRefsDeep($value, $times = 1, $___recursion = false)
{
if (is_array($value) || is_object($value)) {
foreach ($value as &$_value) {
$_value = $this->escRefsDeep($_value, $times, true);
} // unset($_value); // Housekeeping.
return $value... | Escapes regex backreference chars deeply (i.e. `\\$` and `\\\\`).
@since 140417 Initial release.
@note This is a recursive scan running deeply into multiple dimensions of arrays/objects.
@note This routine will usually NOT include private, protected or static properties of an object class.
However, private/protected ... | entailment |
protected function cacheDir($type, $checksum = '', $base_only = false)
{
if ($type !== $this::DIR_PUBLIC_TYPE) {
if ($type !== $this::DIR_PRIVATE_TYPE) {
throw new \Exception('Invalid type.');
}
}
$checksum = (string) $checksum;
if (isset($che... | Get (and possibly create) the cache dir.
@since 140417 Initial release.
@param string $type One of `$this::dir_public_type` or `$this::dir_private_type`.
@param string $checksum Optional. If supplied, we'll build a nested sub-directory based on the checksum.
@param bool $base_only Defaults to a FALSE value. I... | entailment |
protected function cacheDirUrl($type, $checksum = '', $base_only = false)
{
if ($type !== $this::DIR_PUBLIC_TYPE) {
if ($type !== $this::DIR_PRIVATE_TYPE) {
throw new \Exception('Invalid type.');
}
}
$checksum = (string) $checksum;
if (isset($... | Get (and possibly create) the cache dir URL.
@since 140417 Initial release.
@param string $type One of `$this::public_type` or `$this::private_type`.
@param string $checksum Optional. If supplied, we'll build a nested sub-directory based on the checksum.
@param bool $base_only Defaults to a FALSE value. If TR... | entailment |
protected function cleanupCacheDirs()
{
if (($benchmark = !empty($this->options['benchmark']) && $this->options['benchmark'] === 'details')) {
$time = microtime(true);
}
$public_cache_dir = $this->cacheDir($this::DIR_PUBLIC_TYPE);
$private_cache_dir = $this->cacheDir($th... | Cache cleanup routine.
@since 140417 Initial release.
@note This routine is always host-specific.
i.e. We cleanup cache files for the current host only. | entailment |
protected function dirRegexIteration($dir, $regex)
{
$dir = (string) $dir;
$regex = (string) $regex;
$dir_iterator = new \RecursiveDirectoryIterator($dir, \FilesystemIterator::KEY_AS_PATHNAME | \FilesystemIterator::CURRENT_AS_SELF | \FilesystemIterator::SKIP_DOTS | \FilesystemIterato... | Regex directory iterator.
@since 140417 Initial release.
@param string $dir Path to a directory.
@param string $regex Regular expression.
@return \RegexIterator | entailment |
protected function nDirSeps($dir_file, $allow_trailing_slash = false)
{
if (($dir_file = (string) $dir_file) === '') {
return $dir_file; // Nothing to do.
}
if (mb_strpos($dir_file, '://' !== false)) {
if (preg_match('/^(?P<stream_wrapper>[a-z0-9]+)\:\/\//ui', $dir_fi... | Normalizes directory/file separators.
@since 140417 Initial release.
@param string $dir_file Directory/file path.
@param bool $allow_trailing_slash Defaults to FALSE.
If TRUE; and `$dir_file` contains a trailing slash; we'll leave it there.
@return string Normalized directory/file path. | entailment |
protected function currentUrlSsl()
{
if (isset(static::$static[__FUNCTION__])) {
return static::$static[__FUNCTION__];
}
if (!empty($_SERVER['SERVER_PORT'])) {
if ((int) $_SERVER['SERVER_PORT'] === 443) {
return static::$static[__FUNCTION__] = true;
... | Is the current request over SSL?
@since 140417 Initial release.
@return bool TRUE if over SSL; else FALSE. | entailment |
protected function currentUrlScheme()
{
if (isset(static::$static[__FUNCTION__])) {
return static::$static[__FUNCTION__];
}
if (!empty($this->options['current_url_scheme'])) {
return static::$static[__FUNCTION__] = $this->nUrlScheme($this->options['current_url_scheme'... | Gets the current scheme (via environment variables).
@since 140417 Initial release.
@throws \Exception If unable to determine the current scheme.
@return string The current scheme, else an exception is thrown on failure. | entailment |
protected function currentUrlHost()
{
if (isset(static::$static[__FUNCTION__])) {
return static::$static[__FUNCTION__];
}
if (!empty($this->options['current_url_host'])) {
return static::$static[__FUNCTION__] = $this->nUrlHost($this->options['current_url_host']);
... | Gets the current host name (via environment variables).
@since 140417 Initial release.
@throws \Exception If `$_SERVER['HTTP_HOST']` is empty.
@return string The current host name, else an exception is thrown on failure. | entailment |
protected function currentUrlUri()
{
if (isset(static::$static[__FUNCTION__])) {
return static::$static[__FUNCTION__];
}
if (!empty($this->options['current_url_uri'])) {
return static::$static[__FUNCTION__] = $this->mustParseUri($this->options['current_url_uri']);
... | Gets the current URI (via environment variables).
@since 140417 Initial release.
@throws \Exception If unable to determine the current URI.
@return string The current URI, else an exception is thrown on failure. | entailment |
protected function isCurrentUrlUriExcluded()
{
if ($this->regex_uri_exclusions && preg_match($this->regex_uri_exclusions, $this->currentUrlUri())) {
return true;
} elseif ($this->built_in_regex_uri_exclusions && preg_match($this->built_in_regex_uri_exclusions, $this->currentUrlUri())) {
... | Current URI is excluded?
@since 160117 Adding support for URI exclusions.
@return bool Returns `TRUE` if current URI matches an exclusion rule. | entailment |
protected function currentUrl()
{
if (isset(static::$static[__FUNCTION__])) {
return static::$static[__FUNCTION__];
}
$url = $this->currentUrlScheme().'://';
$url .= $this->currentUrlHost();
$url .= $this->currentUrlUri();
return static::$static[__FUNCTIO... | URL to current request.
@since 140417 Initial release.
@return string The current URL. | entailment |
protected function nUrlScheme($scheme)
{
if (!($scheme = (string) $scheme)) {
return $scheme; // Nothing to do.
}
if (mb_strpos($scheme, ':') !== false) {
$scheme = strstr($scheme, ':', true);
}
return mb_strtolower($scheme);
} | Normalizes a URL scheme.
@since 140417 Initial release.
@param string $scheme An input URL scheme.
@return string A normalized URL scheme (always lowercase). | entailment |
protected function nUrlAmps($url_uri_query_fragment)
{
if (!($url_uri_query_fragment = (string) $url_uri_query_fragment)) {
return $url_uri_query_fragment; // Nothing to do.
}
if (mb_strpos($url_uri_query_fragment, '&') === false) {
return $url_uri_query_fragment; // ... | Converts all ampersand entities in a URL (or a URI/query/fragment only); to just `&`.
@since 140417 Initial release.
@param string $url_uri_query_fragment A full URL; or a partial URI;
or only a query string, or only a fragment. Any of these can be normalized here.
@return string Input URL (or a URI/query/fragment o... | entailment |
protected function nUrlPathSeps($url_uri_query_fragment, $allow_trailing_slash = false)
{
if (($url_uri_query_fragment = (string) $url_uri_query_fragment) === '') {
return $url_uri_query_fragment; // Nothing to do.
}
if (!($parts = $this->parseUrl($url_uri_query_fragment, null, 0... | Normalizes a URL path from a URL (or a URI/query/fragment only).
@since 140417 Initial release.
@param string $url_uri_query_fragment A full URL; or a partial URI;
or only a query string, or only a fragment. Any of these can be normalized here.
@param bool $allow_trailing_slash Defaults to a FALSE value.
If TRUE,... | entailment |
protected function setUrlScheme($url, $scheme = '')
{
if (!($url = (string) $url)) {
return $url; // Nothing to do.
}
$scheme = (string) $scheme;
if (!$scheme) {
$scheme = $this->currentUrlScheme();
}
if ($scheme !== '//') {
$schem... | Sets a particular scheme.
@since 140417 Initial release.
@param string $url A full URL.
@param string $scheme Optional. The scheme to use (i.e. `//`, `https`, `http`).
Use `//` to use a cross-protocol compatible scheme.
Defaults to the current scheme.
@return string The full URL w/ `$scheme`. | entailment |
protected function isUrlExternal($url_uri_query_fragment)
{
if (mb_strpos($url_uri_query_fragment, '//') === false) {
return false; // Relative.
}
return mb_stripos($url_uri_query_fragment, '//'.$this->currentUrlHost()) === false;
} | Checks if a given URL is local or external to the current host.
@since 140417 Initial release.
@note Care should be taken when calling upon this method. We need to be 100% sure
we are NOT calling this against a nested remote/relative URL, URI, query or fragment.
This method assumes the URL being analyzed is from the ... | entailment |
protected function parseUrl($url_uri_query_fragment, $component = null, $normalize = null)
{
$url_uri_query_fragment = (string) $url_uri_query_fragment;
if (!isset($normalize)) {
$normalize = $this::URL_SCHEME | $this::URL_HOST | $this::URL_PATH;
}
if (mb_strpos($url_uri... | Parses a URL (or a URI/query/fragment only) into an array.
@since 140417 Initial release.
@param string $url_uri_query_fragment A full URL; or a partial URI;
or only a query string, or only a fragment. Any of these can be parsed here.
@note A query string or fragment MUST be prefixed with the appropriate delimiters.... | entailment |
protected function unparseUrl(array $parsed, $normalize = null)
{
$unparsed = ''; // Initialize string value.
if (!isset($normalize)) {
$normalize = $this::URL_SCHEME | $this::URL_HOST | $this::URL_PATH;
}
if ($normalize & $this::URL_SCHEME) {
if (!isset($par... | Unparses a URL (putting it all back together again).
@since 140417 Initial release.
@param array $parsed An array with at least one URL component.
@param null|int $normalize A bitmask. Defaults to NULL (indicating a default bitmask).
Defaults include: {@link self::url_scheme}, {@link self::url_host}, {@link sel... | entailment |
protected function mustUnparseUrl() // Arguments are NOT listed here.
{
if (($unparsed = call_user_func_array([$this, 'unparseUrl'], func_get_args())) === '') {
throw new \Exception(sprintf('Unable to unparse: `%1$s`.', print_r(func_get_arg(0), true)));
}
return $unparsed;
} | Unparses a URL (putting it all back together again).
@since 140417 Initial release.
@throws \Exception If unable to unparse.
@return string
@see unparseUrl()
unparseUrl() | entailment |
protected function parseUriParts($url_uri_query_fragment, $normalize = null)
{
if (($parts = $this->parseUrl($url_uri_query_fragment, null, $normalize))) {
return ['path' => $parts['path'], 'query' => $parts['query'], 'fragment' => $parts['fragment']];
}
return; // Default return... | Parses URI parts from a URL (or a URI/query/fragment only).
@since 140417 Initial release.
@param string $url_uri_query_fragment A full URL; or a partial URI;
or only a query string, or only a fragment. Any of these can be parsed here.
@param null|int $normalize A bitmask. Defaults to NULL (indicating ... | entailment |
protected function mustParseUriParts() // Arguments are NOT listed here.
{
if (is_null($parts = call_user_func_array([$this, 'parseUriParts'], func_get_args()))) {
throw new \Exception(sprintf('Unable to parse: `%1$s`.', (string) func_get_arg(0)));
}
return $parts;
} | Parses URI parts from a URL (or a URI/query/fragment only).
@since 140417 Initial release.
@throws \Exception If unable to parse.
@return array|null
@see parseUriParts()
parseUriParts() | entailment |
protected function parseUri($url_uri_query_fragment, $normalize = null, $include_fragment = true)
{
if (($parts = $this->parseUriParts($url_uri_query_fragment, $normalize))) {
if (!$include_fragment) {
unset($parts['fragment']);
}
return $this->unparseUrl(... | Parses a URI from a URL (or a URI/query/fragment only).
@since 140417 Initial release.
@param string $url_uri_query_fragment A full URL; or a partial URI;
or only a query string, or only a fragment. Any of these can be parsed here.
@param null|int $normalize A bitmask. Defaults to NULL (indicating a de... | entailment |
protected function mustParseUri() // Arguments are NOT listed here.
{
if (is_null($parsed = call_user_func_array([$this, 'parseUri'], func_get_args()))) {
throw new \Exception(sprintf('Unable to parse: `%1$s`.', (string) func_get_arg(0)));
}
return $parsed;
} | Parses a URI from a URL (or a URI/query/fragment only).
@since 140417 Initial release.
@throws \Exception If unable to parse.
@return string|null
@see parseUri()
parseUri() | entailment |
protected function resolveRelativeUrl($relative_url_uri_query_fragment, $base_url = '')
{
$relative_url_uri_query_fragment = (string) $relative_url_uri_query_fragment;
$base_url = (string) $base_url;
if (!$base_url) {
$base_url = $this->currentUrl();
... | Resolves a relative URL into a full URL from a base.
@since 140417 Initial release.
@param string $relative_url_uri_query_fragment A full URL; or a partial URI;
or only a query string, or only a fragment. Any of these can be parsed here.
@param string $base_url A base URL. Optional. Defaults to... | entailment |
protected function mustGetUrl($url)
{
$url = (string) $url; // Force string value.
$response = $this->remote($url, '', 5, 15, [], '', true, true);
if ($response['code'] >= 400) {
throw new \Exception(sprintf('HTTP response code: `%1$s`. Unable to get URL: `%2$s`.', $respons... | Remote HTTP communication.
@since 150820 Improving HTTP connection handling.
@param string $url A URL to connect to.
@throws \Exception If unable to get the URL; i.e., if the response code is >= 400.
@return string Output data from the HTTP response; excluding headers (i.e., body only).
@note By throwing an except... | entailment |
protected function remote($url, $body = '', $max_con_secs = 5, $max_stream_secs = 15, array $headers = [], $cookie_file = '', $fail_on_error = true, $return_array = false)
{
$can_follow = !filter_var(ini_get('safe_mode'), FILTER_VALIDATE_BOOLEAN) && !ini_get('open_basedir');
if (($benchmark = !empt... | Remote HTTP communication.
@since 140417 Initial release.
@param string $url A URL to connect to.
@param string|array $body Optional request body.
@param int $max_con_secs Defaults to `20` seconds.
@param int $max_stream_secs Defaults to `20` seconds.
@param array ... | entailment |
public function blockFencedCodeComplete($block)
{
$text = print_r($block, true);
$matches = array();
preg_match('/\[class\] => language-([a-zA-Z]+)/', $text, $matches);
if (count($matches) > 1 && $matches[1] === 'shell') {
$block['element']['text']['text... | Use new highlighters for code blocks.
@param unknown $block
@return unknown | entailment |
public function getAtom(User $user, $key, bool $detachFromEntityManager = true)
{
if ($atom = $this->getRepository()->findOneBy(['user_id' => $user->getId(), 'key' => $key])) {
if ($detachFromEntityManager) {
$this->getEntityManager()->detach($atom);
}
re... | Get an atomic piece of user data
@param User $user
@param $key
@param bool $detachFromEntityManager
@return UserAtom|null | entailment |
public function setAtom(User $user, $key, $value)
{
$conn = $this->getEntityManager()->getConnection();
$stmt = $conn->prepare('INSERT INTO users_atoms ( user_id, `key`, `value`) VALUES( ?, ?, ? ) ON DUPLICATE KEY UPDATE `value`=VALUES(`value`)');
$user_id = $user->getId();
$stmt->... | Set a particular atom on a user
@param User $user
@param $key
@param $value
@throws \Doctrine\DBAL\DBALException | entailment |
public function search(string $key, string $value)
{
return $this->getRepository()->findBy(['key' => $key, 'value' => $value]);
} | Key-value pair search.
@param string $key
@param string $value
@return array | entailment |
public function getPermissions($string) : array
{
$query = $this->getRepository()->createQueryBuilder('r')
->select('r')
->where('r.resource_class = :resourceClass AND r.resource_id=:resourceId')
->setParameter('resourceClass', 'string')
->setParameter('resour... | @param $string
@return GroupPermissionInterface[] | entailment |
public function getResourcePermissions(ResourceInterface $resource) : array
{
$query = $this->getRepository()->createQueryBuilder('r')
->select('r')
->where('r.resource_class = :resourceClass AND r.resource_id=:resourceId')
->setParameter('resourceClass', $resource->getCl... | @param ResourceInterface $resource
@return array|\CirclicalUser\Provider\GroupPermissionInterface[] | entailment |
public function getResourcePermissionsByClass($resourceClass) : array
{
$query = $this->getRepository()->createQueryBuilder('r')
->select('r')
->where('r.resource_class = :resourceClass')
->setParameter('resourceClass', $resourceClass)
->getQuery();
r... | @param $resourceClass
@return array | entailment |
public function authenticate(string $email, string $pass)
{
return $this->authenticationService->authenticate($email, $pass);
} | Pass me an email/username combo and I'll start the user session
@param $email
@param $pass
@return User
@throws \CirclicalUser\Exception\BadPasswordException
@throws \CirclicalUser\Exception\NoSuchUserException | entailment |
public function create(User $user, $username, $password)
{
$this->authenticationService->create($user, $username, $password);
} | Give me a user and password, and I'll create authentication records for you
@param User $user
@param string $username Can be an email address or username, should be validated prior
@param string $password | entailment |
public function createProject(
$projectData,
$format = 'php',
$odm = null
) {
// Note: might want to clone error handler, in case state variables
// have been added that should differ for different uses, e.g.,
// a user message that is displayed where you have multipl... | Creates a REDCap project with the specified data.
The data fields that can be set are as follows:
<ul>
<li>
<b>project_title</b> - the title of the project.
</li>
<li>
<b>purpose</b> - the purpose of the project:
<ul>
<li>0 - Practice/Just for fun</li>
<li>1 - Other</li>
<li>2 - Research</li>
<li>3 - Quality Improveme... | entailment |
public function getProject($apiToken)
{
$apiToken = $this->processApiTokenArgument($apiToken);
$connection = clone $this->connection;
$errorHandler = clone $this->errorHandler;
$projectConstructorCallback = $this->projectConstructorCallback;
# By ... | Gets the REDCap project for the specified API token.
@param string $apiToken the API token for the project to get.
@return \IU\PHPCap\RedCapProject the project for the specified API token. | entailment |
private function httpBuildQuery($params)
{
$query = [];
foreach ($params as $key => $param) {
if (!is_array($param)) {
continue;
}
// when a param has many values, it generate the query string separated to join late
foreach ($param as $... | Create a query string
@param array $params
@return string | entailment |
public function getInheritanceList(): array
{
$roleList = [$this];
$role = $this;
while ($parentRole = $role->getParent()) {
$roleList[] = $parentRole;
$role = $parentRole;
}
return $roleList;
} | Return all inherited roles, including the start role, in this to-root traversal.
@return array | entailment |
function it_can_grant_access_to_roles_by_appending_actions($resourceObject, $groupRules, $groupActionRule)
{
$role = $this->getRoleWithName('user');
$groupRules->update(Argument::any())->shouldBeCalled();
$groupActionRule->addAction('foo')->shouldBeCalled();
$this->grantRoleAccess($r... | Give a role, access to a resource | entailment |
public function exportArms($format = 'php', $arms = [])
{
$data = array(
'token' => $this->apiToken,
'content' => 'arm',
'returnFormat' => 'json'
);
$legalFormats = array('csv', 'json', 'php', 'xml');
$data['format'] = $this->p... | Exports the numbers and names of the arms in the project.
@param $format string the format used to export the arm data.
<ul>
<li> 'php' - [default] array of maps of values</li>
<li> 'csv' - string of CSV (comma-separated values)</li>
<li> 'json' - string of JSON encoded values</li>
<li> 'xml' - string of XML encoded d... | entailment |
public function importArms($arms, $format = 'php', $override = false)
{
$data = array(
'token' => $this->apiToken,
'content' => 'arm',
'action' => 'import',
'returnFormat' => 'json'
);
#---------------... | Imports the specified arms into the project.
@param mixed $arms the arms to import. This will
be a PHP array of associative arrays if no format, or 'php' format was specified,
and a string otherwise. The field names (keys) used in both cases
are: arm_num, name
@param string $format the format for the export.
<ul>
<li>... | entailment |
public function deleteArms($arms)
{
$data = array (
'token' => $this->apiToken,
'content' => 'arm',
'action' => 'delete',
'returnFormat' => 'json',
);
$data['arms'] = $this->processArmsArgument($arms, ... | Deletes the specified arms from the project.
@param array $arms array of arm numbers to delete.
@throws PhpCapException if an error occurs, including if the arms array is null or empty
@return integer the number of arms deleted. | entailment |
public function exportEvents($format = 'php', $arms = [])
{
$data = array(
'token' => $this->apiToken,
'content' => 'event',
'returnFormat' => 'json'
);
#---------------------------------------
# Process arguments
#----... | Exports information about the specified events.
Example usage:
<code>
#export information about all events in CSV (Comma-Separated Values) format.
$eventInfo = $project->exportEvents('csv');
# export events in XML format for arms 1 and 2.
$eventInfo = $project->exportEvents('xml', [1, 2]);
</code>
@param string $for... | entailment |
public function importEvents($events, $format = 'php', $override = false)
{
$data = array(
'token' => $this->apiToken,
'content' => 'event',
'action' => 'import',
'returnFormat' => 'json'
);
#---------... | Imports the specified events into the project.
@param mixed $events the events to import. This will
be a PHP array of associative arrays if no format, or 'php' format is specified,
and a string otherwise. The field names (keys) used in both cases
are: event_name, arm_num
@param string $format the format for the export... | entailment |
public function deleteEvents($events)
{
$data = array (
'token' => $this->apiToken,
'content' => 'event',
'action' => 'delete',
'returnFormat' => 'json',
);
$data['events'] = $this->processEventsArgume... | Deletes the specified events from the project.
@param array $events array of event names of events to delete.
@throws PhpCapException if an error occurs, including if the events array is null or empty.
@return integer the number of events deleted. | entailment |
public function exportFieldNames($format = 'php', $field = null)
{
$data = array(
'token' => $this->apiToken,
'content' => 'exportFieldNames',
'returnFormat' => 'json'
);
#---------------------------------------
# Process argum... | Exports the fields names for a project.
@param string $format the format for the export.
<ul>
<li> 'php' - [default] array of maps of values</li>
<li> 'csv' - string of CSV (comma-separated values)</li>
<li> 'json' - string of JSON encoded values</li>
<li> 'xml' - string of XML encoded data</li>
</ul>
@param string $f... | entailment |
public function exportFile($recordId, $field, $event = null, $repeatInstance = null)
{
$data = array(
'token' => $this->apiToken,
'content' => 'file',
'action' => 'export',
'returnFormat' => 'json'
);
... | Exports the specified file.
@param string $recordId the record ID for the file to be exported.
@param string $field the name of the field containing the file to export.
@param string $event name of event for file export (for longitudinal studies).
@param integer $repeatInstance
@throws PhpCapException if an error occ... | entailment |
public function importFile($filename, $recordId, $field, $event = null, $repeatInstance = null)
{
$data = array (
'token' => $this->apiToken,
'content' => 'file',
'action' => 'import',
'returnFormat' => 'json'
);
... | Imports the file into the field of the record
with the specified event and/or repeat istance, if any.
Example usage:
<code>
...
$file = '../data/consent1001.txt';
$recordId = '1001';
$field = 'patient_document';
$event = 'enrollment_arm_1';
$project->importFile($file, $recordId, $field, $event);
...
</code>
... | entailment |
public function deleteFile($recordId, $field, $event = null, $repeatInstance = null)
{
$data = array (
'token' => $this->apiToken,
'content' => 'file',
'action' => 'delete',
'returnFormat' => 'json'
);
... | Deletes the specified file.
@param string $recordId the record ID of the file to delete.
@param string $field the field name of the file to delete.
@param string $event the event of the file to delete
(only for longitudinal studies).
@param integer $repeatInstance repeat instance of the file to delete
(only for studie... | entailment |
public function exportInstruments($format = 'php')
{
$data = array(
'token' => $this->apiToken,
'content' => 'instrument',
'returnFormat' => 'json'
);
$legalFormats = array('csv', 'json', 'php', 'xml');
$data['format'... | Exports information about the instruments (data entry forms) for the project.
Example usage:
<code>
$instruments = $project->getInstruments();
foreach ($instruments as $instrumentName => $instrumentLabel) {
print "{$instrumentName} : {$instrumentLabel}\n";
}
</code>
@param $format string format instruments are export... | entailment |
public function exportPdfFileOfInstruments(
$file = null,
$recordId = null,
$event = null,
$form = null,
$allRecords = null
) {
$data = array(
'token' => $this->apiToken,
'content' => 'pdf',
'returnFormat' => '... | Exports a PDF version of the requested instruments (forms).
@param string $file the name of the file (possibly with a path specified also)
to store the PDF instruments in.
@param string $recordId if record ID is specified, the forms retrieved will
be filled with values for that record. Otherwise, they will be blank.
@... | entailment |
public function exportInstrumentEventMappings($format = 'php', $arms = [])
{
$data = array(
'token' => $this->apiToken,
'content' => 'formEventMapping',
'format' => 'json',
'returnFormat' => 'json'
);
... | Gets the instrument to event mapping for the project.
For example, the following code:
<code>
$map = $project->exportInstrumentEventMappings();
print_r($map[0]); # print first element of map
</code>
might generate the following output:
<pre>
Array
(
[arm_num] => 1
[unique_event_name] => enrollment_arm_1
[form] => demo... | entailment |
public function importInstrumentEventMappings($mappings, $format = 'php')
{
$data = array(
'token' => $this->apiToken,
'content' => 'formEventMapping',
'returnFormat' => 'json'
);
#---------------------------------------
# Proc... | Imports the specified instrument-event mappings into the project.
@param mixed $mappings the mappings to import. This will
be a PHP array of associative arrays if no format, or
'php' format, was specified,
and a string otherwise. In all cases, the field names that
are used in the mappings are:
arm_num, unique_event_na... | entailment |
public function exportMetadata($format = 'php', $fields = [], $forms = [])
{
$data = array(
'token' => $this->apiToken,
'content' => 'metadata',
'returnFormat' => 'json'
);
#---------------------------------------
# Process for... | Exports metadata about the project, i.e., information about the fields in the project.
@param string $format the format for the export.
<ul>
<li> 'php' - [default] array of maps of values</li>
<li> 'csv' - string of CSV (comma-separated values)</li>
<li> 'json' - string of JSON encoded values</li>
<li> 'xml' - string ... | entailment |
public function importMetadata($metadata, $format = 'php')
{
$data = array(
'token' => $this->apiToken,
'content' => 'metadata',
'returnFormat' => 'json'
);
#---------------------------------------
# Process argumen... | Imports the specified metadata (field information) into the project.
@param mixed $metadata the metadata to import. This will
be a PHP associative array if no format, or 'php' format was specified,
and a string otherwise.
@param string $format the format for the export.
<ul>
<li> 'php' - [default] array of maps of val... | entailment |
public function exportProjectInfo($format = 'php')
{
$data = array(
'token' => $this->apiToken,
'content' => 'project',
'returnFormat' => 'json'
);
#---------------------------------------
# Process format
#... | Exports information about the project, e.g., project ID, project title, creation time.
@param string $format the format for the export.
<ul>
<li> 'php' - [default] array of maps of values</li>
<li> 'csv' - string of CSV (comma-separated values)</li>
<li> 'json' - string of JSON encoded values</li>
<li> 'xml' - string ... | entailment |
public function importProjectInfo($projectInfo, $format = 'php')
{
$data = array(
'token' => $this->apiToken,
'content' => 'project_settings',
'returnFormat' => 'json'
);
#---------------------------------------
# Process argum... | Imports the specified project information into the project.
The valid fields that can be imported are:
project_title, project_language, purpose, purpose_other, project_notes,
custom_record_label, secondary_unique_field, is_longitudinal,
surveys_enabled, scheduling_enabled, record_autonumbering_enabled,
randomization_e... | entailment |
public function exportProjectXml(
$returnMetadataOnly = false,
$recordIds = null,
$fields = null,
$events = null,
$filterLogic = null,
$exportSurveyFields = false,
$exportDataAccessGroups = false,
$exportFiles = false
) {
$data = array(
... | Exports the specified information of project in XML format.
@param boolean $returnMetadataOnly if this is set to true, only the metadata for
the project is returned. If it is not set to true, the metadata and data for the project
is returned.
@param array $recordIds array of strings with record id's that are to be ret... | entailment |
public function generateNextRecordName()
{
$data = array(
'token' => $this->apiToken,
'content' => 'generateNextRecordName',
'returnFormat' => 'json'
);
$nextRecordName = $this->connection->callWithArray($data);
$ne... | This method returns the next potential record ID for a project, but it does NOT
actually create a new record. The record ID returned will generally be the current maximum
record ID number incremented by one (but see the REDCap documentation for the case
where Data Access Groups are being used).
This method is intended ... | entailment |
public function exportRecords(
$format = 'php',
$type = 'flat',
$recordIds = null,
$fields = null,
$forms = null,
$events = null,
$filterLogic = null,
$rawOrLabel = 'raw',
$rawOrLabelHeaders = 'raw',
$exportCheckboxLabel = false,
$e... | Exports the specified records.
Example usage:
<code>
$records = $project->exportRecords($format = 'csv', $type = 'flat');
$recordIds = [1001, 1002, 1003];
$records = $project->exportRecords('xml', 'eav', $recordIds);
</code>
@param string $format the format in which to export the records:
<ul>
<li> 'php' - [default] ... | entailment |
public function exportRecordsAp($arrayParameter = [])
{
if (func_num_args() > 1) {
$message = __METHOD__.'() was called with '.func_num_args().' arguments, but '
.' it accepts at most 1 argument.';
$this->errorHandler->throwException($message, ErrorHandlerInterfac... | Export records using an array parameter, where the keys of the array
passed to this method are the argument names, and the values are the
argument values. The argument names to use correspond to the variable
names in the exportRecords method.
Example usage:
<code>
# return all records with last name "Smith" in CSV fo... | entailment |
public function importRecords(
$records,
$format = 'php',
$type = 'flat',
$overwriteBehavior = 'normal',
$dateFormat = 'YMD',
$returnContent = 'count',
$forceAutoNumber = false
) {
$data = array (
'token' => $this->apiT... | Imports the specified records into the project.
@param mixed $records
If the 'php' (default) format is being used, an array of associated arrays (maps)
where each key is a field name,
and its value is the value to store in that field. If any other format is being used, then
the records are represented by a string.
@pa... | entailment |
public function deleteRecords($recordIds, $arm = null)
{
$data = array (
'token' => $this->apiToken,
'content' => 'record',
'action' => 'delete',
'returnFormat' => 'json'
);
$data['records'] = $this->p... | Deletes the specified records from the project.
@param array $recordIds array of record IDs to delete
@param string $arm if an arm is specified, only records that have
one of the specified record IDs that are in that arm will
be deleted.
@throws PhpCapException
@return integer the number of records deleted. Note tha... | entailment |
public function exportRepeatingInstrumentsAndEvents($format = 'php')
{
$data = array(
'token' => $this->apiToken,
'content' => 'repeatingFormsEvents',
'returnFormat' => 'json'
);
#---------------------------------------
# Process the arguments
... | Exports the repeating instruments and events.
@param string $format the format in which to export the records:
<ul>
<li> 'php' - [default] array of maps of values</li>
<li> 'csv' - string of CSV (comma-separated values)</li>
<li> 'json' - string of JSON encoded values</li>
<li> 'xml' - string of XML encoded data</li>
... | entailment |
public function exportRedcapVersion()
{
$data = array(
'token' => $this->apiToken,
'content' => 'version'
);
$redcapVersion = $this->connection->callWithArray($data);
$recapVersion = $this->processExportResult($redcapVersion, 'string');
... | Gets the REDCap version number of the REDCap instance being used by the project.
@return string the REDCap version number of the REDCap instance being used by the project. | entailment |
public function exportReports(
$reportId,
$format = 'php',
$rawOrLabel = 'raw',
$rawOrLabelHeaders = 'raw',
$exportCheckboxLabel = false
) {
$data = array(
'token' => $this->apiToken,
'content' => 'report',
'returnFormat... | Exports the records produced by the specified report.
@param mixed $reportId integer or numeric string ID of the report to use.
@param string $format output data format.
<ul>
<li> 'php' - [default] array of maps of values</li>
<li> 'csv' - string of CSV (comma-separated values)</li>
<li> 'json' - string of JSON encode... | entailment |
public function exportSurveyParticipants($form, $format = 'php', $event = null)
{
$data = array(
'token' => $this->apiToken,
'content' => 'participantList',
'returnFormat' => 'json'
);
#----------------------------------------------
... | Exports the list of survey participants for the specified form and, for
longitudinal studies, event.
@param string $form the form for which the participants should be exported.
@param string $format output data format.
<ul>
<li> 'php' - [default] array of maps of values</li>
<li> 'csv' - string of CSV (comma-separated... | entailment |
public function exportSurveyQueueLink($recordId)
{
$data = array(
'token' => $this->apiToken,
'content' => 'surveyQueueLink',
'returnFormat' => 'json'
);
#----------------------------------------------
# Process arguments
... | Exports the survey queue link for the specified record ID.
@param string $recordId the record ID of the survey queue link that should be returned.
@return string survey queue link. | entailment |
public function exportSurveyReturnCode($recordId, $form, $event = null, $repeatInstance = null)
{
$data = array(
'token' => $this->apiToken,
'content' => 'surveyReturnCode',
'returnFormat' => 'json'
);
#--------------------------------... | Exports the code for returning to a survey that was not completed.
@param string $recordId the record ID for the survey to return to.
@param string $form the form name of the survey to return to.
@param string $event the unique event name (for longitudinal studies) for the survey
to return to.
@param integer $repeatIn... | entailment |
public function exportUsers($format = 'php')
{
$data = array(
'token' => $this->apiToken,
'content' => 'user',
'returnFormat' => 'json'
);
$legalFormats = array('csv', 'json', 'php', 'xml');
$data['format'] = $this->processForm... | Exports the users of the project.
@param string $format output data format.
<ul>
<li> 'php' - [default] array of maps of values</li>
<li> 'csv' - string of CSV (comma-separated values)</li>
<li> 'json' - string of JSON encoded values</li>
<li> 'xml' - string of XML encoded data</li>
</ul>
@return mixed a list of user... | entailment |
public function importUsers($users, $format = 'php')
{
$data = array(
'token' => $this->apiToken,
'content' => 'user',
'returnFormat' => 'json'
);
#----------------------------------------------------
# Process arguments
#---------... | Imports the specified users into the project. This method
can also be used to update user priveleges by importing
a users that already exist in the project and
specifying new privleges for that user in the user
data that is imported.
The available field names for user import are:
<code>
username, expiration, data_acce... | entailment |
public function getRecordIdBatches($batchSize = null, $filterLogic = null, $recordIdFieldName = null)
{
$recordIdBatches = array();
#-----------------------------------
# Check arguments
#-----------------------------------
if (!isset($batchSize)) {
$mess... | Gets an array of record ID batches.
These can be used for batch
processing of records exports to lessen memory requirements, for example:
<code>
...
# Get all the record IDs of the project in 10 batches
$recordIdBatches = $project->getRecordIdBatches(10);
foreach ($recordIdBatches as $recordIdBatch) {
$records = $proj... | entailment |
protected function processExportResult(& $result, $format)
{
if ($format == 'php') {
$phpResult = json_decode($result, true); // true => return as array instead of object
$jsonError = json_last_error();
switch ($jsonError) {
... | Processes an export result from the REDCap API.
@param string $result
@param string $format
@throws PhpCapException | entailment |
protected function processNonExportResult(& $result)
{
$matches = array();
#$hasMatch = preg_match('/^[\s]*{"error":[\s]*"(.*)"}[\s]*$/', $result, $matches);
$hasMatch = preg_match(self::JSON_RESULT_ERROR_PATTERN, $result, $matches);
if ($hasMatch === 1) {
// note: $match... | Checks the result returned from the REDCap API for non-export methods.
PHPCap is set to return errors from REDCap using JSON, so the result
string is checked to see if there is a JSON format error, and if so,
and exception is thrown using the error message returned from the
REDCap API.
@param string $result a result r... | entailment |
private function getUser()
{
if (function_exists('auth') && auth()->check()) {
return auth()->user()->toArray();
}
if (class_exists(\Cartalyst\Sentinel\Sentinel::class) && $user = Sentinel::check()) {
return $user->toArray();
}
return null;
} | Get the authenticated user.
Supported authentication systems: Laravel, Sentinel
@return array|null | entailment |
public function getUsersWithRole(Role $role): array
{
$query = $this->getRepository()->createQueryBuilder('u')
->select('u')
->where(':role MEMBER OF u.roles')
->setParameter('role', $role)
->getQuery();
return $query->getResult() ?? [];
} | Get users with a specific role, and _not_ its hierarchical parents.
In other words, if you have 'admin' which inherits from 'standard' and you request 'admin',
you will not list 'standard' users.
@param Role $role
@return array | entailment |
public function getUserPermission($string, UserInterface $user)
{
$query = $this->getRepository()->createQueryBuilder('r')
->select('r')
->where('r.resource_class = :resourceClass AND r.resource_id=:resourceId AND r.user=:user')
->setParameter('resourceClass', 'string')
... | Get any user-level, string (simple) permissions that are configured in the database.
@param $string
@param UserInterface $user
@return array
@throws \Doctrine\ORM\NonUniqueResultException | entailment |
public function getResourceUserPermission(ResourceInterface $resource, UserInterface $user)
{
$query = $this->getRepository()->createQueryBuilder('r')
->select('r')
->where('r.resource_class = :resourceClass AND r.resource_id=:resourceId AND r.user=:user')
->setParameter(... | Get resource-type permissions from the database
@param ResourceInterface $resource
@param UserInterface $user
@return array
@throws \Doctrine\ORM\NonUniqueResultException | entailment |
public function create(UserInterface $user, $resourceClass, $resourceId, array $actions) : UserPermissionInterface
{
return new UserPermission($user, $resourceClass, $resourceId, $actions);
} | Create a user permission, not persisted, and return it.
@param UserInterface $user
@param $resourceClass
@param $resourceId
@param array $actions
@return UserPermissionInterface | entailment |
public function getCallInfo()
{
$callInfo = curl_getinfo($this->curlHandle);
if ($errno = curl_errno($this->curlHandle)) {
$message = curl_error($this->curlHandle);
$code = ErrorHandlerInterface::CONNECTION_ERROR;
$this->errorHandler->throwException($message, $... | Returns call information for the most recent call.
@throws PhpCapException if an error occurs and the default error handler is being used.
@return array an associative array of values of call information for the most recent call made.
@see <a href="http://php.net/manual/en/function.curl-getinfo.php">http://php.net/ma... | entailment |
public function setCurlOption($option, $value)
{
$this->curlOptions[$option] = $value;
$result = curl_setopt($this->curlHandle, $option, $value);
return $result;
} | Sets the specified cURL option to the specified value.
{@internal
NOTE: this method is cURL specific and is NOT part
of the connection interface, and therefore should
NOT be used internally by PHPCap outside of this class.
}
@see <a href="http://php.net/manual/en/function.curl-setopt.php">http://php.net/manual/en/fun... | entailment |
public function getCurlOption($option)
{
$optionValue = null;
if (array_key_exists($option, $this->curlOptions)) {
$optionValue = $this->curlOptions[$option];
}
return $optionValue;
} | Gets the value for the specified cURL option number.
{@internal
NOTE: this method is cURL specific and is NOT part
of the connection interface, and therefore should
NOT be used internally by PHPCap outside of this class.
}
@see <a href="http://php.net/manual/en/function.curl-setopt.php">http://php.net/manual/en/funct... | entailment |
public function boot()
{
if(function_exists('config_path')) {
/*
* Publish configuration file
*/
$this->publishes( [
__DIR__ . '/../config/larabug.php' => config_path( 'larabug.php' ),
] );
}
$this->app['view']->a... | Bootstrap the application events. | entailment |
public function register()
{
$this->mergeConfigFrom(__DIR__ . '/../config/larabug.php', 'larabug');
$this->app->singleton(LaraBug::SERVICE, function ($app) {
return new LaraBug;
});
} | Register the service provider. | entailment |
public function addTime($function, $start_time, $task)
{
if (!($function = trim((string) $function))) {
return; // Not possible.
}
if (($start_time = (float) $start_time) <= 0) {
return; // Not possible.
}
if (($end_time = (float) microtime(true)) <= 0... | Logs a new time entry.
@since 150315 Enhancing debugger.
@api This method is available for public use.
@param string $function Caller.
@param float $start_time Start time; via `microtime(TRUE)`.
@param string $task Description of the task(s) performed. | entailment |
public function hasHook($hook)
{
$hook = (string) $hook;
return $hook && !empty($this->hooks[$hook]);
} | Do we have a specific hook?
@since 150821 Enhancing hook support.
@param string $hook The name of a filter hook.
@return bool True if actions/filters exist on this hook. | entailment |
public function addHook($hook, $function, $priority = 10, $accepted_args = 1)
{
$hook = (string) $hook;
$priority = (int) $priority;
$accepted_args = max(0, (int) $accepted_args);
$hook_id = $this->hookId($function);
$this->hooks[$hook][$priority][$hook_i... | Adds a new hook (works with both actions & filters).
@since 150321 Adding hook API for plugins.
@param string $hook The name of a hook to attach to.
@param string|callable|mixed $function A string or a callable.
@param int $priority Hook priority; defaults to `10`.
... | entailment |
public function removeHook($hook, $function, $priority = 10)
{
$hook = (string) $hook;
$priority = (int) $priority;
$hook_id = $this->hookId($function);
if (!isset($this->hooks[$hook][$priority][$hook_id])) {
return false; // Nothing to remove.
}
uns... | Removes a hook (works with both actions & filters).
@since 150321 Adding hook API for plugins.
@param string $hook The name of a hook to remove.
@param string|callable|mixed $function A string or a callable.
@param int $priority Hook priority; defaults to `10`.
@return bool `TRUE... | entailment |
public function doAction($hook)
{
$hook = (string) $hook;
if (empty($this->hooks[$hook])) {
return; // No hooks.
}
$hook_actions = $this->hooks[$hook];
$args = func_get_args();
ksort($hook_actions);
foreach ($hook_actions as $_hook_action)... | Runs any callables attached to an action.
@since 150321 Adding hook API for plugins.
@param string $hook The name of an action hook. | entailment |
public function applyFilters($hook, $value)
{
$hook = (string) $hook;
if (empty($this->hooks[$hook])) {
return $value; // No hooks.
}
$hook_filters = $this->hooks[$hook];
$args = func_get_args();
ksort($hook_filters);
foreach ($hook_filter... | Runs any callables attached to a filter.
@since 150321 Adding hook API for plugins.
@param string $hook The name of a filter hook.
@param mixed $value The value to filter.
@return mixed The filtered `$value`. | entailment |
public static function fileToString($filename)
{
$errorHandler = static::getErrorHandler();
if (!file_exists($filename)) {
$errorHandler->throwException(
'The input file "'.$filename.'" could not be found.',
ErrorHandlerInterface::INPUT_FILE_NOT_F... | Reads the contents of the specified file and returns it as a string.
@param string $filename the name of the file that is to be read.
@throws PhpCapException if an error occurs while trying to read the file.
@return string the contents of the specified file. | entailment |
public static function writeStringToFile($string, $filename, $append = false)
{
$errorHandler = static::getErrorHandler();
$result = false;
if ($append === true) {
$result = file_put_contents($filename, $string, FILE_APPEND);
} else {
$result = file_p... | Writes the specified string to the specified file.
@param string $string the string to write to the file.
@param string $filename the name of the file to write the string.
@param boolean $append if true, the file is appended if it already exists. If false,
the file is created if it doesn't exist, and overwritten if it... | entailment |
public static function setErrorHandler($errorHandler)
{
# Get the current error handler to make sure it's set,
# since it will need to be used if the passed error
# handler is invalid
$currentErrorHandler = static::getErrorHandler();
if (!($errorHandler instanceof Er... | Sets the error handler used for methods in this class.
@param ErrorHandlerInterface $errorHandler | entailment |
public function loadConfiguration(): void
{
$builder = $this->getContainerBuilder();
$config = $this->validateConfig($this->defaults);
$config = Helpers::expand($config, $builder->parameters);
// Scheduler
$scheduler = $builder->addDefinition($this->prefix('scheduler'))
->setFactory(LockingScheduler::cla... | Register services | entailment |
public function modelNotFoundException(ModelNotFoundException $exception)
{
$entity = $this->extractEntityName($exception->getModel());
$ids = implode($exception->getIds(), ',');
$error = [[
'status' => 404,
'code' => $this->getCode('model_not_found'),
... | Set the response if Exception is ModelNotFound.
@param ModelNotFoundException $exception | entailment |
public function extractEntityName($model)
{
$classNames = (array) explode('\\', $model);
$entityName = end($classNames);
if ($this->entityHasTranslation($entityName)) {
return __('exception::exceptions.models.'.$entityName);
}
return $entityName;
} | Get entitie name based on model path to mount the message.
@param string $model
@return string | entailment |
public function entityHasTranslation(string $entityName): bool
{
$hasKey = in_array($entityName, $this->translationModelKeys());
if ($hasKey) {
return ! empty($hasKey);
}
return false;
} | Check if entity returned on ModelNotFoundException has translation on
exceptions file
@param string $entityName The model name to check if has translation
@return bool Has translation or not | entailment |
public function clear()
{
$this->dom = null;
$this->nodes = null;
$this->parent = null;
$this->children = null;
} | clean up memory due to php5 circular references memory leak... | entailment |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.