sentence1
stringlengths 52
3.87M
| sentence2
stringlengths 1
47.2k
| label
stringclasses 1
value |
---|---|---|
public function getSurveyResponses($surveyId, $detailed = false, array $filters = [])
{
if ($detailed) {
return $this->sendRequest(
$this->createRequest('GET', sprintf('surveys/%d/responses/bulk', $surveyId), [
'query' => $filters
])
);
} else {
return $this->sendRequest(
$this->createRequest('GET', sprintf('surveys/%d/responses', $surveyId), [
'query' => $filters
])
);
}
} | getSurveyResponses
@param int $surveyId
@param bool $detailed - Defaults to false
@param array $filters - Available filters:
page, per_page, start_created_at, end_created_at,
start_modified_at, end_modified_at, status,
email, first_name, last_name, ip, custom,
total_time_max, total_time_min, total_time_units,
sort_order, sort_by
@return @see Client::sendRequest | entailment |
public function getCollectorResponses($collectorId, $detailed = false, array $filters = [])
{
if ($detailed) {
return $this->sendRequest(
$this->createRequest('GET', sprintf('collectors/%d/responses/bulk', $collectorId), [
'query' => $filters
])
);
} else {
return $this->sendRequest(
$this->createRequest('GET', sprintf('collectors/%d/responses', $collectorId), [
'query' => $filters
])
);
}
} | getCollectorResponses
@param int $collectorId
@param bool $detailed - Defaults to false
@param array $filters - Available filters:
page, per_page, start_created_at, end_created_at,
start_modified_at, end_modified_at, status,
email, first_name, last_name, ip, custom,
total_time_max, total_time_min, total_time_units,
sort_order, sort_by
@return @see Client::sendRequest | entailment |
public function createCollectorResponse($collectorId, array $data = [])
{
return $this->sendRequest(
$this->createRequest('POST', sprintf('collectors/%d/responses', $collectorId), [], $data)
);
} | createCollectorResponse
@param int $collectorId
@param array $data - See API docs for available fields
@return @see Client::sendRequest | entailment |
public function getCollectorResponse($collectorId, $responseId, $detailed = false)
{
if ($detailed) {
return $this->sendRequest(
$this->createRequest('GET', sprintf('collectors/%d/responses/%d', $collectorId, $responseId))
);
} else {
return $this->sendRequest(
$this->createRequest('GET', sprintf('collectors/%d/responses/%d/details', $collectorId, $responseId))
);
}
} | getCollectorResponse
@param int $collectorId
@param int $responseId
@param bool $detailed
@return @see Client::sendRequest | entailment |
public function updateCollectorResponse($collectorId, $responseId, array $data = [])
{
return $this->sendRequest(
$this->createRequest('PATCH', sprintf('collectors/%s/responses/%s', $collectorId, $responseId), [], $data)
);
} | updateCollectorResponse
@param int $collectorId
@param int $responseId
@param array $data - See API docs for available fields
@return @see Client::sendRequest | entailment |
public function replaceCollectorResponse($collectorId, $responseId, array $data = [])
{
return $this->sendRequest(
$this->createRequest('PUT', sprintf('collectors/%s/responses/%s', $collectorId, $responseId), [], $data)
);
} | replaceCollectorResponse
@param int $collectorId
@param int $responseId
@param array $data - See API docs for available fields
@return @see Client::sendRequest | entailment |
public function deleteCollectorResponse($collectorId, $responseId)
{
return $this->sendRequest(
$this->createRequest('DELETE', sprintf('collectors/%s/responses/%s', $collectorId, $responseId))
);
} | deleteCollectorResponse
@param int $collectorId
@param int $responseId
@return @see Client::sendRequest | entailment |
public function getSurveyResponse($surveyId, $responseId, $detailed = false, array $filters = [])
{
if ($detailed) {
return $this->sendRequest(
$this->createRequest('GET', sprintf('surveys/%s/responses/%s/details', $surveyId, $responseId), [
'query' => $filters
])
);
} else {
return $this->sendRequest(
$this->createRequest('GET', sprintf('surveys/%s/responses/%s', $surveyId, $responseId), [
'query' => $filters
])
);
}
} | getSurveyResponse
@param int $collectorId
@param int $responseId
@param bool $detailed
@return @see Client::sendRequest | entailment |
public function updateSurveyResponse($surveyId, $responseId, array $data = [])
{
return $this->sendRequest(
$this->createRequest('PATCH', sprintf('surveys/%s/responses/%s', $surveyId, $responseId), [], $data)
);
} | updateSurveyResponse
@param int $surveyId
@param int $responseId
@param array $data - See API docs for available fields
@return @see Client::sendRequest | entailment |
public function replaceSurveyResponse($surveyId, $responseId, array $data = [])
{
return $this->sendRequest(
$this->createRequest('PUT', sprintf('surveys/%s/responses/%s', $surveyId, $responseId), [], $data)
);
} | replaceSurveyResponse
@param int $surveyId
@param int $responseId
@param array $data - See API docs for available fields
@return @see Client::sendRequest | entailment |
public function deleteSurveyResponse($surveyId, $responseId)
{
return $this->sendRequest(
$this->createRequest('DELETE', sprintf('surveys/%s/responses/%s', $surveyId, $responseId))
);
} | deleteSurveyResponse
@param int $surveyId
@param int $responseId
@return @see Client::sendRequest | entailment |
protected function get($key)
{
$this->checkForNonEmptyKey($key);
if (!isset($this->getBackEndUser()->uc[self::PHPUNIT_SETTINGS_KEY][$key])) {
return null;
}
return $this->getBackEndUser()->uc[self::PHPUNIT_SETTINGS_KEY][$key];
} | Returns the value stored for the key $key.
@param string $key the key of the value to retrieve, must not be empty
@return mixed the value for the given key, will be NULL if there is no value for the given key | entailment |
public function set($key, $value)
{
$this->checkForNonEmptyKey($key);
$this->getBackEndUser()->uc[self::PHPUNIT_SETTINGS_KEY][$key] = $value;
$this->getBackEndUser()->writeUC();
} | Sets the value for the key $key.
@param string $key the key of the value to set, must not be empty
@param mixed $value the value to set
@return void | entailment |
public function isActive($key)
{
switch ($key) {
case 'codeCoverage':
$isActive = extension_loaded('xdebug');
break;
case 'runSeleniumTests':
$isActive = $this->seleniumService->isSeleniumServerRunning();
break;
case 'thisSettingIsAlwaysInactive':
$isActive = false;
break;
default:
// If the given setting is not covered by any of the cases, it should be considered active.
$isActive = true;
}
return $isActive;
} | Returns whether the given setting is active/allowed.
@param string $key
@return bool | entailment |
public function getMetadataFor($value)
{
$metaData = new ClassMetadata(get_class($value));
$fullClass = $this->getClassValidator($value);
if (empty($fullClass)) {
return $metaData;
}
/** @var $loader LoaderMetadataInterface */
$loader = new $fullClass();
$loader->load($metaData);
if ($this->listener) {
$this->listener->onLoaded($value, $metaData);
}
return $metaData;
} | Returns the metadata for the given value.
@param mixed $value Some value
@return MetadataInterface The metadata for the value
@throws NoSuchMetadataException If no metadata exists for the given value | entailment |
private function getClassValidator($value)
{
$classModel = get_class($value);
$className = substr(strrchr($classModel, '\\'), 1);
$fullClass = 'Greenter\\Validator\\Loader\\'.$className.'Loader';
if (!class_exists($fullClass)) {
return false;
}
return $fullClass;
} | @param $value
@return bool|string | entailment |
protected function renderTag($tagName, array $attributes = [], $content = '')
{
if (empty($tagName)) {
throw new \InvalidArgumentException('$tagName must not be NULL or empty.', 1343763729);
}
$output = '<' . htmlspecialchars($tagName);
foreach ($attributes as $key => $value) {
if (!is_string($key) || $key === '') {
throw new \InvalidArgumentException('Attribute key must not be empty.', 1448657422);
}
$output .= ' ' . htmlspecialchars($key) . '="' . htmlspecialchars($value) . '"';
}
if ($content !== '') {
$output .= '>' . $content . '</' . htmlspecialchars($tagName) . '>';
} else {
$output .= ' />';
}
return $output;
} | Renders any HTML tag with its own parameter either around some content.
If the content is empty, the tag gets rendered as a self-closing tag.
@param string $tagName
@param string[] $attributes
use HTML attribute as key, must not be empty
use attribute value as array value, might be empty
@param string $content
@return string the rendered HTML tag
@throws \InvalidArgumentException if the given tagName is empty | entailment |
protected function getPublicHolidays($year)
{
$timezone = $this->timezone;
/** @var Holiday[] $data */
$data = array();
$easter = $this->getEaster($year);
$data[] = new Holiday($easter, "Karfreitag", $timezone);
$data[0]->modify("-2 days");
$data[] = new Holiday($easter, "Ostermontag", $timezone);
$data[1]->modify("+1 day");
$data[] = new Holiday($easter, "Christi Himmelfahrt", $timezone);
$data[2]->modify("+39 days");
$data[] = new Holiday($easter, "Pfingstmontag", $timezone);
$data[3]->modify("+50 days");
$data[] = new Holiday("01.01." . $year, "Neujahrstag", $timezone);
$data[] = new Holiday("01.05." . $year, "Tag der Arbeit", $timezone);
$data[] = new Holiday("03.10." . $year, "Tag der deutschen Einheit", $timezone);
$data[] = new Holiday("25.12." . $year, "1. Weihnachtsfeiertag", $timezone);
$data[] = new Holiday("26.12." . $year, "2. Weihnachtsfeiertag", $timezone);
return $data;
} | Get _public holidays_ only. Not in all states of Germany days from getSpecial() are public holidays.
Moved to dedicated method in order to retain compatibility of getHolidays() with existing code.
@param int $year Year
@return Holiday[] | entailment |
public function updateContactList($contactListId, array $data = [])
{
return $this->sendRequest(
$this->createRequest('PATCH', sprintf('contact_lists/%d', $contactListId), [], $data)
);
} | updateContactList
@param int $contactListId
@param array $data - See API docs for available fields
@return @see Client::sendRequest | entailment |
public function replaceContactList($contactListId, array $data = [])
{
return $this->sendRequest(
$this->createRequest('PUT', sprintf('contact_lists/%d', $contactListId), [], $data)
);
} | replaceContactList
@param int $contactListId
@param array $data - See API docs for available fields
@return @see Client::sendRequest | entailment |
public function mergeContactList($contactListId, $intoContactListId)
{
return $this->sendRequest(
$this->createRequest('POST', sprintf('contact_lists/%d/merge', $contactListId), [], [ 'list_id' => $intoContactListId ])
);
} | mergeContactList
@param int $contactListId
@param int $intoContactListId
@return @see Client::sendRequest | entailment |
public function getContactsInList($contactListId, array $filters = [])
{
return $this->sendRequest(
$this->createRequest('GET', sprintf('contact_lists/%d/contacts', $contactListId), [
'query' => $filters
])
);
} | getContactsInList
@param int $contactListId
@param array $filters - Available filters: page, per_page, status, sort_by, sort_order, search_by
@return @see Client::sendRequest | entailment |
public function createContactInList($contactListId, array $data = [])
{
return $this->sendRequest(
$this->createRequest('POST', sprintf('contact_lists/%d/contacts', $contactListId), [], $data)
);
} | createContactInList
@param int $contactListId
@param array $data - See API docs for available fields
@return @see Client::sendRequest | entailment |
public function createContactsInList($contactListId, array $data = [])
{
return $this->sendRequest(
$this->createRequest('POST', sprintf('contact_lists/%d/contacts/bulk', $contactListId), [], $data)
);
} | createContactsInList
@param int $contactListId
@param array $data - See API docs for available fields
@return @see Client::sendRequest | entailment |
public function updateContact($contactId, array $data = [])
{
return $this->sendRequest(
$this->createRequest('PATCH', sprintf('contacts/%d', $contactId), [], $data)
);
} | updateContact
@param int $contactId
@param array $data - See API docs for available fields
@return @see Client::sendRequest | entailment |
public function replaceContact($contactId, array $data = [])
{
return $this->sendRequest(
$this->createRequest('PUT', sprintf('contacts/%d', $contactId), [], $data)
);
} | replaceContact
@param int $contactId
@param array $data - See API docs for available fields
@return @see Client::sendRequest | entailment |
public function updateContactField($contactFieldId, array $data = [])
{
return $this->sendRequest(
$this->createRequest('PATCH', sprintf('contact_fields/%d', $contactFieldId), [], $data)
);
} | updateContactField
@param int $contactFieldId
@param array $data - See API docs for available fields
@return @see Client::sendRequest | entailment |
public function generate(string $class, \ReflectionClass $sourceClass, BindInterface $bind) : string
{
$methods = $this->codeGenMethod->getMethods($sourceClass, $bind);
$classStmt = $this->buildClass($class, $sourceClass, $methods);
$classStmt = $this->addClassDocComment($classStmt, $sourceClass);
$declareStmt = $this->getPhpFileStmt($sourceClass);
return $this->printer->prettyPrintFile(array_merge($declareStmt, [$classStmt]));
} | {@inheritdoc} | entailment |
private function getPhpFileStmt(\ReflectionClass $class) : array
{
$traverser = new NodeTraverser();
$visitor = new CodeGenVisitor();
$traverser->addVisitor($visitor);
$fileName = $class->getFileName();
if (is_bool($fileName)) {
throw new InvalidSourceClassException(get_class($class));
}
$file = file_get_contents($fileName);
if ($file === false) {
throw new \RuntimeException($fileName); // @codeCoverageIgnore
}
$stmts = $this->parser->parse($file);
if (is_array($stmts)) {
$traverser->traverse($stmts);
}
return $visitor();
} | Return "declare()" and "use" statement code
@return Stmt[] | entailment |
private function getClass(BuilderFactory $factory, string $newClassName, \ReflectionClass $class) : Builder
{
$parentClass = $class->name;
$builder = $factory
->class($newClassName)
->extend($parentClass)
->implement('Ray\Aop\WeavedInterface');
$builder = $this->addInterceptorProp($builder);
return $this->addSerialisedAnnotationProp($builder, $class);
} | Return class statement | entailment |
private function addClassDocComment(Class_ $node, \ReflectionClass $class) : Class_
{
$docComment = $class->getDocComment();
if ($docComment) {
$node->setDocComment(new Doc($docComment));
}
return $node;
} | Add class doc comment | entailment |
private function addSerialisedAnnotationProp(Builder $builder, \ReflectionClass $class) : Builder
{
$builder->addStmt(
$this->factory
->property('methodAnnotations')
->setDefault($this->getMethodAnnotations($class))
->makePublic()
)->addStmt(
$this->factory
->property('classAnnotations')
->setDefault($this->getClassAnnotation($class))
->makePublic()
);
return $builder;
} | Add serialised | entailment |
public function bind(string $class, array $pointcuts) : BindInterface
{
$pointcuts = $this->getAnnotationPointcuts($pointcuts);
$this->annotatedMethodsMatch(new \ReflectionClass($class), $pointcuts);
return $this;
} | {@inheritdoc}
@throws \ReflectionException | entailment |
public function bindInterceptors(string $method, array $interceptors) : BindInterface
{
$this->bindings[$method] = ! array_key_exists($method, $this->bindings) ? $interceptors : array_merge(
$this->bindings[$method],
$interceptors
);
return $this;
} | {@inheritdoc} | entailment |
public function toString($salt) : string
{
unset($salt);
return strtr(rtrim(base64_encode(pack('H*', sprintf('%u', crc32(serialize($this->bindings))))), '='), '+/', '-_');
} | {@inheritdoc} | entailment |
public function getAnnotationPointcuts(array &$pointcuts) : array
{
$keyPointcuts = [];
foreach ($pointcuts as $key => $pointcut) {
if ($pointcut->methodMatcher instanceof AnnotatedMatcher) {
$key = $pointcut->methodMatcher->annotation;
}
$keyPointcuts[$key] = $pointcut;
}
return $keyPointcuts;
} | @param Pointcut[] $pointcuts
@return Pointcut[] | entailment |
public function isSeleniumServerRunning()
{
$seleniumServerIsRunning = false;
$errorLevel = 0;
$errorMessage = '';
$timeout = 1;
$socket = @fsockopen(
$this->getSeleniumHost(),
$this->getSeleniumPort(),
$errorLevel,
$errorMessage,
$timeout
);
if ($socket !== false) {
$seleniumServerIsRunning = true;
fclose($socket);
}
return $seleniumServerIsRunning;
} | Tests if the Selenium RC server is running.
@return bool TRUE if the server is reachable by opening a socket, FALSE otherwise | entailment |
public function getSeleniumBrowserUrl()
{
return $this->extensionSettingsService->hasString('selenium_browserurl')
? $this->extensionSettingsService->getAsString('selenium_browserurl')
: rtrim(GeneralUtility::getIndpEnv('TYPO3_SITE_URL'), '/');
} | Returns the configured Selenium RC browser starting URL.
This functions returns the TYPO3_SITE_URL if no URL is configured.
@return string Selenium RC Browser URL, will not be empty | entailment |
public function getMethod() : ReflectionMethod
{
if ($this->object instanceof WeavedInterface) {
$class = (new \ReflectionObject($this->object))->getParentClass();
if (! $class instanceof \ReflectionClass) {
throw new \LogicException; // @codeCoverageIgnore
}
$method = new ReflectionMethod($class->name, $this->method);
$method->setObject($this->object, $method);
return $method;
}
return new ReflectionMethod($this->object, $this->method);
} | {@inheritdoc}
@throws \ReflectionException | entailment |
public function getNamedArguments() : \ArrayObject
{
$args = $this->getArguments();
$paramas = $this->getMethod()->getParameters();
$namedParams = new \ArrayObject;
foreach ($paramas as $param) {
$namedParams[$param->getName()] = $args[$param->getPosition()];
}
return $namedParams;
} | {@inheritdoc}
@throws \ReflectionException | entailment |
public function proceed()
{
if ($this->interceptors === [] && \is_callable($this->callable)) {
return call_user_func_array($this->callable, (array) $this->arguments);
}
$interceptor = array_shift($this->interceptors);
if ($interceptor instanceof MethodInterceptor) {
return $interceptor->invoke($this);
}
throw new \LogicException;
} | {@inheritdoc} | entailment |
public function matchesClass(\ReflectionClass $class, array $arguments) : bool
{
$isAnd = true;
foreach ($arguments as $matcher) {
/* @var $matcher AbstractMatcher */
$isAnd = $isAnd && $matcher->matchesClass($class, $matcher->getArguments());
}
return $isAnd;
} | {@inheritdoc} | entailment |
public function matchesMethod(\ReflectionMethod $method, array $arguments) : bool
{
$isAnd = true;
foreach ($arguments as $matcher) {
/* @var $matcher AbstractMatcher */
$isAnd = $isAnd && $matcher->matchesMethod($method, $matcher->getArguments());
}
return $isAnd;
} | {@inheritdoc} | entailment |
public function matchesClass(\ReflectionClass $class, array $arguments) : bool
{
foreach ($arguments as $matcher) {
/* @var $matcher AbstractMatcher */
$isMatch = $matcher->matchesClass($class, $matcher->getArguments());
if ($isMatch === true) {
return true;
}
}
return false;
} | {@inheritdoc} | entailment |
public function matchesMethod(\ReflectionMethod $method, array $arguments) : bool
{
foreach ($arguments as $matcher) {
/* @var $matcher AbstractMatcher */
$isMatch = $matcher->matchesMethod($method, $matcher->getArguments());
if ($isMatch === true) {
return true;
}
}
return false;
} | {@inheritdoc} | entailment |
protected function get($key)
{
$this->checkForNonEmptyKey($key);
if (!$this->settingsHaveBeenRetrieved) {
$this->retrieveSettings();
}
if (!isset($this->cachedSettings[$key])) {
return null;
}
return $this->cachedSettings[$key];
} | Returns the value stored for the key $key.
@param string $key the key of the value to retrieve, must not be empty
@return mixed the value for the given key, will be NULL if there is no value for the given key | entailment |
protected function retrieveSettings()
{
if (isset($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['phpunit'])) {
$this->cachedSettings = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['phpunit']);
} else {
$this->cachedSettings = [];
}
$this->settingsHaveBeenRetrieved = true;
} | Retrieves the EM configuration for the PHPUnit extension.
@return void | entailment |
public function getAsArray($key)
{
$rawValue = $this->get($key);
if (!is_array($rawValue)) {
$rawValue = [];
}
return $rawValue;
} | Returns the array value stored for the key $key.
@param string $key the key of the value to retrieve, must not be empty
@return array the value for the given key, will be empty if there is no array value for the given key | entailment |
public function matchesClass(\ReflectionClass $class, array $arguments) : bool
{
list($matcher) = $arguments;
/* @var $matcher AbstractMatcher */
return ! $matcher->matchesClass($class, $matcher->getArguments());
} | {@inheritdoc} | entailment |
public function matchesMethod(\ReflectionMethod $method, array $arguments) : bool
{
list($matcher) = $arguments;
/* @var $matcher AbstractMatcher */
return ! $matcher->matchesMethod($method, [$arguments]);
} | {@inheritdoc} | entailment |
public function getGraceTtl()
{
if (!isset($this->graceTtl)) {
$this->graceTtl = self::DEFAULT_GRACE_TTL;
}
return $this->graceTtl;
} | Gets grace period
@return int | entailment |
public function isSuccess()
{
$data = $this->getData();
if (!$data) {
return false;
}
if (isset($data['error'])) {
return false;
}
return true;
} | isSuccess
@return bool | entailment |
private function getMethod(\ReflectionMethod $method)
{
$methodStmt = $this->factory->method($method->name);
$params = $method->getParameters();
foreach ($params as $param) {
$methodStmt = $this->getMethodStatement($param, $methodStmt);
}
$returnType = $method->getReturnType();
if ($returnType instanceof \ReflectionType) {
$this->setReturnType($returnType, $methodStmt);
}
$methodInsideStatements = $this->getMethodInsideStatement($method);
$methodStmt->addStmts($methodInsideStatements);
return $this->addMethodDocComment($methodStmt, $method);
} | Return method statement
@return \PhpParser\Node\Stmt\ClassMethod | entailment |
private function getMethodStatement(\ReflectionParameter $param, Method $methodStmt) : Method
{
/* @var $paramStmt Param */
$paramStmt = $this->factory->param($param->name);
/* @var $param \ReflectionParameter */
$this->setParameterType($param, $paramStmt);
$this->setDefault($param, $paramStmt);
$methodStmt->addParam($paramStmt);
return $methodStmt;
} | Return parameter reflection | entailment |
public function createSurveyFromTemplate($templateId, array $data = [])
{
return $this->sendRequest(
$this->createRequest('POST', 'surveys', [], array_merge($data, [ 'from_template_id' => $templateId ]))
);
} | createSurveyFromTemplate - Create a new survey from an existing template
@param int $templateId - See template ID to use
@param array $data - See API docs for available fields
@return @see Client::sendRequest | entailment |
public function createSurveyFromExisting($surveyId, array $data = [])
{
return $this->sendRequest(
$this->createRequest('POST', 'surveys', [], array_merge($data, [ 'from_survey_id' => $surveyId ]))
);
} | createSurveyFromTemplate - Create a new survey from an existing survey
@param int $surveyId - See survey ID to use
@param array $data - See API docs for available fields
@return @see Client::sendRequest | entailment |
public function getSurvey($surveyId, $includePages = false)
{
if ($includePages) {
return $this->sendRequest(
$this->createRequest('GET', sprintf('surveys/%d/details', $surveyId))
);
} else {
return $this->sendRequest(
$this->createRequest('GET', sprintf('surveys/%d', $surveyId))
);
}
} | getSurvey - Get information on a survey
@param int $surveyId - See survey ID to use
@param bool $includePages - Include page details or not
@return @see Client::sendRequest | entailment |
public function updateSurvey($surveyId, array $data = [])
{
return $this->sendRequest(
$this->createRequest('PATCH', sprintf('surveys/%d', $surveyId), [], $data)
);
} | updateSurvey - Updates a survey
@param int $surveyId - The survey to update
@param array $data - See API docs for available fields
@return @see Client::sendRequest | entailment |
public function replaceSurvey($surveyId, array $data = [])
{
return $this->sendRequest(
$this->createRequest('PUT', sprintf('surveys/%d', $surveyId), [], $data)
);
} | replaceSurvey - Replaces a survey
@param int $surveyId - The survey to replace
@param array $data - See API docs for available fields
@return @see Client::sendRequest | entailment |
public function getSurveyPages($surveyId, array $filters = [])
{
return $this->sendRequest(
$this->createRequest('GET', sprintf('surveys/%d/pages', $surveyId), [
'query' => $filters
])
);
} | getSurveyPages - Gets all pages for a given survey
@param int $surveyId - The survey to get the pages from
@param array $filters - Available filters: page, per_page
@return @see Client::sendRequest | entailment |
public function createSurveyPage($surveyId, array $data = [])
{
return $this->sendRequest(
$this->createRequest('POST', sprintf('surveys/%d/pages', $surveyId), [], $data)
);
} | createSurveyPage - Creates a new survey page
@param int $surveyId - The survey to get the pages from
@param array $data - See API docs for available fields
@return @see Client::sendRequest | entailment |
public function getSurveyPage($surveyId, $pageId)
{
return $this->sendRequest(
$this->createRequest('GET', sprintf('surveys/%d/pages/%d', $surveyId, $pageId))
);
} | getSurveyPage - Get a single survey page
@param int $surveyId - The survey to get the page from
@param int $pageId - The page to get
@return @see Client::sendRequest | entailment |
public function updateSurveyPage($surveyId, $pageId, array $data = [])
{
return $this->sendRequest(
$this->createRequest('PATCH', sprintf('surveys/%d/pages/%d', $surveyId, $pageId), [], $data)
);
} | updateSurveyPage - Updates a survey page
@param int $surveyId - The survey to get the page from
@param int $pageId - The page to update
@param array $data - See API docs for available fields
@return @see Client::sendRequest | entailment |
public function replaceSurveyPage($surveyId, $pageId, array $data = [])
{
return $this->sendRequest(
$this->createRequest('PUT', sprintf('surveys/%d/pages/%d', $surveyId, $pageId), [], $data)
);
} | replaceSurveyPage - Replaces a survey page
@param int $surveyId - The survey to get the page from
@param int $pageId - The page to replace
@param array $data - See API docs for available fields
@return @see Client::sendRequest | entailment |
public function deleteSurveyPage($surveyId, $pageId)
{
return $this->sendRequest(
$this->createRequest('DELETE', sprintf('surveys/%d/pages/%d', $surveyId, $pageId))
);
} | deleteSurveyPage - Delete a survey page
@param int $surveyId - The survey to get the page from
@param int $pageId - The page to delete
@return @see Client::sendRequest | entailment |
public function getSurveyPageQuestions($surveyId, $pageId, array $filters = [])
{
return $this->sendRequest(
$this->createRequest('GET', sprintf('surveys/%d/pages/%d/questions', $surveyId, $pageId), [
'query' => $filters
])
);
} | getSurveyPageQuestions - Get questions for a given survey page
@param int $surveyId - The survey to get the page from
@param int $pageId - The page to get the qeustions from
@param array $filters - Available filters: page, per_page
@return @see Client::sendRequest | entailment |
public function createSurveyPageQuestion($surveyId, $pageId, array $data = [])
{
return $this->sendRequest(
$this->createRequest('POST', sprintf('surveys/%d/pages/%d/questions', $surveyId, $pageId), [], $data)
);
} | createSurveyPageQuestion - Create a questions for a given survey page
@param int $surveyId - The survey to get the page from
@param int $pageId - The page to add the question to
@param array $data - See API docs for available fields
@return @see Client::sendRequest | entailment |
public function getSurveyPageQuestion($surveyId, $pageId, $questionId)
{
return $this->sendRequest(
$this->createRequest('GET', sprintf('surveys/%d/pages/%d/questions/%d', $surveyId, $pageId, $questionId))
);
} | getSurveyPageQuestion - Get a single survey page question
@param int $surveyId - The survey to get the page from
@param int $pageId - The page the question is on
@param int $questionId - The question to get
@return @see Client::sendRequest | entailment |
public function updateSurveyPageQuestion($surveyId, $pageId, $questionId, array $data = [])
{
return $this->sendRequest(
$this->createRequest('PATCH', sprintf('surveys/%d/pages/%d/questions/%d', $surveyId, $pageId, $questionId), [], $data)
);
} | updateSurveyPageQuestion - Update a survey page question
@param int $surveyId - The survey to get the page from
@param int $pageId - The page the question is on
@param int $questionId - The question to update
@param array $data - See API docs for available fields
@return @see Client::sendRequest | entailment |
public function deleteSurveyPageQuestion($surveyId, $pageId, $questionId)
{
return $this->sendRequest(
$this->createRequest('DELETE', sprintf('surveys/%d/pages/%d/questions/%d', $surveyId, $pageId, $questionId))
);
} | deleteSurveyPageQuestion - Delete a survey page question
@param int $surveyId - The survey to get the page from
@param int $pageId - The page the question is on
@param int $questionId - The question to delete
@return @see Client::sendRequest | entailment |
public function usersGet(array $ids = [], AccessToken $token = null, array $params = [])
{
if (empty($ids) && !$token) {
throw new \InvalidArgumentException('Some of parameters usersIds OR access_token are required');
}
$default = [
'user_ids' => implode(',', $ids),
'fields' => $this->userFields,
'access_token' => $token ? $token->getToken() : null,
'v' => $this->version,
'lang' => $this->language
];
$params = array_merge($default, $params);
$query = $this->buildQueryString($params);
$url = "$this->baseUri/users.get?$query";
$response = $this->getResponse($this->createRequest(static::METHOD_GET, $url, $token, []))['response'];
$users = !empty($response['items']) ? $response['items'] : $response;
$array2user = function ($userData) {
return new User($userData);
};
return array_map($array2user, $users);
} | @see https://vk.com/dev/users.get
@param integer[] $ids
@param AccessToken|null $token Current user if empty
@param array $params
@return User[] | entailment |
public function friendsGet($userId, AccessToken $token = null, array $params = [])
{
$default = [
'user_id' => $userId,
'fields' => $this->userFields,
'access_token' => $token ? $token->getToken() : null,
'v' => $this->version,
'lang' => $this->language
];
$params = array_merge($default, $params);
$query = $this->buildQueryString($params);
$url = "$this->baseUri/friends.get?$query";
$response = $this->getResponse($this->createRequest(static::METHOD_GET, $url, $token, []))['response'];
$friends = !empty($response['items']) ? $response['items'] : $response;
$array2friend = function ($friendData) {
if (is_numeric($friendData)) {
$friendData = ['id' => $friendData];
}
return new User($friendData);
};
return array_map($array2friend, $friends);
} | @see https://vk.com/dev/friends.get
@param integer $userId
@param AccessToken|null $token
@param array $params
@return User[] | entailment |
protected function getEaster($year)
{
$easter = new \DateTime('now', $this->timezone);
$easter->setDate($year, 3, 21);
$easter->setTime(0, 0, 0);
$easter->modify('+' . \easter_days($year) . 'days');
return $easter;
} | Provides a DateTime object that represents easter sunday for this year.
The DateTime object is always set to the current default timezone and
not UTC and time is set 0:00.
@param int $year The year for which to calculate the easter sunday date.
@return \DateTime
TODO: add timezone calculation | entailment |
public function between(\DateTime $start, \DateTime $end)
{
// Comparing DateTime also looks at the time. So we need to make sure the time is 0,
// but don't modify the original referenced DateTime parameters
$start = clone $start;
$end = clone $end;
$start->setTime(0, 0, 0);
$end->setTime(0, 0, 0);
$startyear = (int) $start->format("Y");
$endyear = (int) $end->format("Y");
$holidays = array();
for ($y = $startyear; $y <= $endyear; $y++) {
$holidays = array_merge($holidays, $this->getHolidays($y));
}
return array_filter($holidays,
function(\DateTime $dt) use ($start, $end) {
return $dt >= $start && $dt <= $end;
});
} | Returns all holidays in the given time period.
@param \DateTime $start The start date
@param \DateTime $end The end date
@return array | entailment |
public function newInstance(string $class, array $args, BindInterface $bind)
{
$compiledClass = $this->compile($class, $bind);
$instance = (new ReflectionClass($compiledClass))->newInstanceArgs($args);
$instance->bindings = $bind->getBindings();
return $instance;
} | {@inheritdoc}
@throws \ReflectionException | entailment |
public function compile(string $class, BindInterface $bind) : string
{
if ($this->hasNoBinding($class, $bind)) {
return $class;
}
$newClass = $this->getNewClassName($class, $bind);
if (class_exists($newClass)) {
return $newClass;
}
$file = "{$this->classDir}/{$newClass}.php";
if (file_exists($file)) {
/** @noinspection UntrustedInclusionInspection */
/** @noinspection PhpIncludeInspection */
include $file;
return $newClass;
}
$this->includeGeneratedCode($newClass, new ReflectionClass($class), $file, $bind);
return $newClass;
} | {@inheritdoc}
@throws \ReflectionException | entailment |
public function analyzeSurveyQuestions($benchmarkBundleId, array $questionids, array $filters = [])
{
return $this->sendRequest(
$this->createRequest('GET', sprintf('benchmark_bundles/%d/analyze', $benchmarkBundleId). [
'query' => array_merge($filters, [
'question_ids' => implode(',', $questionIds)
])
])
);
} | analyzeSurveyQuestions
@param int $benchmarkBundleId
@param int $questionids
@param array $filters - Available filters: percentile_start, percentile_end
@return @see Client::sendRequest | entailment |
public function getQuestionBenchmarkResult($surveyId, $pageId, $questionId, array $filters = [])
{
return $this->sendRequest(
$this->createRequest('GET', sprintf('surveys/%d/pages/%d/questions/%d/benchmark', $surveyId, $pageId, $questionId), [
'query' => $filters
])
);
} | getQuestionBenchmarkResult
@param int $surveyId
@param int $pageId
@param int $questionids
@param array $filters - Available filters: percentile_start, percentile_end
@return @see Client::sendRequest | entailment |
public function getToken($code)
{
$request = new Request('POST', 'token', [], http_build_query([
'redirect_uri' => $this->getRedirectUri(),
'client_id' => $this->getClientId(),
'client_secret' => $this->getClientSecret(),
'grant_type' => 'authorization_code',
'code' => $code
]));
try {
$response = $this->getHttpClient()->send($request);
} catch (\Exception $e) {
throw new SurveyMonkeyApiException($e->getMessage(), $e->getCode(), $e);
}
if (!$response->hasHeader('content-type') || !preg_match('/application\/json/i', $response->getHeader('content-type')[0])) {
throw new SurveyMonkeyApiException(spritnf('Response expected to be a JSON response. Received %s', $response->getHeader('content-type')[0]));
}
return json_decode($response->getBody(), true);
} | getToken
@param string $code - Code received from redirect from SurveyMonkey after pointing the user to getAuthorizeUrl()
@return array | entailment |
private function createRequest($method, $uri, array $options = [], $body = null)
{
if (empty($body)) {
// Empty arrays and NULL data inputs both need casting to an empty JSON object.
// See https://stackoverflow.com/a/41150809/2803757
$bodyString = '{}';
} elseif (is_array($body)) {
$bodyString = json_encode($body);
}
$ret = new Request($method, $uri, $options, $bodyString);
if (isset($options['query'])) {
$uri = $ret->getUri()->withQuery(is_array($options['query']) ? http_build_query($options['query']) : $options['query']);
return $ret->withUri($uri, true);
}
return $ret;
} | createRequest
@param string $method
@param string $uri
@param array $options Guzzle compatible request options
@param array|null $body Request body if applicable, using associative arrays for named properties & numeric
arrays for array data types.
@return RequestInterface | entailment |
public function matchesClass(\ReflectionClass $class, array $arguments) : bool
{
list($annotation) = $arguments;
$annotation = $this->reader->getClassAnnotation($class, $annotation);
return $annotation ? true : false;
} | {@inheritdoc} | entailment |
public function matchesMethod(\ReflectionMethod $method, array $arguments) : bool
{
list($annotation) = $arguments;
$annotation = $this->reader->getMethodAnnotation($method, $annotation);
return $annotation ? true : false;
} | {@inheritdoc} | entailment |
protected function _list_tables($prefix_limit = FALSE)
{
$sql = 'SELECT "NAME" FROM "SQLITE_MASTER" WHERE "TYPE" = \'table\'';
if ($prefix_limit === TRUE && $this->dbprefix !== '')
{
return $sql.' AND "NAME" LIKE \''.$this->escape_like_str($this->dbprefix)."%' "
.sprintf($this->_like_escape_str, $this->_like_escape_chr);
}
return $sql;
} | Show table query
Generates a platform-specific query string so that the table names can be fetched
@param bool $prefix_limit
@return string | entailment |
public function list_fields($table)
{
// Is there a cached result?
if (isset($this->data_cache['field_names'][$table]))
{
return $this->data_cache['field_names'][$table];
}
if (($result = $this->query('PRAGMA TABLE_INFO('.$this->protect_identifiers($table, TRUE, NULL, FALSE).')')) === FALSE)
{
return FALSE;
}
$this->data_cache['field_names'][$table] = array();
foreach ($result->result_array() as $row)
{
$this->data_cache['field_names'][$table][] = $row['name'];
}
return $this->data_cache['field_names'][$table];
} | Fetch Field Names
@param string $table Table name
@return array | entailment |
public function field_data($table)
{
if (($query = $this->query('PRAGMA TABLE_INFO('.$this->protect_identifiers($table, TRUE, NULL, FALSE).')')) === FALSE)
{
return FALSE;
}
$query = $query->result_array();
if (empty($query))
{
return FALSE;
}
$retval = array();
for ($i = 0, $c = count($query); $i < $c; $i++)
{
$retval[$i] = new stdClass();
$retval[$i]->name = $query[$i]['name'];
$retval[$i]->type = $query[$i]['type'];
$retval[$i]->max_length = NULL;
$retval[$i]->default = $query[$i]['dflt_value'];
$retval[$i]->primary_key = isset($query[$i]['pk']) ? (int) $query[$i]['pk'] : 0;
}
return $retval;
} | Returns an object with field data
@param string $table
@return array | entailment |
public function db_connect($persistent = FALSE)
{
$this->options[PDO::ATTR_PERSISTENT] = $persistent;
try
{
return new PDO($this->dsn, $this->username, $this->password, $this->options);
}
catch (PDOException $e)
{
if ($this->db_debug && empty($this->failover))
{
$this->display_error($e->getMessage(), '', TRUE);
}
return FALSE;
}
} | Database connection
@param bool $persistent
@return object | entailment |
public function version()
{
if (isset($this->data_cache['version']))
{
return $this->data_cache['version'];
}
// Not all subdrivers support the getAttribute() method
try
{
return $this->data_cache['version'] = $this->conn_id->getAttribute(PDO::ATTR_SERVER_VERSION);
}
catch (PDOException $e)
{
return parent::version();
}
} | Database version number
@return string | entailment |
protected function _escape_str($str)
{
// Escape the string
$str = $this->conn_id->quote($str);
// If there are duplicated quotes, trim them away
return ($str[0] === "'")
? substr($str, 1, -1)
: $str;
} | Platform-dependant string escape
@param string
@return string | entailment |
public function error()
{
$error = array('code' => '00000', 'message' => '');
$pdo_error = $this->conn_id->errorInfo();
if (empty($pdo_error[0]))
{
return $error;
}
$error['code'] = isset($pdo_error[1]) ? $pdo_error[0].'/'.$pdo_error[1] : $pdo_error[0];
if (isset($pdo_error[2]))
{
$error['message'] = $pdo_error[2];
}
return $error;
} | Error
Returns an array containing code and message of the last
database error that has occured.
@return array | entailment |
protected function _update_batch($table, $values, $index)
{
$ids = array();
foreach ($values as $key => $val)
{
$ids[] = $val[$index];
foreach (array_keys($val) as $field)
{
if ($field !== $index)
{
$final[$field][] = 'WHEN '.$index.' = '.$val[$index].' THEN '.$val[$field];
}
}
}
$cases = '';
foreach ($final as $k => $v)
{
$cases .= $k.' = CASE '."\n";
foreach ($v as $row)
{
$cases .= $row."\n";
}
$cases .= 'ELSE '.$k.' END, ';
}
$this->where($index.' IN('.implode(',', $ids).')', NULL, FALSE);
return 'UPDATE '.$table.' SET '.substr($cases, 0, -2).$this->_compile_wh('qb_where');
} | Update_Batch statement
Generates a platform-specific batch update string from the supplied data
@param string $table Table name
@param array $values Update data
@param string $index WHERE key
@return string | entailment |
protected function _alter_table($alter_type, $table, $field)
{
if ($alter_type === 'CHANGE')
{
$alter_type = 'MODIFY';
}
return parent::_alter_table($alter_type, $table, $field);
} | ALTER TABLE
@param string $alter_type ALTER type
@param string $table Table name
@param mixed $field Column definition
@return string|string[] | entailment |
public function getHttpClient()
{
if (!is_object($this->_httpClient)) {
$this->_httpClient = new Client([
'requestConfig' => [
'options' => [
'timeout' => 30,
]
],
'responseConfig' => [
'format' => Client::FORMAT_JSON
],
]);
}
return $this->_httpClient;
} | 获取Http Client
@return Client | entailment |
public function getToken($forceRefresh = false)
{
$cacheKey = [__CLASS__, 'appId' => Yii::$app->wechat->appId];
if ($forceRefresh || ($accessToken = Yii::$app->wechat->cache->get($cacheKey)) === false) {
$token = $this->getTokenFromServer();
Yii::$app->wechat->cache->set($cacheKey, $token[$this->tokenJsonKey], $token['expires_in'] - 1500);
return $token[$this->tokenJsonKey];
}
return $accessToken;
} | Get token from WeChat API.
@param bool $forceRefresh
@return string
@throws Exception | entailment |
public function setToken($token, $expires = 7200)
{
Yii::$app->wechat->cache->set([__CLASS__, 'appId' => Yii::$app->wechat->appId], $token, $expires - 1500);
return $this;
} | 设置自定义 token.
@param string $token
@param int $expires
@return $this | entailment |
public function getTokenFromServer()
{
$params = ['appid' => Yii::$app->wechat->appId, 'secret' => Yii::$app->wechat->appSecret, 'grant_type' => 'client_credential',];
$response = $this->getHttpClient()->createRequest()
->setUrl(self::API_TOKEN_GET)
->setMethod('GET')
->setData($params)
->send();
if (!$response->isOk || empty($response->data[$this->tokenJsonKey])) {
throw new Exception('Request AccessToken fail. response: ' . $response->content, $response->statusCode);
}
return $response->data;
} | 从微信服务器获取Token
@return array|mixed
@throws Exception | entailment |
public function add(array $buttons, array $matchRule = [])
{
if (!empty($matchRule)) {
return $this->json(self::API_CONDITIONAL_CREATE, [
'button' => $buttons,
'matchrule' => $matchRule,
]);
}
return $this->json(self::API_CREATE,['button' => $buttons]);
} | 添加菜单
@param array $buttons
@param array $matchRule
@return array
@throws \yii\httpclient\Exception | entailment |
public function destroy($menuId = null)
{
if ($menuId !== null) {
return $this->json(self::API_CONDITIONAL_DELETE,['menuid' => $menuId]);
}
return $this->get(self::API_DELETE);
} | Destroy menu.
@param int $menuId
@return array
@throws \yii\httpclient\Exception | entailment |
protected function _alter_table($alter_type, $table, $field)
{
if (in_array($alter_type, array('DROP', 'ADD'), TRUE))
{
return parent::_alter_table($alter_type, $table, $field);
}
$sql = 'ALTER TABLE '.$this->db->escape_identifiers($table);
$sqls = array();
for ($i = 0, $c = count($field); $i < $c; $i++)
{
if ($field[$i]['_literal'] !== FALSE)
{
return FALSE;
}
if (version_compare($this->db->version(), '8', '>=') && isset($field[$i]['type']))
{
$sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name'])
.' TYPE '.$field[$i]['type'].$field[$i]['length'];
}
if ( ! empty($field[$i]['default']))
{
$sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name'])
.' SET DEFAULT '.$field[$i]['default'];
}
if (isset($field[$i]['null']))
{
$sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name'])
.($field[$i]['null'] === TRUE ? ' DROP NOT NULL' : ' SET NOT NULL');
}
if ( ! empty($field[$i]['new_name']))
{
$sqls[] = $sql.' RENAME COLUMN '.$this->db->escape_identifiers($field[$i]['name'])
.' TO '.$this->db->escape_identifiers($field[$i]['new_name']);
}
if ( ! empty($field[$i]['comment']))
{
$sqls[] = 'COMMENT ON COLUMN '
.$this->db->escape_identifiers($table).'.'.$this->db->escape_identifiers($field[$i]['name'])
.' IS '.$field[$i]['comment'];
}
}
return $sqls;
} | ALTER TABLE
@param string $alter_type ALTER type
@param string $table Table name
@param mixed $field Column definition
@return string|string[] | entailment |
protected function _attr_type(&$attributes)
{
// Reset field lenghts for data types that don't support it
if (isset($attributes['CONSTRAINT']) && stripos($attributes['TYPE'], 'int') !== FALSE)
{
$attributes['CONSTRAINT'] = NULL;
}
switch (strtoupper($attributes['TYPE']))
{
case 'TINYINT':
$attributes['TYPE'] = 'SMALLINT';
$attributes['UNSIGNED'] = FALSE;
return;
case 'MEDIUMINT':
$attributes['TYPE'] = 'INTEGER';
$attributes['UNSIGNED'] = FALSE;
return;
default: return;
}
} | Field attribute TYPE
Performs a data type mapping between different databases.
@param array &$attributes
@return void | entailment |
public function db_connect($persistent = FALSE)
{
$this->conn_id = ($persistent)
? mssql_pconnect($this->hostname, $this->username, $this->password)
: mssql_connect($this->hostname, $this->username, $this->password);
if ( ! $this->conn_id)
{
return FALSE;
}
// ----------------------------------------------------------------
// Select the DB... assuming a database name is specified in the config file
if ($this->database !== '' && ! $this->db_select())
{
return ($this->db_debug === TRUE)
? $this->display_error('db_unable_to_select', $this->database)
: FALSE;
}
// Determine how identifiers are escaped
$query = $this->query('SELECT CASE WHEN (@@OPTIONS | 256) = @@OPTIONS THEN 1 ELSE 0 END AS qi');
$query = $query->row_array();
$this->_quoted_identifier = empty($query) ? FALSE : (bool) $query['qi'];
$this->_escape_char = ($this->_quoted_identifier) ? '"' : array('[', ']');
return $this->conn_id;
} | Non-persistent database connection
@param bool $persistent
@return resource | entailment |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.