_id stringlengths 2 7 | title stringlengths 3 151 | partition stringclasses 3
values | text stringlengths 83 13k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q4200 | CNabuXMLSiteTargetSectionLanguageBase.setAttributes | train | protected function setAttributes(SimpleXMLElement $element)
{
$nb_parent = $this->nb_data_object->getTranslatedObject();
if ($nb_parent !== null) {
$nb_language = $nb_parent->getLanguage($this->nb_data_object->getLanguageId());
$element->addAttribute('lang', $nb_language->grantHash(true));
$this->putAttributesFromList($element, array(
'nb_site_target_section_main_image' => 'image'
), false);
}
} | php | {
"resource": ""
} |
q4201 | TNabuDataObjectTreeNode.addChild | train | public function addChild(INabuDataObjectTreeNode $child)
{
$retval = $this->nb_tree_child_list->addItem($child);
$child->setParent($this);
return $retval;
} | php | {
"resource": ""
} |
q4202 | TNabuDataObjectTreeNode.setChild | train | public function setChild(INabuDataObjectTreeNode $child)
{
$this->nb_tree_child_list->setItem($child);
$child->setParent($this);
return $this;
} | php | {
"resource": ""
} |
q4203 | TNabuDataObjectTreeNode.setParent | train | public function setParent(INabuDataObjectTreeNode $parent)
{
$this->nb_tree_parent = $parent;
if ($parent instanceof CNabuDataObject &&
method_exists($parent, 'getId') &&
$this instanceof CNabuDataObject &&
method_exists($this, 'setParentId')
) {
$this->setParentId($parent->getId());
}
return $this;
} | php | {
"resource": ""
} |
q4204 | CNabuHTTPSession.init | train | private function init()
{
$nb_engine = CNabuEngine::getEngine();
$session_name = session_name();
$nb_engine->traceLog("Session Name", $session_name);
if (array_key_exists($session_name, $_GET)) {
$sessid = filter_input(INPUT_GET, $session_name);
if (preg_match('/^[a-zA-Z0-9]{26}$/', $sessid)) {
session_id($sessid);
$nb_engine->traceLog("Session source", "GET");
} else {
$nb_engine->traceLog("Session source", "COOKIE");
}
} else {
$nb_engine->traceLog("Session source", "COOKIE");
}
} | php | {
"resource": ""
} |
q4205 | CNabuHTTPSession.applySecurityRules | train | public function applySecurityRules(bool $secure = false, bool $httponly = false)
{
$nb_engine = CNabuEngine::getEngine();
$attrs = session_get_cookie_params();
session_set_cookie_params(
$attrs['lifetime'],
$attrs['path'],
$attrs['domain'],
$secure || $attrs['secure'],
$httponly || (array_key_exists('httponly', $attrs) && $attrs['httponly'])
);
session_start();
$nb_engine->traceLog("Session ID", session_id());
$this->purgeNonce();
if (isset($_SESSION) && count($_SESSION) > 0) {
foreach ($_SESSION as $value) {
if ($value instanceof INabuDBObject && !$value->isBuiltIn()) {
$value->relinkDB();
}
}
}
} | php | {
"resource": ""
} |
q4206 | CNabuHTTPSession.purgeNonce | train | public function purgeNonce()
{
$nonce_list = $this->getVariable('nonce_list', array());
$new_nonce_list = array();
if (count($nonce_list) > 0) {
$stop_nonce = time() - 1800;
foreach ($nonce_list as $key => $word) {
if (count($word) > 0) {
$this->purgeNonceWord($key, $word, $stop_nonce, $new_nonce_list);
}
}
}
if (count($new_nonce_list) > 0) {
$this->setVariable('nonce_list', $new_nonce_list);
} else {
$this->unsetVariable('nonce_list');
}
} | php | {
"resource": ""
} |
q4207 | CNabuHTTPSession.purgeNonceWord | train | private function purgeNonceWord(string $key, array $word, int $stop_nonce, array &$new_nonce_list)
{
foreach ($word as $nonce) {
if ($nonce['time'] >= $stop_nonce) {
if (!array_key_exists($key, $new_nonce_list)) {
$new_nonce_list[$key] = array();
}
$new_nonce_list[$key][] = $nonce;
}
}
} | php | {
"resource": ""
} |
q4208 | CNabuHTTPSession.unsetVariable | train | public function unsetVariable($name)
{
$retval = false;
if (array_key_exists($name, $_SESSION)) {
unset($_SESSION[$name]);
$retval = true;
}
return $retval;
} | php | {
"resource": ""
} |
q4209 | CNabuHTTPSession.setCookie | train | public function setCookie($name, $value, $expires = null, $path = null, $domain = null, $secure = false, $httponly = false) {
if ($expires !== null) {
setcookie($name, $value, time() + $expires, $path, $domain, $secure, $httponly);
} else {
setcookie($name, $value, 0, $path, $domain, $secure, $httponly);
}
} | php | {
"resource": ""
} |
q4210 | EntityValidator.validateEmbeddedClass | train | public function validateEmbeddedClass($class, $classAnnotations)
{
$check = false;
foreach ($classAnnotations as $annotation) {
if ($annotation instanceof \ProAI\Datamapper\Annotations\Embeddable) {
$check = true;
}
}
if (! $check) {
throw new InvalidArgumentException('Embedded class '.$class.' has no @Embeddable annotation.');
}
} | php | {
"resource": ""
} |
q4211 | EntityValidator.validateName | train | public function validateName($name, $definedClass)
{
if ($name != camel_case($name)) {
throw new Exception('Name "'.$name.'" (defined in class "'.$definedClass.'") is not a camel case name.');
}
return true;
} | php | {
"resource": ""
} |
q4212 | EntityValidator.validatePrimaryKey | train | public function validatePrimaryKey(EntityDefinition $entityMetadata)
{
// check if all tables have exactly one primary key
$countPrimaryKeys = 0;
foreach ($entityMetadata['table']['columns'] as $column) {
if (! empty($column['primary'])) {
$countPrimaryKeys++;
}
}
if ($countPrimaryKeys == 0) {
throw new DomainException('No primary key defined in class ' . $entityMetadata['class'] . '.');
} elseif ($countPrimaryKeys > 1) {
throw new DomainException('No composite primary keys allowed for class ' . $entityMetadata['class'] . '.');
}
} | php | {
"resource": ""
} |
q4213 | EntityValidator.validateTimestamps | train | public function validateTimestamps(EntityDefinition $entityMetadata)
{
$columnNames = [];
// get column names
foreach ($entityMetadata['table']['columns'] as $column) {
$columnNames[] = $column['name'];
}
// get version column names
if (! empty($entityMetadata['versionTable'])) {
foreach ($entityMetadata['versionTable']['columns'] as $column) {
$columnNames[] = $column['name'];
}
}
if (! in_array('created_at', $columnNames) || ! in_array('updated_at', $columnNames)) {
throw new DomainException('@Timestamps annotation defined in class ' . $entityMetadata['class'] . ' requires a $createdAt and an $updatedAt column property.');
}
} | php | {
"resource": ""
} |
q4214 | EntityValidator.validateVersionTable | train | public function validateVersionTable(EntityDefinition $entityMetadata)
{
$columnNames = [];
$countPrimaryKeys = 0;
$versionPrimaryKey = false;
// get column names
foreach ($entityMetadata['table']['columns'] as $column) {
$columnNames[] = $column['name'];
}
if (! in_array('latest_version', $columnNames)) {
throw new DomainException('@Versionable annotation defined in class ' . $entityMetadata['class'] . ' requires a $latestVersion column property.');
}
$columnNames = [];
// get version column names
foreach ($entityMetadata['versionTable']['columns'] as $column) {
$columnNames[] = $column['name'];
if (! empty($column['primary'])) {
$countPrimaryKeys++;
}
if (! empty($column['primary']) && $column['name'] == 'version') {
$versionPrimaryKey = true;
}
}
if (! in_array('version', $columnNames) || ! $versionPrimaryKey) {
throw new DomainException('@Versionable annotation defined in class ' . $entityMetadata['class'] . ' requires a $version property column, which is a primary key.');
}
if ($countPrimaryKeys > 2) {
throw new DomainException('No more than 2 primary keys are allowed for version table in class ' . $entityMetadata['class'] . '.');
}
} | php | {
"resource": ""
} |
q4215 | EntityValidator.validatePivotTables | train | public function validatePivotTables($metadata)
{
$pivotTables = [];
foreach ($metadata as $entityMetadata) {
foreach ($entityMetadata['relations'] as $relationMetadata) {
if (! empty($relationMetadata['pivotTable'])) {
$pivotTables[$entityMetadata['class'].$relationMetadata['relatedEntity']] = $relationMetadata;
if (isset($pivotTables[$relationMetadata['relatedEntity'].$entityMetadata['class']])) {
$relation1 = $pivotTables[$relationMetadata['relatedEntity'].$entityMetadata['class']];
$relation2 = $relationMetadata;
$error = null;
// check name
if ($relation1['pivotTable']['name'] != $relation2['pivotTable']['name']) {
$error = 'Different table names (compared '.$relation1['pivotTable']['name'].' with '.$relation2['pivotTable']['name'].').';
}
// check name
if (! empty(array_diff_key($relation1['pivotTable']['columns'], $relation2['pivotTable']['columns']))) {
$columns1 = implode(', ', array_keys($relation1['pivotTable']['columns']));
$columns2 = implode(', ', array_keys($relation2['pivotTable']['columns']));
$error = 'Different column names (compared '.$columns1.' with '.$columns2.').';
}
if ($error) {
throw new DomainException('Error syncing pivot tables for relations "'.$relation1['name'].'" in "'.$relation2['relatedEntity'].'" and "'.$relation2['name'].'" in "'.$relation1['relatedEntity'].'": '.$error);
}
}
}
}
}
} | php | {
"resource": ""
} |
q4216 | CNabuMediotecaItemLanguageBase.setMediotecaItemId | train | public function setMediotecaItemId(int $nb_medioteca_item_id) : CNabuDataObject
{
if ($nb_medioteca_item_id === null) {
throw new ENabuCoreException(
ENabuCoreException::ERROR_NULL_VALUE_NOT_ALLOWED_IN,
array("\$nb_medioteca_item_id")
);
}
$this->setValue('nb_medioteca_item_id', $nb_medioteca_item_id);
return $this;
} | php | {
"resource": ""
} |
q4217 | CNabuMediotecaItemLanguageBase.setHavePublic | train | public function setHavePublic($have_public) : CNabuDataObject
{
if ($have_public === null) {
throw new ENabuCoreException(
ENabuCoreException::ERROR_NULL_VALUE_NOT_ALLOWED_IN,
array("\$have_public")
);
}
$this->setValue('nb_medioteca_item_lang_have_public', $have_public);
return $this;
} | php | {
"resource": ""
} |
q4218 | CNabuProviderInterfaceFactoryAdapter.discoverInterface | train | protected function discoverInterface() : bool
{
if (!($this->nb_interface instanceof INabuProviderInterface) &&
($nb_manager = $this->nb_descriptor->getManager()) instanceof INabuProviderManager
) {
$this->nb_interface = $this->createInterface($nb_manager, $this->nb_descriptor);
}
return ($this->nb_interface instanceof INabuProviderInterface);
} | php | {
"resource": ""
} |
q4219 | CNabuProviderInterfaceFactoryAdapter.setRequest | train | public function setRequest(CNabuHTTPRequest $nb_request) : CNabuProviderInterfaceFactoryAdapter
{
if ($this->discoverInterface()) {
$this->nb_interface->setRequest($nb_request);
} else {
throw new ENabuProviderException(ENabuProviderException::ERROR_INTERFACE_NOT_SETTED);
}
return $this;
} | php | {
"resource": ""
} |
q4220 | CNabuProviderInterfaceFactoryAdapter.setResponse | train | public function setResponse(CNabuHTTPResponse $nb_response = null) : CNabuProviderInterfaceFactoryAdapter
{
if ($this->discoverInterface()) {
$this->nb_interface->setResponse($nb_response);
} else {
throw new ENabuProviderException(ENabuProviderException::ERROR_INTERFACE_NOT_SETTED);
}
return $this;
} | php | {
"resource": ""
} |
q4221 | CNabuXMLObject.collect | train | public function collect(SimpleXMLElement $element)
{
if ($element->getName() === get_called_class()::getTagName() && $this->locateDataObject($element)) {
$this->getAttributes($element);
$this->getChilds($element);
} else {
throw new ENabuXMLException(ENabuXMLException::ERROR_UNEXPECTED_ELEMENT, array($element->getName()));
}
} | php | {
"resource": ""
} |
q4222 | NonDB.driver | train | public static function driver(string $name){
//Get the name.
$name = explode(':', $name);
//Get the classname.
$class = "\\NonDB\\Drivers\\" . $name[0];
//Get the parameter.
$param = $name[1];
//See if the driver exists.
if(!class_exists($class) || !( \NonDB\Components\Tool::checkImplement($class, "NonDB\\Interfaces\\Driver") )){
throw new \NonDB\Exceptions\CoreException("Driver $class wasn't exists.", "0011");
return false;
}
//Get driver.
$driver = eval("return new $class(urldecode(\$param));");
return $driver;
} | php | {
"resource": ""
} |
q4223 | CNabuXMLDataObject.getAttributesFromList | train | protected function getAttributesFromList(
SimpleXMLElement $element,
array $attributes,
bool $ignore_empty = false
) : int {
$count = 0;
if (count($attributes) > 0) {
foreach ($attributes as $field => $attr) {
if (isset($element[$attr])) {
$value = (string)$element[$attr];
if ($ignore_empty || strlen($value) > 0) {
$this->nb_data_object->setValue($field, $value);
$count++;
}
}
}
}
return $count;
} | php | {
"resource": ""
} |
q4224 | CNabuXMLDataObject.putAttributesFromList | train | protected function putAttributesFromList(
SimpleXMLElement $element,
array $attributes,
bool $ignore_empty = false
) : int {
$count = 0;
if (count($attributes) > 0) {
foreach ($attributes as $field => $attr) {
if ($this->nb_data_object->contains($field) &&
(!$ignore_empty ||
!$this->nb_data_object->isValueNull($field) ||
!$this->nb_data_object->isValueEmptyString($field)
)
) {
$element->addAttribute($attr, $this->nb_data_object->getValue($field));
$count++;
}
}
}
return $count;
} | php | {
"resource": ""
} |
q4225 | CNabuXMLDataObject.putChildsAsCDATAFromList | train | protected function putChildsAsCDATAFromList(
SimpleXMLElement $element,
array $childs,
bool $ignore_empty = false
) : int {
$count = 0;
if (count($childs) > 0) {
foreach ($childs as $field => $child) {
if ($this->nb_data_object->contains($field) &&
(!$ignore_empty ||
!$this->nb_data_object->isValueNull($field) ||
!$this->nb_data_object->isValueEmptyString($field)
)
) {
$element->addChild($child, $this->packCDATA($this->nb_data_object->getValue($field)));
$count++;
}
}
}
return $count;
} | php | {
"resource": ""
} |
q4226 | PatchService.getAll | train | public function getAll(array $queryParams = [])
{
$response = $this->api
->applications()
->scans()
->issues()
->types()
->patches()
->getAll($queryParams);
return new PatchesResponse($response);
} | php | {
"resource": ""
} |
q4227 | PatchService.getById | train | public function getById($patchId, array $queryParams = [])
{
$response = $this->api
->applications()
->scans()
->issues()
->types()
->patches()
->getById($patchId, $queryParams);
return new PatchResponse($response);
} | php | {
"resource": ""
} |
q4228 | LanguageHydrator.hydrateCollection | train | public static function hydrateCollection(array $languages)
{
$hydrated = [];
foreach ($languages as $language) {
$hydrated[] = self::hydrate($language);
}
return $hydrated;
} | php | {
"resource": ""
} |
q4229 | LanguageHydrator.hydrate | train | public static function hydrate(stdClass $language)
{
$hydrated = new LanguageEntity();
if (isset($language->id)) {
$hydrated->setId($language->id);
}
if (isset($language->name)) {
$hydrated->setName($language->name);
}
if (isset($language->file_extensions)) {
$hydrated->setFileExtensions($language->file_extensions);
}
if (isset($language->config_file_extensions)) {
$hydrated->setConfigFileExtensions($language->config_file_extensions);
}
return $hydrated;
} | php | {
"resource": ""
} |
q4230 | TNabuRoleChild.getRole | train | public function getRole($force = false)
{
if ($this->nb_role === null || $force) {
$this->nb_role = null;
if ($this->isValueNumeric('nb_role_id')) {
$nb_role = new CNabuRole($this);
if ($nb_role->isFetched()) {
$this->nb_role = $nb_role;
}
}
}
return $this->nb_role;
} | php | {
"resource": ""
} |
q4231 | TNabuRoleChild.setRole | train | public function setRole(CNabuRole $nb_role)
{
$this->nb_role = $nb_role;
if ($this instanceof CNabuDataObject) {
$this->transferValue($nb_role, NABU_ROLE_FIELD_ID);
}
return $this;
} | php | {
"resource": ""
} |
q4232 | Migrate.postPackageInstall | train | public static function postPackageInstall(PackageEvent $event){
$installedPackage = $event->getOperation()->getPackage()->getName();
if (self::checkConfig($event, $installedPackage)) {
self::phinxMigrateFromPackageName($event, $installedPackage, true);
} else {
die();
}
} | php | {
"resource": ""
} |
q4233 | Migrate.postPackageUpdate | train | public static function postPackageUpdate(PackageEvent $event){
$installedPackage = $event->getOperation()->getTargetPackage()->getName();
if (self::checkConfig($event, $installedPackage)) {
self::phinxMigrateFromPackageName($event, $installedPackage);
} else {
die();
}
} | php | {
"resource": ""
} |
q4234 | Migrate.prePackageUninstall | train | public static function prePackageUninstall(PackageEvent $event){
$installedPackage = $event->getOperation()->getPackage()->getName();
if (self::checkConfig($event, $installedPackage)) {
self::phinxRollbackFromPackageName($event, $installedPackage);
} else {
die();
}
} | php | {
"resource": ""
} |
q4235 | AbstractViewCompiler.replaceBreadcrumb | train | protected function replaceBreadcrumb($modelName, $modelLabel)
{
$this->stub = str_replace('{{breadcrumb}}', ucfirst(strtolower($modelLabel)), $this->stub);
$this->stub = str_replace('{{breadcrumb_lw}}', strtolower($modelName), $this->stub);
return $this;
} | php | {
"resource": ""
} |
q4236 | Definition.offsetSet | train | public function offsetSet($key, $newval)
{
if ($def = in_array($key, array_keys($this->keys))) {
parent::offsetSet($key, $newval);
} else {
throw new UnexpectedValueException($key.' is not defined in metadata definition '.get_class($this).'.');
}
} | php | {
"resource": ""
} |
q4237 | Guard.authenticate | train | public function authenticate(Request $request, Route $route)
{
if (! $user = $this->auth->user()) {
throw new UnauthorizedHttpException(
get_class($this),
'Unable to authenticate with invalid API key and token.'
);
}
return $user;
} | php | {
"resource": ""
} |
q4238 | OrgHydrator.hydrateCollection | train | public static function hydrateCollection(array $organizations)
{
$hydrated = [];
foreach ($organizations as $organization) {
$hydrated[] = self::hydrate($organization);
}
return $hydrated;
} | php | {
"resource": ""
} |
q4239 | OrgHydrator.hydrate | train | public static function hydrate(stdClass $organization)
{
$hydrated = new OrgEntity();
if (isset($organization->id)) {
$hydrated->setId($organization->id);
}
if (isset($organization->name)) {
$hydrated->setName($organization->name);
}
if (isset($organization->valid_until)) {
$hydrated->setValidUntil(new DateTime($organization->valid_until));
}
if (isset($organization->quotas) && is_array($organization->quotas)) {
$hydrated->setQuotas(QuotaHydrator::hydrateCollection($organization->quotas));
}
if (isset($organization->trial_issue_types) && is_array($organization->trial_issue_types)) {
$hydrated->setTrialIssueTypes(TypeHydrator::hydrateCollection($organization->trial_issue_types));
}
if (isset($organization->disabled)) {
$hydrated->setDisabled($organization->disabled);
}
return $hydrated;
} | php | {
"resource": ""
} |
q4240 | CNabuHTTPStandaloneApplication.enableLanguage | train | public function enableLanguage($ISO639_1, $name, $default_country_code, $default_lang = false)
{
$nb_language = new CNabuBuiltInLanguage();
$nb_language->setISO6391($ISO639_1)
->setName($name)
->setDefaultCountryCode($default_country_code)
->setEnabled(CNabuLanguage::LANGUAGE_ENABLED)
;
$nb_site = $this->nb_engine->getHTTPServer()->getSite();
$nb_site->setLanguage($nb_language);
if ($default_lang) {
$nb_site->setDefaultLanguage($nb_language);
}
return $nb_language;
} | php | {
"resource": ""
} |
q4241 | CNabuHTTPStandaloneApplication.addSmartyTarget | train | public function addSmartyTarget($display, $content, $default = false)
{
$target = new CNabuBuiltInSiteTarget();
$target->setMIMETypeId('text/html')
->setOutputTypeHTML()
->setSmartyDisplayFile($display)
->setSmartyContentFile($content)
;
return $this->addTarget($target, $default);
} | php | {
"resource": ""
} |
q4242 | CNabuHTTPStandaloneApplication.addTarget | train | protected function addTarget(CNabuSiteTarget $nb_site_target, $default = false)
{
$nb_site = $this->nb_engine->getHTTPServer()->getSite();
if ($nb_site instanceof CNabuSite) {
return $nb_site->addTarget($nb_site_target, $default);
} else {
throw new ENabuCoreException(ENabuCoreException::ERROR_SITE_NOT_INSTANTIATED);
}
} | php | {
"resource": ""
} |
q4243 | CNabuHTTPStandaloneApplication.setLoginTarget | train | public function setLoginTarget(CNabuSiteTarget $nb_site_target)
{
$nb_site = $this->nb_engine->getHTTPServer()->getSite();
if ($nb_site instanceof CNabuSite) {
return $nb_site->setLoginTarget($nb_site_target);
} else {
throw new ENabuCoreException(ENabuCoreException::ERROR_SITE_NOT_INSTANTIATED);
}
} | php | {
"resource": ""
} |
q4244 | CNabuHTTPStandaloneApplication.addRootSiteMapForURL | train | public function addRootSiteMapForURL($order, CNabuRole $nb_role = null)
{
if ($nb_role === null) {
$nb_role = $this->nb_engine->getHTTPServer()->getSite()->getDefaultRole();
}
$nb_site_map = new CNabuBuiltInSiteMap();
$nb_site_map->setOrder($order);
return $this->addRootSiteMap($nb_site_map);
} | php | {
"resource": ""
} |
q4245 | CNabuHTTPStandaloneApplication.addRootSiteMapForTarget | train | public function addRootSiteMapForTarget(CNabuSiteTarget $nb_site_target, $order, CNabuRole $nb_role = null)
{
if ($nb_role === null) {
$nb_role = $this->nb_engine->getHTTPServer()->getSite()->getDefaultRole();
}
$nb_site_map = new CNabuBuiltInSiteMap();
$nb_site_map->setSiteTarget($nb_site_target)
->setOrder($order)
;
return $this->addRootSiteMap($nb_site_map);
} | php | {
"resource": ""
} |
q4246 | CNabuHTTPStandaloneApplication.addRootSiteMap | train | public function addRootSiteMap(CNabuSiteMap $nb_site_map)
{
$nb_site = $this->nb_engine->getHTTPServer()->getSite();
if ($nb_site instanceof CNabuSite) {
return $nb_site->addSiteMap($nb_site_map);
} else {
throw new ENabuCoreException(ENabuCoreException::ERROR_SITE_NOT_INSTANTIATED);
}
} | php | {
"resource": ""
} |
q4247 | CNabuHTTPStandaloneApplication.newMedioteca | train | public function newMedioteca($key)
{
$nb_medioteca = new CNabuBuiltInMedioteca();
$nb_medioteca->setKey($key);
return $this->addMedioteca($nb_medioteca);
} | php | {
"resource": ""
} |
q4248 | Model.getPrimaryKey | train | public function getPrimaryKey() {
if ($this->primaryKey === null) {
$schema = $this->getSchema();
$pk = [];
foreach ($schema->getSchemaArray()['properties'] as $column => $property) {
if (!empty($property['primary'])) {
$pk[] = $column;
}
}
$this->primaryKey = $pk;
}
return $this->primaryKey;
} | php | {
"resource": ""
} |
q4249 | Model.mapID | train | protected function mapID($id) {
$idArray = (array)$id;
$result = [];
foreach ($this->getPrimaryKey() as $i => $column) {
if (isset($idArray[$i])) {
$result[$column] = $idArray[$i];
} elseif (isset($idArray[$column])) {
$result[$column] = $idArray[$column];
} else {
$result[$column] = null;
}
}
return $result;
} | php | {
"resource": ""
} |
q4250 | Model.getSchema | train | final public function getSchema() {
if ($this->schema === null) {
$this->schema = $this->fetchSchema();
}
return $this->schema;
} | php | {
"resource": ""
} |
q4251 | Model.fetchSchema | train | protected function fetchSchema() {
$columns = $this->getDb()->fetchColumnDefs($this->name);
if ($columns === null) {
throw new \InvalidArgumentException("Cannot fetch schema foor {$this->name}.");
}
$schema = [
'type' => 'object',
'dbtype' => 'table',
'properties' => $columns
];
$required = $this->requiredFields($columns);
if (!empty($required)) {
$schema['required'] = $required;
}
return new Schema($schema);
} | php | {
"resource": ""
} |
q4252 | Model.requiredFields | train | private function requiredFields(array $columns) {
$required = [];
foreach ($columns as $name => $column) {
if (empty($column['autoIncrement']) && !isset($column['default']) && empty($column['allowNull'])) {
$required[] = $name;
}
}
return $required;
} | php | {
"resource": ""
} |
q4253 | Model.get | train | public function get(array $where) {
$options = [
Db::OPTION_FETCH_MODE => $this->getFetchArgs(),
'rowCallback' => [$this, 'unserialize']
];
$qry = new TableQuery($this->name, $where, $this->db, $options);
$qry->setLimit($this->getDefaultLimit())
->setOrder(...$this->getDefaultOrder());
return $qry;
} | php | {
"resource": ""
} |
q4254 | Model.query | train | public function query(array $where, array $options = []) {
$options += [
'order' => $this->getDefaultOrder(),
'limit' => $this->getDefaultLimit(),
Db::OPTION_FETCH_MODE => $this->getFetchArgs()
];
$stmt = $this->db->get($this->name, $where, $options);
return $stmt;
} | php | {
"resource": ""
} |
q4255 | Model.updateID | train | public function updateID($id, array $set): int {
$r = $this->update($set, $this->mapID($id));
return $r;
} | php | {
"resource": ""
} |
q4256 | Model.validate | train | public function validate($row, $sparse = false) {
$schema = $this->getSchema();
$valid = $schema->validate($row, ['sparse' => $sparse]);
return $valid;
} | php | {
"resource": ""
} |
q4257 | Settings.index | train | public function index()
{
if (!userHasPermission('admin:captcha:settings:*')) {
unauthorised();
}
$oDb = Factory::service('Database');
$oInput = Factory::service('Input');
$oCaptchaDriverService = Factory::service('CaptchaDriver', 'nails/module-captcha');
if ($oInput->post()) {
// Settings keys
$sKeyCaptchaDriver = $oCaptchaDriverService->getSettingKey();
// Validation
$oFormValidation = Factory::service('FormValidation');
$oFormValidation->set_rules($sKeyCaptchaDriver, '', 'required');
if ($oFormValidation->run()) {
try {
$oDb->trans_begin();
// Drivers
$oCaptchaDriverService->saveEnabled($oInput->post($sKeyCaptchaDriver));
$oDb->trans_commit();
$this->data['success'] = 'Captcha settings were saved.';
} catch (\Exception $e) {
$oDb->trans_rollback();
$this->data['error'] = 'There was a problem saving settings. ' . $e->getMessage();
}
} else {
$this->data['error'] = lang('fv_there_were_errors');
}
}
// --------------------------------------------------------------------------
// Get data
$this->data['settings'] = appSetting(null, 'nails/module-captcha', true);
$this->data['captcha_drivers'] = $oCaptchaDriverService->getAll();
$this->data['captcha_drivers_enabled'] = $oCaptchaDriverService->getEnabledSlug();
Helper::loadView('index');
} | php | {
"resource": ""
} |
q4258 | MfaQuestion.askQuestion | train | protected function askQuestion()
{
// Ask away cap'n!
$this->data['page']->title = lang('auth_twofactor_answer_title');
$this->loadStyles(NAILS_APP_PATH . 'application/modules/auth/views/mfa/question/ask.php');
Factory::service('View')
->load([
'structure/header/blank',
'auth/mfa/question/ask',
'structure/footer/blank',
]);
} | php | {
"resource": ""
} |
q4259 | Attachment.isPresentable | train | public function isPresentable($presenter = null)
{
if (is_bool($presenter)) {
$this->presentable = $presenter;
}
return $this->presentable;
} | php | {
"resource": ""
} |
q4260 | Attachment.setContainerObj | train | public function setContainerObj($obj)
{
if ($obj === null) {
$this->containerObj = null;
return $this;
}
if (!$obj instanceof AttachmentContainerInterface) {
throw new InvalidArgumentException(sprintf(
'Container object must be an instance of %s; received %s',
AttachmentContainerInterface::class,
(is_object($obj) ? get_class($obj) : gettype($obj))
));
}
if (!$obj->id()) {
throw new InvalidArgumentException(sprintf(
'Container object must have an ID.',
(is_object($obj) ? get_class($obj) : gettype($obj))
));
}
$this->containerObj = $obj;
return $this;
} | php | {
"resource": ""
} |
q4261 | Attachment.microType | train | public function microType()
{
$classname = get_called_class();
if (!isset(static::$resolvedType[$classname])) {
$reflect = new ReflectionClass($this);
static::$resolvedType[$classname] = strtolower($reflect->getShortName());
}
return static::$resolvedType[$classname];
} | php | {
"resource": ""
} |
q4262 | Attachment.heading | train | public function heading()
{
$heading = $this->render((string)$this->heading);
if (!$heading) {
$heading = $this->translator()->translation('{{ objType }} #{{ id }}', [
'{{ objType }}' => ucfirst($this->microType()),
'{{ id }}' => $this->id()
]);
}
return $heading;
} | php | {
"resource": ""
} |
q4263 | Attachment.setDescription | train | public function setDescription($description)
{
$this->description = $this->translator()->translation($description);
if ($this->isPresentable()) {
foreach ($this->description->data() as $lang => $trans) {
$this->description[$lang] = $this->resolveUrls($trans);
}
}
return $this;
} | php | {
"resource": ""
} |
q4264 | Attachment.setFileSize | train | public function setFileSize($size)
{
if ($size === null) {
$this->fileSize = null;
return $this;
}
if (!is_numeric($size)) {
throw new InvalidArgumentException('File size must be an integer or a float.');
}
$this->fileSize = $size;
return $this;
} | php | {
"resource": ""
} |
q4265 | Attachment.preDelete | train | public function preDelete()
{
$attId = $this->id();
$joinProto = $this->modelFactory()->get(Join::class);
$loader = $this->collectionLoader();
$loader->setModel($joinProto);
$collection = $loader->addFilter('attachment_id', $attId)->load();
foreach ($collection as $obj) {
$obj->delete();
}
return parent::preDelete();
} | php | {
"resource": ""
} |
q4266 | LoginRecorderComponent.getFileArray | train | public function getFileArray()
{
if (!$this->FileArray) {
$user = $this->getConfig('user');
is_true_or_fail(is_positive($user), __d('me_cms', 'You have to set a valid user id'), InvalidArgumentException::class);
$this->FileArray = new FileArray(LOGIN_RECORDS . 'user_' . $user . '.log');
}
return $this->FileArray;
} | php | {
"resource": ""
} |
q4267 | PHP.extensions | train | public function extensions()
{
foreach ($this->extensionsToCheck as $extension) {
$extensions[$extension] = extension_loaded($extension);
}
return $extensions;
} | php | {
"resource": ""
} |
q4268 | Difficulty.getCurrentRealmsIncrement | train | public function getCurrentRealmsIncrement(): int
{
$currentDifficulty = $this->getValue();
$maximalDifficulty = $this->getMaximal();
if ($currentDifficulty <= $maximalDifficulty) {
return 0;
}
$additionalDifficulty = $currentDifficulty - $maximalDifficulty;
$steps = $additionalDifficulty / $this->getDifficultyAddition()->getDifficultyAdditionPerStep();
$realmsIncrement = $steps * $this->getDifficultyAddition()->getRealmsChangePerAdditionStep();
return (int)\ceil($realmsIncrement); // even a tiny piece of a higher realm means the lower realm is not able to create that formula
} | php | {
"resource": ""
} |
q4269 | BaseAlias.configure | train | protected function configure()
{
if (empty(static::COMMAND)) {
throw new NailsException('static::COMMAND must be defined');
}
if (empty(static::ALIAS)) {
throw new NailsException('static::ALIAS must be defined');
}
// --------------------------------------------------------------------------
$this->setName(static::ALIAS);
$this->setDescription('Alias to <info>' . static::COMMAND . '</info>');
} | php | {
"resource": ""
} |
q4270 | Body.setContentType | train | public function setContentType(string $contentType, string $contentCharset = null): self
{
$this->contentType = $contentType;
if ($contentCharset !== null) {
$this->setContentCharset($contentCharset);
}
return $this;
} | php | {
"resource": ""
} |
q4271 | Body.isImage | train | public function isImage(): bool
{
return is_resource($this->content) && in_array($this->contentType, [
self::CONTENT_TYPE_IMAGE_JPEG, self::CONTENT_TYPE_IMAGE_PNG, self::CONTENT_TYPE_IMAGE_GIF,
]);
} | php | {
"resource": ""
} |
q4272 | ArrayExchanger.getRate | train | public function getRate($fromCurrency, $toCurrency)
{
if ($fromCurrency === $toCurrency) {
return 1;
}
$currencyString = "{$fromCurrency}-{$toCurrency}";
if (!isset($this->rates[$currencyString])) {
throw new NoExchangeRateException(sprintf(
'Cannot convert %s to %s, no exchange rate found.',
$fromCurrency,
$toCurrency
));
}
return $this->rates[$currencyString];
} | php | {
"resource": ""
} |
q4273 | PagesCategoriesController.view | train | public function view($slug = null)
{
//The category can be passed as query string, from a widget
if ($this->request->getQuery('q')) {
return $this->redirect([$this->request->getQuery('q')]);
}
$category = $this->PagesCategories->findActiveBySlug($slug)
->select(['id', 'title'])
->contain($this->PagesCategories->Pages->getAlias(), function (Query $q) {
return $q->find('active')->select(['category_id', 'slug', 'title']);
})
->cache(sprintf('category_%s', md5($slug)), $this->PagesCategories->getCacheName())
->firstOrFail();
$this->set(compact('category'));
} | php | {
"resource": ""
} |
q4274 | Join.getObject | train | public function getObject()
{
if ($this->sourceObject === null && $this->isSourceObjectResolved === false) {
$this->isSourceObjectResolved = true;
try {
$model = $this->modelFactory()->create($this->objectType())->load($this->objectId());
if ($model->id()) {
$this->sourceObject = $model;
}
} catch (Exception $e) {
throw new LogicException(sprintf(
'Could not load the source object of the relationship: %s',
$e->getMessage()
), 0, $e);
}
}
return $this->sourceObject;
} | php | {
"resource": ""
} |
q4275 | Join.getAttachment | train | public function getAttachment()
{
if ($this->relatedObject === null && $this->isRelatedObjectResolved === false) {
$this->isRelatedObjectResolved = true;
try {
$model = $this->modelFactory()->create(Attachment::class)->load($this->attachmentId());
if ($model->id()) {
$this->relatedObject = $model;
$type = $model->type();
if ($type !== $model->objType()) {
$this->relatedObject = $this->modelFactory()->create($type)->setData($model->data());
}
}
} catch (Exception $e) {
throw new LogicException(sprintf(
'Could not load the related object of the relationship: %s',
$e->getMessage()
), 0, $e);
}
}
return $this->relatedObject;
} | php | {
"resource": ""
} |
q4276 | Join.getParent | train | public function getParent()
{
if ($this->parentRelation === null && $this->isParentRelationResolved === false) {
$this->isParentRelationResolved = true;
try {
$source = $this->getObject();
if ($source instanceof AttachmentContainerInterface) {
$model = $this->modelFactory()->create(self::class)->loadFrom('attachment_id', $source->id());
if ($model->id()) {
$this->parentRelation = $model;
}
}
} catch (Exception $e) {
throw new LogicException(sprintf(
'Could not load the parent relationship: %s',
$e->getMessage()
), 0, $e);
}
}
return $this->parentRelation;
} | php | {
"resource": ""
} |
q4277 | Join.setPosition | train | public function setPosition($position)
{
if ($position === null) {
$this->position = null;
return $this;
}
if (!is_numeric($position)) {
throw new InvalidArgumentException(
'Position must be an integer.'
);
}
$this->position = (int)$position;
return $this;
} | php | {
"resource": ""
} |
q4278 | FormDisableElementsCapableFormSettings.render | train | public function render(ElementInterface $element)
{
/* @var $element DisableElementsCapableFormSettings
* @var $renderer \Zend\View\Renderer\PhpRenderer
* @var $headscript \Zend\View\Helper\HeadScript
* @var $basepath \Zend\View\Helper\BasePath */
$renderer = $this->getView();
$headscript = $renderer->plugin('headscript');
$basepath = $renderer->plugin('basepath');
$headscript->appendFile($basepath('modules/Settings/js/forms.decfs.js'));
return '<ul class="disable-elements-list" id="' . $element->getAttribute('id') . '-list"' . '>'
. $this->renderCheckboxes($element->getCheckboxes())
. '</ul>';
} | php | {
"resource": ""
} |
q4279 | FormDisableElementsCapableFormSettings.renderCheckboxes | train | protected function renderCheckboxes($checkboxes)
{
$markup = '';
foreach ($checkboxes as $boxes) {
$markup .= '<li class="disable-element">';
if (is_array($boxes)) {
if (isset($boxes['__all__'])) {
$markup .= $this->renderCheckbox($boxes['__all__'], 'disable-elements-toggle');
unset($boxes['__all__']);
}
$markup .= '<ul class="disable-elements">' . $this->renderCheckboxes($boxes) . '</ul>';
} else {
$markup .= $this->renderCheckbox($boxes);
}
$markup .= '</li>';
}
return $markup;
} | php | {
"resource": ""
} |
q4280 | Pdf.instantiate | train | protected function instantiate()
{
$oOptions = new Options();
$aOptions = [];
// Default options
foreach (self::DEFAULT_OPTIONS as $sOption => $mValue) {
$aOptions[$sOption] = $mValue;
}
// Custom options override default options
foreach ($this->aCustomOptions as $sOption => $mValue) {
$aOptions[$sOption] = $mValue;
}
// Set the options
foreach ($aOptions as $sOption => $mValue) {
$oOptions->set($sOption, $mValue);
}
$this->oDomPdf = new Dompdf($oOptions);
$this->setPaperSize($this->sPaperSize, $this->sPaperOrientation);
return $this;
} | php | {
"resource": ""
} |
q4281 | Pdf.setOption | train | public function setOption($sOption, $mValue)
{
$this->aCustomOptions[$sOption] = $mValue;
$this->oDomPdf->set_option($sOption, $mValue);
return $this;
} | php | {
"resource": ""
} |
q4282 | Pdf.setPaperSize | train | public function setPaperSize($sSize = null, $sOrientation = null)
{
$this->sPaperSize = $sSize ?: static::DEFAULT_PAPER_SIZE;
$this->sPaperOrientation = $sOrientation ?: static::DEFAULT_PAPER_ORIENTATION;
$this->oDomPdf->setPaper($this->sPaperSize, $this->sPaperOrientation);
return $this;
} | php | {
"resource": ""
} |
q4283 | Pdf.loadView | train | public function loadView($mViews, $aData = [])
{
$sHtml = '';
$aViews = array_filter((array) $mViews);
$oView = Factory::service('View');
foreach ($aViews as $sView) {
$sHtml .= $oView->load($sView, $aData, true);
}
$this->oDomPdf->loadHtml($sHtml);
} | php | {
"resource": ""
} |
q4284 | Pdf.download | train | public function download($sFilename = '', $aOptions = [])
{
$sFilename = $sFilename ? $sFilename : self::DEFAULT_FILE_NAME;
// Set the content attachment, by default send to the browser
$aOptions['Attachment'] = 1;
$this->oDomPdf->render();
$this->oDomPdf->stream($sFilename, $aOptions);
exit();
} | php | {
"resource": ""
} |
q4285 | Pdf.save | train | public function save($sPath, $sFilename)
{
if (!is_writable($sPath)) {
$this->setError('Cannot write to ' . $sPath);
return false;
}
$this->oDomPdf->render();
$bResult = (bool) file_put_contents(
rtrim($sPath, '/') . '/' . $sFilename,
$this->oDomPdf->output()
);
$this->reset();
return $bResult;
} | php | {
"resource": ""
} |
q4286 | Pdf.saveToCdn | train | public function saveToCdn($sFilename, $sBucket = null)
{
if (Components::exists('nails/module-cdn')) {
// Save temporary file
$sCacheDir = CACHE_PATH;
$sCacheFile = 'TEMP-PDF-' . md5(uniqid() . microtime(true)) . '.pdf';
if ($this->save($sCacheDir, $sCacheFile)) {
$oCdn = Factory::service('Cdn', 'nails/module-cdn');
$oResult = $oCdn->objectCreate(
$sCacheDir . $sCacheFile,
$sBucket,
['filename_display' => $sFilename]
);
if ($oResult) {
@unlink($sCacheDir . $sCacheFile);
$this->reset();
return $oResult;
} else {
$this->setError($oCdn->lastError());
return false;
}
} else {
return false;
}
} else {
$this->setError('CDN module is not available');
return false;
}
} | php | {
"resource": ""
} |
q4287 | PageMapper.findPageById | train | public function findPageById($pageId)
{
$this->makeCollectionPageSelect(true);
$this->sql .= ' and p.id = ?';
$this->bindValues[] = $pageId;
return $this->findRow();
} | php | {
"resource": ""
} |
q4288 | PageMapper.findPublishedPageBySlug | train | public function findPublishedPageBySlug($pageSlug)
{
$this->makeSelect();
if (is_string($pageSlug)) {
$this->sql .= ' and collection_id is null and slug = ?';
$this->bindValues[] = $pageSlug;
} else {
throw new Exception('Unknown page identifier type');
}
$this->sql .= " and published_date <= '{$this->today()}'";
return $this->findRow();
} | php | {
"resource": ""
} |
q4289 | PageMapper.findPages | train | public function findPages($unpublished = false)
{
$this->makeSelect();
$this->sql .= " and collection_id is null";
if (!$unpublished) {
$this->sql .= " and published_date <= '{$this->today()}'";
}
return $this->find();
} | php | {
"resource": ""
} |
q4290 | PageMapper.findCollectionPagesById | train | public function findCollectionPagesById($collectionId, $published = true)
{
$this->makeCollectionPageSelect();
$this->sql .= ' and c.id = ?';
$this->bindValues[] = $collectionId;
if ($published) {
$this->sql .= " and p.published_date <= '{$this->today()}'";
}
return $this->find();
} | php | {
"resource": ""
} |
q4291 | PageMapper.findPublishedCollectionPageBySlug | train | public function findPublishedCollectionPageBySlug($collectionSlug, $pageSlug)
{
$this->makeCollectionPageSelect();
$this->sql .= " and p.published_date <= '{$this->today()}'";
$this->sql .= ' and c.slug = ? and p.slug = ?';
$this->bindValues[] = $collectionSlug;
$this->bindValues[] = $pageSlug;
return $this->findRow();
} | php | {
"resource": ""
} |
q4292 | Email.setData | train | public function setData(array $data)
{
foreach ($data as $prop => $val) {
$func = [$this, $this->setter($prop)];
if (is_callable($func)) {
call_user_func($func, $val);
} else {
$this->{$prop} = $val;
}
}
return $this;
} | php | {
"resource": ""
} |
q4293 | Email.campaign | train | public function campaign()
{
if ($this->campaign === null) {
$this->campaign = $this->generateCampaign();
}
return $this->campaign;
} | php | {
"resource": ""
} |
q4294 | Email.from | train | public function from()
{
if ($this->from === null) {
$this->setFrom($this->config()->defaultFrom());
}
return $this->from;
} | php | {
"resource": ""
} |
q4295 | Email.replyTo | train | public function replyTo()
{
if ($this->replyTo === null) {
$this->replyTo = $this->config()->defaultReplyTo();
}
return $this->replyTo;
} | php | {
"resource": ""
} |
q4296 | Email.msgHtml | train | public function msgHtml()
{
if ($this->msgHtml === null) {
$this->msgHtml = $this->generateMsgHtml();
}
return $this->msgHtml;
} | php | {
"resource": ""
} |
q4297 | Email.msgTxt | train | public function msgTxt()
{
if ($this->msgTxt === null) {
$this->msgTxt = $this->stripHtml($this->msgHtml());
}
return $this->msgTxt;
} | php | {
"resource": ""
} |
q4298 | Email.log | train | public function log()
{
if ($this->log === null) {
$this->log = $this->config()->defaultLog();
}
return $this->log;
} | php | {
"resource": ""
} |
q4299 | Email.track | train | public function track()
{
if ($this->track === null) {
$this->track = $this->config()->defaultTrack();
}
return $this->track;
} | php | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.