repository_name
stringlengths 5
67
| func_path_in_repository
stringlengths 4
234
| func_name
stringlengths 0
314
| whole_func_string
stringlengths 52
3.87M
| language
stringclasses 6
values | func_code_string
stringlengths 52
3.87M
| func_code_tokens
sequencelengths 15
672k
| func_documentation_string
stringlengths 1
47.2k
| func_documentation_tokens
sequencelengths 1
3.92k
| split_name
stringclasses 1
value | func_code_url
stringlengths 85
339
|
---|---|---|---|---|---|---|---|---|---|---|
nicklaw5/larapi | src/Larapi.php | Larapi.notAvailable | public function notAvailable($msg = '', $errorCode = null, $headers = [])
{
return $this->getErrorResponse($msg, $errorCode, self::HTTP_SERVICE_UNAVAILABLE, $headers);
} | php | public function notAvailable($msg = '', $errorCode = null, $headers = [])
{
return $this->getErrorResponse($msg, $errorCode, self::HTTP_SERVICE_UNAVAILABLE, $headers);
} | [
"public",
"function",
"notAvailable",
"(",
"$",
"msg",
"=",
"''",
",",
"$",
"errorCode",
"=",
"null",
",",
"$",
"headers",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"getErrorResponse",
"(",
"$",
"msg",
",",
"$",
"errorCode",
",",
"self",
"::",
"HTTP_SERVICE_UNAVAILABLE",
",",
"$",
"headers",
")",
";",
"}"
] | Returns 503 Not Available HTTP Response
@param string $msg
@param int $errorCode
@param array $headers
@return json | [
"Returns",
"503",
"Not",
"Available",
"HTTP",
"Response"
] | train | https://github.com/nicklaw5/larapi/blob/fb3493118bb9c6ce01567230c09e8402ac148d0e/src/Larapi.php#L227-L230 |
phpmob/changmin | src/PhpMob/CoreBundle/Form/Type/WebUserType.php | WebUserType.buildForm | public function buildForm(FormBuilderInterface $builder, array $options): void
{
parent::buildForm($builder, $options);
$builder
->add('firstName', TextType::class, [
'label' => 'phpmob.form.user.first_name',
'required' => false,
])
->add('lastName', TextType::class, [
'label' => 'phpmob.form.user.last_name',
'required' => false,
])
->add('gender', ChoiceType::class, [
'label' => 'phpmob.form.user.gender',
'choices' => array_flip([
'm' => 'phpmob.form.user.gender_man',
'f' => 'phpmob.form.user.gender_female',
]),
'required' => false,
])
->add('phoneNumber', TelType::class, [
'label' => 'phpmob.form.user.phone_number',
'required' => false,
])
->add('birthday', DateType::class, [
'label' => 'phpmob.form.user.birthday',
'widget' => 'single_text',
'required' => false,
])
->add('countryCode', CountryType::class, [
'label' => 'phpmob.form.user.country_code',
'required' => false,
])
->add('locale', LocaleChoiceType::class, [
'label' => 'phpmob.form.user.locale',
'required' => false,
])
->add('statusMessage', TextType::class, [
'label' => 'phpmob.form.user.status_message',
'required' => false,
])
->add('displayName', TextType::class, [
'label' => 'phpmob.form.user.display_name',
'required' => false,
])
->add('picture', WebUserPictureType::class, [
'label' => 'phpmob.form.user.picture',
'required' => false,
])
;
} | php | public function buildForm(FormBuilderInterface $builder, array $options): void
{
parent::buildForm($builder, $options);
$builder
->add('firstName', TextType::class, [
'label' => 'phpmob.form.user.first_name',
'required' => false,
])
->add('lastName', TextType::class, [
'label' => 'phpmob.form.user.last_name',
'required' => false,
])
->add('gender', ChoiceType::class, [
'label' => 'phpmob.form.user.gender',
'choices' => array_flip([
'm' => 'phpmob.form.user.gender_man',
'f' => 'phpmob.form.user.gender_female',
]),
'required' => false,
])
->add('phoneNumber', TelType::class, [
'label' => 'phpmob.form.user.phone_number',
'required' => false,
])
->add('birthday', DateType::class, [
'label' => 'phpmob.form.user.birthday',
'widget' => 'single_text',
'required' => false,
])
->add('countryCode', CountryType::class, [
'label' => 'phpmob.form.user.country_code',
'required' => false,
])
->add('locale', LocaleChoiceType::class, [
'label' => 'phpmob.form.user.locale',
'required' => false,
])
->add('statusMessage', TextType::class, [
'label' => 'phpmob.form.user.status_message',
'required' => false,
])
->add('displayName', TextType::class, [
'label' => 'phpmob.form.user.display_name',
'required' => false,
])
->add('picture', WebUserPictureType::class, [
'label' => 'phpmob.form.user.picture',
'required' => false,
])
;
} | [
"public",
"function",
"buildForm",
"(",
"FormBuilderInterface",
"$",
"builder",
",",
"array",
"$",
"options",
")",
":",
"void",
"{",
"parent",
"::",
"buildForm",
"(",
"$",
"builder",
",",
"$",
"options",
")",
";",
"$",
"builder",
"->",
"add",
"(",
"'firstName'",
",",
"TextType",
"::",
"class",
",",
"[",
"'label'",
"=>",
"'phpmob.form.user.first_name'",
",",
"'required'",
"=>",
"false",
",",
"]",
")",
"->",
"add",
"(",
"'lastName'",
",",
"TextType",
"::",
"class",
",",
"[",
"'label'",
"=>",
"'phpmob.form.user.last_name'",
",",
"'required'",
"=>",
"false",
",",
"]",
")",
"->",
"add",
"(",
"'gender'",
",",
"ChoiceType",
"::",
"class",
",",
"[",
"'label'",
"=>",
"'phpmob.form.user.gender'",
",",
"'choices'",
"=>",
"array_flip",
"(",
"[",
"'m'",
"=>",
"'phpmob.form.user.gender_man'",
",",
"'f'",
"=>",
"'phpmob.form.user.gender_female'",
",",
"]",
")",
",",
"'required'",
"=>",
"false",
",",
"]",
")",
"->",
"add",
"(",
"'phoneNumber'",
",",
"TelType",
"::",
"class",
",",
"[",
"'label'",
"=>",
"'phpmob.form.user.phone_number'",
",",
"'required'",
"=>",
"false",
",",
"]",
")",
"->",
"add",
"(",
"'birthday'",
",",
"DateType",
"::",
"class",
",",
"[",
"'label'",
"=>",
"'phpmob.form.user.birthday'",
",",
"'widget'",
"=>",
"'single_text'",
",",
"'required'",
"=>",
"false",
",",
"]",
")",
"->",
"add",
"(",
"'countryCode'",
",",
"CountryType",
"::",
"class",
",",
"[",
"'label'",
"=>",
"'phpmob.form.user.country_code'",
",",
"'required'",
"=>",
"false",
",",
"]",
")",
"->",
"add",
"(",
"'locale'",
",",
"LocaleChoiceType",
"::",
"class",
",",
"[",
"'label'",
"=>",
"'phpmob.form.user.locale'",
",",
"'required'",
"=>",
"false",
",",
"]",
")",
"->",
"add",
"(",
"'statusMessage'",
",",
"TextType",
"::",
"class",
",",
"[",
"'label'",
"=>",
"'phpmob.form.user.status_message'",
",",
"'required'",
"=>",
"false",
",",
"]",
")",
"->",
"add",
"(",
"'displayName'",
",",
"TextType",
"::",
"class",
",",
"[",
"'label'",
"=>",
"'phpmob.form.user.display_name'",
",",
"'required'",
"=>",
"false",
",",
"]",
")",
"->",
"add",
"(",
"'picture'",
",",
"WebUserPictureType",
"::",
"class",
",",
"[",
"'label'",
"=>",
"'phpmob.form.user.picture'",
",",
"'required'",
"=>",
"false",
",",
"]",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/phpmob/changmin/blob/bfebb1561229094d1c138574abab75f2f1d17d66/src/PhpMob/CoreBundle/Form/Type/WebUserType.php#L19-L70 |
fyuze/framework | src/Fyuze/Kernel/Services/Debug.php | Debug.bootstrap | public function bootstrap()
{
$this->registry->make('toolbar')
->addCollector(new Response($this->registry->make('response')), true);
} | php | public function bootstrap()
{
$this->registry->make('toolbar')
->addCollector(new Response($this->registry->make('response')), true);
} | [
"public",
"function",
"bootstrap",
"(",
")",
"{",
"$",
"this",
"->",
"registry",
"->",
"make",
"(",
"'toolbar'",
")",
"->",
"addCollector",
"(",
"new",
"Response",
"(",
"$",
"this",
"->",
"registry",
"->",
"make",
"(",
"'response'",
")",
")",
",",
"true",
")",
";",
"}"
] | Once the has started | [
"Once",
"the",
"has",
"started"
] | train | https://github.com/fyuze/framework/blob/89b3984f7225e24bfcdafb090ee197275b3222c9/src/Fyuze/Kernel/Services/Debug.php#L16-L20 |
teneleven/GeolocatorBundle | Command/GeocodeCommand.php | GeocodeCommand.execute | protected function execute(InputInterface $input, OutputInterface $output)
{
$geocoder = $this->getContainer()->get('teneleven.geolocator.geocoder');
$manager = $this->getContainer()->get('doctrine.orm.entity_manager');
$providers = $this->getContainer()->get('teneleven.geolocator.providers');
$addressExtractors = $this->getContainer()->get('teneleven.geolocator.address_extractors');
$entities = $input->getArgument('entity');
$flushInterval = $input->getOption('flush-interval');
if (!count($entities)) {
$entities = array_keys($providers->getProviders());
}
$counter = 0;
foreach ($entities as $entity) {
$output->write(sprintf('Processing entity type <comment>"%s"</comment>...', $entity));
$provider = $providers->getProvider($entity);
$addressExtractor = $addressExtractors->getExtractor($entity);
$locations = $provider->getUncodedLocations();
$output->writeln(sprintf('<comment>%s</comment> uncoded objects.', count($locations)));
if (!count($locations)) {
continue;
}
foreach ($locations as $location) {
if (!$location instanceof GeolocatableInterface) {
throw new \Exception('Geolocatable objects must implement GeolocatableInterface');
}
try {
$address = $addressExtractor->extractAddress($location);
$result = $geocoder->geocode($address);
} catch (AddressExtractionFailedException $e) { //this error indicates a misconfiguration
throw $e;
} catch (GeocoderException $e) {
$output->writeln(sprintf('<error>Error: %s</error>', $e->getMessage()));
continue;
}
$location->setLatitude($result->getLatitude());
$location->setLongitude($result->getLongitude());
$output->writeln(sprintf('<info>Success (Lat: %s, Lng: %s)</info>', $location->getLatitude(), $location->getLongitude()));
$counter++;
if ($flushInterval && (0 === $counter % $flushInterval)) {
$manager->flush();
}
}
$manager->flush();
}
$output->writeln('Done.');
} | php | protected function execute(InputInterface $input, OutputInterface $output)
{
$geocoder = $this->getContainer()->get('teneleven.geolocator.geocoder');
$manager = $this->getContainer()->get('doctrine.orm.entity_manager');
$providers = $this->getContainer()->get('teneleven.geolocator.providers');
$addressExtractors = $this->getContainer()->get('teneleven.geolocator.address_extractors');
$entities = $input->getArgument('entity');
$flushInterval = $input->getOption('flush-interval');
if (!count($entities)) {
$entities = array_keys($providers->getProviders());
}
$counter = 0;
foreach ($entities as $entity) {
$output->write(sprintf('Processing entity type <comment>"%s"</comment>...', $entity));
$provider = $providers->getProvider($entity);
$addressExtractor = $addressExtractors->getExtractor($entity);
$locations = $provider->getUncodedLocations();
$output->writeln(sprintf('<comment>%s</comment> uncoded objects.', count($locations)));
if (!count($locations)) {
continue;
}
foreach ($locations as $location) {
if (!$location instanceof GeolocatableInterface) {
throw new \Exception('Geolocatable objects must implement GeolocatableInterface');
}
try {
$address = $addressExtractor->extractAddress($location);
$result = $geocoder->geocode($address);
} catch (AddressExtractionFailedException $e) { //this error indicates a misconfiguration
throw $e;
} catch (GeocoderException $e) {
$output->writeln(sprintf('<error>Error: %s</error>', $e->getMessage()));
continue;
}
$location->setLatitude($result->getLatitude());
$location->setLongitude($result->getLongitude());
$output->writeln(sprintf('<info>Success (Lat: %s, Lng: %s)</info>', $location->getLatitude(), $location->getLongitude()));
$counter++;
if ($flushInterval && (0 === $counter % $flushInterval)) {
$manager->flush();
}
}
$manager->flush();
}
$output->writeln('Done.');
} | [
"protected",
"function",
"execute",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"$",
"geocoder",
"=",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"get",
"(",
"'teneleven.geolocator.geocoder'",
")",
";",
"$",
"manager",
"=",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"get",
"(",
"'doctrine.orm.entity_manager'",
")",
";",
"$",
"providers",
"=",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"get",
"(",
"'teneleven.geolocator.providers'",
")",
";",
"$",
"addressExtractors",
"=",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"get",
"(",
"'teneleven.geolocator.address_extractors'",
")",
";",
"$",
"entities",
"=",
"$",
"input",
"->",
"getArgument",
"(",
"'entity'",
")",
";",
"$",
"flushInterval",
"=",
"$",
"input",
"->",
"getOption",
"(",
"'flush-interval'",
")",
";",
"if",
"(",
"!",
"count",
"(",
"$",
"entities",
")",
")",
"{",
"$",
"entities",
"=",
"array_keys",
"(",
"$",
"providers",
"->",
"getProviders",
"(",
")",
")",
";",
"}",
"$",
"counter",
"=",
"0",
";",
"foreach",
"(",
"$",
"entities",
"as",
"$",
"entity",
")",
"{",
"$",
"output",
"->",
"write",
"(",
"sprintf",
"(",
"'Processing entity type <comment>\"%s\"</comment>...'",
",",
"$",
"entity",
")",
")",
";",
"$",
"provider",
"=",
"$",
"providers",
"->",
"getProvider",
"(",
"$",
"entity",
")",
";",
"$",
"addressExtractor",
"=",
"$",
"addressExtractors",
"->",
"getExtractor",
"(",
"$",
"entity",
")",
";",
"$",
"locations",
"=",
"$",
"provider",
"->",
"getUncodedLocations",
"(",
")",
";",
"$",
"output",
"->",
"writeln",
"(",
"sprintf",
"(",
"'<comment>%s</comment> uncoded objects.'",
",",
"count",
"(",
"$",
"locations",
")",
")",
")",
";",
"if",
"(",
"!",
"count",
"(",
"$",
"locations",
")",
")",
"{",
"continue",
";",
"}",
"foreach",
"(",
"$",
"locations",
"as",
"$",
"location",
")",
"{",
"if",
"(",
"!",
"$",
"location",
"instanceof",
"GeolocatableInterface",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Geolocatable objects must implement GeolocatableInterface'",
")",
";",
"}",
"try",
"{",
"$",
"address",
"=",
"$",
"addressExtractor",
"->",
"extractAddress",
"(",
"$",
"location",
")",
";",
"$",
"result",
"=",
"$",
"geocoder",
"->",
"geocode",
"(",
"$",
"address",
")",
";",
"}",
"catch",
"(",
"AddressExtractionFailedException",
"$",
"e",
")",
"{",
"//this error indicates a misconfiguration",
"throw",
"$",
"e",
";",
"}",
"catch",
"(",
"GeocoderException",
"$",
"e",
")",
"{",
"$",
"output",
"->",
"writeln",
"(",
"sprintf",
"(",
"'<error>Error: %s</error>'",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
")",
";",
"continue",
";",
"}",
"$",
"location",
"->",
"setLatitude",
"(",
"$",
"result",
"->",
"getLatitude",
"(",
")",
")",
";",
"$",
"location",
"->",
"setLongitude",
"(",
"$",
"result",
"->",
"getLongitude",
"(",
")",
")",
";",
"$",
"output",
"->",
"writeln",
"(",
"sprintf",
"(",
"'<info>Success (Lat: %s, Lng: %s)</info>'",
",",
"$",
"location",
"->",
"getLatitude",
"(",
")",
",",
"$",
"location",
"->",
"getLongitude",
"(",
")",
")",
")",
";",
"$",
"counter",
"++",
";",
"if",
"(",
"$",
"flushInterval",
"&&",
"(",
"0",
"===",
"$",
"counter",
"%",
"$",
"flushInterval",
")",
")",
"{",
"$",
"manager",
"->",
"flush",
"(",
")",
";",
"}",
"}",
"$",
"manager",
"->",
"flush",
"(",
")",
";",
"}",
"$",
"output",
"->",
"writeln",
"(",
"'Done.'",
")",
";",
"}"
] | {@inheritDoc} | [
"{"
] | train | https://github.com/teneleven/GeolocatorBundle/blob/4ead8e783a91577f2a67aa302b79641d4b9e99ad/Command/GeocodeCommand.php#L46-L105 |
VincentChalnot/SidusEAVFilterBundle | Filter/Type/DateRangeFilterType.php | DateRangeFilterType.handleData | public function handleData(QueryHandlerInterface $queryHandler, FilterInterface $filter, $data): void
{
if (!$queryHandler instanceof EAVQueryHandlerInterface) {
throw new BadQueryHandlerException($queryHandler, EAVQueryHandlerInterface::class);
}
if (!$queryHandler->isEAVFilter($filter)) {
$this->fallbackFilterType->handleData($queryHandler, $filter, $data);
return;
}
$eavQb = new EAVQueryBuilder($queryHandler->getQueryBuilder(), $queryHandler->getAlias());
$eavQb->setContext($queryHandler->getQueryContext());
$dqlHandlers = [];
foreach ($filter->getAttributes() as $attributePath) {
$attributeDqlHandlers = [];
$attributeQb = null;
if (!empty($data[DateRangeType::START_NAME])) {
$attributeQb = $queryHandler->getEAVAttributeQueryBuilder($eavQb, $attributePath);
$attributeDqlHandlers[] = $attributeQb->gte($data[DateRangeType::START_NAME]);
}
if (!empty($data[DateRangeType::END_NAME])) {
if ($attributeQb) {
$attributeQb = clone $attributeQb;
} else {
$attributeQb = $queryHandler->getEAVAttributeQueryBuilder($eavQb, $attributePath);
}
$attributeDqlHandlers[] = $attributeQb->lte($data[DateRangeType::END_NAME]);
}
if (0 < \count($attributeDqlHandlers)) {
$dqlHandlers[] = $eavQb->getAnd($attributeDqlHandlers);
}
}
if (0 < \count($dqlHandlers)) {
$eavQb->apply($eavQb->getOr($dqlHandlers));
}
} | php | public function handleData(QueryHandlerInterface $queryHandler, FilterInterface $filter, $data): void
{
if (!$queryHandler instanceof EAVQueryHandlerInterface) {
throw new BadQueryHandlerException($queryHandler, EAVQueryHandlerInterface::class);
}
if (!$queryHandler->isEAVFilter($filter)) {
$this->fallbackFilterType->handleData($queryHandler, $filter, $data);
return;
}
$eavQb = new EAVQueryBuilder($queryHandler->getQueryBuilder(), $queryHandler->getAlias());
$eavQb->setContext($queryHandler->getQueryContext());
$dqlHandlers = [];
foreach ($filter->getAttributes() as $attributePath) {
$attributeDqlHandlers = [];
$attributeQb = null;
if (!empty($data[DateRangeType::START_NAME])) {
$attributeQb = $queryHandler->getEAVAttributeQueryBuilder($eavQb, $attributePath);
$attributeDqlHandlers[] = $attributeQb->gte($data[DateRangeType::START_NAME]);
}
if (!empty($data[DateRangeType::END_NAME])) {
if ($attributeQb) {
$attributeQb = clone $attributeQb;
} else {
$attributeQb = $queryHandler->getEAVAttributeQueryBuilder($eavQb, $attributePath);
}
$attributeDqlHandlers[] = $attributeQb->lte($data[DateRangeType::END_NAME]);
}
if (0 < \count($attributeDqlHandlers)) {
$dqlHandlers[] = $eavQb->getAnd($attributeDqlHandlers);
}
}
if (0 < \count($dqlHandlers)) {
$eavQb->apply($eavQb->getOr($dqlHandlers));
}
} | [
"public",
"function",
"handleData",
"(",
"QueryHandlerInterface",
"$",
"queryHandler",
",",
"FilterInterface",
"$",
"filter",
",",
"$",
"data",
")",
":",
"void",
"{",
"if",
"(",
"!",
"$",
"queryHandler",
"instanceof",
"EAVQueryHandlerInterface",
")",
"{",
"throw",
"new",
"BadQueryHandlerException",
"(",
"$",
"queryHandler",
",",
"EAVQueryHandlerInterface",
"::",
"class",
")",
";",
"}",
"if",
"(",
"!",
"$",
"queryHandler",
"->",
"isEAVFilter",
"(",
"$",
"filter",
")",
")",
"{",
"$",
"this",
"->",
"fallbackFilterType",
"->",
"handleData",
"(",
"$",
"queryHandler",
",",
"$",
"filter",
",",
"$",
"data",
")",
";",
"return",
";",
"}",
"$",
"eavQb",
"=",
"new",
"EAVQueryBuilder",
"(",
"$",
"queryHandler",
"->",
"getQueryBuilder",
"(",
")",
",",
"$",
"queryHandler",
"->",
"getAlias",
"(",
")",
")",
";",
"$",
"eavQb",
"->",
"setContext",
"(",
"$",
"queryHandler",
"->",
"getQueryContext",
"(",
")",
")",
";",
"$",
"dqlHandlers",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"filter",
"->",
"getAttributes",
"(",
")",
"as",
"$",
"attributePath",
")",
"{",
"$",
"attributeDqlHandlers",
"=",
"[",
"]",
";",
"$",
"attributeQb",
"=",
"null",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"data",
"[",
"DateRangeType",
"::",
"START_NAME",
"]",
")",
")",
"{",
"$",
"attributeQb",
"=",
"$",
"queryHandler",
"->",
"getEAVAttributeQueryBuilder",
"(",
"$",
"eavQb",
",",
"$",
"attributePath",
")",
";",
"$",
"attributeDqlHandlers",
"[",
"]",
"=",
"$",
"attributeQb",
"->",
"gte",
"(",
"$",
"data",
"[",
"DateRangeType",
"::",
"START_NAME",
"]",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"data",
"[",
"DateRangeType",
"::",
"END_NAME",
"]",
")",
")",
"{",
"if",
"(",
"$",
"attributeQb",
")",
"{",
"$",
"attributeQb",
"=",
"clone",
"$",
"attributeQb",
";",
"}",
"else",
"{",
"$",
"attributeQb",
"=",
"$",
"queryHandler",
"->",
"getEAVAttributeQueryBuilder",
"(",
"$",
"eavQb",
",",
"$",
"attributePath",
")",
";",
"}",
"$",
"attributeDqlHandlers",
"[",
"]",
"=",
"$",
"attributeQb",
"->",
"lte",
"(",
"$",
"data",
"[",
"DateRangeType",
"::",
"END_NAME",
"]",
")",
";",
"}",
"if",
"(",
"0",
"<",
"\\",
"count",
"(",
"$",
"attributeDqlHandlers",
")",
")",
"{",
"$",
"dqlHandlers",
"[",
"]",
"=",
"$",
"eavQb",
"->",
"getAnd",
"(",
"$",
"attributeDqlHandlers",
")",
";",
"}",
"}",
"if",
"(",
"0",
"<",
"\\",
"count",
"(",
"$",
"dqlHandlers",
")",
")",
"{",
"$",
"eavQb",
"->",
"apply",
"(",
"$",
"eavQb",
"->",
"getOr",
"(",
"$",
"dqlHandlers",
")",
")",
";",
"}",
"}"
] | {@inheritdoc}
@throws \LogicException
@throws \UnexpectedValueException | [
"{",
"@inheritdoc",
"}"
] | train | https://github.com/VincentChalnot/SidusEAVFilterBundle/blob/25a9e0495fae30cb96ecded56c50cf7fe70c9032/Filter/Type/DateRangeFilterType.php#L23-L60 |
qcubed/orm | install/project/qcubed/Codegen/CodegenBase.php | CodegenBase.pluralize | protected function pluralize($strName)
{
// Special Rules go Here
switch (true) {
case ($strName == 'person'):
return 'people';
case ($strName == 'Person'):
return 'People';
case ($strName == 'PERSON'):
return 'PEOPLE';
// Trying to be cute here...
case (strtolower($strName) == 'fish'):
return $strName . 'ies';
// Otherwise, call parent
default:
return parent::pluralize($strName);
}
} | php | protected function pluralize($strName)
{
// Special Rules go Here
switch (true) {
case ($strName == 'person'):
return 'people';
case ($strName == 'Person'):
return 'People';
case ($strName == 'PERSON'):
return 'PEOPLE';
// Trying to be cute here...
case (strtolower($strName) == 'fish'):
return $strName . 'ies';
// Otherwise, call parent
default:
return parent::pluralize($strName);
}
} | [
"protected",
"function",
"pluralize",
"(",
"$",
"strName",
")",
"{",
"// Special Rules go Here",
"switch",
"(",
"true",
")",
"{",
"case",
"(",
"$",
"strName",
"==",
"'person'",
")",
":",
"return",
"'people'",
";",
"case",
"(",
"$",
"strName",
"==",
"'Person'",
")",
":",
"return",
"'People'",
";",
"case",
"(",
"$",
"strName",
"==",
"'PERSON'",
")",
":",
"return",
"'PEOPLE'",
";",
"// Trying to be cute here...",
"case",
"(",
"strtolower",
"(",
"$",
"strName",
")",
"==",
"'fish'",
")",
":",
"return",
"$",
"strName",
".",
"'ies'",
";",
"// Otherwise, call parent",
"default",
":",
"return",
"parent",
"::",
"pluralize",
"(",
"$",
"strName",
")",
";",
"}",
"}"
] | QCodeGen::pluralize()
Example: Overriding the Pluralize method
@param string $strName
@return string | [
"QCodeGen",
"::",
"pluralize",
"()"
] | train | https://github.com/qcubed/orm/blob/f320eba671f20874b1f3809c5293f8c02d5b1204/install/project/qcubed/Codegen/CodegenBase.php#L54-L73 |
drsdre/yii2-xmlsoccer | models/Player.php | Player.beforeSave | public function beforeSave($insert)
{
$this->date_of_birth = (empty($this->date_of_birth)) ? null : strtotime($this->date_of_birth);
$this->date_of_signing = (empty($this->date_of_signing)) ? null : strtotime($this->date_of_signing);
return parent::beforeSave($insert);
} | php | public function beforeSave($insert)
{
$this->date_of_birth = (empty($this->date_of_birth)) ? null : strtotime($this->date_of_birth);
$this->date_of_signing = (empty($this->date_of_signing)) ? null : strtotime($this->date_of_signing);
return parent::beforeSave($insert);
} | [
"public",
"function",
"beforeSave",
"(",
"$",
"insert",
")",
"{",
"$",
"this",
"->",
"date_of_birth",
"=",
"(",
"empty",
"(",
"$",
"this",
"->",
"date_of_birth",
")",
")",
"?",
"null",
":",
"strtotime",
"(",
"$",
"this",
"->",
"date_of_birth",
")",
";",
"$",
"this",
"->",
"date_of_signing",
"=",
"(",
"empty",
"(",
"$",
"this",
"->",
"date_of_signing",
")",
")",
"?",
"null",
":",
"strtotime",
"(",
"$",
"this",
"->",
"date_of_signing",
")",
";",
"return",
"parent",
"::",
"beforeSave",
"(",
"$",
"insert",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/drsdre/yii2-xmlsoccer/blob/a746edee6269ed0791bac6c6165a946adc30d994/models/Player.php#L93-L98 |
drsdre/yii2-xmlsoccer | models/Player.php | Player.afterFind | public function afterFind()
{
if (\Yii::$app->has('formatter')) {
if (!empty($this->date_of_birth)) {
$this->date_of_birth = \Yii::$app->formatter->asDate($this->date_of_birth);
}
if (!empty($this->date_of_signing)) {
$this->date_of_signing = \Yii::$app->formatter->asDate($this->date_of_signing);
}
}
return parent::afterFind();
} | php | public function afterFind()
{
if (\Yii::$app->has('formatter')) {
if (!empty($this->date_of_birth)) {
$this->date_of_birth = \Yii::$app->formatter->asDate($this->date_of_birth);
}
if (!empty($this->date_of_signing)) {
$this->date_of_signing = \Yii::$app->formatter->asDate($this->date_of_signing);
}
}
return parent::afterFind();
} | [
"public",
"function",
"afterFind",
"(",
")",
"{",
"if",
"(",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"has",
"(",
"'formatter'",
")",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"date_of_birth",
")",
")",
"{",
"$",
"this",
"->",
"date_of_birth",
"=",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"formatter",
"->",
"asDate",
"(",
"$",
"this",
"->",
"date_of_birth",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"date_of_signing",
")",
")",
"{",
"$",
"this",
"->",
"date_of_signing",
"=",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"formatter",
"->",
"asDate",
"(",
"$",
"this",
"->",
"date_of_signing",
")",
";",
"}",
"}",
"return",
"parent",
"::",
"afterFind",
"(",
")",
";",
"}"
] | {@inheritdoc}
@throws \yii\base\InvalidConfigException | [
"{"
] | train | https://github.com/drsdre/yii2-xmlsoccer/blob/a746edee6269ed0791bac6c6165a946adc30d994/models/Player.php#L104-L115 |
titon/db | src/Titon/Db/Repository.php | Repository.addBehavior | public function addBehavior(Behavior $behavior) {
$behavior->setRepository($this);
$this->_behaviors[$behavior->getAlias()] = $behavior;
$this->attachObject($behavior->getAlias(), $behavior);
if ($behavior instanceof Listener) {
$this->on('db', $behavior);
}
return $this;
} | php | public function addBehavior(Behavior $behavior) {
$behavior->setRepository($this);
$this->_behaviors[$behavior->getAlias()] = $behavior;
$this->attachObject($behavior->getAlias(), $behavior);
if ($behavior instanceof Listener) {
$this->on('db', $behavior);
}
return $this;
} | [
"public",
"function",
"addBehavior",
"(",
"Behavior",
"$",
"behavior",
")",
"{",
"$",
"behavior",
"->",
"setRepository",
"(",
"$",
"this",
")",
";",
"$",
"this",
"->",
"_behaviors",
"[",
"$",
"behavior",
"->",
"getAlias",
"(",
")",
"]",
"=",
"$",
"behavior",
";",
"$",
"this",
"->",
"attachObject",
"(",
"$",
"behavior",
"->",
"getAlias",
"(",
")",
",",
"$",
"behavior",
")",
";",
"if",
"(",
"$",
"behavior",
"instanceof",
"Listener",
")",
"{",
"$",
"this",
"->",
"on",
"(",
"'db'",
",",
"$",
"behavior",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Add a behavior.
@param \Titon\Db\Behavior $behavior
@return $this | [
"Add",
"a",
"behavior",
"."
] | train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Repository.php#L142-L154 |
titon/db | src/Titon/Db/Repository.php | Repository.aggregate | public function aggregate(Query $query, $function, $field) {
$query->fields(
Query::func(strtoupper($function), [$field => Func::FIELD])->asAlias('aggregate')
);
$results = $this->getDriver()
->setContext('read')
->executeQuery($query)
->find();
if (isset($results[0])) {
return (int) $results[0]['aggregate'];
}
return 0;
} | php | public function aggregate(Query $query, $function, $field) {
$query->fields(
Query::func(strtoupper($function), [$field => Func::FIELD])->asAlias('aggregate')
);
$results = $this->getDriver()
->setContext('read')
->executeQuery($query)
->find();
if (isset($results[0])) {
return (int) $results[0]['aggregate'];
}
return 0;
} | [
"public",
"function",
"aggregate",
"(",
"Query",
"$",
"query",
",",
"$",
"function",
",",
"$",
"field",
")",
"{",
"$",
"query",
"->",
"fields",
"(",
"Query",
"::",
"func",
"(",
"strtoupper",
"(",
"$",
"function",
")",
",",
"[",
"$",
"field",
"=>",
"Func",
"::",
"FIELD",
"]",
")",
"->",
"asAlias",
"(",
"'aggregate'",
")",
")",
";",
"$",
"results",
"=",
"$",
"this",
"->",
"getDriver",
"(",
")",
"->",
"setContext",
"(",
"'read'",
")",
"->",
"executeQuery",
"(",
"$",
"query",
")",
"->",
"find",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"results",
"[",
"0",
"]",
")",
")",
"{",
"return",
"(",
"int",
")",
"$",
"results",
"[",
"0",
"]",
"[",
"'aggregate'",
"]",
";",
"}",
"return",
"0",
";",
"}"
] | Perform an aggregation on the database and return the calculated value.
The currently supported aggregates are `avg`, `count`, `min`, `max`, and `sum`.
@param \Titon\Db\Query $query
@param string $function
@param string $field
@return int | [
"Perform",
"an",
"aggregation",
"on",
"the",
"database",
"and",
"return",
"the",
"calculated",
"value",
".",
"The",
"currently",
"supported",
"aggregates",
"are",
"avg",
"count",
"min",
"max",
"and",
"sum",
"."
] | train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Repository.php#L178-L193 |
titon/db | src/Titon/Db/Repository.php | Repository.castResults | public function castResults(Event $event, array &$results, $finder) {
$columns = $this->getSchema()->getColumns();
$driver = $this->getDriver();
$entityClass = $this->getEntity();
foreach ($results as $i => $result) {
foreach ($result as $field => $value) {
if (isset($columns[$field])) {
$result[$field] = $driver->getType($columns[$field]['type'])->from($value);
}
if (!is_array($value)) {
continue;
}
$result[$field] = new Entity($value);
}
$results[$i] = new $entityClass($result);
}
} | php | public function castResults(Event $event, array &$results, $finder) {
$columns = $this->getSchema()->getColumns();
$driver = $this->getDriver();
$entityClass = $this->getEntity();
foreach ($results as $i => $result) {
foreach ($result as $field => $value) {
if (isset($columns[$field])) {
$result[$field] = $driver->getType($columns[$field]['type'])->from($value);
}
if (!is_array($value)) {
continue;
}
$result[$field] = new Entity($value);
}
$results[$i] = new $entityClass($result);
}
} | [
"public",
"function",
"castResults",
"(",
"Event",
"$",
"event",
",",
"array",
"&",
"$",
"results",
",",
"$",
"finder",
")",
"{",
"$",
"columns",
"=",
"$",
"this",
"->",
"getSchema",
"(",
")",
"->",
"getColumns",
"(",
")",
";",
"$",
"driver",
"=",
"$",
"this",
"->",
"getDriver",
"(",
")",
";",
"$",
"entityClass",
"=",
"$",
"this",
"->",
"getEntity",
"(",
")",
";",
"foreach",
"(",
"$",
"results",
"as",
"$",
"i",
"=>",
"$",
"result",
")",
"{",
"foreach",
"(",
"$",
"result",
"as",
"$",
"field",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"columns",
"[",
"$",
"field",
"]",
")",
")",
"{",
"$",
"result",
"[",
"$",
"field",
"]",
"=",
"$",
"driver",
"->",
"getType",
"(",
"$",
"columns",
"[",
"$",
"field",
"]",
"[",
"'type'",
"]",
")",
"->",
"from",
"(",
"$",
"value",
")",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"continue",
";",
"}",
"$",
"result",
"[",
"$",
"field",
"]",
"=",
"new",
"Entity",
"(",
"$",
"value",
")",
";",
"}",
"$",
"results",
"[",
"$",
"i",
"]",
"=",
"new",
"$",
"entityClass",
"(",
"$",
"result",
")",
";",
"}",
"}"
] | Type cast the results and wrap each result in an entity after a find operation.
@param \Titon\Event\Event $event
@param array $results
@param string $finder | [
"Type",
"cast",
"the",
"results",
"and",
"wrap",
"each",
"result",
"in",
"an",
"entity",
"after",
"a",
"find",
"operation",
"."
] | train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Repository.php#L202-L222 |
titon/db | src/Titon/Db/Repository.php | Repository.create | public function create($data, array $options = []) {
return $this->query(Query::INSERT)->save($data, $options);
} | php | public function create($data, array $options = []) {
return $this->query(Query::INSERT)->save($data, $options);
} | [
"public",
"function",
"create",
"(",
"$",
"data",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"query",
"(",
"Query",
"::",
"INSERT",
")",
"->",
"save",
"(",
"$",
"data",
",",
"$",
"options",
")",
";",
"}"
] | Insert data into the database as a new record.
If any related data exists, insert new records after joining them to the original record.
Validate schema data and related data structure before inserting.
@param array|\Titon\Type\Contract\Arrayable $data
@param array $options
@return int The record ID on success, 0 on failure | [
"Insert",
"data",
"into",
"the",
"database",
"as",
"a",
"new",
"record",
".",
"If",
"any",
"related",
"data",
"exists",
"insert",
"new",
"records",
"after",
"joining",
"them",
"to",
"the",
"original",
"record",
".",
"Validate",
"schema",
"data",
"and",
"related",
"data",
"structure",
"before",
"inserting",
"."
] | train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Repository.php#L233-L235 |
titon/db | src/Titon/Db/Repository.php | Repository.createMany | public function createMany(array $data, $allowPk = false, array $options = []) {
$pk = $this->getPrimaryKey();
$columns = $this->getSchema()->getColumns();
$records = [];
$defaults = [];
if ($columns) {
foreach ($columns as $key => $column) {
$defaults[$key] = array_key_exists('default', $column) ? $column['default'] : '';
}
unset($defaults[$pk]);
}
foreach ($data as $record) {
// Convert from an entity
if ($record instanceof Arrayable) {
$record = $record->toArray();
}
// Merge in defaults
$record = Hash::merge($defaults, $record);
// Remove primary key
if (!$allowPk) {
unset($record[$pk]);
}
// Filter out invalid columns
if ($columns) {
$record = array_intersect_key($record, $columns);
}
$records[] = $record;
}
return $this->query(Query::MULTI_INSERT)->save($records, $options);
} | php | public function createMany(array $data, $allowPk = false, array $options = []) {
$pk = $this->getPrimaryKey();
$columns = $this->getSchema()->getColumns();
$records = [];
$defaults = [];
if ($columns) {
foreach ($columns as $key => $column) {
$defaults[$key] = array_key_exists('default', $column) ? $column['default'] : '';
}
unset($defaults[$pk]);
}
foreach ($data as $record) {
// Convert from an entity
if ($record instanceof Arrayable) {
$record = $record->toArray();
}
// Merge in defaults
$record = Hash::merge($defaults, $record);
// Remove primary key
if (!$allowPk) {
unset($record[$pk]);
}
// Filter out invalid columns
if ($columns) {
$record = array_intersect_key($record, $columns);
}
$records[] = $record;
}
return $this->query(Query::MULTI_INSERT)->save($records, $options);
} | [
"public",
"function",
"createMany",
"(",
"array",
"$",
"data",
",",
"$",
"allowPk",
"=",
"false",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"pk",
"=",
"$",
"this",
"->",
"getPrimaryKey",
"(",
")",
";",
"$",
"columns",
"=",
"$",
"this",
"->",
"getSchema",
"(",
")",
"->",
"getColumns",
"(",
")",
";",
"$",
"records",
"=",
"[",
"]",
";",
"$",
"defaults",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"columns",
")",
"{",
"foreach",
"(",
"$",
"columns",
"as",
"$",
"key",
"=>",
"$",
"column",
")",
"{",
"$",
"defaults",
"[",
"$",
"key",
"]",
"=",
"array_key_exists",
"(",
"'default'",
",",
"$",
"column",
")",
"?",
"$",
"column",
"[",
"'default'",
"]",
":",
"''",
";",
"}",
"unset",
"(",
"$",
"defaults",
"[",
"$",
"pk",
"]",
")",
";",
"}",
"foreach",
"(",
"$",
"data",
"as",
"$",
"record",
")",
"{",
"// Convert from an entity",
"if",
"(",
"$",
"record",
"instanceof",
"Arrayable",
")",
"{",
"$",
"record",
"=",
"$",
"record",
"->",
"toArray",
"(",
")",
";",
"}",
"// Merge in defaults",
"$",
"record",
"=",
"Hash",
"::",
"merge",
"(",
"$",
"defaults",
",",
"$",
"record",
")",
";",
"// Remove primary key",
"if",
"(",
"!",
"$",
"allowPk",
")",
"{",
"unset",
"(",
"$",
"record",
"[",
"$",
"pk",
"]",
")",
";",
"}",
"// Filter out invalid columns",
"if",
"(",
"$",
"columns",
")",
"{",
"$",
"record",
"=",
"array_intersect_key",
"(",
"$",
"record",
",",
"$",
"columns",
")",
";",
"}",
"$",
"records",
"[",
"]",
"=",
"$",
"record",
";",
"}",
"return",
"$",
"this",
"->",
"query",
"(",
"Query",
"::",
"MULTI_INSERT",
")",
"->",
"save",
"(",
"$",
"records",
",",
"$",
"options",
")",
";",
"}"
] | Insert multiple records into the database using a single query.
Missing fields will be added with an empty value or the schema default value.
Does not support callbacks or transactions.
@uses Titon\Utility\Hash
@param array $data Multi-dimensional array of records
@param bool $allowPk If true will allow primary key fields, else will remove them
@param array $options
@return int The count of records inserted | [
"Insert",
"multiple",
"records",
"into",
"the",
"database",
"using",
"a",
"single",
"query",
".",
"Missing",
"fields",
"will",
"be",
"added",
"with",
"an",
"empty",
"value",
"or",
"the",
"schema",
"default",
"value",
".",
"Does",
"not",
"support",
"callbacks",
"or",
"transactions",
"."
] | train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Repository.php#L249-L287 |
titon/db | src/Titon/Db/Repository.php | Repository.createTable | public function createTable(array $options = [], array $attributes = []) {
$schema = $this->getSchema();
$schema->addOptions($options);
// Create the table
$status = (bool) $this->query(Query::CREATE_TABLE)
->attribute($attributes)
->schema($schema)
->save();
// Create the indexes
if ($status) {
foreach ($schema->getIndexes() as $index => $columns) {
$this->query(Query::CREATE_INDEX)
->from($schema->getTable(), $index)
->save($columns);
}
}
return $status;
} | php | public function createTable(array $options = [], array $attributes = []) {
$schema = $this->getSchema();
$schema->addOptions($options);
// Create the table
$status = (bool) $this->query(Query::CREATE_TABLE)
->attribute($attributes)
->schema($schema)
->save();
// Create the indexes
if ($status) {
foreach ($schema->getIndexes() as $index => $columns) {
$this->query(Query::CREATE_INDEX)
->from($schema->getTable(), $index)
->save($columns);
}
}
return $status;
} | [
"public",
"function",
"createTable",
"(",
"array",
"$",
"options",
"=",
"[",
"]",
",",
"array",
"$",
"attributes",
"=",
"[",
"]",
")",
"{",
"$",
"schema",
"=",
"$",
"this",
"->",
"getSchema",
"(",
")",
";",
"$",
"schema",
"->",
"addOptions",
"(",
"$",
"options",
")",
";",
"// Create the table",
"$",
"status",
"=",
"(",
"bool",
")",
"$",
"this",
"->",
"query",
"(",
"Query",
"::",
"CREATE_TABLE",
")",
"->",
"attribute",
"(",
"$",
"attributes",
")",
"->",
"schema",
"(",
"$",
"schema",
")",
"->",
"save",
"(",
")",
";",
"// Create the indexes",
"if",
"(",
"$",
"status",
")",
"{",
"foreach",
"(",
"$",
"schema",
"->",
"getIndexes",
"(",
")",
"as",
"$",
"index",
"=>",
"$",
"columns",
")",
"{",
"$",
"this",
"->",
"query",
"(",
"Query",
"::",
"CREATE_INDEX",
")",
"->",
"from",
"(",
"$",
"schema",
"->",
"getTable",
"(",
")",
",",
"$",
"index",
")",
"->",
"save",
"(",
"$",
"columns",
")",
";",
"}",
"}",
"return",
"$",
"status",
";",
"}"
] | Create a database table and indexes based off the tables schema.
The schema must be an array of column data.
@param array $options
@param array $attributes
@return bool | [
"Create",
"a",
"database",
"table",
"and",
"indexes",
"based",
"off",
"the",
"tables",
"schema",
".",
"The",
"schema",
"must",
"be",
"an",
"array",
"of",
"column",
"data",
"."
] | train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Repository.php#L297-L317 |
titon/db | src/Titon/Db/Repository.php | Repository.decrement | public function decrement($id, array $fields) {
$data = [];
foreach ($fields as $field => $step) {
$data[$field] = Query::expr($field, '-', $step);
}
$query = $this->query(Query::UPDATE);
if ($id instanceof Closure) {
$query->bindCallback($id);
} else if ($id) {
$query->where($this->getPrimaryKey(), $id);
}
return $query->save($data);
} | php | public function decrement($id, array $fields) {
$data = [];
foreach ($fields as $field => $step) {
$data[$field] = Query::expr($field, '-', $step);
}
$query = $this->query(Query::UPDATE);
if ($id instanceof Closure) {
$query->bindCallback($id);
} else if ($id) {
$query->where($this->getPrimaryKey(), $id);
}
return $query->save($data);
} | [
"public",
"function",
"decrement",
"(",
"$",
"id",
",",
"array",
"$",
"fields",
")",
"{",
"$",
"data",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"field",
"=>",
"$",
"step",
")",
"{",
"$",
"data",
"[",
"$",
"field",
"]",
"=",
"Query",
"::",
"expr",
"(",
"$",
"field",
",",
"'-'",
",",
"$",
"step",
")",
";",
"}",
"$",
"query",
"=",
"$",
"this",
"->",
"query",
"(",
"Query",
"::",
"UPDATE",
")",
";",
"if",
"(",
"$",
"id",
"instanceof",
"Closure",
")",
"{",
"$",
"query",
"->",
"bindCallback",
"(",
"$",
"id",
")",
";",
"}",
"else",
"if",
"(",
"$",
"id",
")",
"{",
"$",
"query",
"->",
"where",
"(",
"$",
"this",
"->",
"getPrimaryKey",
"(",
")",
",",
"$",
"id",
")",
";",
"}",
"return",
"$",
"query",
"->",
"save",
"(",
"$",
"data",
")",
";",
"}"
] | Decrement the value of a field(s) using a step number.
Will update all records, or a single record.
@param int|int[]|\Closure $id
@param array $fields
@return int | [
"Decrement",
"the",
"value",
"of",
"a",
"field",
"(",
"s",
")",
"using",
"a",
"step",
"number",
".",
"Will",
"update",
"all",
"records",
"or",
"a",
"single",
"record",
"."
] | train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Repository.php#L327-L344 |
titon/db | src/Titon/Db/Repository.php | Repository.delete | public function delete($id, array $options = []) {
return $this->query(Query::DELETE)
->where($this->getPrimaryKey(), $id)
->save([], $options);
} | php | public function delete($id, array $options = []) {
return $this->query(Query::DELETE)
->where($this->getPrimaryKey(), $id)
->save([], $options);
} | [
"public",
"function",
"delete",
"(",
"$",
"id",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"query",
"(",
"Query",
"::",
"DELETE",
")",
"->",
"where",
"(",
"$",
"this",
"->",
"getPrimaryKey",
"(",
")",
",",
"$",
"id",
")",
"->",
"save",
"(",
"[",
"]",
",",
"$",
"options",
")",
";",
"}"
] | Delete a record by ID.
@param int|int[] $id
@param array $options
@return int The count of records deleted | [
"Delete",
"a",
"record",
"by",
"ID",
"."
] | train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Repository.php#L353-L357 |
titon/db | src/Titon/Db/Repository.php | Repository.deleteMany | public function deleteMany(Closure $conditions, array $options = []) {
$query = $this->query(Query::DELETE)->bindCallback($conditions);
// Validate that this won't delete all records
$where = $query->getWhere()->getParams();
if (empty($where)) {
throw new InvalidQueryException('No where clause detected, will not delete all records');
}
return $query->save([], $options);
} | php | public function deleteMany(Closure $conditions, array $options = []) {
$query = $this->query(Query::DELETE)->bindCallback($conditions);
// Validate that this won't delete all records
$where = $query->getWhere()->getParams();
if (empty($where)) {
throw new InvalidQueryException('No where clause detected, will not delete all records');
}
return $query->save([], $options);
} | [
"public",
"function",
"deleteMany",
"(",
"Closure",
"$",
"conditions",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"query",
"(",
"Query",
"::",
"DELETE",
")",
"->",
"bindCallback",
"(",
"$",
"conditions",
")",
";",
"// Validate that this won't delete all records",
"$",
"where",
"=",
"$",
"query",
"->",
"getWhere",
"(",
")",
"->",
"getParams",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"where",
")",
")",
"{",
"throw",
"new",
"InvalidQueryException",
"(",
"'No where clause detected, will not delete all records'",
")",
";",
"}",
"return",
"$",
"query",
"->",
"save",
"(",
"[",
"]",
",",
"$",
"options",
")",
";",
"}"
] | Delete multiple records with conditions.
@param \Closure $conditions
@param array $options
@return int The count of records deleted
@throws \Titon\Db\Exception\InvalidQueryException | [
"Delete",
"multiple",
"records",
"with",
"conditions",
"."
] | train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Repository.php#L367-L378 |
titon/db | src/Titon/Db/Repository.php | Repository.exists | public function exists($id) {
return (bool) $this->select()->where($this->getPrimaryKey(), $id)->count();
} | php | public function exists($id) {
return (bool) $this->select()->where($this->getPrimaryKey(), $id)->count();
} | [
"public",
"function",
"exists",
"(",
"$",
"id",
")",
"{",
"return",
"(",
"bool",
")",
"$",
"this",
"->",
"select",
"(",
")",
"->",
"where",
"(",
"$",
"this",
"->",
"getPrimaryKey",
"(",
")",
",",
"$",
"id",
")",
"->",
"count",
"(",
")",
";",
"}"
] | Check if a record with an ID exists.
@param int $id
@return bool | [
"Check",
"if",
"a",
"record",
"with",
"an",
"ID",
"exists",
"."
] | train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Repository.php#L395-L397 |
titon/db | src/Titon/Db/Repository.php | Repository.filterData | public function filterData(Event $event, Query $query, $id, array &$data) {
if ($columns = $this->getSchema()->getColumns()) {
$data = array_intersect_key($data, $columns);
}
return true;
} | php | public function filterData(Event $event, Query $query, $id, array &$data) {
if ($columns = $this->getSchema()->getColumns()) {
$data = array_intersect_key($data, $columns);
}
return true;
} | [
"public",
"function",
"filterData",
"(",
"Event",
"$",
"event",
",",
"Query",
"$",
"query",
",",
"$",
"id",
",",
"array",
"&",
"$",
"data",
")",
"{",
"if",
"(",
"$",
"columns",
"=",
"$",
"this",
"->",
"getSchema",
"(",
")",
"->",
"getColumns",
"(",
")",
")",
"{",
"$",
"data",
"=",
"array_intersect_key",
"(",
"$",
"data",
",",
"$",
"columns",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Filter out invalid columns before a save operation.
@param \Titon\Event\Event $event
@param \Titon\Db\Query $query
@param int|int[] $id
@param array $data
@return bool | [
"Filter",
"out",
"invalid",
"columns",
"before",
"a",
"save",
"operation",
"."
] | train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Repository.php#L408-L414 |
titon/db | src/Titon/Db/Repository.php | Repository.find | public function find(Query $query, $type, array $options = []) {
$options = $options + [
'before' => true,
'after' => true,
'collection' => $this->getConfig('collection')
];
$finder = $this->getFinder($type);
$state = null;
if ($options['before']) {
$event = $this->emit('db.preFind', [$query, $type]);
$state = $event->getState();
if (!$state) {
return $finder->noResults($options);
}
}
// Use the event response as the results
if (is_array($state)) {
$results = $state;
// Query the driver for results
} else {
$finder->before($query, $options);
// Update the connection context
$results = $this->getDriver()
->setContext('read')
->executeQuery($query)
->find();
}
if (!$results) {
return $finder->noResults($options);
}
if ($options['after']) {
$this->emit('db.postFind', [&$results, $type]);
}
return $finder->after($results, $options);
} | php | public function find(Query $query, $type, array $options = []) {
$options = $options + [
'before' => true,
'after' => true,
'collection' => $this->getConfig('collection')
];
$finder = $this->getFinder($type);
$state = null;
if ($options['before']) {
$event = $this->emit('db.preFind', [$query, $type]);
$state = $event->getState();
if (!$state) {
return $finder->noResults($options);
}
}
// Use the event response as the results
if (is_array($state)) {
$results = $state;
// Query the driver for results
} else {
$finder->before($query, $options);
// Update the connection context
$results = $this->getDriver()
->setContext('read')
->executeQuery($query)
->find();
}
if (!$results) {
return $finder->noResults($options);
}
if ($options['after']) {
$this->emit('db.postFind', [&$results, $type]);
}
return $finder->after($results, $options);
} | [
"public",
"function",
"find",
"(",
"Query",
"$",
"query",
",",
"$",
"type",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"options",
"=",
"$",
"options",
"+",
"[",
"'before'",
"=>",
"true",
",",
"'after'",
"=>",
"true",
",",
"'collection'",
"=>",
"$",
"this",
"->",
"getConfig",
"(",
"'collection'",
")",
"]",
";",
"$",
"finder",
"=",
"$",
"this",
"->",
"getFinder",
"(",
"$",
"type",
")",
";",
"$",
"state",
"=",
"null",
";",
"if",
"(",
"$",
"options",
"[",
"'before'",
"]",
")",
"{",
"$",
"event",
"=",
"$",
"this",
"->",
"emit",
"(",
"'db.preFind'",
",",
"[",
"$",
"query",
",",
"$",
"type",
"]",
")",
";",
"$",
"state",
"=",
"$",
"event",
"->",
"getState",
"(",
")",
";",
"if",
"(",
"!",
"$",
"state",
")",
"{",
"return",
"$",
"finder",
"->",
"noResults",
"(",
"$",
"options",
")",
";",
"}",
"}",
"// Use the event response as the results",
"if",
"(",
"is_array",
"(",
"$",
"state",
")",
")",
"{",
"$",
"results",
"=",
"$",
"state",
";",
"// Query the driver for results",
"}",
"else",
"{",
"$",
"finder",
"->",
"before",
"(",
"$",
"query",
",",
"$",
"options",
")",
";",
"// Update the connection context",
"$",
"results",
"=",
"$",
"this",
"->",
"getDriver",
"(",
")",
"->",
"setContext",
"(",
"'read'",
")",
"->",
"executeQuery",
"(",
"$",
"query",
")",
"->",
"find",
"(",
")",
";",
"}",
"if",
"(",
"!",
"$",
"results",
")",
"{",
"return",
"$",
"finder",
"->",
"noResults",
"(",
"$",
"options",
")",
";",
"}",
"if",
"(",
"$",
"options",
"[",
"'after'",
"]",
")",
"{",
"$",
"this",
"->",
"emit",
"(",
"'db.postFind'",
",",
"[",
"&",
"$",
"results",
",",
"$",
"type",
"]",
")",
";",
"}",
"return",
"$",
"finder",
"->",
"after",
"(",
"$",
"results",
",",
"$",
"options",
")",
";",
"}"
] | All-in-one method for fetching results from a query.
Depending on the type of finder, the returned results will differ.
Before a fetch is executed, a `preFind` event will be triggered.
If this event returns a falsey value, the find will exit and
return a `noResults` value based on the current finder.
If this event returns an array of data, the find will exit and
return the array as the results instead of querying the driver.
Before executing against the driver, the finders `before` method
will be called allowing the current query to be modified.
The driver connection context will also be set to `read`.
If no results are returned from the driver, the finders `noResults`
method will be called.
After a fetch is executed (or a `preFind` event returns data),
a `postFind` event will be triggered. This event allows
the results to be modified via references.
Finally, before the results are returned, wrap each row in an
entity object and pass it through the finders `after` method.
@param \Titon\Db\Query $query
@param string $type
@param mixed $options {
@type bool $before Will trigger before callbacks
@type bool $after Will trigger after callbacks
}
@return array|\Titon\Db\Entity|\Titon\Db\EntityCollection | [
"All",
"-",
"in",
"-",
"one",
"method",
"for",
"fetching",
"results",
"from",
"a",
"query",
".",
"Depending",
"on",
"the",
"type",
"of",
"finder",
"the",
"returned",
"results",
"will",
"differ",
"."
] | train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Repository.php#L447-L490 |
titon/db | src/Titon/Db/Repository.php | Repository.findID | public function findID(Query $query) {
$pk = $this->getPrimaryKey();
// Gather ID from where clause
foreach ($query->getWhere()->getParams() as $param) {
if ($param instanceof Expr && $param->getField() === $pk && in_array($param->getOperator(), ['=', 'in'])) {
return $param->getValue();
}
}
// Query for the ID then
$select = clone $query;
$results = array_values($select->setType(Query::SELECT)->fields($pk)->lists($pk, $pk, [
'before' => false,
'after' => false
]));
if (count($results) > 1) {
return $results;
} else if (count($results) === 1) {
return $results[0];
}
return null;
} | php | public function findID(Query $query) {
$pk = $this->getPrimaryKey();
// Gather ID from where clause
foreach ($query->getWhere()->getParams() as $param) {
if ($param instanceof Expr && $param->getField() === $pk && in_array($param->getOperator(), ['=', 'in'])) {
return $param->getValue();
}
}
// Query for the ID then
$select = clone $query;
$results = array_values($select->setType(Query::SELECT)->fields($pk)->lists($pk, $pk, [
'before' => false,
'after' => false
]));
if (count($results) > 1) {
return $results;
} else if (count($results) === 1) {
return $results[0];
}
return null;
} | [
"public",
"function",
"findID",
"(",
"Query",
"$",
"query",
")",
"{",
"$",
"pk",
"=",
"$",
"this",
"->",
"getPrimaryKey",
"(",
")",
";",
"// Gather ID from where clause",
"foreach",
"(",
"$",
"query",
"->",
"getWhere",
"(",
")",
"->",
"getParams",
"(",
")",
"as",
"$",
"param",
")",
"{",
"if",
"(",
"$",
"param",
"instanceof",
"Expr",
"&&",
"$",
"param",
"->",
"getField",
"(",
")",
"===",
"$",
"pk",
"&&",
"in_array",
"(",
"$",
"param",
"->",
"getOperator",
"(",
")",
",",
"[",
"'='",
",",
"'in'",
"]",
")",
")",
"{",
"return",
"$",
"param",
"->",
"getValue",
"(",
")",
";",
"}",
"}",
"// Query for the ID then",
"$",
"select",
"=",
"clone",
"$",
"query",
";",
"$",
"results",
"=",
"array_values",
"(",
"$",
"select",
"->",
"setType",
"(",
"Query",
"::",
"SELECT",
")",
"->",
"fields",
"(",
"$",
"pk",
")",
"->",
"lists",
"(",
"$",
"pk",
",",
"$",
"pk",
",",
"[",
"'before'",
"=>",
"false",
",",
"'after'",
"=>",
"false",
"]",
")",
")",
";",
"if",
"(",
"count",
"(",
"$",
"results",
")",
">",
"1",
")",
"{",
"return",
"$",
"results",
";",
"}",
"else",
"if",
"(",
"count",
"(",
"$",
"results",
")",
"===",
"1",
")",
"{",
"return",
"$",
"results",
"[",
"0",
"]",
";",
"}",
"return",
"null",
";",
"}"
] | Find the a primary key value within a query. Begin by looping through the where clause and match any value
that equates to the PK field. If none can be found, do a select query for a list of IDs.
@param \Titon\Db\Query $query
@return int|int[] | [
"Find",
"the",
"a",
"primary",
"key",
"value",
"within",
"a",
"query",
".",
"Begin",
"by",
"looping",
"through",
"the",
"where",
"clause",
"and",
"match",
"any",
"value",
"that",
"equates",
"to",
"the",
"PK",
"field",
".",
"If",
"none",
"can",
"be",
"found",
"do",
"a",
"select",
"query",
"for",
"a",
"list",
"of",
"IDs",
"."
] | train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Repository.php#L499-L524 |
titon/db | src/Titon/Db/Repository.php | Repository.getBehavior | public function getBehavior($alias) {
if ($this->hasBehavior($alias)) {
return $this->_behaviors[$alias];
}
throw new MissingBehaviorException(sprintf('Behavior %s does not exist', $alias));
} | php | public function getBehavior($alias) {
if ($this->hasBehavior($alias)) {
return $this->_behaviors[$alias];
}
throw new MissingBehaviorException(sprintf('Behavior %s does not exist', $alias));
} | [
"public",
"function",
"getBehavior",
"(",
"$",
"alias",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasBehavior",
"(",
"$",
"alias",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_behaviors",
"[",
"$",
"alias",
"]",
";",
"}",
"throw",
"new",
"MissingBehaviorException",
"(",
"sprintf",
"(",
"'Behavior %s does not exist'",
",",
"$",
"alias",
")",
")",
";",
"}"
] | Return a behavior by alias.
@param string $alias
@return \Titon\Db\Behavior
@throws \Titon\Db\Exception\MissingBehaviorException | [
"Return",
"a",
"behavior",
"by",
"alias",
"."
] | train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Repository.php#L542-L548 |
titon/db | src/Titon/Db/Repository.php | Repository.getDisplayField | public function getDisplayField() {
return $this->cache(__METHOD__, function() {
$fields = $this->getConfig('displayField');
$schema = $this->getSchema();
foreach ((array) $fields as $field) {
if ($schema->hasColumn($field)) {
return $field;
}
}
return $this->getPrimaryKey();
});
} | php | public function getDisplayField() {
return $this->cache(__METHOD__, function() {
$fields = $this->getConfig('displayField');
$schema = $this->getSchema();
foreach ((array) $fields as $field) {
if ($schema->hasColumn($field)) {
return $field;
}
}
return $this->getPrimaryKey();
});
} | [
"public",
"function",
"getDisplayField",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"cache",
"(",
"__METHOD__",
",",
"function",
"(",
")",
"{",
"$",
"fields",
"=",
"$",
"this",
"->",
"getConfig",
"(",
"'displayField'",
")",
";",
"$",
"schema",
"=",
"$",
"this",
"->",
"getSchema",
"(",
")",
";",
"foreach",
"(",
"(",
"array",
")",
"$",
"fields",
"as",
"$",
"field",
")",
"{",
"if",
"(",
"$",
"schema",
"->",
"hasColumn",
"(",
"$",
"field",
")",
")",
"{",
"return",
"$",
"field",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"getPrimaryKey",
"(",
")",
";",
"}",
")",
";",
"}"
] | Return the field used as the display field.
@return string | [
"Return",
"the",
"field",
"used",
"as",
"the",
"display",
"field",
"."
] | train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Repository.php#L587-L600 |
titon/db | src/Titon/Db/Repository.php | Repository.getDriver | public function getDriver() {
if ($this->_driver) {
return $this->_driver;
}
return $this->_driver = $this->getDatabase()->getDriver($this->getConnectionKey());
} | php | public function getDriver() {
if ($this->_driver) {
return $this->_driver;
}
return $this->_driver = $this->getDatabase()->getDriver($this->getConnectionKey());
} | [
"public",
"function",
"getDriver",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_driver",
")",
"{",
"return",
"$",
"this",
"->",
"_driver",
";",
"}",
"return",
"$",
"this",
"->",
"_driver",
"=",
"$",
"this",
"->",
"getDatabase",
"(",
")",
"->",
"getDriver",
"(",
"$",
"this",
"->",
"getConnectionKey",
"(",
")",
")",
";",
"}"
] | Return the driver defined by key.
@uses Titon\Common\Registry
@return \Titon\Db\Driver | [
"Return",
"the",
"driver",
"defined",
"by",
"key",
"."
] | train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Repository.php#L609-L615 |
titon/db | src/Titon/Db/Repository.php | Repository.getFinder | public function getFinder($key) {
if (isset($this->_finders[$key])) {
return $this->_finders[$key];
}
throw new MissingFinderException(sprintf('Finder %s does not exist', $key));
} | php | public function getFinder($key) {
if (isset($this->_finders[$key])) {
return $this->_finders[$key];
}
throw new MissingFinderException(sprintf('Finder %s does not exist', $key));
} | [
"public",
"function",
"getFinder",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_finders",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_finders",
"[",
"$",
"key",
"]",
";",
"}",
"throw",
"new",
"MissingFinderException",
"(",
"sprintf",
"(",
"'Finder %s does not exist'",
",",
"$",
"key",
")",
")",
";",
"}"
] | Return a finder by name.
@param string $key
@return \Titon\Db\Finder
@throws \Titon\Db\Exception\MissingFinderException | [
"Return",
"a",
"finder",
"by",
"name",
"."
] | train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Repository.php#L633-L639 |
titon/db | src/Titon/Db/Repository.php | Repository.getPrimaryKey | public function getPrimaryKey() {
return $this->cache(__METHOD__, function() {
$pk = $this->getConfig('primaryKey');
$schema = $this->getSchema();
if ($schema->hasColumn($pk)) {
return $pk;
}
if ($pk = $schema->getPrimaryKey()) {
return $pk['columns'][0];
}
return 'id';
});
} | php | public function getPrimaryKey() {
return $this->cache(__METHOD__, function() {
$pk = $this->getConfig('primaryKey');
$schema = $this->getSchema();
if ($schema->hasColumn($pk)) {
return $pk;
}
if ($pk = $schema->getPrimaryKey()) {
return $pk['columns'][0];
}
return 'id';
});
} | [
"public",
"function",
"getPrimaryKey",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"cache",
"(",
"__METHOD__",
",",
"function",
"(",
")",
"{",
"$",
"pk",
"=",
"$",
"this",
"->",
"getConfig",
"(",
"'primaryKey'",
")",
";",
"$",
"schema",
"=",
"$",
"this",
"->",
"getSchema",
"(",
")",
";",
"if",
"(",
"$",
"schema",
"->",
"hasColumn",
"(",
"$",
"pk",
")",
")",
"{",
"return",
"$",
"pk",
";",
"}",
"if",
"(",
"$",
"pk",
"=",
"$",
"schema",
"->",
"getPrimaryKey",
"(",
")",
")",
"{",
"return",
"$",
"pk",
"[",
"'columns'",
"]",
"[",
"0",
"]",
";",
"}",
"return",
"'id'",
";",
"}",
")",
";",
"}"
] | Return the field used as the primary, usually the ID.
@return string | [
"Return",
"the",
"field",
"used",
"as",
"the",
"primary",
"usually",
"the",
"ID",
"."
] | train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Repository.php#L655-L670 |
titon/db | src/Titon/Db/Repository.php | Repository.getSchema | public function getSchema() {
if ($this->_schema instanceof Schema) {
return $this->_schema;
// Manually defined columns
// Allows for full schema and key/index support
} else if ($this->_schema && is_array($this->_schema)) {
$columns = $this->_schema;
// Inspect database for columns
// This approach should only be used for validating columns and types
} else {
$columns = $this->getDriver()->describeTable($this->getTable());
}
$this->setSchema(new Schema($this->getTable(), $columns));
return $this->_schema;
} | php | public function getSchema() {
if ($this->_schema instanceof Schema) {
return $this->_schema;
// Manually defined columns
// Allows for full schema and key/index support
} else if ($this->_schema && is_array($this->_schema)) {
$columns = $this->_schema;
// Inspect database for columns
// This approach should only be used for validating columns and types
} else {
$columns = $this->getDriver()->describeTable($this->getTable());
}
$this->setSchema(new Schema($this->getTable(), $columns));
return $this->_schema;
} | [
"public",
"function",
"getSchema",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_schema",
"instanceof",
"Schema",
")",
"{",
"return",
"$",
"this",
"->",
"_schema",
";",
"// Manually defined columns",
"// Allows for full schema and key/index support",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"_schema",
"&&",
"is_array",
"(",
"$",
"this",
"->",
"_schema",
")",
")",
"{",
"$",
"columns",
"=",
"$",
"this",
"->",
"_schema",
";",
"// Inspect database for columns",
"// This approach should only be used for validating columns and types",
"}",
"else",
"{",
"$",
"columns",
"=",
"$",
"this",
"->",
"getDriver",
"(",
")",
"->",
"describeTable",
"(",
"$",
"this",
"->",
"getTable",
"(",
")",
")",
";",
"}",
"$",
"this",
"->",
"setSchema",
"(",
"new",
"Schema",
"(",
"$",
"this",
"->",
"getTable",
"(",
")",
",",
"$",
"columns",
")",
")",
";",
"return",
"$",
"this",
"->",
"_schema",
";",
"}"
] | Return a schema object that represents the database table.
@return \Titon\Db\Driver\Schema | [
"Return",
"a",
"schema",
"object",
"that",
"represents",
"the",
"database",
"table",
"."
] | train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Repository.php#L677-L695 |
titon/db | src/Titon/Db/Repository.php | Repository.query | public function query($type) {
$query = $this->getDriver()->newQuery($type);
$query->setRepository($this);
$query->from($this->getTable(), $this->getAlias());
return $query;
} | php | public function query($type) {
$query = $this->getDriver()->newQuery($type);
$query->setRepository($this);
$query->from($this->getTable(), $this->getAlias());
return $query;
} | [
"public",
"function",
"query",
"(",
"$",
"type",
")",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"getDriver",
"(",
")",
"->",
"newQuery",
"(",
"$",
"type",
")",
";",
"$",
"query",
"->",
"setRepository",
"(",
"$",
"this",
")",
";",
"$",
"query",
"->",
"from",
"(",
"$",
"this",
"->",
"getTable",
"(",
")",
",",
"$",
"this",
"->",
"getAlias",
"(",
")",
")",
";",
"return",
"$",
"query",
";",
"}"
] | Instantiate a new query builder.
@param string $type
@return \Titon\Db\Query | [
"Instantiate",
"a",
"new",
"query",
"builder",
"."
] | train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Repository.php#L786-L792 |
titon/db | src/Titon/Db/Repository.php | Repository.read | public function read($id, array $options = [], Closure $callback = null) {
return $this->select()
->where($this->getPrimaryKey(), $id)
->bindCallback($callback)
->first($options);
} | php | public function read($id, array $options = [], Closure $callback = null) {
return $this->select()
->where($this->getPrimaryKey(), $id)
->bindCallback($callback)
->first($options);
} | [
"public",
"function",
"read",
"(",
"$",
"id",
",",
"array",
"$",
"options",
"=",
"[",
"]",
",",
"Closure",
"$",
"callback",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"select",
"(",
")",
"->",
"where",
"(",
"$",
"this",
"->",
"getPrimaryKey",
"(",
")",
",",
"$",
"id",
")",
"->",
"bindCallback",
"(",
"$",
"callback",
")",
"->",
"first",
"(",
"$",
"options",
")",
";",
"}"
] | Fetch a single record by ID.
@param int $id
@param array $options
@param \Closure $callback
@return \Titon\Db\Entity|array | [
"Fetch",
"a",
"single",
"record",
"by",
"ID",
"."
] | train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Repository.php#L802-L807 |
titon/db | src/Titon/Db/Repository.php | Repository.save | public function save(Query $query, array $options = []) {
$type = $query->getType();
if ($type === Query::DELETE) {
return $this->_processDelete($query, $options);
} else if ($type === Query::INSERT) {
return $this->_processCreate($query, $options);
} else if ($type === Query::UPDATE) {
return $this->_processUpdate($query, $options);
}
// No processing or events, just execute it directly
return $this->getDriver()->executeQuery($query)->save();
} | php | public function save(Query $query, array $options = []) {
$type = $query->getType();
if ($type === Query::DELETE) {
return $this->_processDelete($query, $options);
} else if ($type === Query::INSERT) {
return $this->_processCreate($query, $options);
} else if ($type === Query::UPDATE) {
return $this->_processUpdate($query, $options);
}
// No processing or events, just execute it directly
return $this->getDriver()->executeQuery($query)->save();
} | [
"public",
"function",
"save",
"(",
"Query",
"$",
"query",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"type",
"=",
"$",
"query",
"->",
"getType",
"(",
")",
";",
"if",
"(",
"$",
"type",
"===",
"Query",
"::",
"DELETE",
")",
"{",
"return",
"$",
"this",
"->",
"_processDelete",
"(",
"$",
"query",
",",
"$",
"options",
")",
";",
"}",
"else",
"if",
"(",
"$",
"type",
"===",
"Query",
"::",
"INSERT",
")",
"{",
"return",
"$",
"this",
"->",
"_processCreate",
"(",
"$",
"query",
",",
"$",
"options",
")",
";",
"}",
"else",
"if",
"(",
"$",
"type",
"===",
"Query",
"::",
"UPDATE",
")",
"{",
"return",
"$",
"this",
"->",
"_processUpdate",
"(",
"$",
"query",
",",
"$",
"options",
")",
";",
"}",
"// No processing or events, just execute it directly",
"return",
"$",
"this",
"->",
"getDriver",
"(",
")",
"->",
"executeQuery",
"(",
"$",
"query",
")",
"->",
"save",
"(",
")",
";",
"}"
] | Return a count of how many rows were affected by the query.
@param \Titon\Db\Query $query
@param array $options
@return int | [
"Return",
"a",
"count",
"of",
"how",
"many",
"rows",
"were",
"affected",
"by",
"the",
"query",
"."
] | train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Repository.php#L826-L841 |
titon/db | src/Titon/Db/Repository.php | Repository.update | public function update($id, $data, array $options = []) {
return $this->query(Query::UPDATE)
->where($this->getPrimaryKey(), $id)
->save($data, $options);
} | php | public function update($id, $data, array $options = []) {
return $this->query(Query::UPDATE)
->where($this->getPrimaryKey(), $id)
->save($data, $options);
} | [
"public",
"function",
"update",
"(",
"$",
"id",
",",
"$",
"data",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"query",
"(",
"Query",
"::",
"UPDATE",
")",
"->",
"where",
"(",
"$",
"this",
"->",
"getPrimaryKey",
"(",
")",
",",
"$",
"id",
")",
"->",
"save",
"(",
"$",
"data",
",",
"$",
"options",
")",
";",
"}"
] | Update a database record based on ID.
@param int $id
@param array|\Titon\Type\Contract\Arrayable $data
@param array $options
@return int The count of records updated | [
"Update",
"a",
"database",
"record",
"based",
"on",
"ID",
"."
] | train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Repository.php#L893-L897 |
titon/db | src/Titon/Db/Repository.php | Repository.updateMany | public function updateMany($data, Closure $conditions, array $options = []) {
return $this->query(Query::UPDATE)
->bindCallback($conditions)
->save($data, $options);
} | php | public function updateMany($data, Closure $conditions, array $options = []) {
return $this->query(Query::UPDATE)
->bindCallback($conditions)
->save($data, $options);
} | [
"public",
"function",
"updateMany",
"(",
"$",
"data",
",",
"Closure",
"$",
"conditions",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"query",
"(",
"Query",
"::",
"UPDATE",
")",
"->",
"bindCallback",
"(",
"$",
"conditions",
")",
"->",
"save",
"(",
"$",
"data",
",",
"$",
"options",
")",
";",
"}"
] | Update multiple records with conditions.
@param array|\Titon\Type\Contract\Arrayable $data
@param \Closure $conditions
@param array $options
@return int The count of records updated
@throws \Titon\Db\Exception\InvalidQueryException | [
"Update",
"multiple",
"records",
"with",
"conditions",
"."
] | train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Repository.php#L908-L912 |
titon/db | src/Titon/Db/Repository.php | Repository.upsert | public function upsert($data, $id = null, array $options = []) {
$pk = $this->getPrimaryKey();
$update = false;
// Check for an ID in the data
if (!$id && isset($data[$pk])) {
$id = $data[$pk];
}
unset($data[$pk]);
// Check for record existence
if ($id) {
$update = $this->exists($id);
}
// Either update
if ($update) {
if ($this->update($id, $data, $options) === false) {
return 0;
}
// Or insert
} else {
$id = $this->create($data, $options);
}
return $id;
} | php | public function upsert($data, $id = null, array $options = []) {
$pk = $this->getPrimaryKey();
$update = false;
// Check for an ID in the data
if (!$id && isset($data[$pk])) {
$id = $data[$pk];
}
unset($data[$pk]);
// Check for record existence
if ($id) {
$update = $this->exists($id);
}
// Either update
if ($update) {
if ($this->update($id, $data, $options) === false) {
return 0;
}
// Or insert
} else {
$id = $this->create($data, $options);
}
return $id;
} | [
"public",
"function",
"upsert",
"(",
"$",
"data",
",",
"$",
"id",
"=",
"null",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"pk",
"=",
"$",
"this",
"->",
"getPrimaryKey",
"(",
")",
";",
"$",
"update",
"=",
"false",
";",
"// Check for an ID in the data",
"if",
"(",
"!",
"$",
"id",
"&&",
"isset",
"(",
"$",
"data",
"[",
"$",
"pk",
"]",
")",
")",
"{",
"$",
"id",
"=",
"$",
"data",
"[",
"$",
"pk",
"]",
";",
"}",
"unset",
"(",
"$",
"data",
"[",
"$",
"pk",
"]",
")",
";",
"// Check for record existence",
"if",
"(",
"$",
"id",
")",
"{",
"$",
"update",
"=",
"$",
"this",
"->",
"exists",
"(",
"$",
"id",
")",
";",
"}",
"// Either update",
"if",
"(",
"$",
"update",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"update",
"(",
"$",
"id",
",",
"$",
"data",
",",
"$",
"options",
")",
"===",
"false",
")",
"{",
"return",
"0",
";",
"}",
"// Or insert",
"}",
"else",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"create",
"(",
"$",
"data",
",",
"$",
"options",
")",
";",
"}",
"return",
"$",
"id",
";",
"}"
] | Either update or insert a record by checking for ID and record existence.
@param array|\Titon\Type\Contract\Arrayable $data
@param int $id
@param array $options
@return int The record ID on success, 0 on failure | [
"Either",
"update",
"or",
"insert",
"a",
"record",
"by",
"checking",
"for",
"ID",
"and",
"record",
"existence",
"."
] | train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Repository.php#L922-L950 |
titon/db | src/Titon/Db/Repository.php | Repository._processCreate | protected function _processCreate(Query $query, array $options = []) {
$data = $query->getData();
$options = $options + [
'before' => true,
'after' => true
];
if ($options['before']) {
foreach (['db.preSave', 'db.preCreate'] as $event) {
$event = $this->emit($event, [$query, null, &$data]);
if (!$event->getState()) {
return 0;
}
}
}
// Reset the modified data
$query->data($data);
// Update the connection context
$driver = $this->getDriver();
$driver->setContext('write');
// Execute the query
$count = $driver->executeQuery($query)->save();
// Exit early if save failed
if ($count === false) {
return 0;
}
$id = $driver->getLastInsertID($this);
if ($options['after']) {
$this->emit('db.postSave db.postCreate', [$id, $count]);
}
return $this->id = $id;
} | php | protected function _processCreate(Query $query, array $options = []) {
$data = $query->getData();
$options = $options + [
'before' => true,
'after' => true
];
if ($options['before']) {
foreach (['db.preSave', 'db.preCreate'] as $event) {
$event = $this->emit($event, [$query, null, &$data]);
if (!$event->getState()) {
return 0;
}
}
}
// Reset the modified data
$query->data($data);
// Update the connection context
$driver = $this->getDriver();
$driver->setContext('write');
// Execute the query
$count = $driver->executeQuery($query)->save();
// Exit early if save failed
if ($count === false) {
return 0;
}
$id = $driver->getLastInsertID($this);
if ($options['after']) {
$this->emit('db.postSave db.postCreate', [$id, $count]);
}
return $this->id = $id;
} | [
"protected",
"function",
"_processCreate",
"(",
"Query",
"$",
"query",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"data",
"=",
"$",
"query",
"->",
"getData",
"(",
")",
";",
"$",
"options",
"=",
"$",
"options",
"+",
"[",
"'before'",
"=>",
"true",
",",
"'after'",
"=>",
"true",
"]",
";",
"if",
"(",
"$",
"options",
"[",
"'before'",
"]",
")",
"{",
"foreach",
"(",
"[",
"'db.preSave'",
",",
"'db.preCreate'",
"]",
"as",
"$",
"event",
")",
"{",
"$",
"event",
"=",
"$",
"this",
"->",
"emit",
"(",
"$",
"event",
",",
"[",
"$",
"query",
",",
"null",
",",
"&",
"$",
"data",
"]",
")",
";",
"if",
"(",
"!",
"$",
"event",
"->",
"getState",
"(",
")",
")",
"{",
"return",
"0",
";",
"}",
"}",
"}",
"// Reset the modified data",
"$",
"query",
"->",
"data",
"(",
"$",
"data",
")",
";",
"// Update the connection context",
"$",
"driver",
"=",
"$",
"this",
"->",
"getDriver",
"(",
")",
";",
"$",
"driver",
"->",
"setContext",
"(",
"'write'",
")",
";",
"// Execute the query",
"$",
"count",
"=",
"$",
"driver",
"->",
"executeQuery",
"(",
"$",
"query",
")",
"->",
"save",
"(",
")",
";",
"// Exit early if save failed",
"if",
"(",
"$",
"count",
"===",
"false",
")",
"{",
"return",
"0",
";",
"}",
"$",
"id",
"=",
"$",
"driver",
"->",
"getLastInsertID",
"(",
"$",
"this",
")",
";",
"if",
"(",
"$",
"options",
"[",
"'after'",
"]",
")",
"{",
"$",
"this",
"->",
"emit",
"(",
"'db.postSave db.postCreate'",
",",
"[",
"$",
"id",
",",
"$",
"count",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"id",
"=",
"$",
"id",
";",
"}"
] | Primary method that handles the processing of insert queries.
Before a save is executed, a `preSave` and `preCreate` event will be triggered.
This event allows data to be modified before saving via references.
If this event returns a falsey value, the save will exit early and
return a 0. This allows behaviors and events to cease save operations.
Before the driver is queried, the connection context will be set to `write`.
After the query has executed, and no rows have been affected, the method
will exit early with a 0 response. Otherwise, a `postSave` and `postCreate` event will be triggered.
@param \Titon\Db\Query $query
@param mixed $options {
@type bool $before Will trigger before callbacks
@type bool $after Will trigger after callbacks
}
@return int
- The ID of the record if successful
- 0 if save operation failed | [
"Primary",
"method",
"that",
"handles",
"the",
"processing",
"of",
"insert",
"queries",
"."
] | train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Repository.php#L974-L1013 |
titon/db | src/Titon/Db/Repository.php | Repository._processDelete | protected function _processDelete(Query $query, array $options = []) {
$options = $options + [
'before' => true,
'after' => true
];
// Fetch ID
$this->id = $id = $this->findID($query);
if ($options['before']) {
$event = $this->emit('db.preDelete', [$query, $id]);
$state = $event->getState();
if (!$state) {
return 0;
} else if (is_numeric($state)) {
return (int) $state;
}
}
// Update the connection context and execute the query
$count = $this->getDriver()
->setContext('delete')
->executeQuery($query)
->save();
// Only trigger callback if something was deleted
if ($count && $options['after']) {
$this->emit('db.postDelete', [$id, $count]);
}
return (int) $count;
} | php | protected function _processDelete(Query $query, array $options = []) {
$options = $options + [
'before' => true,
'after' => true
];
// Fetch ID
$this->id = $id = $this->findID($query);
if ($options['before']) {
$event = $this->emit('db.preDelete', [$query, $id]);
$state = $event->getState();
if (!$state) {
return 0;
} else if (is_numeric($state)) {
return (int) $state;
}
}
// Update the connection context and execute the query
$count = $this->getDriver()
->setContext('delete')
->executeQuery($query)
->save();
// Only trigger callback if something was deleted
if ($count && $options['after']) {
$this->emit('db.postDelete', [$id, $count]);
}
return (int) $count;
} | [
"protected",
"function",
"_processDelete",
"(",
"Query",
"$",
"query",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"options",
"=",
"$",
"options",
"+",
"[",
"'before'",
"=>",
"true",
",",
"'after'",
"=>",
"true",
"]",
";",
"// Fetch ID",
"$",
"this",
"->",
"id",
"=",
"$",
"id",
"=",
"$",
"this",
"->",
"findID",
"(",
"$",
"query",
")",
";",
"if",
"(",
"$",
"options",
"[",
"'before'",
"]",
")",
"{",
"$",
"event",
"=",
"$",
"this",
"->",
"emit",
"(",
"'db.preDelete'",
",",
"[",
"$",
"query",
",",
"$",
"id",
"]",
")",
";",
"$",
"state",
"=",
"$",
"event",
"->",
"getState",
"(",
")",
";",
"if",
"(",
"!",
"$",
"state",
")",
"{",
"return",
"0",
";",
"}",
"else",
"if",
"(",
"is_numeric",
"(",
"$",
"state",
")",
")",
"{",
"return",
"(",
"int",
")",
"$",
"state",
";",
"}",
"}",
"// Update the connection context and execute the query",
"$",
"count",
"=",
"$",
"this",
"->",
"getDriver",
"(",
")",
"->",
"setContext",
"(",
"'delete'",
")",
"->",
"executeQuery",
"(",
"$",
"query",
")",
"->",
"save",
"(",
")",
";",
"// Only trigger callback if something was deleted",
"if",
"(",
"$",
"count",
"&&",
"$",
"options",
"[",
"'after'",
"]",
")",
"{",
"$",
"this",
"->",
"emit",
"(",
"'db.postDelete'",
",",
"[",
"$",
"id",
",",
"$",
"count",
"]",
")",
";",
"}",
"return",
"(",
"int",
")",
"$",
"count",
";",
"}"
] | Primary method that handles the processing of delete queries.
Before a delete is executed, a `preDelete` event will be triggered.
If a falsey value is returned, exit early with a 0. If a numeric value
is returned, exit early and return the number, which acts as a virtual
affected row count (permitting behaviors to short circuit the process).
Before the driver is queried, the connection context will be set to `delete`.
After a delete has executed successfully, a `postDelete` event will be triggered.
@param \Titon\Db\Query $query
@param mixed $options {
@type bool $before Will trigger before callbacks
@type bool $after Will trigger after callbacks
}
@return int The count of records deleted | [
"Primary",
"method",
"that",
"handles",
"the",
"processing",
"of",
"delete",
"queries",
"."
] | train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Repository.php#L1034-L1066 |
titon/db | src/Titon/Db/Repository.php | Repository._processUpdate | protected function _processUpdate(Query $query, array $options = []) {
$data = $query->getData();
$options = $options + [
'before' => true,
'after' => true
];
// Fetch ID
$this->id = $id = $this->findID($query);
if ($options['before']) {
foreach (['db.preSave', 'db.preUpdate'] as $event) {
$event = $this->emit($event, [$query, $id, &$data]);
if (!$event->getState()) {
return 0;
}
}
}
// Reset the modified data
$query->data($data);
// Update the connection context and execute the query
$count = $this->getDriver()
->setContext('write')
->executeQuery($query)
->save();
// Exit early if save failed
if ($count === false) {
return false;
}
if ($options['after']) {
$this->emit('db.postSave db.postUpdate', [$id, $count]);
}
return $count;
} | php | protected function _processUpdate(Query $query, array $options = []) {
$data = $query->getData();
$options = $options + [
'before' => true,
'after' => true
];
// Fetch ID
$this->id = $id = $this->findID($query);
if ($options['before']) {
foreach (['db.preSave', 'db.preUpdate'] as $event) {
$event = $this->emit($event, [$query, $id, &$data]);
if (!$event->getState()) {
return 0;
}
}
}
// Reset the modified data
$query->data($data);
// Update the connection context and execute the query
$count = $this->getDriver()
->setContext('write')
->executeQuery($query)
->save();
// Exit early if save failed
if ($count === false) {
return false;
}
if ($options['after']) {
$this->emit('db.postSave db.postUpdate', [$id, $count]);
}
return $count;
} | [
"protected",
"function",
"_processUpdate",
"(",
"Query",
"$",
"query",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"data",
"=",
"$",
"query",
"->",
"getData",
"(",
")",
";",
"$",
"options",
"=",
"$",
"options",
"+",
"[",
"'before'",
"=>",
"true",
",",
"'after'",
"=>",
"true",
"]",
";",
"// Fetch ID",
"$",
"this",
"->",
"id",
"=",
"$",
"id",
"=",
"$",
"this",
"->",
"findID",
"(",
"$",
"query",
")",
";",
"if",
"(",
"$",
"options",
"[",
"'before'",
"]",
")",
"{",
"foreach",
"(",
"[",
"'db.preSave'",
",",
"'db.preUpdate'",
"]",
"as",
"$",
"event",
")",
"{",
"$",
"event",
"=",
"$",
"this",
"->",
"emit",
"(",
"$",
"event",
",",
"[",
"$",
"query",
",",
"$",
"id",
",",
"&",
"$",
"data",
"]",
")",
";",
"if",
"(",
"!",
"$",
"event",
"->",
"getState",
"(",
")",
")",
"{",
"return",
"0",
";",
"}",
"}",
"}",
"// Reset the modified data",
"$",
"query",
"->",
"data",
"(",
"$",
"data",
")",
";",
"// Update the connection context and execute the query",
"$",
"count",
"=",
"$",
"this",
"->",
"getDriver",
"(",
")",
"->",
"setContext",
"(",
"'write'",
")",
"->",
"executeQuery",
"(",
"$",
"query",
")",
"->",
"save",
"(",
")",
";",
"// Exit early if save failed",
"if",
"(",
"$",
"count",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"options",
"[",
"'after'",
"]",
")",
"{",
"$",
"this",
"->",
"emit",
"(",
"'db.postSave db.postUpdate'",
",",
"[",
"$",
"id",
",",
"$",
"count",
"]",
")",
";",
"}",
"return",
"$",
"count",
";",
"}"
] | Primary method that handles the processing of update queries.
Before a save is executed, a `preSave` and `preUpdate` event will be triggered.
This event allows data to be modified before saving via references.
If this event returns a falsey value, the save will exit early and
return a 0. This allows behaviors and events to cease save operations.
Before the driver is queried, the connection context will be set to `write`.
After the query has executed, and no rows have been affected, the method
will exit early with a 0 response. Otherwise, a `postSave` and `postUpdate` event will be triggered.
@param \Titon\Db\Query $query
@param mixed $options {
@type bool $before Will trigger before callbacks
@type bool $after Will trigger after callbacks
}
@return int
- The count of records updated
- 0 if save operation failed | [
"Primary",
"method",
"that",
"handles",
"the",
"processing",
"of",
"update",
"queries",
"."
] | train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Repository.php#L1090-L1129 |
arsengoian/viper-framework | src/Viper/Daemon/DaemonHistorian.php | DaemonHistorian.clearLog | function clearLog() : void
{
@unlink($this -> errLogger -> getFile());
@unlink($this -> logger -> getFile());
@unlink($this -> errLogger -> getFile().'.shell');
@unlink($this -> logger -> getFile().'.shell');
} | php | function clearLog() : void
{
@unlink($this -> errLogger -> getFile());
@unlink($this -> logger -> getFile());
@unlink($this -> errLogger -> getFile().'.shell');
@unlink($this -> logger -> getFile().'.shell');
} | [
"function",
"clearLog",
"(",
")",
":",
"void",
"{",
"@",
"unlink",
"(",
"$",
"this",
"->",
"errLogger",
"->",
"getFile",
"(",
")",
")",
";",
"@",
"unlink",
"(",
"$",
"this",
"->",
"logger",
"->",
"getFile",
"(",
")",
")",
";",
"@",
"unlink",
"(",
"$",
"this",
"->",
"errLogger",
"->",
"getFile",
"(",
")",
".",
"'.shell'",
")",
";",
"@",
"unlink",
"(",
"$",
"this",
"->",
"logger",
"->",
"getFile",
"(",
")",
".",
"'.shell'",
")",
";",
"}"
] | Cleans daemon log | [
"Cleans",
"daemon",
"log"
] | train | https://github.com/arsengoian/viper-framework/blob/22796c5cc219cae3ca0b4af370a347ba2acab0f2/src/Viper/Daemon/DaemonHistorian.php#L75-L81 |
phpmob/changmin | src/PhpMob/CmsBundle/Controller/PageController.php | PageController.viewAction | public function viewAction(Request $request): Response
{
$configuration = $this->requestConfigurationFactory->create($this->metadata, $request);
$this->isGrantedOr403($configuration, ResourceActions::SHOW);
/** @var DefinedTranslationInterface|TemplateAwareInterface|ResourceInterface $resource */
$resource = $this->findOr404($configuration);
$this->eventDispatcher->dispatch(ResourceActions::SHOW, $configuration, $resource);
$view = View::create($resource);
if ($configuration->isHtmlRequest()) {
$template = $resource->getTemplate();
if ($template) {
$tpl = $resource->getTemplateName();
$options = $template->getOptions();
} else {
$tpl = $configuration->getTemplate(ResourceActions::SHOW.'.html');
$options = [];
}
$this->addTranslations($resource);
$view
->setTemplate($tpl)
->setTemplateVar($this->metadata->getName())
->setData(
[
'configuration' => $configuration,
'metadata' => $this->metadata,
'resource' => $resource,
'tpl' => ['options' => $options],
$this->metadata->getName() => $resource,
]
);
}
return $this->viewHandler->handle($configuration, $view);
} | php | public function viewAction(Request $request): Response
{
$configuration = $this->requestConfigurationFactory->create($this->metadata, $request);
$this->isGrantedOr403($configuration, ResourceActions::SHOW);
/** @var DefinedTranslationInterface|TemplateAwareInterface|ResourceInterface $resource */
$resource = $this->findOr404($configuration);
$this->eventDispatcher->dispatch(ResourceActions::SHOW, $configuration, $resource);
$view = View::create($resource);
if ($configuration->isHtmlRequest()) {
$template = $resource->getTemplate();
if ($template) {
$tpl = $resource->getTemplateName();
$options = $template->getOptions();
} else {
$tpl = $configuration->getTemplate(ResourceActions::SHOW.'.html');
$options = [];
}
$this->addTranslations($resource);
$view
->setTemplate($tpl)
->setTemplateVar($this->metadata->getName())
->setData(
[
'configuration' => $configuration,
'metadata' => $this->metadata,
'resource' => $resource,
'tpl' => ['options' => $options],
$this->metadata->getName() => $resource,
]
);
}
return $this->viewHandler->handle($configuration, $view);
} | [
"public",
"function",
"viewAction",
"(",
"Request",
"$",
"request",
")",
":",
"Response",
"{",
"$",
"configuration",
"=",
"$",
"this",
"->",
"requestConfigurationFactory",
"->",
"create",
"(",
"$",
"this",
"->",
"metadata",
",",
"$",
"request",
")",
";",
"$",
"this",
"->",
"isGrantedOr403",
"(",
"$",
"configuration",
",",
"ResourceActions",
"::",
"SHOW",
")",
";",
"/** @var DefinedTranslationInterface|TemplateAwareInterface|ResourceInterface $resource */",
"$",
"resource",
"=",
"$",
"this",
"->",
"findOr404",
"(",
"$",
"configuration",
")",
";",
"$",
"this",
"->",
"eventDispatcher",
"->",
"dispatch",
"(",
"ResourceActions",
"::",
"SHOW",
",",
"$",
"configuration",
",",
"$",
"resource",
")",
";",
"$",
"view",
"=",
"View",
"::",
"create",
"(",
"$",
"resource",
")",
";",
"if",
"(",
"$",
"configuration",
"->",
"isHtmlRequest",
"(",
")",
")",
"{",
"$",
"template",
"=",
"$",
"resource",
"->",
"getTemplate",
"(",
")",
";",
"if",
"(",
"$",
"template",
")",
"{",
"$",
"tpl",
"=",
"$",
"resource",
"->",
"getTemplateName",
"(",
")",
";",
"$",
"options",
"=",
"$",
"template",
"->",
"getOptions",
"(",
")",
";",
"}",
"else",
"{",
"$",
"tpl",
"=",
"$",
"configuration",
"->",
"getTemplate",
"(",
"ResourceActions",
"::",
"SHOW",
".",
"'.html'",
")",
";",
"$",
"options",
"=",
"[",
"]",
";",
"}",
"$",
"this",
"->",
"addTranslations",
"(",
"$",
"resource",
")",
";",
"$",
"view",
"->",
"setTemplate",
"(",
"$",
"tpl",
")",
"->",
"setTemplateVar",
"(",
"$",
"this",
"->",
"metadata",
"->",
"getName",
"(",
")",
")",
"->",
"setData",
"(",
"[",
"'configuration'",
"=>",
"$",
"configuration",
",",
"'metadata'",
"=>",
"$",
"this",
"->",
"metadata",
",",
"'resource'",
"=>",
"$",
"resource",
",",
"'tpl'",
"=>",
"[",
"'options'",
"=>",
"$",
"options",
"]",
",",
"$",
"this",
"->",
"metadata",
"->",
"getName",
"(",
")",
"=>",
"$",
"resource",
",",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"viewHandler",
"->",
"handle",
"(",
"$",
"configuration",
",",
"$",
"view",
")",
";",
"}"
] | @param Request $request
@return Response | [
"@param",
"Request",
"$request"
] | train | https://github.com/phpmob/changmin/blob/bfebb1561229094d1c138574abab75f2f1d17d66/src/PhpMob/CmsBundle/Controller/PageController.php#L41-L82 |
slashworks/control-bundle | src/Slashworks/BackendBundle/Model/map/UserRoleTableMap.php | UserRoleTableMap.initialize | public function initialize()
{
// attributes
$this->setName('user_role');
$this->setPhpName('UserRole');
$this->setClassname('Slashworks\\BackendBundle\\Model\\UserRole');
$this->setPackage('src.Slashworks.BackendBundle.Model');
$this->setUseIdGenerator(false);
// columns
$this->addForeignPrimaryKey('user_id', 'UserId', 'INTEGER' , 'user', 'id', true, null, null);
$this->addForeignPrimaryKey('role_id', 'RoleId', 'INTEGER' , 'role', 'id', true, null, null);
// validators
} | php | public function initialize()
{
// attributes
$this->setName('user_role');
$this->setPhpName('UserRole');
$this->setClassname('Slashworks\\BackendBundle\\Model\\UserRole');
$this->setPackage('src.Slashworks.BackendBundle.Model');
$this->setUseIdGenerator(false);
// columns
$this->addForeignPrimaryKey('user_id', 'UserId', 'INTEGER' , 'user', 'id', true, null, null);
$this->addForeignPrimaryKey('role_id', 'RoleId', 'INTEGER' , 'role', 'id', true, null, null);
// validators
} | [
"public",
"function",
"initialize",
"(",
")",
"{",
"// attributes",
"$",
"this",
"->",
"setName",
"(",
"'user_role'",
")",
";",
"$",
"this",
"->",
"setPhpName",
"(",
"'UserRole'",
")",
";",
"$",
"this",
"->",
"setClassname",
"(",
"'Slashworks\\\\BackendBundle\\\\Model\\\\UserRole'",
")",
";",
"$",
"this",
"->",
"setPackage",
"(",
"'src.Slashworks.BackendBundle.Model'",
")",
";",
"$",
"this",
"->",
"setUseIdGenerator",
"(",
"false",
")",
";",
"// columns",
"$",
"this",
"->",
"addForeignPrimaryKey",
"(",
"'user_id'",
",",
"'UserId'",
",",
"'INTEGER'",
",",
"'user'",
",",
"'id'",
",",
"true",
",",
"null",
",",
"null",
")",
";",
"$",
"this",
"->",
"addForeignPrimaryKey",
"(",
"'role_id'",
",",
"'RoleId'",
",",
"'INTEGER'",
",",
"'role'",
",",
"'id'",
",",
"true",
",",
"null",
",",
"null",
")",
";",
"// validators",
"}"
] | Initialize the table attributes, columns and validators
Relations are not initialized by this method since they are lazy loaded
@return void
@throws PropelException | [
"Initialize",
"the",
"table",
"attributes",
"columns",
"and",
"validators",
"Relations",
"are",
"not",
"initialized",
"by",
"this",
"method",
"since",
"they",
"are",
"lazy",
"loaded"
] | train | https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/BackendBundle/Model/map/UserRoleTableMap.php#L36-L48 |
andrelohmann/silverstripe-geolocation | code/helpers/GeoFunctions.php | GeoFunctions.calcOneOnLng | public static function calcOneOnLng($geo_lat, $scale = 'km'){
switch(strtolower($scale)){
case 'miles':
$earth = 3960;
break;
case 'km':
default:
$earth = 6371;
break;
}
//Point 1 cords
$lat = deg2rad($geo_lat);
$long1 = deg2rad(0);
$long2 = deg2rad(1);
//Haversine Formula
$dlong = $long2 - $long1;
$sinlong = sin($dlong / 2);
$a = cos($lat) * cos($lat) * ($sinlong * $sinlong);
$c = 2 * asin(min(1, sqrt($a)));
return (1/($earth * $c));
} | php | public static function calcOneOnLng($geo_lat, $scale = 'km'){
switch(strtolower($scale)){
case 'miles':
$earth = 3960;
break;
case 'km':
default:
$earth = 6371;
break;
}
//Point 1 cords
$lat = deg2rad($geo_lat);
$long1 = deg2rad(0);
$long2 = deg2rad(1);
//Haversine Formula
$dlong = $long2 - $long1;
$sinlong = sin($dlong / 2);
$a = cos($lat) * cos($lat) * ($sinlong * $sinlong);
$c = 2 * asin(min(1, sqrt($a)));
return (1/($earth * $c));
} | [
"public",
"static",
"function",
"calcOneOnLng",
"(",
"$",
"geo_lat",
",",
"$",
"scale",
"=",
"'km'",
")",
"{",
"switch",
"(",
"strtolower",
"(",
"$",
"scale",
")",
")",
"{",
"case",
"'miles'",
":",
"$",
"earth",
"=",
"3960",
";",
"break",
";",
"case",
"'km'",
":",
"default",
":",
"$",
"earth",
"=",
"6371",
";",
"break",
";",
"}",
"//Point 1 cords",
"$",
"lat",
"=",
"deg2rad",
"(",
"$",
"geo_lat",
")",
";",
"$",
"long1",
"=",
"deg2rad",
"(",
"0",
")",
";",
"$",
"long2",
"=",
"deg2rad",
"(",
"1",
")",
";",
"//Haversine Formula",
"$",
"dlong",
"=",
"$",
"long2",
"-",
"$",
"long1",
";",
"$",
"sinlong",
"=",
"sin",
"(",
"$",
"dlong",
"/",
"2",
")",
";",
"$",
"a",
"=",
"cos",
"(",
"$",
"lat",
")",
"*",
"cos",
"(",
"$",
"lat",
")",
"*",
"(",
"$",
"sinlong",
"*",
"$",
"sinlong",
")",
";",
"$",
"c",
"=",
"2",
"*",
"asin",
"(",
"min",
"(",
"1",
",",
"sqrt",
"(",
"$",
"a",
")",
")",
")",
";",
"return",
"(",
"1",
"/",
"(",
"$",
"earth",
"*",
"$",
"c",
")",
")",
";",
"}"
] | errechnet, wieviel Grad Länge bei einem gegebenen Grad Breite = 1KM entsprechen | [
"errechnet",
"wieviel",
"Grad",
"Länge",
"bei",
"einem",
"gegebenen",
"Grad",
"Breite",
"=",
"1KM",
"entsprechen"
] | train | https://github.com/andrelohmann/silverstripe-geolocation/blob/124062008d8fa25b631bf5bb69b2ca79b53ef81b/code/helpers/GeoFunctions.php#L18-L43 |
webforge-labs/psc-cms | lib/Psc/CMS/UploadManager.php | UploadManager.store | public function store(File $file, $description = NULL, $flags = 0x000000) {
$hash = $file->getSha1();
if ($flags & self::IF_NOT_EXISTS) {
try {
$uplFile = $this->load($hash);
if (($flags & self::UPDATE_ORIGINALNAME) && $file instanceof \Psc\System\UploadedFile) {
$uplFile->setOriginalName($file->getOriginalName());
}
return $uplFile;
} catch (UploadedFileNotFoundException $e) {
}
}
$uplFile = $this->newInstance($file, $description);
$uplFile->setHash($hash); // wir speichern das hier "doppelt", damit wir in der datenbank danach indizieren können
if ($file instanceof \Psc\System\UploadedFile) {
$uplFile->setOriginalName($file->getOriginalName());
}
/* im Cache ablegen */
$cacheFile = $this->cache->store(array(mb_substr($hash,0,1), $hash),
$file
);
// afaik brauchen wir sourcePath hier nicht, denn es ist eignetlich egal wo der Cache seinen Krams ablegt
// mit derselben Instanz des Caches kommen wir immer wieder an die SourceFile ran
$this->persist($uplFile);
return $uplFile;
} | php | public function store(File $file, $description = NULL, $flags = 0x000000) {
$hash = $file->getSha1();
if ($flags & self::IF_NOT_EXISTS) {
try {
$uplFile = $this->load($hash);
if (($flags & self::UPDATE_ORIGINALNAME) && $file instanceof \Psc\System\UploadedFile) {
$uplFile->setOriginalName($file->getOriginalName());
}
return $uplFile;
} catch (UploadedFileNotFoundException $e) {
}
}
$uplFile = $this->newInstance($file, $description);
$uplFile->setHash($hash); // wir speichern das hier "doppelt", damit wir in der datenbank danach indizieren können
if ($file instanceof \Psc\System\UploadedFile) {
$uplFile->setOriginalName($file->getOriginalName());
}
/* im Cache ablegen */
$cacheFile = $this->cache->store(array(mb_substr($hash,0,1), $hash),
$file
);
// afaik brauchen wir sourcePath hier nicht, denn es ist eignetlich egal wo der Cache seinen Krams ablegt
// mit derselben Instanz des Caches kommen wir immer wieder an die SourceFile ran
$this->persist($uplFile);
return $uplFile;
} | [
"public",
"function",
"store",
"(",
"File",
"$",
"file",
",",
"$",
"description",
"=",
"NULL",
",",
"$",
"flags",
"=",
"0x000000",
")",
"{",
"$",
"hash",
"=",
"$",
"file",
"->",
"getSha1",
"(",
")",
";",
"if",
"(",
"$",
"flags",
"&",
"self",
"::",
"IF_NOT_EXISTS",
")",
"{",
"try",
"{",
"$",
"uplFile",
"=",
"$",
"this",
"->",
"load",
"(",
"$",
"hash",
")",
";",
"if",
"(",
"(",
"$",
"flags",
"&",
"self",
"::",
"UPDATE_ORIGINALNAME",
")",
"&&",
"$",
"file",
"instanceof",
"\\",
"Psc",
"\\",
"System",
"\\",
"UploadedFile",
")",
"{",
"$",
"uplFile",
"->",
"setOriginalName",
"(",
"$",
"file",
"->",
"getOriginalName",
"(",
")",
")",
";",
"}",
"return",
"$",
"uplFile",
";",
"}",
"catch",
"(",
"UploadedFileNotFoundException",
"$",
"e",
")",
"{",
"}",
"}",
"$",
"uplFile",
"=",
"$",
"this",
"->",
"newInstance",
"(",
"$",
"file",
",",
"$",
"description",
")",
";",
"$",
"uplFile",
"->",
"setHash",
"(",
"$",
"hash",
")",
";",
"// wir speichern das hier \"doppelt\", damit wir in der datenbank danach indizieren können",
"if",
"(",
"$",
"file",
"instanceof",
"\\",
"Psc",
"\\",
"System",
"\\",
"UploadedFile",
")",
"{",
"$",
"uplFile",
"->",
"setOriginalName",
"(",
"$",
"file",
"->",
"getOriginalName",
"(",
")",
")",
";",
"}",
"/* im Cache ablegen */",
"$",
"cacheFile",
"=",
"$",
"this",
"->",
"cache",
"->",
"store",
"(",
"array",
"(",
"mb_substr",
"(",
"$",
"hash",
",",
"0",
",",
"1",
")",
",",
"$",
"hash",
")",
",",
"$",
"file",
")",
";",
"// afaik brauchen wir sourcePath hier nicht, denn es ist eignetlich egal wo der Cache seinen Krams ablegt",
"// mit derselben Instanz des Caches kommen wir immer wieder an die SourceFile ran",
"$",
"this",
"->",
"persist",
"(",
"$",
"uplFile",
")",
";",
"return",
"$",
"uplFile",
";",
"}"
] | Speichert eine gewöhnliche Datei als UploadedFile | [
"Speichert",
"eine",
"gewöhnliche",
"Datei",
"als",
"UploadedFile"
] | train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/CMS/UploadManager.php#L68-L102 |
webforge-labs/psc-cms | lib/Psc/CMS/UploadManager.php | UploadManager.load | public function load($input) {
try {
if ($input instanceof File) {
$input = $input->getSha1();
}
if (is_numeric($input)) {
$uplFile = $this->getRepository()->hydrate((int) $input);
/*
} elseif (is_string($input) && (mb_strpos($input,'/') !== FALSE || mb_strpos($input,'\\') !== FALSE)) {
$uplFile = $this->repository->hydrateBy(array('sourcePath'=>(string) $input));
*/
} elseif (is_string($input)) { // hash
$uplFile = $this->getRepository()->hydrateBy(array('hash'=>(string) $input));
} elseif ($input instanceof UploadedFile) {
$uplFile = $input;
} else {
throw new \Psc\Exception('Input kann nicht analyisiert werden: '.Code::varInfo($input));
}
$this->doAttach($uplFile);
return $uplFile;
} catch (\Psc\Doctrine\EntityNotFoundException $e) {
throw UploadedFileNotFoundException::fromEntityNotFound($e, $input);
}
} | php | public function load($input) {
try {
if ($input instanceof File) {
$input = $input->getSha1();
}
if (is_numeric($input)) {
$uplFile = $this->getRepository()->hydrate((int) $input);
/*
} elseif (is_string($input) && (mb_strpos($input,'/') !== FALSE || mb_strpos($input,'\\') !== FALSE)) {
$uplFile = $this->repository->hydrateBy(array('sourcePath'=>(string) $input));
*/
} elseif (is_string($input)) { // hash
$uplFile = $this->getRepository()->hydrateBy(array('hash'=>(string) $input));
} elseif ($input instanceof UploadedFile) {
$uplFile = $input;
} else {
throw new \Psc\Exception('Input kann nicht analyisiert werden: '.Code::varInfo($input));
}
$this->doAttach($uplFile);
return $uplFile;
} catch (\Psc\Doctrine\EntityNotFoundException $e) {
throw UploadedFileNotFoundException::fromEntityNotFound($e, $input);
}
} | [
"public",
"function",
"load",
"(",
"$",
"input",
")",
"{",
"try",
"{",
"if",
"(",
"$",
"input",
"instanceof",
"File",
")",
"{",
"$",
"input",
"=",
"$",
"input",
"->",
"getSha1",
"(",
")",
";",
"}",
"if",
"(",
"is_numeric",
"(",
"$",
"input",
")",
")",
"{",
"$",
"uplFile",
"=",
"$",
"this",
"->",
"getRepository",
"(",
")",
"->",
"hydrate",
"(",
"(",
"int",
")",
"$",
"input",
")",
";",
"/*\n } elseif (is_string($input) && (mb_strpos($input,'/') !== FALSE || mb_strpos($input,'\\\\') !== FALSE)) {\n $uplFile = $this->repository->hydrateBy(array('sourcePath'=>(string) $input));\n */",
"}",
"elseif",
"(",
"is_string",
"(",
"$",
"input",
")",
")",
"{",
"// hash",
"$",
"uplFile",
"=",
"$",
"this",
"->",
"getRepository",
"(",
")",
"->",
"hydrateBy",
"(",
"array",
"(",
"'hash'",
"=>",
"(",
"string",
")",
"$",
"input",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"input",
"instanceof",
"UploadedFile",
")",
"{",
"$",
"uplFile",
"=",
"$",
"input",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"Psc",
"\\",
"Exception",
"(",
"'Input kann nicht analyisiert werden: '",
".",
"Code",
"::",
"varInfo",
"(",
"$",
"input",
")",
")",
";",
"}",
"$",
"this",
"->",
"doAttach",
"(",
"$",
"uplFile",
")",
";",
"return",
"$",
"uplFile",
";",
"}",
"catch",
"(",
"\\",
"Psc",
"\\",
"Doctrine",
"\\",
"EntityNotFoundException",
"$",
"e",
")",
"{",
"throw",
"UploadedFileNotFoundException",
"::",
"fromEntityNotFound",
"(",
"$",
"e",
",",
"$",
"input",
")",
";",
"}",
"}"
] | Lädt eine Datei aus der Datenbank
@params $input
@param int $input die ID des Entities
//@param string $input der gespeicherte sourcePath des Entities (muss / oder \ enthalten)
@param string $input der sha1 hash des Contents der Datei
@return Psc\CMS\UploadedFile
@throws Psc\CMS\UploadedFileNotFoundException | [
"Lädt",
"eine",
"Datei",
"aus",
"der",
"Datenbank"
] | train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/CMS/UploadManager.php#L115-L142 |
webforge-labs/psc-cms | lib/Psc/CMS/UploadManager.php | UploadManager.getSourceFile | public function getSourceFile(UploadedFile $uplFile) {
$hash = $uplFile->getHash();
$loaded = FALSE;
return $this->cache->load(array(mb_substr($hash, 0, 1), $hash), $loaded);
} | php | public function getSourceFile(UploadedFile $uplFile) {
$hash = $uplFile->getHash();
$loaded = FALSE;
return $this->cache->load(array(mb_substr($hash, 0, 1), $hash), $loaded);
} | [
"public",
"function",
"getSourceFile",
"(",
"UploadedFile",
"$",
"uplFile",
")",
"{",
"$",
"hash",
"=",
"$",
"uplFile",
"->",
"getHash",
"(",
")",
";",
"$",
"loaded",
"=",
"FALSE",
";",
"return",
"$",
"this",
"->",
"cache",
"->",
"load",
"(",
"array",
"(",
"mb_substr",
"(",
"$",
"hash",
",",
"0",
",",
"1",
")",
",",
"$",
"hash",
")",
",",
"$",
"loaded",
")",
";",
"}"
] | Gibt für eine UploadedFile die SourceFile (Binary) zurück
@TODO bei anderen Caches die kein FileCache sind muss hier noch die Datei temporär erzeugt werden (sense?)
@return Webforge\Common\System\File | [
"Gibt",
"für",
"eine",
"UploadedFile",
"die",
"SourceFile",
"(",
"Binary",
")",
"zurück"
] | train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/CMS/UploadManager.php#L182-L186 |
aedart/laravel-helpers | src/Traits/View/BladeTrait.php | BladeTrait.getBlade | public function getBlade(): ?BladeCompiler
{
if (!$this->hasBlade()) {
$this->setBlade($this->getDefaultBlade());
}
return $this->blade;
} | php | public function getBlade(): ?BladeCompiler
{
if (!$this->hasBlade()) {
$this->setBlade($this->getDefaultBlade());
}
return $this->blade;
} | [
"public",
"function",
"getBlade",
"(",
")",
":",
"?",
"BladeCompiler",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasBlade",
"(",
")",
")",
"{",
"$",
"this",
"->",
"setBlade",
"(",
"$",
"this",
"->",
"getDefaultBlade",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"blade",
";",
"}"
] | Get blade
If no blade has been set, this method will
set and return a default blade, if any such
value is available
@see getDefaultBlade()
@return BladeCompiler|null blade or null if none blade has been set | [
"Get",
"blade"
] | train | https://github.com/aedart/laravel-helpers/blob/8b81a2d6658f3f8cb62b6be2c34773aaa2df219a/src/Traits/View/BladeTrait.php#L54-L60 |
aedart/laravel-helpers | src/Traits/View/BladeTrait.php | BladeTrait.getDefaultBlade | public function getDefaultBlade(): ?BladeCompiler
{
// The blade compiler is usually only available, once
// Laravel's view service provider has been initialised.
// Thus, before just returning the Blade Facade's root
// instance, we must make sure that the view facade
// actually returns something
$view = View::getFacadeRoot();
if (isset($view)) {
return Blade::getFacadeRoot();
}
return $view;
} | php | public function getDefaultBlade(): ?BladeCompiler
{
// The blade compiler is usually only available, once
// Laravel's view service provider has been initialised.
// Thus, before just returning the Blade Facade's root
// instance, we must make sure that the view facade
// actually returns something
$view = View::getFacadeRoot();
if (isset($view)) {
return Blade::getFacadeRoot();
}
return $view;
} | [
"public",
"function",
"getDefaultBlade",
"(",
")",
":",
"?",
"BladeCompiler",
"{",
"// The blade compiler is usually only available, once",
"// Laravel's view service provider has been initialised.",
"// Thus, before just returning the Blade Facade's root",
"// instance, we must make sure that the view facade",
"// actually returns something",
"$",
"view",
"=",
"View",
"::",
"getFacadeRoot",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"view",
")",
")",
"{",
"return",
"Blade",
"::",
"getFacadeRoot",
"(",
")",
";",
"}",
"return",
"$",
"view",
";",
"}"
] | Get a default blade value, if any is available
@return BladeCompiler|null A default blade value or Null if no default value is available | [
"Get",
"a",
"default",
"blade",
"value",
"if",
"any",
"is",
"available"
] | train | https://github.com/aedart/laravel-helpers/blob/8b81a2d6658f3f8cb62b6be2c34773aaa2df219a/src/Traits/View/BladeTrait.php#L77-L89 |
redaigbaria/oauth2 | src/Exception/OAuthException.php | OAuthException.getHttpHeaders | public function getHttpHeaders()
{
$headers = [];
switch ($this->httpStatusCode) {
case 401:
$headers[] = 'HTTP/1.1 401 Unauthorized';
break;
case 500:
$headers[] = 'HTTP/1.1 500 Internal Server Error';
break;
case 501:
$headers[] = 'HTTP/1.1 501 Not Implemented';
break;
case 400:
default:
$headers[] = 'HTTP/1.1 400 Bad Request';
break;
}
// Add "WWW-Authenticate" header
//
// RFC 6749, section 5.2.:
// "If the client attempted to authenticate via the 'Authorization'
// request header field, the authorization server MUST
// respond with an HTTP 401 (Unauthorized) status code and
// include the "WWW-Authenticate" response header field
// matching the authentication scheme used by the client.
// @codeCoverageIgnoreStart
if ($this->errorType === 'invalid_client') {
$authScheme = null;
$request = new Request();
if ($request->getUser() !== null) {
$authScheme = 'Basic';
} else {
$authHeader = $request->headers->get('Authorization');
if ($authHeader !== null) {
if (strpos($authHeader, 'Bearer') === 0) {
$authScheme = 'Bearer';
} elseif (strpos($authHeader, 'Basic') === 0) {
$authScheme = 'Basic';
}
}
}
if ($authScheme !== null) {
$headers[] = 'WWW-Authenticate: '.$authScheme.' realm=""';
}
}
// @codeCoverageIgnoreEnd
return $headers;
} | php | public function getHttpHeaders()
{
$headers = [];
switch ($this->httpStatusCode) {
case 401:
$headers[] = 'HTTP/1.1 401 Unauthorized';
break;
case 500:
$headers[] = 'HTTP/1.1 500 Internal Server Error';
break;
case 501:
$headers[] = 'HTTP/1.1 501 Not Implemented';
break;
case 400:
default:
$headers[] = 'HTTP/1.1 400 Bad Request';
break;
}
// Add "WWW-Authenticate" header
//
// RFC 6749, section 5.2.:
// "If the client attempted to authenticate via the 'Authorization'
// request header field, the authorization server MUST
// respond with an HTTP 401 (Unauthorized) status code and
// include the "WWW-Authenticate" response header field
// matching the authentication scheme used by the client.
// @codeCoverageIgnoreStart
if ($this->errorType === 'invalid_client') {
$authScheme = null;
$request = new Request();
if ($request->getUser() !== null) {
$authScheme = 'Basic';
} else {
$authHeader = $request->headers->get('Authorization');
if ($authHeader !== null) {
if (strpos($authHeader, 'Bearer') === 0) {
$authScheme = 'Bearer';
} elseif (strpos($authHeader, 'Basic') === 0) {
$authScheme = 'Basic';
}
}
}
if ($authScheme !== null) {
$headers[] = 'WWW-Authenticate: '.$authScheme.' realm=""';
}
}
// @codeCoverageIgnoreEnd
return $headers;
} | [
"public",
"function",
"getHttpHeaders",
"(",
")",
"{",
"$",
"headers",
"=",
"[",
"]",
";",
"switch",
"(",
"$",
"this",
"->",
"httpStatusCode",
")",
"{",
"case",
"401",
":",
"$",
"headers",
"[",
"]",
"=",
"'HTTP/1.1 401 Unauthorized'",
";",
"break",
";",
"case",
"500",
":",
"$",
"headers",
"[",
"]",
"=",
"'HTTP/1.1 500 Internal Server Error'",
";",
"break",
";",
"case",
"501",
":",
"$",
"headers",
"[",
"]",
"=",
"'HTTP/1.1 501 Not Implemented'",
";",
"break",
";",
"case",
"400",
":",
"default",
":",
"$",
"headers",
"[",
"]",
"=",
"'HTTP/1.1 400 Bad Request'",
";",
"break",
";",
"}",
"// Add \"WWW-Authenticate\" header",
"//",
"// RFC 6749, section 5.2.:",
"// \"If the client attempted to authenticate via the 'Authorization'",
"// request header field, the authorization server MUST",
"// respond with an HTTP 401 (Unauthorized) status code and",
"// include the \"WWW-Authenticate\" response header field",
"// matching the authentication scheme used by the client.",
"// @codeCoverageIgnoreStart",
"if",
"(",
"$",
"this",
"->",
"errorType",
"===",
"'invalid_client'",
")",
"{",
"$",
"authScheme",
"=",
"null",
";",
"$",
"request",
"=",
"new",
"Request",
"(",
")",
";",
"if",
"(",
"$",
"request",
"->",
"getUser",
"(",
")",
"!==",
"null",
")",
"{",
"$",
"authScheme",
"=",
"'Basic'",
";",
"}",
"else",
"{",
"$",
"authHeader",
"=",
"$",
"request",
"->",
"headers",
"->",
"get",
"(",
"'Authorization'",
")",
";",
"if",
"(",
"$",
"authHeader",
"!==",
"null",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"authHeader",
",",
"'Bearer'",
")",
"===",
"0",
")",
"{",
"$",
"authScheme",
"=",
"'Bearer'",
";",
"}",
"elseif",
"(",
"strpos",
"(",
"$",
"authHeader",
",",
"'Basic'",
")",
"===",
"0",
")",
"{",
"$",
"authScheme",
"=",
"'Basic'",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"authScheme",
"!==",
"null",
")",
"{",
"$",
"headers",
"[",
"]",
"=",
"'WWW-Authenticate: '",
".",
"$",
"authScheme",
".",
"' realm=\"\"'",
";",
"}",
"}",
"// @codeCoverageIgnoreEnd",
"return",
"$",
"headers",
";",
"}"
] | Get all headers that have to be send with the error response
@return array Array with header values | [
"Get",
"all",
"headers",
"that",
"have",
"to",
"be",
"send",
"with",
"the",
"error",
"response"
] | train | https://github.com/redaigbaria/oauth2/blob/54cca4aaaff6a095cbf1c8010f2fe2cc7de4e45a/src/Exception/OAuthException.php#L95-L144 |
ClanCats/Core | src/classes/CCStorage.php | CCStorage.add | public static function add( $key, $path, $url = null )
{
static::$paths[$key] = $path;
if ( !is_null( $url ) )
{
static::$urls[$key] = $url;
}
} | php | public static function add( $key, $path, $url = null )
{
static::$paths[$key] = $path;
if ( !is_null( $url ) )
{
static::$urls[$key] = $url;
}
} | [
"public",
"static",
"function",
"add",
"(",
"$",
"key",
",",
"$",
"path",
",",
"$",
"url",
"=",
"null",
")",
"{",
"static",
"::",
"$",
"paths",
"[",
"$",
"key",
"]",
"=",
"$",
"path",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"url",
")",
")",
"{",
"static",
"::",
"$",
"urls",
"[",
"$",
"key",
"]",
"=",
"$",
"url",
";",
"}",
"}"
] | Adds a new storage directory
@param string $key
@param string $path
@param string $url
@return void | [
"Adds",
"a",
"new",
"storage",
"directory"
] | train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCStorage.php#L75-L83 |
ClanCats/Core | src/classes/CCStorage.php | CCStorage.file | public static function file( $file )
{
$params = array_merge( static::$params, array(
'time' => time(),
'fingerprint' => \CCSession::fingerprint(),
'random' => CCStr::random(),
));
foreach( $params as $param => $value )
{
$file = str_replace( ':'.$param, $value, $file );
}
return $file;
} | php | public static function file( $file )
{
$params = array_merge( static::$params, array(
'time' => time(),
'fingerprint' => \CCSession::fingerprint(),
'random' => CCStr::random(),
));
foreach( $params as $param => $value )
{
$file = str_replace( ':'.$param, $value, $file );
}
return $file;
} | [
"public",
"static",
"function",
"file",
"(",
"$",
"file",
")",
"{",
"$",
"params",
"=",
"array_merge",
"(",
"static",
"::",
"$",
"params",
",",
"array",
"(",
"'time'",
"=>",
"time",
"(",
")",
",",
"'fingerprint'",
"=>",
"\\",
"CCSession",
"::",
"fingerprint",
"(",
")",
",",
"'random'",
"=>",
"CCStr",
"::",
"random",
"(",
")",
",",
")",
")",
";",
"foreach",
"(",
"$",
"params",
"as",
"$",
"param",
"=>",
"$",
"value",
")",
"{",
"$",
"file",
"=",
"str_replace",
"(",
"':'",
".",
"$",
"param",
",",
"$",
"value",
",",
"$",
"file",
")",
";",
"}",
"return",
"$",
"file",
";",
"}"
] | Prepares a file with the parameters
@param string $file
@return $file | [
"Prepares",
"a",
"file",
"with",
"the",
"parameters"
] | train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCStorage.php#L91-L105 |
ClanCats/Core | src/classes/CCStorage.php | CCStorage.path | public static function path( $file = null, $key = null )
{
// get the storage key
if ( is_null( $key ) )
{
$key = static::$default;
}
// check if path exists
if ( !isset( static::$paths[$key] ) )
{
throw new CCException( 'CCStorage - use of undefined storage path '.$key.'.' );
}
if ( strpos( $file, ':' ) )
{
$file = static::file( $file );
}
return static::$paths[$key].$file;
} | php | public static function path( $file = null, $key = null )
{
// get the storage key
if ( is_null( $key ) )
{
$key = static::$default;
}
// check if path exists
if ( !isset( static::$paths[$key] ) )
{
throw new CCException( 'CCStorage - use of undefined storage path '.$key.'.' );
}
if ( strpos( $file, ':' ) )
{
$file = static::file( $file );
}
return static::$paths[$key].$file;
} | [
"public",
"static",
"function",
"path",
"(",
"$",
"file",
"=",
"null",
",",
"$",
"key",
"=",
"null",
")",
"{",
"// get the storage key",
"if",
"(",
"is_null",
"(",
"$",
"key",
")",
")",
"{",
"$",
"key",
"=",
"static",
"::",
"$",
"default",
";",
"}",
"// check if path exists",
"if",
"(",
"!",
"isset",
"(",
"static",
"::",
"$",
"paths",
"[",
"$",
"key",
"]",
")",
")",
"{",
"throw",
"new",
"CCException",
"(",
"'CCStorage - use of undefined storage path '",
".",
"$",
"key",
".",
"'.'",
")",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"file",
",",
"':'",
")",
")",
"{",
"$",
"file",
"=",
"static",
"::",
"file",
"(",
"$",
"file",
")",
";",
"}",
"return",
"static",
"::",
"$",
"paths",
"[",
"$",
"key",
"]",
".",
"$",
"file",
";",
"}"
] | Get a storage path ( absolute )
@param string $file
@param string $key
@return string | [
"Get",
"a",
"storage",
"path",
"(",
"absolute",
")"
] | train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCStorage.php#L114-L134 |
ClanCats/Core | src/classes/CCStorage.php | CCStorage.url | public static function url( $file = null, $key = null )
{
// get the storage key
if ( is_null( $key ) )
{
$key = static::$default;
}
// check if path exists
if ( !isset( static::$urls[$key] ) )
{
throw new CCException( 'CCStorage - use of undefined public url '.$key.'.' );
}
return CCUrl::to( static::$urls[$key].$file );
} | php | public static function url( $file = null, $key = null )
{
// get the storage key
if ( is_null( $key ) )
{
$key = static::$default;
}
// check if path exists
if ( !isset( static::$urls[$key] ) )
{
throw new CCException( 'CCStorage - use of undefined public url '.$key.'.' );
}
return CCUrl::to( static::$urls[$key].$file );
} | [
"public",
"static",
"function",
"url",
"(",
"$",
"file",
"=",
"null",
",",
"$",
"key",
"=",
"null",
")",
"{",
"// get the storage key",
"if",
"(",
"is_null",
"(",
"$",
"key",
")",
")",
"{",
"$",
"key",
"=",
"static",
"::",
"$",
"default",
";",
"}",
"// check if path exists",
"if",
"(",
"!",
"isset",
"(",
"static",
"::",
"$",
"urls",
"[",
"$",
"key",
"]",
")",
")",
"{",
"throw",
"new",
"CCException",
"(",
"'CCStorage - use of undefined public url '",
".",
"$",
"key",
".",
"'.'",
")",
";",
"}",
"return",
"CCUrl",
"::",
"to",
"(",
"static",
"::",
"$",
"urls",
"[",
"$",
"key",
"]",
".",
"$",
"file",
")",
";",
"}"
] | Get the public url to a file if available
@param string $file
@param string $key
@return string | [
"Get",
"the",
"public",
"url",
"to",
"a",
"file",
"if",
"available"
] | train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCStorage.php#L143-L158 |
ClanCats/Core | src/classes/CCStorage.php | CCStorage.write | public static function write( $file, $content, $key = null )
{
return CCFile::write( static::path( $file, $key ), $content );
} | php | public static function write( $file, $content, $key = null )
{
return CCFile::write( static::path( $file, $key ), $content );
} | [
"public",
"static",
"function",
"write",
"(",
"$",
"file",
",",
"$",
"content",
",",
"$",
"key",
"=",
"null",
")",
"{",
"return",
"CCFile",
"::",
"write",
"(",
"static",
"::",
"path",
"(",
"$",
"file",
",",
"$",
"key",
")",
",",
"$",
"content",
")",
";",
"}"
] | Write a file to the storage
@param string $file
@param string $key
@return string | [
"Write",
"a",
"file",
"to",
"the",
"storage"
] | train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCStorage.php#L167-L170 |
slashworks/control-bundle | src/Slashworks/AppBundle/Resources/private/api/zip.lib.php | Zip.setComment | public function setComment($newComment = NULL) {
if ($this->isFinalized) {
return FALSE;
}
$this->zipComment = $newComment;
return TRUE;
} | php | public function setComment($newComment = NULL) {
if ($this->isFinalized) {
return FALSE;
}
$this->zipComment = $newComment;
return TRUE;
} | [
"public",
"function",
"setComment",
"(",
"$",
"newComment",
"=",
"NULL",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isFinalized",
")",
"{",
"return",
"FALSE",
";",
"}",
"$",
"this",
"->",
"zipComment",
"=",
"$",
"newComment",
";",
"return",
"TRUE",
";",
"}"
] | Set Zip archive comment.
@param string $newComment New comment. NULL to clear.
@return bool $success | [
"Set",
"Zip",
"archive",
"comment",
"."
] | train | https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Resources/private/api/zip.lib.php#L139-L146 |
slashworks/control-bundle | src/Slashworks/AppBundle/Resources/private/api/zip.lib.php | Zip.setZipFile | public function setZipFile($fileName) {
if (is_file($fileName)) {
unlink($fileName);
}
$fd=fopen($fileName, "x+b");
if (is_resource($this->zipFile)) {
rewind($this->zipFile);
while (!feof($this->zipFile)) {
fwrite($fd, fread($this->zipFile, $this->streamChunkSize));
}
fclose($this->zipFile);
} else {
fwrite($fd, $this->zipData);
$this->zipData = NULL;
}
$this->zipFile = $fd;
return TRUE;
} | php | public function setZipFile($fileName) {
if (is_file($fileName)) {
unlink($fileName);
}
$fd=fopen($fileName, "x+b");
if (is_resource($this->zipFile)) {
rewind($this->zipFile);
while (!feof($this->zipFile)) {
fwrite($fd, fread($this->zipFile, $this->streamChunkSize));
}
fclose($this->zipFile);
} else {
fwrite($fd, $this->zipData);
$this->zipData = NULL;
}
$this->zipFile = $fd;
return TRUE;
} | [
"public",
"function",
"setZipFile",
"(",
"$",
"fileName",
")",
"{",
"if",
"(",
"is_file",
"(",
"$",
"fileName",
")",
")",
"{",
"unlink",
"(",
"$",
"fileName",
")",
";",
"}",
"$",
"fd",
"=",
"fopen",
"(",
"$",
"fileName",
",",
"\"x+b\"",
")",
";",
"if",
"(",
"is_resource",
"(",
"$",
"this",
"->",
"zipFile",
")",
")",
"{",
"rewind",
"(",
"$",
"this",
"->",
"zipFile",
")",
";",
"while",
"(",
"!",
"feof",
"(",
"$",
"this",
"->",
"zipFile",
")",
")",
"{",
"fwrite",
"(",
"$",
"fd",
",",
"fread",
"(",
"$",
"this",
"->",
"zipFile",
",",
"$",
"this",
"->",
"streamChunkSize",
")",
")",
";",
"}",
"fclose",
"(",
"$",
"this",
"->",
"zipFile",
")",
";",
"}",
"else",
"{",
"fwrite",
"(",
"$",
"fd",
",",
"$",
"this",
"->",
"zipData",
")",
";",
"$",
"this",
"->",
"zipData",
"=",
"NULL",
";",
"}",
"$",
"this",
"->",
"zipFile",
"=",
"$",
"fd",
";",
"return",
"TRUE",
";",
"}"
] | Set zip file to write zip data to.
This will cause all present and future data written to this class to be written to this file.
This can be used at any time, even after the Zip Archive have been finalized. Any previous file will be closed.
Warning: If the given file already exists, it will be overwritten.
@param string $fileName
@return bool $success | [
"Set",
"zip",
"file",
"to",
"write",
"zip",
"data",
"to",
".",
"This",
"will",
"cause",
"all",
"present",
"and",
"future",
"data",
"written",
"to",
"this",
"class",
"to",
"be",
"written",
"to",
"this",
"file",
".",
"This",
"can",
"be",
"used",
"at",
"any",
"time",
"even",
"after",
"the",
"Zip",
"Archive",
"have",
"been",
"finalized",
".",
"Any",
"previous",
"file",
"will",
"be",
"closed",
".",
"Warning",
":",
"If",
"the",
"given",
"file",
"already",
"exists",
"it",
"will",
"be",
"overwritten",
"."
] | train | https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Resources/private/api/zip.lib.php#L157-L176 |
slashworks/control-bundle | src/Slashworks/AppBundle/Resources/private/api/zip.lib.php | Zip.addDirectory | public function addDirectory($directoryPath, $timestamp = 0, $fileComment = NULL, $extFileAttr = self::EXT_FILE_ATTR_DIR) {
if ($this->isFinalized) {
return FALSE;
}
$directoryPath = str_replace("\\", "/", $directoryPath);
$directoryPath = rtrim($directoryPath, "/");
if (strlen($directoryPath) > 0) {
$this->buildZipEntry($directoryPath.'/', $fileComment, "\x00\x00", "\x00\x00", $timestamp, "\x00\x00\x00\x00", 0, 0, $extFileAttr);
return TRUE;
}
return FALSE;
} | php | public function addDirectory($directoryPath, $timestamp = 0, $fileComment = NULL, $extFileAttr = self::EXT_FILE_ATTR_DIR) {
if ($this->isFinalized) {
return FALSE;
}
$directoryPath = str_replace("\\", "/", $directoryPath);
$directoryPath = rtrim($directoryPath, "/");
if (strlen($directoryPath) > 0) {
$this->buildZipEntry($directoryPath.'/', $fileComment, "\x00\x00", "\x00\x00", $timestamp, "\x00\x00\x00\x00", 0, 0, $extFileAttr);
return TRUE;
}
return FALSE;
} | [
"public",
"function",
"addDirectory",
"(",
"$",
"directoryPath",
",",
"$",
"timestamp",
"=",
"0",
",",
"$",
"fileComment",
"=",
"NULL",
",",
"$",
"extFileAttr",
"=",
"self",
"::",
"EXT_FILE_ATTR_DIR",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isFinalized",
")",
"{",
"return",
"FALSE",
";",
"}",
"$",
"directoryPath",
"=",
"str_replace",
"(",
"\"\\\\\"",
",",
"\"/\"",
",",
"$",
"directoryPath",
")",
";",
"$",
"directoryPath",
"=",
"rtrim",
"(",
"$",
"directoryPath",
",",
"\"/\"",
")",
";",
"if",
"(",
"strlen",
"(",
"$",
"directoryPath",
")",
">",
"0",
")",
"{",
"$",
"this",
"->",
"buildZipEntry",
"(",
"$",
"directoryPath",
".",
"'/'",
",",
"$",
"fileComment",
",",
"\"\\x00\\x00\"",
",",
"\"\\x00\\x00\"",
",",
"$",
"timestamp",
",",
"\"\\x00\\x00\\x00\\x00\"",
",",
"0",
",",
"0",
",",
"$",
"extFileAttr",
")",
";",
"return",
"TRUE",
";",
"}",
"return",
"FALSE",
";",
"}"
] | Add an empty directory entry to the zip archive.
Basically this is only used if an empty directory is added.
@param string $directoryPath Directory Path and name to be added to the archive.
@param int $timestamp (Optional) Timestamp for the added directory, if omitted or set to 0, the current time will be used.
@param string $fileComment (Optional) Comment to be added to the archive for this directory. To use fileComment, timestamp must be given.
@param int $extFileAttr (Optional) The external file reference, use generateExtAttr to generate this.
@return bool $success | [
"Add",
"an",
"empty",
"directory",
"entry",
"to",
"the",
"zip",
"archive",
".",
"Basically",
"this",
"is",
"only",
"used",
"if",
"an",
"empty",
"directory",
"is",
"added",
"."
] | train | https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Resources/private/api/zip.lib.php#L188-L200 |
slashworks/control-bundle | src/Slashworks/AppBundle/Resources/private/api/zip.lib.php | Zip.addFile | public function addFile($data, $filePath, $timestamp = 0, $fileComment = NULL, $compress = TRUE, $extFileAttr = self::EXT_FILE_ATTR_FILE) {
if ($this->isFinalized) {
return FALSE;
}
if (is_resource($data) && get_resource_type($data) == "stream") {
$this->addLargeFile($data, $filePath, $timestamp, $fileComment, $extFileAttr);
return FALSE;
}
$gzData = "";
$gzType = "\x08\x00"; // Compression type 8 = deflate
$gpFlags = "\x00\x00"; // General Purpose bit flags for compression type 8 it is: 0=Normal, 1=Maximum, 2=Fast, 3=super fast compression.
$dataLength = strlen($data);
$fileCRC32 = pack("V", crc32($data));
if ($compress) {
$gzTmp = gzcompress($data);
$gzData = substr(substr($gzTmp, 0, strlen($gzTmp) - 4), 2); // gzcompress adds a 2 byte header and 4 byte CRC we can't use.
// The 2 byte header does contain useful data, though in this case the 2 parameters we'd be interrested in will always be 8 for compression type, and 2 for General purpose flag.
$gzLength = strlen($gzData);
} else {
$gzLength = $dataLength;
}
if ($gzLength >= $dataLength) {
$gzLength = $dataLength;
$gzData = $data;
$gzType = "\x00\x00"; // Compression type 0 = stored
$gpFlags = "\x00\x00"; // Compression type 0 = stored
}
if (!is_resource($this->zipFile) && ($this->offset + $gzLength) > $this->zipMemoryThreshold) {
$this->zipflush();
}
$this->buildZipEntry($filePath, $fileComment, $gpFlags, $gzType, $timestamp, $fileCRC32, $gzLength, $dataLength, $extFileAttr);
$this->zipwrite($gzData);
return TRUE;
} | php | public function addFile($data, $filePath, $timestamp = 0, $fileComment = NULL, $compress = TRUE, $extFileAttr = self::EXT_FILE_ATTR_FILE) {
if ($this->isFinalized) {
return FALSE;
}
if (is_resource($data) && get_resource_type($data) == "stream") {
$this->addLargeFile($data, $filePath, $timestamp, $fileComment, $extFileAttr);
return FALSE;
}
$gzData = "";
$gzType = "\x08\x00"; // Compression type 8 = deflate
$gpFlags = "\x00\x00"; // General Purpose bit flags for compression type 8 it is: 0=Normal, 1=Maximum, 2=Fast, 3=super fast compression.
$dataLength = strlen($data);
$fileCRC32 = pack("V", crc32($data));
if ($compress) {
$gzTmp = gzcompress($data);
$gzData = substr(substr($gzTmp, 0, strlen($gzTmp) - 4), 2); // gzcompress adds a 2 byte header and 4 byte CRC we can't use.
// The 2 byte header does contain useful data, though in this case the 2 parameters we'd be interrested in will always be 8 for compression type, and 2 for General purpose flag.
$gzLength = strlen($gzData);
} else {
$gzLength = $dataLength;
}
if ($gzLength >= $dataLength) {
$gzLength = $dataLength;
$gzData = $data;
$gzType = "\x00\x00"; // Compression type 0 = stored
$gpFlags = "\x00\x00"; // Compression type 0 = stored
}
if (!is_resource($this->zipFile) && ($this->offset + $gzLength) > $this->zipMemoryThreshold) {
$this->zipflush();
}
$this->buildZipEntry($filePath, $fileComment, $gpFlags, $gzType, $timestamp, $fileCRC32, $gzLength, $dataLength, $extFileAttr);
$this->zipwrite($gzData);
return TRUE;
} | [
"public",
"function",
"addFile",
"(",
"$",
"data",
",",
"$",
"filePath",
",",
"$",
"timestamp",
"=",
"0",
",",
"$",
"fileComment",
"=",
"NULL",
",",
"$",
"compress",
"=",
"TRUE",
",",
"$",
"extFileAttr",
"=",
"self",
"::",
"EXT_FILE_ATTR_FILE",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isFinalized",
")",
"{",
"return",
"FALSE",
";",
"}",
"if",
"(",
"is_resource",
"(",
"$",
"data",
")",
"&&",
"get_resource_type",
"(",
"$",
"data",
")",
"==",
"\"stream\"",
")",
"{",
"$",
"this",
"->",
"addLargeFile",
"(",
"$",
"data",
",",
"$",
"filePath",
",",
"$",
"timestamp",
",",
"$",
"fileComment",
",",
"$",
"extFileAttr",
")",
";",
"return",
"FALSE",
";",
"}",
"$",
"gzData",
"=",
"\"\"",
";",
"$",
"gzType",
"=",
"\"\\x08\\x00\"",
";",
"// Compression type 8 = deflate",
"$",
"gpFlags",
"=",
"\"\\x00\\x00\"",
";",
"// General Purpose bit flags for compression type 8 it is: 0=Normal, 1=Maximum, 2=Fast, 3=super fast compression.",
"$",
"dataLength",
"=",
"strlen",
"(",
"$",
"data",
")",
";",
"$",
"fileCRC32",
"=",
"pack",
"(",
"\"V\"",
",",
"crc32",
"(",
"$",
"data",
")",
")",
";",
"if",
"(",
"$",
"compress",
")",
"{",
"$",
"gzTmp",
"=",
"gzcompress",
"(",
"$",
"data",
")",
";",
"$",
"gzData",
"=",
"substr",
"(",
"substr",
"(",
"$",
"gzTmp",
",",
"0",
",",
"strlen",
"(",
"$",
"gzTmp",
")",
"-",
"4",
")",
",",
"2",
")",
";",
"// gzcompress adds a 2 byte header and 4 byte CRC we can't use.",
"// The 2 byte header does contain useful data, though in this case the 2 parameters we'd be interrested in will always be 8 for compression type, and 2 for General purpose flag.",
"$",
"gzLength",
"=",
"strlen",
"(",
"$",
"gzData",
")",
";",
"}",
"else",
"{",
"$",
"gzLength",
"=",
"$",
"dataLength",
";",
"}",
"if",
"(",
"$",
"gzLength",
">=",
"$",
"dataLength",
")",
"{",
"$",
"gzLength",
"=",
"$",
"dataLength",
";",
"$",
"gzData",
"=",
"$",
"data",
";",
"$",
"gzType",
"=",
"\"\\x00\\x00\"",
";",
"// Compression type 0 = stored",
"$",
"gpFlags",
"=",
"\"\\x00\\x00\"",
";",
"// Compression type 0 = stored",
"}",
"if",
"(",
"!",
"is_resource",
"(",
"$",
"this",
"->",
"zipFile",
")",
"&&",
"(",
"$",
"this",
"->",
"offset",
"+",
"$",
"gzLength",
")",
">",
"$",
"this",
"->",
"zipMemoryThreshold",
")",
"{",
"$",
"this",
"->",
"zipflush",
"(",
")",
";",
"}",
"$",
"this",
"->",
"buildZipEntry",
"(",
"$",
"filePath",
",",
"$",
"fileComment",
",",
"$",
"gpFlags",
",",
"$",
"gzType",
",",
"$",
"timestamp",
",",
"$",
"fileCRC32",
",",
"$",
"gzLength",
",",
"$",
"dataLength",
",",
"$",
"extFileAttr",
")",
";",
"$",
"this",
"->",
"zipwrite",
"(",
"$",
"gzData",
")",
";",
"return",
"TRUE",
";",
"}"
] | Add a file to the archive at the specified location and file name.
@param string $data File data.
@param string $filePath Filepath and name to be used in the archive.
@param int $timestamp (Optional) Timestamp for the added file, if omitted or set to 0, the current time will be used.
@param string $fileComment (Optional) Comment to be added to the archive for this file. To use fileComment, timestamp must be given.
@param bool $compress (Optional) Compress file, if set to FALSE the file will only be stored. Default TRUE.
@param int $extFileAttr (Optional) The external file reference, use generateExtAttr to generate this.
@return bool $success | [
"Add",
"a",
"file",
"to",
"the",
"archive",
"at",
"the",
"specified",
"location",
"and",
"file",
"name",
"."
] | train | https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Resources/private/api/zip.lib.php#L213-L254 |
slashworks/control-bundle | src/Slashworks/AppBundle/Resources/private/api/zip.lib.php | Zip.addDirectoryContent | public function addDirectoryContent($realPath, $zipPath, $recursive = TRUE, $followSymlinks = TRUE, &$addedFiles = array(),
$overrideFilePermissions = FALSE, $extDirAttr = self::EXT_FILE_ATTR_DIR, $extFileAttr = self::EXT_FILE_ATTR_FILE) {
if (file_exists($realPath) && !isset($addedFiles[realpath($realPath)])) {
if (is_dir($realPath)) {
if ($overrideFilePermissions) {
$this->addDirectory($zipPath, 0, null, $extDirAttr);
} else {
$this->addDirectory($zipPath, 0, null, self::getFileExtAttr($realPath));
}
}
$addedFiles[realpath($realPath)] = $zipPath;
$iter = new \DirectoryIterator($realPath);
foreach ($iter as $file) {
if ($file->isDot()) {
continue;
}
$newRealPath = $file->getPathname();
$newZipPath = self::pathJoin($zipPath, $file->getFilename());
if (file_exists($newRealPath) && ($followSymlinks === TRUE || !is_link($newRealPath))) {
if ($file->isFile()) {
$addedFiles[realpath($newRealPath)] = $newZipPath;
if ($overrideFilePermissions) {
$this->addLargeFile($newRealPath, $newZipPath, 0, null, $extFileAttr);
} else {
$this->addLargeFile($newRealPath, $newZipPath, 0, null, self::getFileExtAttr($newRealPath));
}
} else if ($recursive === TRUE) {
$this->addDirectoryContent($newRealPath, $newZipPath, $recursive, $followSymlinks, $addedFiles, $overrideFilePermissions, $extDirAttr, $extFileAttr);
} else {
if ($overrideFilePermissions) {
$this->addDirectory($zipPath, 0, null, $extDirAttr);
} else {
$this->addDirectory($zipPath, 0, null, self::getFileExtAttr($newRealPath));
}
}
}
}
}
} | php | public function addDirectoryContent($realPath, $zipPath, $recursive = TRUE, $followSymlinks = TRUE, &$addedFiles = array(),
$overrideFilePermissions = FALSE, $extDirAttr = self::EXT_FILE_ATTR_DIR, $extFileAttr = self::EXT_FILE_ATTR_FILE) {
if (file_exists($realPath) && !isset($addedFiles[realpath($realPath)])) {
if (is_dir($realPath)) {
if ($overrideFilePermissions) {
$this->addDirectory($zipPath, 0, null, $extDirAttr);
} else {
$this->addDirectory($zipPath, 0, null, self::getFileExtAttr($realPath));
}
}
$addedFiles[realpath($realPath)] = $zipPath;
$iter = new \DirectoryIterator($realPath);
foreach ($iter as $file) {
if ($file->isDot()) {
continue;
}
$newRealPath = $file->getPathname();
$newZipPath = self::pathJoin($zipPath, $file->getFilename());
if (file_exists($newRealPath) && ($followSymlinks === TRUE || !is_link($newRealPath))) {
if ($file->isFile()) {
$addedFiles[realpath($newRealPath)] = $newZipPath;
if ($overrideFilePermissions) {
$this->addLargeFile($newRealPath, $newZipPath, 0, null, $extFileAttr);
} else {
$this->addLargeFile($newRealPath, $newZipPath, 0, null, self::getFileExtAttr($newRealPath));
}
} else if ($recursive === TRUE) {
$this->addDirectoryContent($newRealPath, $newZipPath, $recursive, $followSymlinks, $addedFiles, $overrideFilePermissions, $extDirAttr, $extFileAttr);
} else {
if ($overrideFilePermissions) {
$this->addDirectory($zipPath, 0, null, $extDirAttr);
} else {
$this->addDirectory($zipPath, 0, null, self::getFileExtAttr($newRealPath));
}
}
}
}
}
} | [
"public",
"function",
"addDirectoryContent",
"(",
"$",
"realPath",
",",
"$",
"zipPath",
",",
"$",
"recursive",
"=",
"TRUE",
",",
"$",
"followSymlinks",
"=",
"TRUE",
",",
"&",
"$",
"addedFiles",
"=",
"array",
"(",
")",
",",
"$",
"overrideFilePermissions",
"=",
"FALSE",
",",
"$",
"extDirAttr",
"=",
"self",
"::",
"EXT_FILE_ATTR_DIR",
",",
"$",
"extFileAttr",
"=",
"self",
"::",
"EXT_FILE_ATTR_FILE",
")",
"{",
"if",
"(",
"file_exists",
"(",
"$",
"realPath",
")",
"&&",
"!",
"isset",
"(",
"$",
"addedFiles",
"[",
"realpath",
"(",
"$",
"realPath",
")",
"]",
")",
")",
"{",
"if",
"(",
"is_dir",
"(",
"$",
"realPath",
")",
")",
"{",
"if",
"(",
"$",
"overrideFilePermissions",
")",
"{",
"$",
"this",
"->",
"addDirectory",
"(",
"$",
"zipPath",
",",
"0",
",",
"null",
",",
"$",
"extDirAttr",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"addDirectory",
"(",
"$",
"zipPath",
",",
"0",
",",
"null",
",",
"self",
"::",
"getFileExtAttr",
"(",
"$",
"realPath",
")",
")",
";",
"}",
"}",
"$",
"addedFiles",
"[",
"realpath",
"(",
"$",
"realPath",
")",
"]",
"=",
"$",
"zipPath",
";",
"$",
"iter",
"=",
"new",
"\\",
"DirectoryIterator",
"(",
"$",
"realPath",
")",
";",
"foreach",
"(",
"$",
"iter",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"$",
"file",
"->",
"isDot",
"(",
")",
")",
"{",
"continue",
";",
"}",
"$",
"newRealPath",
"=",
"$",
"file",
"->",
"getPathname",
"(",
")",
";",
"$",
"newZipPath",
"=",
"self",
"::",
"pathJoin",
"(",
"$",
"zipPath",
",",
"$",
"file",
"->",
"getFilename",
"(",
")",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"newRealPath",
")",
"&&",
"(",
"$",
"followSymlinks",
"===",
"TRUE",
"||",
"!",
"is_link",
"(",
"$",
"newRealPath",
")",
")",
")",
"{",
"if",
"(",
"$",
"file",
"->",
"isFile",
"(",
")",
")",
"{",
"$",
"addedFiles",
"[",
"realpath",
"(",
"$",
"newRealPath",
")",
"]",
"=",
"$",
"newZipPath",
";",
"if",
"(",
"$",
"overrideFilePermissions",
")",
"{",
"$",
"this",
"->",
"addLargeFile",
"(",
"$",
"newRealPath",
",",
"$",
"newZipPath",
",",
"0",
",",
"null",
",",
"$",
"extFileAttr",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"addLargeFile",
"(",
"$",
"newRealPath",
",",
"$",
"newZipPath",
",",
"0",
",",
"null",
",",
"self",
"::",
"getFileExtAttr",
"(",
"$",
"newRealPath",
")",
")",
";",
"}",
"}",
"else",
"if",
"(",
"$",
"recursive",
"===",
"TRUE",
")",
"{",
"$",
"this",
"->",
"addDirectoryContent",
"(",
"$",
"newRealPath",
",",
"$",
"newZipPath",
",",
"$",
"recursive",
",",
"$",
"followSymlinks",
",",
"$",
"addedFiles",
",",
"$",
"overrideFilePermissions",
",",
"$",
"extDirAttr",
",",
"$",
"extFileAttr",
")",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"overrideFilePermissions",
")",
"{",
"$",
"this",
"->",
"addDirectory",
"(",
"$",
"zipPath",
",",
"0",
",",
"null",
",",
"$",
"extDirAttr",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"addDirectory",
"(",
"$",
"zipPath",
",",
"0",
",",
"null",
",",
"self",
"::",
"getFileExtAttr",
"(",
"$",
"newRealPath",
")",
")",
";",
"}",
"}",
"}",
"}",
"}",
"}"
] | Add the content to a directory.
@author Adam Schmalhofer <[email protected]>
@author A. Grandt
@param string $realPath Path on the file system.
@param string $zipPath Filepath and name to be used in the archive.
@param bool $recursive Add content recursively, default is TRUE.
@param bool $followSymlinks Follow and add symbolic links, if they are accessible, default is TRUE.
@param array &$addedFiles Reference to the added files, this is used to prevent duplicates, efault is an empty array.
If you start the function by parsing an array, the array will be populated with the realPath
and zipPath kay/value pairs added to the archive by the function.
@param bool $overrideFilePermissions Force the use of the file/dir permissions set in the $extDirAttr
and $extFileAttr parameters.
@param int $extDirAttr Permissions for directories.
@param int $extFileAttr Permissions for files. | [
"Add",
"the",
"content",
"to",
"a",
"directory",
"."
] | train | https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Resources/private/api/zip.lib.php#L274-L315 |
slashworks/control-bundle | src/Slashworks/AppBundle/Resources/private/api/zip.lib.php | Zip.addLargeFile | public function addLargeFile($dataFile, $filePath, $timestamp = 0, $fileComment = NULL, $extFileAttr = self::EXT_FILE_ATTR_FILE) {
if ($this->isFinalized) {
return FALSE;
}
if (is_string($dataFile) && is_file($dataFile)) {
$this->processFile($dataFile, $filePath, $timestamp, $fileComment, $extFileAttr);
} else if (is_resource($dataFile) && get_resource_type($dataFile) == "stream") {
$fh = $dataFile;
$this->openStream($filePath, $timestamp, $fileComment, $extFileAttr);
while (!feof($fh)) {
$this->addStreamData(fread($fh, $this->streamChunkSize));
}
$this->closeStream($this->addExtraField);
}
return TRUE;
} | php | public function addLargeFile($dataFile, $filePath, $timestamp = 0, $fileComment = NULL, $extFileAttr = self::EXT_FILE_ATTR_FILE) {
if ($this->isFinalized) {
return FALSE;
}
if (is_string($dataFile) && is_file($dataFile)) {
$this->processFile($dataFile, $filePath, $timestamp, $fileComment, $extFileAttr);
} else if (is_resource($dataFile) && get_resource_type($dataFile) == "stream") {
$fh = $dataFile;
$this->openStream($filePath, $timestamp, $fileComment, $extFileAttr);
while (!feof($fh)) {
$this->addStreamData(fread($fh, $this->streamChunkSize));
}
$this->closeStream($this->addExtraField);
}
return TRUE;
} | [
"public",
"function",
"addLargeFile",
"(",
"$",
"dataFile",
",",
"$",
"filePath",
",",
"$",
"timestamp",
"=",
"0",
",",
"$",
"fileComment",
"=",
"NULL",
",",
"$",
"extFileAttr",
"=",
"self",
"::",
"EXT_FILE_ATTR_FILE",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isFinalized",
")",
"{",
"return",
"FALSE",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"dataFile",
")",
"&&",
"is_file",
"(",
"$",
"dataFile",
")",
")",
"{",
"$",
"this",
"->",
"processFile",
"(",
"$",
"dataFile",
",",
"$",
"filePath",
",",
"$",
"timestamp",
",",
"$",
"fileComment",
",",
"$",
"extFileAttr",
")",
";",
"}",
"else",
"if",
"(",
"is_resource",
"(",
"$",
"dataFile",
")",
"&&",
"get_resource_type",
"(",
"$",
"dataFile",
")",
"==",
"\"stream\"",
")",
"{",
"$",
"fh",
"=",
"$",
"dataFile",
";",
"$",
"this",
"->",
"openStream",
"(",
"$",
"filePath",
",",
"$",
"timestamp",
",",
"$",
"fileComment",
",",
"$",
"extFileAttr",
")",
";",
"while",
"(",
"!",
"feof",
"(",
"$",
"fh",
")",
")",
"{",
"$",
"this",
"->",
"addStreamData",
"(",
"fread",
"(",
"$",
"fh",
",",
"$",
"this",
"->",
"streamChunkSize",
")",
")",
";",
"}",
"$",
"this",
"->",
"closeStream",
"(",
"$",
"this",
"->",
"addExtraField",
")",
";",
"}",
"return",
"TRUE",
";",
"}"
] | Add a file to the archive at the specified location and file name.
@param string $dataFile File name/path.
@param string $filePath Filepath and name to be used in the archive.
@param int $timestamp (Optional) Timestamp for the added file, if omitted or set to 0, the current time will be used.
@param string $fileComment (Optional) Comment to be added to the archive for this file. To use fileComment, timestamp must be given.
@param int $extFileAttr (Optional) The external file reference, use generateExtAttr to generate this.
@return bool $success | [
"Add",
"a",
"file",
"to",
"the",
"archive",
"at",
"the",
"specified",
"location",
"and",
"file",
"name",
"."
] | train | https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Resources/private/api/zip.lib.php#L327-L344 |
slashworks/control-bundle | src/Slashworks/AppBundle/Resources/private/api/zip.lib.php | Zip.openStream | public function openStream($filePath, $timestamp = 0, $fileComment = null, $extFileAttr = self::EXT_FILE_ATTR_FILE) {
if (!function_exists('sys_get_temp_dir')) {
throw new Exception("Zip " . self::VERSION . " requires PHP version 5.2.1 or above if large files are used.");
}
if ($this->isFinalized) {
return FALSE;
}
$this->zipflush();
if (strlen($this->streamFilePath) > 0) {
$this->closeStream();
}
$this->streamFile = self::getTemporaryFile();
$this->streamData = fopen($this->streamFile, "wb");
$this->streamFilePath = $filePath;
$this->streamTimestamp = $timestamp;
$this->streamFileComment = $fileComment;
$this->streamFileLength = 0;
$this->streamExtFileAttr = $extFileAttr;
return TRUE;
} | php | public function openStream($filePath, $timestamp = 0, $fileComment = null, $extFileAttr = self::EXT_FILE_ATTR_FILE) {
if (!function_exists('sys_get_temp_dir')) {
throw new Exception("Zip " . self::VERSION . " requires PHP version 5.2.1 or above if large files are used.");
}
if ($this->isFinalized) {
return FALSE;
}
$this->zipflush();
if (strlen($this->streamFilePath) > 0) {
$this->closeStream();
}
$this->streamFile = self::getTemporaryFile();
$this->streamData = fopen($this->streamFile, "wb");
$this->streamFilePath = $filePath;
$this->streamTimestamp = $timestamp;
$this->streamFileComment = $fileComment;
$this->streamFileLength = 0;
$this->streamExtFileAttr = $extFileAttr;
return TRUE;
} | [
"public",
"function",
"openStream",
"(",
"$",
"filePath",
",",
"$",
"timestamp",
"=",
"0",
",",
"$",
"fileComment",
"=",
"null",
",",
"$",
"extFileAttr",
"=",
"self",
"::",
"EXT_FILE_ATTR_FILE",
")",
"{",
"if",
"(",
"!",
"function_exists",
"(",
"'sys_get_temp_dir'",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Zip \"",
".",
"self",
"::",
"VERSION",
".",
"\" requires PHP version 5.2.1 or above if large files are used.\"",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"isFinalized",
")",
"{",
"return",
"FALSE",
";",
"}",
"$",
"this",
"->",
"zipflush",
"(",
")",
";",
"if",
"(",
"strlen",
"(",
"$",
"this",
"->",
"streamFilePath",
")",
">",
"0",
")",
"{",
"$",
"this",
"->",
"closeStream",
"(",
")",
";",
"}",
"$",
"this",
"->",
"streamFile",
"=",
"self",
"::",
"getTemporaryFile",
"(",
")",
";",
"$",
"this",
"->",
"streamData",
"=",
"fopen",
"(",
"$",
"this",
"->",
"streamFile",
",",
"\"wb\"",
")",
";",
"$",
"this",
"->",
"streamFilePath",
"=",
"$",
"filePath",
";",
"$",
"this",
"->",
"streamTimestamp",
"=",
"$",
"timestamp",
";",
"$",
"this",
"->",
"streamFileComment",
"=",
"$",
"fileComment",
";",
"$",
"this",
"->",
"streamFileLength",
"=",
"0",
";",
"$",
"this",
"->",
"streamExtFileAttr",
"=",
"$",
"extFileAttr",
";",
"return",
"TRUE",
";",
"}"
] | Create a stream to be used for large entries.
@param string $filePath Filepath and name to be used in the archive.
@param int $timestamp (Optional) Timestamp for the added file, if omitted or set to 0, the current time will be used.
@param string $fileComment (Optional) Comment to be added to the archive for this file. To use fileComment, timestamp must be given.
@param int $extFileAttr (Optional) The external file reference, use generateExtAttr to generate this.
@throws Exception Throws an exception in case of errors
@return bool $success | [
"Create",
"a",
"stream",
"to",
"be",
"used",
"for",
"large",
"entries",
"."
] | train | https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Resources/private/api/zip.lib.php#L356-L380 |
slashworks/control-bundle | src/Slashworks/AppBundle/Resources/private/api/zip.lib.php | Zip.addStreamData | public function addStreamData($data) {
if ($this->isFinalized || strlen($this->streamFilePath) == 0) {
return FALSE;
}
$length = fwrite($this->streamData, $data, strlen($data));
if ($length != strlen($data)) {
throw new Exception("File IO: Error writing; Length mismatch: Expected " . strlen($data) . " bytes, wrote " . ($length === FALSE ? "NONE!" : $length));
}
$this->streamFileLength += $length;
return $length;
} | php | public function addStreamData($data) {
if ($this->isFinalized || strlen($this->streamFilePath) == 0) {
return FALSE;
}
$length = fwrite($this->streamData, $data, strlen($data));
if ($length != strlen($data)) {
throw new Exception("File IO: Error writing; Length mismatch: Expected " . strlen($data) . " bytes, wrote " . ($length === FALSE ? "NONE!" : $length));
}
$this->streamFileLength += $length;
return $length;
} | [
"public",
"function",
"addStreamData",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isFinalized",
"||",
"strlen",
"(",
"$",
"this",
"->",
"streamFilePath",
")",
"==",
"0",
")",
"{",
"return",
"FALSE",
";",
"}",
"$",
"length",
"=",
"fwrite",
"(",
"$",
"this",
"->",
"streamData",
",",
"$",
"data",
",",
"strlen",
"(",
"$",
"data",
")",
")",
";",
"if",
"(",
"$",
"length",
"!=",
"strlen",
"(",
"$",
"data",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"File IO: Error writing; Length mismatch: Expected \"",
".",
"strlen",
"(",
"$",
"data",
")",
".",
"\" bytes, wrote \"",
".",
"(",
"$",
"length",
"===",
"FALSE",
"?",
"\"NONE!\"",
":",
"$",
"length",
")",
")",
";",
"}",
"$",
"this",
"->",
"streamFileLength",
"+=",
"$",
"length",
";",
"return",
"$",
"length",
";",
"}"
] | Add data to the open stream.
@param string $data
@throws Exception Throws an exception in case of errors
@return mixed length in bytes added or FALSE if the archive is finalized or there are no open stream. | [
"Add",
"data",
"to",
"the",
"open",
"stream",
"."
] | train | https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Resources/private/api/zip.lib.php#L389-L401 |
slashworks/control-bundle | src/Slashworks/AppBundle/Resources/private/api/zip.lib.php | Zip.closeStream | public function closeStream() {
if ($this->isFinalized || strlen($this->streamFilePath) == 0) {
return FALSE;
}
fflush($this->streamData);
fclose($this->streamData);
$this->processFile($this->streamFile, $this->streamFilePath, $this->streamTimestamp, $this->streamFileComment, $this->streamExtFileAttr);
$this->streamData = null;
$this->streamFilePath = null;
$this->streamTimestamp = null;
$this->streamFileComment = null;
$this->streamFileLength = 0;
$this->streamExtFileAttr = null;
// Windows is a little slow at times, so a millisecond later, we can unlink this.
unlink($this->streamFile);
$this->streamFile = null;
return TRUE;
} | php | public function closeStream() {
if ($this->isFinalized || strlen($this->streamFilePath) == 0) {
return FALSE;
}
fflush($this->streamData);
fclose($this->streamData);
$this->processFile($this->streamFile, $this->streamFilePath, $this->streamTimestamp, $this->streamFileComment, $this->streamExtFileAttr);
$this->streamData = null;
$this->streamFilePath = null;
$this->streamTimestamp = null;
$this->streamFileComment = null;
$this->streamFileLength = 0;
$this->streamExtFileAttr = null;
// Windows is a little slow at times, so a millisecond later, we can unlink this.
unlink($this->streamFile);
$this->streamFile = null;
return TRUE;
} | [
"public",
"function",
"closeStream",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isFinalized",
"||",
"strlen",
"(",
"$",
"this",
"->",
"streamFilePath",
")",
"==",
"0",
")",
"{",
"return",
"FALSE",
";",
"}",
"fflush",
"(",
"$",
"this",
"->",
"streamData",
")",
";",
"fclose",
"(",
"$",
"this",
"->",
"streamData",
")",
";",
"$",
"this",
"->",
"processFile",
"(",
"$",
"this",
"->",
"streamFile",
",",
"$",
"this",
"->",
"streamFilePath",
",",
"$",
"this",
"->",
"streamTimestamp",
",",
"$",
"this",
"->",
"streamFileComment",
",",
"$",
"this",
"->",
"streamExtFileAttr",
")",
";",
"$",
"this",
"->",
"streamData",
"=",
"null",
";",
"$",
"this",
"->",
"streamFilePath",
"=",
"null",
";",
"$",
"this",
"->",
"streamTimestamp",
"=",
"null",
";",
"$",
"this",
"->",
"streamFileComment",
"=",
"null",
";",
"$",
"this",
"->",
"streamFileLength",
"=",
"0",
";",
"$",
"this",
"->",
"streamExtFileAttr",
"=",
"null",
";",
"// Windows is a little slow at times, so a millisecond later, we can unlink this.",
"unlink",
"(",
"$",
"this",
"->",
"streamFile",
")",
";",
"$",
"this",
"->",
"streamFile",
"=",
"null",
";",
"return",
"TRUE",
";",
"}"
] | Close the current stream.
@return bool $success | [
"Close",
"the",
"current",
"stream",
"."
] | train | https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Resources/private/api/zip.lib.php#L408-L431 |
slashworks/control-bundle | src/Slashworks/AppBundle/Resources/private/api/zip.lib.php | Zip.finalize | public function finalize() {
if (!$this->isFinalized) {
if (strlen($this->streamFilePath) > 0) {
$this->closeStream();
}
$cd = implode("", $this->cdRec);
$cdRecSize = pack("v", sizeof($this->cdRec));
$cdRec = $cd . self::ZIP_END_OF_CENTRAL_DIRECTORY
. $cdRecSize . $cdRecSize
. pack("VV", strlen($cd), $this->offset);
if (!empty($this->zipComment)) {
$cdRec .= pack("v", strlen($this->zipComment)) . $this->zipComment;
} else {
$cdRec .= "\x00\x00";
}
$this->zipwrite($cdRec);
$this->isFinalized = TRUE;
$this->cdRec = NULL;
return TRUE;
}
return FALSE;
} | php | public function finalize() {
if (!$this->isFinalized) {
if (strlen($this->streamFilePath) > 0) {
$this->closeStream();
}
$cd = implode("", $this->cdRec);
$cdRecSize = pack("v", sizeof($this->cdRec));
$cdRec = $cd . self::ZIP_END_OF_CENTRAL_DIRECTORY
. $cdRecSize . $cdRecSize
. pack("VV", strlen($cd), $this->offset);
if (!empty($this->zipComment)) {
$cdRec .= pack("v", strlen($this->zipComment)) . $this->zipComment;
} else {
$cdRec .= "\x00\x00";
}
$this->zipwrite($cdRec);
$this->isFinalized = TRUE;
$this->cdRec = NULL;
return TRUE;
}
return FALSE;
} | [
"public",
"function",
"finalize",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isFinalized",
")",
"{",
"if",
"(",
"strlen",
"(",
"$",
"this",
"->",
"streamFilePath",
")",
">",
"0",
")",
"{",
"$",
"this",
"->",
"closeStream",
"(",
")",
";",
"}",
"$",
"cd",
"=",
"implode",
"(",
"\"\"",
",",
"$",
"this",
"->",
"cdRec",
")",
";",
"$",
"cdRecSize",
"=",
"pack",
"(",
"\"v\"",
",",
"sizeof",
"(",
"$",
"this",
"->",
"cdRec",
")",
")",
";",
"$",
"cdRec",
"=",
"$",
"cd",
".",
"self",
"::",
"ZIP_END_OF_CENTRAL_DIRECTORY",
".",
"$",
"cdRecSize",
".",
"$",
"cdRecSize",
".",
"pack",
"(",
"\"VV\"",
",",
"strlen",
"(",
"$",
"cd",
")",
",",
"$",
"this",
"->",
"offset",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"zipComment",
")",
")",
"{",
"$",
"cdRec",
".=",
"pack",
"(",
"\"v\"",
",",
"strlen",
"(",
"$",
"this",
"->",
"zipComment",
")",
")",
".",
"$",
"this",
"->",
"zipComment",
";",
"}",
"else",
"{",
"$",
"cdRec",
".=",
"\"\\x00\\x00\"",
";",
"}",
"$",
"this",
"->",
"zipwrite",
"(",
"$",
"cdRec",
")",
";",
"$",
"this",
"->",
"isFinalized",
"=",
"TRUE",
";",
"$",
"this",
"->",
"cdRec",
"=",
"NULL",
";",
"return",
"TRUE",
";",
"}",
"return",
"FALSE",
";",
"}"
] | Close the archive.
A closed archive can no longer have new files added to it.
@return bool $success | [
"Close",
"the",
"archive",
".",
"A",
"closed",
"archive",
"can",
"no",
"longer",
"have",
"new",
"files",
"added",
"to",
"it",
"."
] | train | https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Resources/private/api/zip.lib.php#L488-L513 |
slashworks/control-bundle | src/Slashworks/AppBundle/Resources/private/api/zip.lib.php | Zip.getZipFile | public function getZipFile() {
if (!$this->isFinalized) {
$this->finalize();
}
$this->zipflush();
rewind($this->zipFile);
return $this->zipFile;
} | php | public function getZipFile() {
if (!$this->isFinalized) {
$this->finalize();
}
$this->zipflush();
rewind($this->zipFile);
return $this->zipFile;
} | [
"public",
"function",
"getZipFile",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isFinalized",
")",
"{",
"$",
"this",
"->",
"finalize",
"(",
")",
";",
"}",
"$",
"this",
"->",
"zipflush",
"(",
")",
";",
"rewind",
"(",
"$",
"this",
"->",
"zipFile",
")",
";",
"return",
"$",
"this",
"->",
"zipFile",
";",
"}"
] | Get the handle ressource for the archive zip file.
If the zip haven't been finalized yet, this will cause it to become finalized
@return zip file handle | [
"Get",
"the",
"handle",
"ressource",
"for",
"the",
"archive",
"zip",
"file",
".",
"If",
"the",
"zip",
"haven",
"t",
"been",
"finalized",
"yet",
"this",
"will",
"cause",
"it",
"to",
"become",
"finalized"
] | train | https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Resources/private/api/zip.lib.php#L521-L531 |
slashworks/control-bundle | src/Slashworks/AppBundle/Resources/private/api/zip.lib.php | Zip.getZipData | public function getZipData() {
if (!$this->isFinalized) {
$this->finalize();
}
if (!is_resource($this->zipFile)) {
return $this->zipData;
} else {
rewind($this->zipFile);
$filestat = fstat($this->zipFile);
return fread($this->zipFile, $filestat['size']);
}
} | php | public function getZipData() {
if (!$this->isFinalized) {
$this->finalize();
}
if (!is_resource($this->zipFile)) {
return $this->zipData;
} else {
rewind($this->zipFile);
$filestat = fstat($this->zipFile);
return fread($this->zipFile, $filestat['size']);
}
} | [
"public",
"function",
"getZipData",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isFinalized",
")",
"{",
"$",
"this",
"->",
"finalize",
"(",
")",
";",
"}",
"if",
"(",
"!",
"is_resource",
"(",
"$",
"this",
"->",
"zipFile",
")",
")",
"{",
"return",
"$",
"this",
"->",
"zipData",
";",
"}",
"else",
"{",
"rewind",
"(",
"$",
"this",
"->",
"zipFile",
")",
";",
"$",
"filestat",
"=",
"fstat",
"(",
"$",
"this",
"->",
"zipFile",
")",
";",
"return",
"fread",
"(",
"$",
"this",
"->",
"zipFile",
",",
"$",
"filestat",
"[",
"'size'",
"]",
")",
";",
"}",
"}"
] | Get the zip file contents
If the zip haven't been finalized yet, this will cause it to become finalized
@return zip data | [
"Get",
"the",
"zip",
"file",
"contents",
"If",
"the",
"zip",
"haven",
"t",
"been",
"finalized",
"yet",
"this",
"will",
"cause",
"it",
"to",
"become",
"finalized"
] | train | https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Resources/private/api/zip.lib.php#L539-L550 |
slashworks/control-bundle | src/Slashworks/AppBundle/Resources/private/api/zip.lib.php | Zip.sendZip | function sendZip($fileName = null, $contentType = "application/zip", $utf8FileName = null, $inline = false) {
if (!$this->isFinalized) {
$this->finalize();
}
$headerFile = null;
$headerLine = null;
if(headers_sent($headerFile, $headerLine)) {
throw new Exception("Unable to send file '$fileName'. Headers have already been sent from '$headerFile' in line $headerLine");
}
if(ob_get_contents() !== false && strlen(ob_get_contents())) {
throw new Exception("Unable to send file '$fileName'. Output buffer contains the following text (typically warnings or errors):\n" . ob_get_contents());
}
if(@ini_get('zlib.output_compression')) {
@ini_set('zlib.output_compression', 'Off');
}
header("Pragma: public");
header("Last-Modified: " . @gmdate("D, d M Y H:i:s T"));
header("Expires: 0");
header("Accept-Ranges: bytes");
header("Connection: close");
header("Content-Type: " . $contentType);
$cd = "Content-Disposition: ";
if ($inline) {
$cd .= "inline";
} else {
$cd .= "attached";
}
if ($fileName) {
$cd .= '; filename="' . $fileName . '"';
}
if ($utf8FileName) {
$cd .= "; filename*=UTF-8''" . rawurlencode($utf8FileName);
}
header($cd);
header("Content-Length: ". $this->getArchiveSize());
if (!is_resource($this->zipFile)) {
echo $this->zipData;
} else {
rewind($this->zipFile);
while (!feof($this->zipFile)) {
echo fread($this->zipFile, $this->streamChunkSize);
}
}
return true;
} | php | function sendZip($fileName = null, $contentType = "application/zip", $utf8FileName = null, $inline = false) {
if (!$this->isFinalized) {
$this->finalize();
}
$headerFile = null;
$headerLine = null;
if(headers_sent($headerFile, $headerLine)) {
throw new Exception("Unable to send file '$fileName'. Headers have already been sent from '$headerFile' in line $headerLine");
}
if(ob_get_contents() !== false && strlen(ob_get_contents())) {
throw new Exception("Unable to send file '$fileName'. Output buffer contains the following text (typically warnings or errors):\n" . ob_get_contents());
}
if(@ini_get('zlib.output_compression')) {
@ini_set('zlib.output_compression', 'Off');
}
header("Pragma: public");
header("Last-Modified: " . @gmdate("D, d M Y H:i:s T"));
header("Expires: 0");
header("Accept-Ranges: bytes");
header("Connection: close");
header("Content-Type: " . $contentType);
$cd = "Content-Disposition: ";
if ($inline) {
$cd .= "inline";
} else {
$cd .= "attached";
}
if ($fileName) {
$cd .= '; filename="' . $fileName . '"';
}
if ($utf8FileName) {
$cd .= "; filename*=UTF-8''" . rawurlencode($utf8FileName);
}
header($cd);
header("Content-Length: ". $this->getArchiveSize());
if (!is_resource($this->zipFile)) {
echo $this->zipData;
} else {
rewind($this->zipFile);
while (!feof($this->zipFile)) {
echo fread($this->zipFile, $this->streamChunkSize);
}
}
return true;
} | [
"function",
"sendZip",
"(",
"$",
"fileName",
"=",
"null",
",",
"$",
"contentType",
"=",
"\"application/zip\"",
",",
"$",
"utf8FileName",
"=",
"null",
",",
"$",
"inline",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isFinalized",
")",
"{",
"$",
"this",
"->",
"finalize",
"(",
")",
";",
"}",
"$",
"headerFile",
"=",
"null",
";",
"$",
"headerLine",
"=",
"null",
";",
"if",
"(",
"headers_sent",
"(",
"$",
"headerFile",
",",
"$",
"headerLine",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Unable to send file '$fileName'. Headers have already been sent from '$headerFile' in line $headerLine\"",
")",
";",
"}",
"if",
"(",
"ob_get_contents",
"(",
")",
"!==",
"false",
"&&",
"strlen",
"(",
"ob_get_contents",
"(",
")",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Unable to send file '$fileName'. Output buffer contains the following text (typically warnings or errors):\\n\"",
".",
"ob_get_contents",
"(",
")",
")",
";",
"}",
"if",
"(",
"@",
"ini_get",
"(",
"'zlib.output_compression'",
")",
")",
"{",
"@",
"ini_set",
"(",
"'zlib.output_compression'",
",",
"'Off'",
")",
";",
"}",
"header",
"(",
"\"Pragma: public\"",
")",
";",
"header",
"(",
"\"Last-Modified: \"",
".",
"@",
"gmdate",
"(",
"\"D, d M Y H:i:s T\"",
")",
")",
";",
"header",
"(",
"\"Expires: 0\"",
")",
";",
"header",
"(",
"\"Accept-Ranges: bytes\"",
")",
";",
"header",
"(",
"\"Connection: close\"",
")",
";",
"header",
"(",
"\"Content-Type: \"",
".",
"$",
"contentType",
")",
";",
"$",
"cd",
"=",
"\"Content-Disposition: \"",
";",
"if",
"(",
"$",
"inline",
")",
"{",
"$",
"cd",
".=",
"\"inline\"",
";",
"}",
"else",
"{",
"$",
"cd",
".=",
"\"attached\"",
";",
"}",
"if",
"(",
"$",
"fileName",
")",
"{",
"$",
"cd",
".=",
"'; filename=\"'",
".",
"$",
"fileName",
".",
"'\"'",
";",
"}",
"if",
"(",
"$",
"utf8FileName",
")",
"{",
"$",
"cd",
".=",
"\"; filename*=UTF-8''\"",
".",
"rawurlencode",
"(",
"$",
"utf8FileName",
")",
";",
"}",
"header",
"(",
"$",
"cd",
")",
";",
"header",
"(",
"\"Content-Length: \"",
".",
"$",
"this",
"->",
"getArchiveSize",
"(",
")",
")",
";",
"if",
"(",
"!",
"is_resource",
"(",
"$",
"this",
"->",
"zipFile",
")",
")",
"{",
"echo",
"$",
"this",
"->",
"zipData",
";",
"}",
"else",
"{",
"rewind",
"(",
"$",
"this",
"->",
"zipFile",
")",
";",
"while",
"(",
"!",
"feof",
"(",
"$",
"this",
"->",
"zipFile",
")",
")",
"{",
"echo",
"fread",
"(",
"$",
"this",
"->",
"zipFile",
",",
"$",
"this",
"->",
"streamChunkSize",
")",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Send the archive as a zip download
@param String $fileName The name of the Zip archive, in ISO-8859-1 (or ASCII) encoding, ie. "archive.zip". Optional, defaults to NULL, which means that no ISO-8859-1 encoded file name will be specified.
@param String $contentType Content mime type. Optional, defaults to "application/zip".
@param String $utf8FileName The name of the Zip archive, in UTF-8 encoding. Optional, defaults to NULL, which means that no UTF-8 encoded file name will be specified.
@param bool $inline Use Content-Disposition with "inline" instead of "attached". Optional, defaults to FALSE.
@throws Exception Throws an exception in case of errors
@return bool Always returns true (for backward compatibility). | [
"Send",
"the",
"archive",
"as",
"a",
"zip",
"download"
] | train | https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Resources/private/api/zip.lib.php#L562-L606 |
slashworks/control-bundle | src/Slashworks/AppBundle/Resources/private/api/zip.lib.php | Zip.getArchiveSize | public function getArchiveSize() {
if (!is_resource($this->zipFile)) {
return strlen($this->zipData);
}
$filestat = fstat($this->zipFile);
return $filestat['size'];
} | php | public function getArchiveSize() {
if (!is_resource($this->zipFile)) {
return strlen($this->zipData);
}
$filestat = fstat($this->zipFile);
return $filestat['size'];
} | [
"public",
"function",
"getArchiveSize",
"(",
")",
"{",
"if",
"(",
"!",
"is_resource",
"(",
"$",
"this",
"->",
"zipFile",
")",
")",
"{",
"return",
"strlen",
"(",
"$",
"this",
"->",
"zipData",
")",
";",
"}",
"$",
"filestat",
"=",
"fstat",
"(",
"$",
"this",
"->",
"zipFile",
")",
";",
"return",
"$",
"filestat",
"[",
"'size'",
"]",
";",
"}"
] | Return the current size of the archive
@return $size Size of the archive | [
"Return",
"the",
"current",
"size",
"of",
"the",
"archive"
] | train | https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Resources/private/api/zip.lib.php#L613-L620 |
slashworks/control-bundle | src/Slashworks/AppBundle/Resources/private/api/zip.lib.php | Zip.getDosTime | private function getDosTime($timestamp = 0) {
$timestamp = (int)$timestamp;
$oldTZ = @date_default_timezone_get();
date_default_timezone_set('UTC');
$date = ($timestamp == 0 ? getdate() : getdate($timestamp));
date_default_timezone_set($oldTZ);
if ($date["year"] >= 1980) {
return pack("V", (($date["mday"] + ($date["mon"] << 5) + (($date["year"]-1980) << 9)) << 16) |
(($date["seconds"] >> 1) + ($date["minutes"] << 5) + ($date["hours"] << 11)));
}
return "\x00\x00\x00\x00";
} | php | private function getDosTime($timestamp = 0) {
$timestamp = (int)$timestamp;
$oldTZ = @date_default_timezone_get();
date_default_timezone_set('UTC');
$date = ($timestamp == 0 ? getdate() : getdate($timestamp));
date_default_timezone_set($oldTZ);
if ($date["year"] >= 1980) {
return pack("V", (($date["mday"] + ($date["mon"] << 5) + (($date["year"]-1980) << 9)) << 16) |
(($date["seconds"] >> 1) + ($date["minutes"] << 5) + ($date["hours"] << 11)));
}
return "\x00\x00\x00\x00";
} | [
"private",
"function",
"getDosTime",
"(",
"$",
"timestamp",
"=",
"0",
")",
"{",
"$",
"timestamp",
"=",
"(",
"int",
")",
"$",
"timestamp",
";",
"$",
"oldTZ",
"=",
"@",
"date_default_timezone_get",
"(",
")",
";",
"date_default_timezone_set",
"(",
"'UTC'",
")",
";",
"$",
"date",
"=",
"(",
"$",
"timestamp",
"==",
"0",
"?",
"getdate",
"(",
")",
":",
"getdate",
"(",
"$",
"timestamp",
")",
")",
";",
"date_default_timezone_set",
"(",
"$",
"oldTZ",
")",
";",
"if",
"(",
"$",
"date",
"[",
"\"year\"",
"]",
">=",
"1980",
")",
"{",
"return",
"pack",
"(",
"\"V\"",
",",
"(",
"(",
"$",
"date",
"[",
"\"mday\"",
"]",
"+",
"(",
"$",
"date",
"[",
"\"mon\"",
"]",
"<<",
"5",
")",
"+",
"(",
"(",
"$",
"date",
"[",
"\"year\"",
"]",
"-",
"1980",
")",
"<<",
"9",
")",
")",
"<<",
"16",
")",
"|",
"(",
"(",
"$",
"date",
"[",
"\"seconds\"",
"]",
">>",
"1",
")",
"+",
"(",
"$",
"date",
"[",
"\"minutes\"",
"]",
"<<",
"5",
")",
"+",
"(",
"$",
"date",
"[",
"\"hours\"",
"]",
"<<",
"11",
")",
")",
")",
";",
"}",
"return",
"\"\\x00\\x00\\x00\\x00\"",
";",
"}"
] | Calculate the 2 byte dostime used in the zip entries.
@param int $timestamp
@return 2-byte encoded DOS Date | [
"Calculate",
"the",
"2",
"byte",
"dostime",
"used",
"in",
"the",
"zip",
"entries",
"."
] | train | https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Resources/private/api/zip.lib.php#L628-L639 |
slashworks/control-bundle | src/Slashworks/AppBundle/Resources/private/api/zip.lib.php | Zip.buildZipEntry | private function buildZipEntry($filePath, $fileComment, $gpFlags, $gzType, $timestamp, $fileCRC32, $gzLength, $dataLength, $extFileAttr) {
$filePath = str_replace("\\", "/", $filePath);
$fileCommentLength = (empty($fileComment) ? 0 : strlen($fileComment));
$timestamp = (int)$timestamp;
$timestamp = ($timestamp == 0 ? time() : $timestamp);
$dosTime = $this->getDosTime($timestamp);
$tsPack = pack("V", $timestamp);
if (!isset($gpFlags) || strlen($gpFlags) != 2) {
$gpFlags = "\x00\x00";
}
$isFileUTF8 = mb_check_encoding($filePath, "UTF-8") && !mb_check_encoding($filePath, "ASCII");
$isCommentUTF8 = !empty($fileComment) && mb_check_encoding($fileComment, "UTF-8") && !mb_check_encoding($fileComment, "ASCII");
$localExtraField = "";
$centralExtraField = "";
if ($this->addExtraField) {
$localExtraField .= "\x55\x54\x09\x00\x03" . $tsPack . $tsPack . Zip::EXTRA_FIELD_NEW_UNIX_GUID;
$centralExtraField .= "\x55\x54\x05\x00\x03" . $tsPack . Zip::EXTRA_FIELD_NEW_UNIX_GUID;
}
if ($isFileUTF8 || $isCommentUTF8) {
$flag = 0;
$gpFlagsV = unpack("vflags", $gpFlags);
if (isset($gpFlagsV['flags'])) {
$flag = $gpFlagsV['flags'];
}
$gpFlags = pack("v", $flag | (1 << 11));
if ($isFileUTF8) {
$utfPathExtraField = "\x75\x70"
. pack ("v", (5 + strlen($filePath)))
. "\x01"
. pack("V", crc32($filePath))
. $filePath;
$localExtraField .= $utfPathExtraField;
$centralExtraField .= $utfPathExtraField;
}
if ($isCommentUTF8) {
$centralExtraField .= "\x75\x63" // utf8 encoded file comment extra field
. pack ("v", (5 + strlen($fileComment)))
. "\x01"
. pack("V", crc32($fileComment))
. $fileComment;
}
}
$header = $gpFlags . $gzType . $dosTime. $fileCRC32
. pack("VVv", $gzLength, $dataLength, strlen($filePath)); // File name length
$zipEntry = self::ZIP_LOCAL_FILE_HEADER
. self::ATTR_VERSION_TO_EXTRACT
. $header
. pack("v", strlen($localExtraField)) // Extra field length
. $filePath // FileName
. $localExtraField; // Extra fields
$this->zipwrite($zipEntry);
$cdEntry = self::ZIP_CENTRAL_FILE_HEADER
. self::ATTR_MADE_BY_VERSION
. ($dataLength === 0 ? "\x0A\x00" : self::ATTR_VERSION_TO_EXTRACT)
. $header
. pack("v", strlen($centralExtraField)) // Extra field length
. pack("v", $fileCommentLength) // File comment length
. "\x00\x00" // Disk number start
. "\x00\x00" // internal file attributes
. pack("V", $extFileAttr) // External file attributes
. pack("V", $this->offset) // Relative offset of local header
. $filePath // FileName
. $centralExtraField; // Extra fields
if (!empty($fileComment)) {
$cdEntry .= $fileComment; // Comment
}
$this->cdRec[] = $cdEntry;
$this->offset += strlen($zipEntry) + $gzLength;
} | php | private function buildZipEntry($filePath, $fileComment, $gpFlags, $gzType, $timestamp, $fileCRC32, $gzLength, $dataLength, $extFileAttr) {
$filePath = str_replace("\\", "/", $filePath);
$fileCommentLength = (empty($fileComment) ? 0 : strlen($fileComment));
$timestamp = (int)$timestamp;
$timestamp = ($timestamp == 0 ? time() : $timestamp);
$dosTime = $this->getDosTime($timestamp);
$tsPack = pack("V", $timestamp);
if (!isset($gpFlags) || strlen($gpFlags) != 2) {
$gpFlags = "\x00\x00";
}
$isFileUTF8 = mb_check_encoding($filePath, "UTF-8") && !mb_check_encoding($filePath, "ASCII");
$isCommentUTF8 = !empty($fileComment) && mb_check_encoding($fileComment, "UTF-8") && !mb_check_encoding($fileComment, "ASCII");
$localExtraField = "";
$centralExtraField = "";
if ($this->addExtraField) {
$localExtraField .= "\x55\x54\x09\x00\x03" . $tsPack . $tsPack . Zip::EXTRA_FIELD_NEW_UNIX_GUID;
$centralExtraField .= "\x55\x54\x05\x00\x03" . $tsPack . Zip::EXTRA_FIELD_NEW_UNIX_GUID;
}
if ($isFileUTF8 || $isCommentUTF8) {
$flag = 0;
$gpFlagsV = unpack("vflags", $gpFlags);
if (isset($gpFlagsV['flags'])) {
$flag = $gpFlagsV['flags'];
}
$gpFlags = pack("v", $flag | (1 << 11));
if ($isFileUTF8) {
$utfPathExtraField = "\x75\x70"
. pack ("v", (5 + strlen($filePath)))
. "\x01"
. pack("V", crc32($filePath))
. $filePath;
$localExtraField .= $utfPathExtraField;
$centralExtraField .= $utfPathExtraField;
}
if ($isCommentUTF8) {
$centralExtraField .= "\x75\x63" // utf8 encoded file comment extra field
. pack ("v", (5 + strlen($fileComment)))
. "\x01"
. pack("V", crc32($fileComment))
. $fileComment;
}
}
$header = $gpFlags . $gzType . $dosTime. $fileCRC32
. pack("VVv", $gzLength, $dataLength, strlen($filePath)); // File name length
$zipEntry = self::ZIP_LOCAL_FILE_HEADER
. self::ATTR_VERSION_TO_EXTRACT
. $header
. pack("v", strlen($localExtraField)) // Extra field length
. $filePath // FileName
. $localExtraField; // Extra fields
$this->zipwrite($zipEntry);
$cdEntry = self::ZIP_CENTRAL_FILE_HEADER
. self::ATTR_MADE_BY_VERSION
. ($dataLength === 0 ? "\x0A\x00" : self::ATTR_VERSION_TO_EXTRACT)
. $header
. pack("v", strlen($centralExtraField)) // Extra field length
. pack("v", $fileCommentLength) // File comment length
. "\x00\x00" // Disk number start
. "\x00\x00" // internal file attributes
. pack("V", $extFileAttr) // External file attributes
. pack("V", $this->offset) // Relative offset of local header
. $filePath // FileName
. $centralExtraField; // Extra fields
if (!empty($fileComment)) {
$cdEntry .= $fileComment; // Comment
}
$this->cdRec[] = $cdEntry;
$this->offset += strlen($zipEntry) + $gzLength;
} | [
"private",
"function",
"buildZipEntry",
"(",
"$",
"filePath",
",",
"$",
"fileComment",
",",
"$",
"gpFlags",
",",
"$",
"gzType",
",",
"$",
"timestamp",
",",
"$",
"fileCRC32",
",",
"$",
"gzLength",
",",
"$",
"dataLength",
",",
"$",
"extFileAttr",
")",
"{",
"$",
"filePath",
"=",
"str_replace",
"(",
"\"\\\\\"",
",",
"\"/\"",
",",
"$",
"filePath",
")",
";",
"$",
"fileCommentLength",
"=",
"(",
"empty",
"(",
"$",
"fileComment",
")",
"?",
"0",
":",
"strlen",
"(",
"$",
"fileComment",
")",
")",
";",
"$",
"timestamp",
"=",
"(",
"int",
")",
"$",
"timestamp",
";",
"$",
"timestamp",
"=",
"(",
"$",
"timestamp",
"==",
"0",
"?",
"time",
"(",
")",
":",
"$",
"timestamp",
")",
";",
"$",
"dosTime",
"=",
"$",
"this",
"->",
"getDosTime",
"(",
"$",
"timestamp",
")",
";",
"$",
"tsPack",
"=",
"pack",
"(",
"\"V\"",
",",
"$",
"timestamp",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"gpFlags",
")",
"||",
"strlen",
"(",
"$",
"gpFlags",
")",
"!=",
"2",
")",
"{",
"$",
"gpFlags",
"=",
"\"\\x00\\x00\"",
";",
"}",
"$",
"isFileUTF8",
"=",
"mb_check_encoding",
"(",
"$",
"filePath",
",",
"\"UTF-8\"",
")",
"&&",
"!",
"mb_check_encoding",
"(",
"$",
"filePath",
",",
"\"ASCII\"",
")",
";",
"$",
"isCommentUTF8",
"=",
"!",
"empty",
"(",
"$",
"fileComment",
")",
"&&",
"mb_check_encoding",
"(",
"$",
"fileComment",
",",
"\"UTF-8\"",
")",
"&&",
"!",
"mb_check_encoding",
"(",
"$",
"fileComment",
",",
"\"ASCII\"",
")",
";",
"$",
"localExtraField",
"=",
"\"\"",
";",
"$",
"centralExtraField",
"=",
"\"\"",
";",
"if",
"(",
"$",
"this",
"->",
"addExtraField",
")",
"{",
"$",
"localExtraField",
".=",
"\"\\x55\\x54\\x09\\x00\\x03\"",
".",
"$",
"tsPack",
".",
"$",
"tsPack",
".",
"Zip",
"::",
"EXTRA_FIELD_NEW_UNIX_GUID",
";",
"$",
"centralExtraField",
".=",
"\"\\x55\\x54\\x05\\x00\\x03\"",
".",
"$",
"tsPack",
".",
"Zip",
"::",
"EXTRA_FIELD_NEW_UNIX_GUID",
";",
"}",
"if",
"(",
"$",
"isFileUTF8",
"||",
"$",
"isCommentUTF8",
")",
"{",
"$",
"flag",
"=",
"0",
";",
"$",
"gpFlagsV",
"=",
"unpack",
"(",
"\"vflags\"",
",",
"$",
"gpFlags",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"gpFlagsV",
"[",
"'flags'",
"]",
")",
")",
"{",
"$",
"flag",
"=",
"$",
"gpFlagsV",
"[",
"'flags'",
"]",
";",
"}",
"$",
"gpFlags",
"=",
"pack",
"(",
"\"v\"",
",",
"$",
"flag",
"|",
"(",
"1",
"<<",
"11",
")",
")",
";",
"if",
"(",
"$",
"isFileUTF8",
")",
"{",
"$",
"utfPathExtraField",
"=",
"\"\\x75\\x70\"",
".",
"pack",
"(",
"\"v\"",
",",
"(",
"5",
"+",
"strlen",
"(",
"$",
"filePath",
")",
")",
")",
".",
"\"\\x01\"",
".",
"pack",
"(",
"\"V\"",
",",
"crc32",
"(",
"$",
"filePath",
")",
")",
".",
"$",
"filePath",
";",
"$",
"localExtraField",
".=",
"$",
"utfPathExtraField",
";",
"$",
"centralExtraField",
".=",
"$",
"utfPathExtraField",
";",
"}",
"if",
"(",
"$",
"isCommentUTF8",
")",
"{",
"$",
"centralExtraField",
".=",
"\"\\x75\\x63\"",
"// utf8 encoded file comment extra field",
".",
"pack",
"(",
"\"v\"",
",",
"(",
"5",
"+",
"strlen",
"(",
"$",
"fileComment",
")",
")",
")",
".",
"\"\\x01\"",
".",
"pack",
"(",
"\"V\"",
",",
"crc32",
"(",
"$",
"fileComment",
")",
")",
".",
"$",
"fileComment",
";",
"}",
"}",
"$",
"header",
"=",
"$",
"gpFlags",
".",
"$",
"gzType",
".",
"$",
"dosTime",
".",
"$",
"fileCRC32",
".",
"pack",
"(",
"\"VVv\"",
",",
"$",
"gzLength",
",",
"$",
"dataLength",
",",
"strlen",
"(",
"$",
"filePath",
")",
")",
";",
"// File name length",
"$",
"zipEntry",
"=",
"self",
"::",
"ZIP_LOCAL_FILE_HEADER",
".",
"self",
"::",
"ATTR_VERSION_TO_EXTRACT",
".",
"$",
"header",
".",
"pack",
"(",
"\"v\"",
",",
"strlen",
"(",
"$",
"localExtraField",
")",
")",
"// Extra field length",
".",
"$",
"filePath",
"// FileName",
".",
"$",
"localExtraField",
";",
"// Extra fields",
"$",
"this",
"->",
"zipwrite",
"(",
"$",
"zipEntry",
")",
";",
"$",
"cdEntry",
"=",
"self",
"::",
"ZIP_CENTRAL_FILE_HEADER",
".",
"self",
"::",
"ATTR_MADE_BY_VERSION",
".",
"(",
"$",
"dataLength",
"===",
"0",
"?",
"\"\\x0A\\x00\"",
":",
"self",
"::",
"ATTR_VERSION_TO_EXTRACT",
")",
".",
"$",
"header",
".",
"pack",
"(",
"\"v\"",
",",
"strlen",
"(",
"$",
"centralExtraField",
")",
")",
"// Extra field length",
".",
"pack",
"(",
"\"v\"",
",",
"$",
"fileCommentLength",
")",
"// File comment length",
".",
"\"\\x00\\x00\"",
"// Disk number start",
".",
"\"\\x00\\x00\"",
"// internal file attributes",
".",
"pack",
"(",
"\"V\"",
",",
"$",
"extFileAttr",
")",
"// External file attributes",
".",
"pack",
"(",
"\"V\"",
",",
"$",
"this",
"->",
"offset",
")",
"// Relative offset of local header",
".",
"$",
"filePath",
"// FileName",
".",
"$",
"centralExtraField",
";",
"// Extra fields",
"if",
"(",
"!",
"empty",
"(",
"$",
"fileComment",
")",
")",
"{",
"$",
"cdEntry",
".=",
"$",
"fileComment",
";",
"// Comment",
"}",
"$",
"this",
"->",
"cdRec",
"[",
"]",
"=",
"$",
"cdEntry",
";",
"$",
"this",
"->",
"offset",
"+=",
"strlen",
"(",
"$",
"zipEntry",
")",
"+",
"$",
"gzLength",
";",
"}"
] | Build the Zip file structures
@param string $filePath
@param string $fileComment
@param string $gpFlags
@param string $gzType
@param int $timestamp
@param string $fileCRC32
@param int $gzLength
@param int $dataLength
@param int $extFileAttr Use self::EXT_FILE_ATTR_FILE for files, self::EXT_FILE_ATTR_DIR for Directories. | [
"Build",
"the",
"Zip",
"file",
"structures"
] | train | https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Resources/private/api/zip.lib.php#L654-L736 |
slashworks/control-bundle | src/Slashworks/AppBundle/Resources/private/api/zip.lib.php | Zip.pathJoin | public static function pathJoin($dir, $file) {
if (empty($dir) || empty($file)) {
return self::getRelativePath($dir . $file);
}
return self::getRelativePath($dir . '/' . $file);
} | php | public static function pathJoin($dir, $file) {
if (empty($dir) || empty($file)) {
return self::getRelativePath($dir . $file);
}
return self::getRelativePath($dir . '/' . $file);
} | [
"public",
"static",
"function",
"pathJoin",
"(",
"$",
"dir",
",",
"$",
"file",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"dir",
")",
"||",
"empty",
"(",
"$",
"file",
")",
")",
"{",
"return",
"self",
"::",
"getRelativePath",
"(",
"$",
"dir",
".",
"$",
"file",
")",
";",
"}",
"return",
"self",
"::",
"getRelativePath",
"(",
"$",
"dir",
".",
"'/'",
".",
"$",
"file",
")",
";",
"}"
] | Join $file to $dir path, and clean up any excess slashes.
@param string $dir
@param string $file | [
"Join",
"$file",
"to",
"$dir",
"path",
"and",
"clean",
"up",
"any",
"excess",
"slashes",
"."
] | train | https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Resources/private/api/zip.lib.php#L761-L766 |
slashworks/control-bundle | src/Slashworks/AppBundle/Resources/private/api/zip.lib.php | Zip.getRelativePath | public static function getRelativePath($path) {
$path = preg_replace("#/+\.?/+#", "/", str_replace("\\", "/", $path));
$dirs = explode("/", rtrim(preg_replace('#^(?:\./)+#', '', $path), '/'));
$offset = 0;
$sub = 0;
$subOffset = 0;
$root = "";
if (empty($dirs[0])) {
$root = "/";
$dirs = array_splice($dirs, 1);
} else if (preg_match("#[A-Za-z]:#", $dirs[0])) {
$root = strtoupper($dirs[0]) . "/";
$dirs = array_splice($dirs, 1);
}
$newDirs = array();
foreach ($dirs as $dir) {
if ($dir !== "..") {
$subOffset--;
$newDirs[++$offset] = $dir;
} else {
$subOffset++;
if (--$offset < 0) {
$offset = 0;
if ($subOffset > $sub) {
$sub++;
}
}
}
}
if (empty($root)) {
$root = str_repeat("../", $sub);
}
return $root . implode("/", array_slice($newDirs, 0, $offset));
} | php | public static function getRelativePath($path) {
$path = preg_replace("#/+\.?/+#", "/", str_replace("\\", "/", $path));
$dirs = explode("/", rtrim(preg_replace('#^(?:\./)+#', '', $path), '/'));
$offset = 0;
$sub = 0;
$subOffset = 0;
$root = "";
if (empty($dirs[0])) {
$root = "/";
$dirs = array_splice($dirs, 1);
} else if (preg_match("#[A-Za-z]:#", $dirs[0])) {
$root = strtoupper($dirs[0]) . "/";
$dirs = array_splice($dirs, 1);
}
$newDirs = array();
foreach ($dirs as $dir) {
if ($dir !== "..") {
$subOffset--;
$newDirs[++$offset] = $dir;
} else {
$subOffset++;
if (--$offset < 0) {
$offset = 0;
if ($subOffset > $sub) {
$sub++;
}
}
}
}
if (empty($root)) {
$root = str_repeat("../", $sub);
}
return $root . implode("/", array_slice($newDirs, 0, $offset));
} | [
"public",
"static",
"function",
"getRelativePath",
"(",
"$",
"path",
")",
"{",
"$",
"path",
"=",
"preg_replace",
"(",
"\"#/+\\.?/+#\"",
",",
"\"/\"",
",",
"str_replace",
"(",
"\"\\\\\"",
",",
"\"/\"",
",",
"$",
"path",
")",
")",
";",
"$",
"dirs",
"=",
"explode",
"(",
"\"/\"",
",",
"rtrim",
"(",
"preg_replace",
"(",
"'#^(?:\\./)+#'",
",",
"''",
",",
"$",
"path",
")",
",",
"'/'",
")",
")",
";",
"$",
"offset",
"=",
"0",
";",
"$",
"sub",
"=",
"0",
";",
"$",
"subOffset",
"=",
"0",
";",
"$",
"root",
"=",
"\"\"",
";",
"if",
"(",
"empty",
"(",
"$",
"dirs",
"[",
"0",
"]",
")",
")",
"{",
"$",
"root",
"=",
"\"/\"",
";",
"$",
"dirs",
"=",
"array_splice",
"(",
"$",
"dirs",
",",
"1",
")",
";",
"}",
"else",
"if",
"(",
"preg_match",
"(",
"\"#[A-Za-z]:#\"",
",",
"$",
"dirs",
"[",
"0",
"]",
")",
")",
"{",
"$",
"root",
"=",
"strtoupper",
"(",
"$",
"dirs",
"[",
"0",
"]",
")",
".",
"\"/\"",
";",
"$",
"dirs",
"=",
"array_splice",
"(",
"$",
"dirs",
",",
"1",
")",
";",
"}",
"$",
"newDirs",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"dirs",
"as",
"$",
"dir",
")",
"{",
"if",
"(",
"$",
"dir",
"!==",
"\"..\"",
")",
"{",
"$",
"subOffset",
"--",
";",
"$",
"newDirs",
"[",
"++",
"$",
"offset",
"]",
"=",
"$",
"dir",
";",
"}",
"else",
"{",
"$",
"subOffset",
"++",
";",
"if",
"(",
"--",
"$",
"offset",
"<",
"0",
")",
"{",
"$",
"offset",
"=",
"0",
";",
"if",
"(",
"$",
"subOffset",
">",
"$",
"sub",
")",
"{",
"$",
"sub",
"++",
";",
"}",
"}",
"}",
"}",
"if",
"(",
"empty",
"(",
"$",
"root",
")",
")",
"{",
"$",
"root",
"=",
"str_repeat",
"(",
"\"../\"",
",",
"$",
"sub",
")",
";",
"}",
"return",
"$",
"root",
".",
"implode",
"(",
"\"/\"",
",",
"array_slice",
"(",
"$",
"newDirs",
",",
"0",
",",
"$",
"offset",
")",
")",
";",
"}"
] | Clean up a path, removing any unnecessary elements such as /./, // or redundant ../ segments.
If the path starts with a "/", it is deemed an absolute path and any /../ in the beginning is stripped off.
The returned path will not end in a "/".
Sometimes, when a path is generated from multiple fragments,
you can get something like "../data/html/../images/image.jpeg"
This will normalize that example path to "../data/images/image.jpeg"
@param string $path The path to clean up
@return string the clean path | [
"Clean",
"up",
"a",
"path",
"removing",
"any",
"unnecessary",
"elements",
"such",
"as",
"/",
".",
"/",
"//",
"or",
"redundant",
"..",
"/",
"segments",
".",
"If",
"the",
"path",
"starts",
"with",
"a",
"/",
"it",
"is",
"deemed",
"an",
"absolute",
"path",
"and",
"any",
"/",
"..",
"/",
"in",
"the",
"beginning",
"is",
"stripped",
"off",
".",
"The",
"returned",
"path",
"will",
"not",
"end",
"in",
"a",
"/",
"."
] | train | https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Resources/private/api/zip.lib.php#L780-L817 |
slashworks/control-bundle | src/Slashworks/AppBundle/Resources/private/api/zip.lib.php | Zip.generateExtAttr | public static function generateExtAttr($owner = 07, $group = 05, $other = 05, $isFile = true) {
$fp = $isFile ? self::S_IFREG : self::S_IFDIR;
$fp |= (($owner & 07) << 6) | (($group & 07) << 3) | ($other & 07);
return ($fp << 16) | ($isFile ? self::S_DOS_A : self::S_DOS_D);
} | php | public static function generateExtAttr($owner = 07, $group = 05, $other = 05, $isFile = true) {
$fp = $isFile ? self::S_IFREG : self::S_IFDIR;
$fp |= (($owner & 07) << 6) | (($group & 07) << 3) | ($other & 07);
return ($fp << 16) | ($isFile ? self::S_DOS_A : self::S_DOS_D);
} | [
"public",
"static",
"function",
"generateExtAttr",
"(",
"$",
"owner",
"=",
"07",
",",
"$",
"group",
"=",
"05",
",",
"$",
"other",
"=",
"05",
",",
"$",
"isFile",
"=",
"true",
")",
"{",
"$",
"fp",
"=",
"$",
"isFile",
"?",
"self",
"::",
"S_IFREG",
":",
"self",
"::",
"S_IFDIR",
";",
"$",
"fp",
"|=",
"(",
"(",
"$",
"owner",
"&",
"07",
")",
"<<",
"6",
")",
"|",
"(",
"(",
"$",
"group",
"&",
"07",
")",
"<<",
"3",
")",
"|",
"(",
"$",
"other",
"&",
"07",
")",
";",
"return",
"(",
"$",
"fp",
"<<",
"16",
")",
"|",
"(",
"$",
"isFile",
"?",
"self",
"::",
"S_DOS_A",
":",
"self",
"::",
"S_DOS_D",
")",
";",
"}"
] | Create the file permissions for a file or directory, for use in the extFileAttr parameters.
@param int $owner Unix permisions for owner (octal from 00 to 07)
@param int $group Unix permisions for group (octal from 00 to 07)
@param int $other Unix permisions for others (octal from 00 to 07)
@param bool $isFile
@return EXTRERNAL_REF field. | [
"Create",
"the",
"file",
"permissions",
"for",
"a",
"file",
"or",
"directory",
"for",
"use",
"in",
"the",
"extFileAttr",
"parameters",
"."
] | train | https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Resources/private/api/zip.lib.php#L828-L833 |
slashworks/control-bundle | src/Slashworks/AppBundle/Resources/private/api/zip.lib.php | Zip.getFileExtAttr | public static function getFileExtAttr($filename) {
if (file_exists($filename)) {
$fp = fileperms($filename) << 16;
return $fp | (is_dir($filename) ? self::S_DOS_D : self::S_DOS_A);
}
return FALSE;
} | php | public static function getFileExtAttr($filename) {
if (file_exists($filename)) {
$fp = fileperms($filename) << 16;
return $fp | (is_dir($filename) ? self::S_DOS_D : self::S_DOS_A);
}
return FALSE;
} | [
"public",
"static",
"function",
"getFileExtAttr",
"(",
"$",
"filename",
")",
"{",
"if",
"(",
"file_exists",
"(",
"$",
"filename",
")",
")",
"{",
"$",
"fp",
"=",
"fileperms",
"(",
"$",
"filename",
")",
"<<",
"16",
";",
"return",
"$",
"fp",
"|",
"(",
"is_dir",
"(",
"$",
"filename",
")",
"?",
"self",
"::",
"S_DOS_D",
":",
"self",
"::",
"S_DOS_A",
")",
";",
"}",
"return",
"FALSE",
";",
"}"
] | Get the file permissions for a file or directory, for use in the extFileAttr parameters.
@param string $filename
@return external ref field, or FALSE if the file is not found. | [
"Get",
"the",
"file",
"permissions",
"for",
"a",
"file",
"or",
"directory",
"for",
"use",
"in",
"the",
"extFileAttr",
"parameters",
"."
] | train | https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Resources/private/api/zip.lib.php#L841-L847 |
slashworks/control-bundle | src/Slashworks/AppBundle/Resources/private/api/zip.lib.php | Zip.getTemporaryFile | private static function getTemporaryFile() {
if(is_callable(self::$temp)) {
$temporaryFile = @call_user_func(self::$temp);
if(is_string($temporaryFile) && strlen($temporaryFile) && is_writable($temporaryFile)) {
return $temporaryFile;
}
}
$temporaryDirectory = (is_string(self::$temp) && strlen(self::$temp)) ? self::$temp : sys_get_temp_dir();
return tempnam($temporaryDirectory, 'Zip');
} | php | private static function getTemporaryFile() {
if(is_callable(self::$temp)) {
$temporaryFile = @call_user_func(self::$temp);
if(is_string($temporaryFile) && strlen($temporaryFile) && is_writable($temporaryFile)) {
return $temporaryFile;
}
}
$temporaryDirectory = (is_string(self::$temp) && strlen(self::$temp)) ? self::$temp : sys_get_temp_dir();
return tempnam($temporaryDirectory, 'Zip');
} | [
"private",
"static",
"function",
"getTemporaryFile",
"(",
")",
"{",
"if",
"(",
"is_callable",
"(",
"self",
"::",
"$",
"temp",
")",
")",
"{",
"$",
"temporaryFile",
"=",
"@",
"call_user_func",
"(",
"self",
"::",
"$",
"temp",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"temporaryFile",
")",
"&&",
"strlen",
"(",
"$",
"temporaryFile",
")",
"&&",
"is_writable",
"(",
"$",
"temporaryFile",
")",
")",
"{",
"return",
"$",
"temporaryFile",
";",
"}",
"}",
"$",
"temporaryDirectory",
"=",
"(",
"is_string",
"(",
"self",
"::",
"$",
"temp",
")",
"&&",
"strlen",
"(",
"self",
"::",
"$",
"temp",
")",
")",
"?",
"self",
"::",
"$",
"temp",
":",
"sys_get_temp_dir",
"(",
")",
";",
"return",
"tempnam",
"(",
"$",
"temporaryDirectory",
",",
"'Zip'",
")",
";",
"}"
] | Returns the path to a temporary file.
@return string | [
"Returns",
"the",
"path",
"to",
"a",
"temporary",
"file",
"."
] | train | https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Resources/private/api/zip.lib.php#L852-L861 |
webforge-labs/psc-cms | lib/Psc/Form/Validator.php | Validator.validate | public function validate($field, $data = NULL, $flags = 0x000000) {
$key = $this->getKey($field);
if (isset($this->dataProvider)) {
$data = $this->dataProvider->getValidatorData($field);
}
if ($this->hasField($field)) {
try {
foreach ($this->rules[$key] as $rule) {
$data = $rule->validate($data); // wenn wir hier data zurückgeben, können wir die rules chainen
}
} catch (EmptyDataException $e) {
if (($flags & self::OPTIONAL) == self::OPTIONAL || $this->isOptional($field)) {
return $e->getDefaultValue();
} else {
if ($e->getMessage() == NULL) {
$e->setMessage(sprintf($this->standardEmptyMessage,$this->getKey($field)));
}
throw $this->convertToValidatorException($e, $field, $data);
}
} catch (\Exception $e) {
throw $this->convertToValidatorException($e, $field, $data);
}
} else {
throw new \Psc\Exception('Feld: '.Code::varInfo($field).' ist dem Validator nicht bekannt.');
}
return $data;
} | php | public function validate($field, $data = NULL, $flags = 0x000000) {
$key = $this->getKey($field);
if (isset($this->dataProvider)) {
$data = $this->dataProvider->getValidatorData($field);
}
if ($this->hasField($field)) {
try {
foreach ($this->rules[$key] as $rule) {
$data = $rule->validate($data); // wenn wir hier data zurückgeben, können wir die rules chainen
}
} catch (EmptyDataException $e) {
if (($flags & self::OPTIONAL) == self::OPTIONAL || $this->isOptional($field)) {
return $e->getDefaultValue();
} else {
if ($e->getMessage() == NULL) {
$e->setMessage(sprintf($this->standardEmptyMessage,$this->getKey($field)));
}
throw $this->convertToValidatorException($e, $field, $data);
}
} catch (\Exception $e) {
throw $this->convertToValidatorException($e, $field, $data);
}
} else {
throw new \Psc\Exception('Feld: '.Code::varInfo($field).' ist dem Validator nicht bekannt.');
}
return $data;
} | [
"public",
"function",
"validate",
"(",
"$",
"field",
",",
"$",
"data",
"=",
"NULL",
",",
"$",
"flags",
"=",
"0x000000",
")",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"getKey",
"(",
"$",
"field",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"dataProvider",
")",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"dataProvider",
"->",
"getValidatorData",
"(",
"$",
"field",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"hasField",
"(",
"$",
"field",
")",
")",
"{",
"try",
"{",
"foreach",
"(",
"$",
"this",
"->",
"rules",
"[",
"$",
"key",
"]",
"as",
"$",
"rule",
")",
"{",
"$",
"data",
"=",
"$",
"rule",
"->",
"validate",
"(",
"$",
"data",
")",
";",
"// wenn wir hier data zurückgeben, können wir die rules chainen",
"}",
"}",
"catch",
"(",
"EmptyDataException",
"$",
"e",
")",
"{",
"if",
"(",
"(",
"$",
"flags",
"&",
"self",
"::",
"OPTIONAL",
")",
"==",
"self",
"::",
"OPTIONAL",
"||",
"$",
"this",
"->",
"isOptional",
"(",
"$",
"field",
")",
")",
"{",
"return",
"$",
"e",
"->",
"getDefaultValue",
"(",
")",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
"==",
"NULL",
")",
"{",
"$",
"e",
"->",
"setMessage",
"(",
"sprintf",
"(",
"$",
"this",
"->",
"standardEmptyMessage",
",",
"$",
"this",
"->",
"getKey",
"(",
"$",
"field",
")",
")",
")",
";",
"}",
"throw",
"$",
"this",
"->",
"convertToValidatorException",
"(",
"$",
"e",
",",
"$",
"field",
",",
"$",
"data",
")",
";",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"throw",
"$",
"this",
"->",
"convertToValidatorException",
"(",
"$",
"e",
",",
"$",
"field",
",",
"$",
"data",
")",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"\\",
"Psc",
"\\",
"Exception",
"(",
"'Feld: '",
".",
"Code",
"::",
"varInfo",
"(",
"$",
"field",
")",
".",
"' ist dem Validator nicht bekannt.'",
")",
";",
"}",
"return",
"$",
"data",
";",
"}"
] | Validiert die Daten zu einem Feld
gibt die Daten zurück!
Wenn das Feld nicht validiert werden, wird eine Exception geworfen!
@throws ValidatorException wenn die Daten nicht zum Feld passen
ist $flags OPTIONAL gesetzt und wird die Rule eine EmptyDataException werfen, wird der DefaultWert (normal: NULL) der Exception zurückgegeben
wenn $this->dataProvider gesetzt ist, wird IMMER $this->dataProvider->getValidatorData() benutzt und nicht der $data Parameter | [
"Validiert",
"die",
"Daten",
"zu",
"einem",
"Feld"
] | train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Form/Validator.php#L53-L89 |
webforge-labs/psc-cms | lib/Psc/Form/Validator.php | Validator.addRule | public function addRule(ValidatorRule $rule, $field, $flags = 0x00000) {
$key = $this->getKey($field);
$this->rules[$key][] = $rule;
if ($rule instanceof FieldValidatorRule) {
$rule->setField($field);
}
if ($flags & self::OPTIONAL) {
$this->setOptional($field);
}
} | php | public function addRule(ValidatorRule $rule, $field, $flags = 0x00000) {
$key = $this->getKey($field);
$this->rules[$key][] = $rule;
if ($rule instanceof FieldValidatorRule) {
$rule->setField($field);
}
if ($flags & self::OPTIONAL) {
$this->setOptional($field);
}
} | [
"public",
"function",
"addRule",
"(",
"ValidatorRule",
"$",
"rule",
",",
"$",
"field",
",",
"$",
"flags",
"=",
"0x00000",
")",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"getKey",
"(",
"$",
"field",
")",
";",
"$",
"this",
"->",
"rules",
"[",
"$",
"key",
"]",
"[",
"]",
"=",
"$",
"rule",
";",
"if",
"(",
"$",
"rule",
"instanceof",
"FieldValidatorRule",
")",
"{",
"$",
"rule",
"->",
"setField",
"(",
"$",
"field",
")",
";",
"}",
"if",
"(",
"$",
"flags",
"&",
"self",
"::",
"OPTIONAL",
")",
"{",
"$",
"this",
"->",
"setOptional",
"(",
"$",
"field",
")",
";",
"}",
"}"
] | Fügt einem Feld eine ValidationRule hinzu
die Reihenfolge der Rules ist wichtig, denn die zweite Rule bekommt die Rückgabe der ersten Rule | [
"Fügt",
"einem",
"Feld",
"eine",
"ValidationRule",
"hinzu"
] | train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Form/Validator.php#L139-L150 |
webforge-labs/psc-cms | lib/Psc/Form/Validator.php | Validator.addRuleToAll | public function addRuleToAll(ValidatorRule $rule, $position = self::APPEND) {
if ($position == self::APPEND) {
foreach ($this->rules as $key => $NULL) {
array_push($this->rules[$key],$rule);
}
}
if ($position == self::PREPEND) {
foreach ($this->rules as $key => $NULL) {
array_unshift($this->rules[$key], $rule);
}
}
if (is_numeric($position)) {
foreach ($this->rules as $key => $NULL) {
A::insert($this->rules[$key], $rule, (int) $position);
}
}
throw new \Psc\Exception('unbekanter Parameter für position: '.Code::getInfo($position));
} | php | public function addRuleToAll(ValidatorRule $rule, $position = self::APPEND) {
if ($position == self::APPEND) {
foreach ($this->rules as $key => $NULL) {
array_push($this->rules[$key],$rule);
}
}
if ($position == self::PREPEND) {
foreach ($this->rules as $key => $NULL) {
array_unshift($this->rules[$key], $rule);
}
}
if (is_numeric($position)) {
foreach ($this->rules as $key => $NULL) {
A::insert($this->rules[$key], $rule, (int) $position);
}
}
throw new \Psc\Exception('unbekanter Parameter für position: '.Code::getInfo($position));
} | [
"public",
"function",
"addRuleToAll",
"(",
"ValidatorRule",
"$",
"rule",
",",
"$",
"position",
"=",
"self",
"::",
"APPEND",
")",
"{",
"if",
"(",
"$",
"position",
"==",
"self",
"::",
"APPEND",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"rules",
"as",
"$",
"key",
"=>",
"$",
"NULL",
")",
"{",
"array_push",
"(",
"$",
"this",
"->",
"rules",
"[",
"$",
"key",
"]",
",",
"$",
"rule",
")",
";",
"}",
"}",
"if",
"(",
"$",
"position",
"==",
"self",
"::",
"PREPEND",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"rules",
"as",
"$",
"key",
"=>",
"$",
"NULL",
")",
"{",
"array_unshift",
"(",
"$",
"this",
"->",
"rules",
"[",
"$",
"key",
"]",
",",
"$",
"rule",
")",
";",
"}",
"}",
"if",
"(",
"is_numeric",
"(",
"$",
"position",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"rules",
"as",
"$",
"key",
"=>",
"$",
"NULL",
")",
"{",
"A",
"::",
"insert",
"(",
"$",
"this",
"->",
"rules",
"[",
"$",
"key",
"]",
",",
"$",
"rule",
",",
"(",
"int",
")",
"$",
"position",
")",
";",
"}",
"}",
"throw",
"new",
"\\",
"Psc",
"\\",
"Exception",
"(",
"'unbekanter Parameter für position: '.",
"C",
"ode:",
":g",
"etInfo(",
"$",
"p",
"osition)",
")",
";",
"",
"}"
] | Fügt allen Feldern eine bestimmte Rule zurück
@param style bestimmt die Position der Rule (append oder prepend) | [
"Fügt",
"allen",
"Feldern",
"eine",
"bestimmte",
"Rule",
"zurück"
] | train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Form/Validator.php#L181-L201 |
PortaText/php-sdk | src/PortaText/Command/Api/Sounds.php | Sounds.getBody | protected function getBody($method)
{
$file = $this->getArgument("sound_file");
if (!is_null($file)) {
return "file:$file";
}
return parent::getBody($method);
} | php | protected function getBody($method)
{
$file = $this->getArgument("sound_file");
if (!is_null($file)) {
return "file:$file";
}
return parent::getBody($method);
} | [
"protected",
"function",
"getBody",
"(",
"$",
"method",
")",
"{",
"$",
"file",
"=",
"$",
"this",
"->",
"getArgument",
"(",
"\"sound_file\"",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"file",
")",
")",
"{",
"return",
"\"file:$file\"",
";",
"}",
"return",
"parent",
"::",
"getBody",
"(",
"$",
"method",
")",
";",
"}"
] | Returns the body for this endpoint.
@param string $method Method for this command.
@return string | [
"Returns",
"the",
"body",
"for",
"this",
"endpoint",
"."
] | train | https://github.com/PortaText/php-sdk/blob/dbe04ef043db5b251953f9de57aa4d0f1785dfcc/src/PortaText/Command/Api/Sounds.php#L87-L94 |
PortaText/php-sdk | src/PortaText/Command/Api/Sounds.php | Sounds.getEndpoint | protected function getEndpoint($method)
{
$endpoint = "sounds";
$soundId = $this->getArgument("id");
if (!is_null($soundId)) {
$endpoint .= "/$soundId";
$this->delArgument("id");
}
$queryString = array();
$name = $this->getArgument("name");
if (!is_null($name)) {
$queryString['name'] = $name;
$this->delArgument("name");
}
$description = $this->getArgument("description");
if (!is_null($description)) {
$queryString['description'] = $description;
$this->delArgument("description");
}
if (!empty($queryString)) {
$queryString = http_build_query($queryString);
return "$endpoint?$queryString";
}
return $endpoint;
} | php | protected function getEndpoint($method)
{
$endpoint = "sounds";
$soundId = $this->getArgument("id");
if (!is_null($soundId)) {
$endpoint .= "/$soundId";
$this->delArgument("id");
}
$queryString = array();
$name = $this->getArgument("name");
if (!is_null($name)) {
$queryString['name'] = $name;
$this->delArgument("name");
}
$description = $this->getArgument("description");
if (!is_null($description)) {
$queryString['description'] = $description;
$this->delArgument("description");
}
if (!empty($queryString)) {
$queryString = http_build_query($queryString);
return "$endpoint?$queryString";
}
return $endpoint;
} | [
"protected",
"function",
"getEndpoint",
"(",
"$",
"method",
")",
"{",
"$",
"endpoint",
"=",
"\"sounds\"",
";",
"$",
"soundId",
"=",
"$",
"this",
"->",
"getArgument",
"(",
"\"id\"",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"soundId",
")",
")",
"{",
"$",
"endpoint",
".=",
"\"/$soundId\"",
";",
"$",
"this",
"->",
"delArgument",
"(",
"\"id\"",
")",
";",
"}",
"$",
"queryString",
"=",
"array",
"(",
")",
";",
"$",
"name",
"=",
"$",
"this",
"->",
"getArgument",
"(",
"\"name\"",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"name",
")",
")",
"{",
"$",
"queryString",
"[",
"'name'",
"]",
"=",
"$",
"name",
";",
"$",
"this",
"->",
"delArgument",
"(",
"\"name\"",
")",
";",
"}",
"$",
"description",
"=",
"$",
"this",
"->",
"getArgument",
"(",
"\"description\"",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"description",
")",
")",
"{",
"$",
"queryString",
"[",
"'description'",
"]",
"=",
"$",
"description",
";",
"$",
"this",
"->",
"delArgument",
"(",
"\"description\"",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"queryString",
")",
")",
"{",
"$",
"queryString",
"=",
"http_build_query",
"(",
"$",
"queryString",
")",
";",
"return",
"\"$endpoint?$queryString\"",
";",
"}",
"return",
"$",
"endpoint",
";",
"}"
] | Returns a string with the endpoint for the given command.
@param string $method Method for this command.
@return string | [
"Returns",
"a",
"string",
"with",
"the",
"endpoint",
"for",
"the",
"given",
"command",
"."
] | train | https://github.com/PortaText/php-sdk/blob/dbe04ef043db5b251953f9de57aa4d0f1785dfcc/src/PortaText/Command/Api/Sounds.php#L103-L127 |
steeffeen/FancyManiaLinks | FML/Stylesheet/Mood.php | Mood.setLightAmbientColor | public function setLightAmbientColor($red, $green, $blue)
{
$this->lightAmbientColor = floatval($red) . ' ' . floatval($green) . ' ' . floatval($blue);
return $this;
} | php | public function setLightAmbientColor($red, $green, $blue)
{
$this->lightAmbientColor = floatval($red) . ' ' . floatval($green) . ' ' . floatval($blue);
return $this;
} | [
"public",
"function",
"setLightAmbientColor",
"(",
"$",
"red",
",",
"$",
"green",
",",
"$",
"blue",
")",
"{",
"$",
"this",
"->",
"lightAmbientColor",
"=",
"floatval",
"(",
"$",
"red",
")",
".",
"' '",
".",
"floatval",
"(",
"$",
"green",
")",
".",
"' '",
".",
"floatval",
"(",
"$",
"blue",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Set the ambient color in which elements reflect the light
@api
@param float $red Red color value
@param float $green Green color value
@param float $blue Blue color value
@return static | [
"Set",
"the",
"ambient",
"color",
"in",
"which",
"elements",
"reflect",
"the",
"light"
] | train | https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/Stylesheet/Mood.php#L117-L121 |
steeffeen/FancyManiaLinks | FML/Stylesheet/Mood.php | Mood.setCloudsMinimumColor | public function setCloudsMinimumColor($red, $green, $blue)
{
$this->cloudsMinimumColor = floatval($red) . ' ' . floatval($green) . ' ' . floatval($blue);
return $this;
} | php | public function setCloudsMinimumColor($red, $green, $blue)
{
$this->cloudsMinimumColor = floatval($red) . ' ' . floatval($green) . ' ' . floatval($blue);
return $this;
} | [
"public",
"function",
"setCloudsMinimumColor",
"(",
"$",
"red",
",",
"$",
"green",
",",
"$",
"blue",
")",
"{",
"$",
"this",
"->",
"cloudsMinimumColor",
"=",
"floatval",
"(",
"$",
"red",
")",
".",
"' '",
".",
"floatval",
"(",
"$",
"green",
")",
".",
"' '",
".",
"floatval",
"(",
"$",
"blue",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Set the minimum value for the background color range
@api
@param float $red Red color value
@param float $green Green color value
@param float $blue Blue color value
@return static | [
"Set",
"the",
"minimum",
"value",
"for",
"the",
"background",
"color",
"range"
] | train | https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/Stylesheet/Mood.php#L143-L147 |
steeffeen/FancyManiaLinks | FML/Stylesheet/Mood.php | Mood.setCloudsMaximumColor | public function setCloudsMaximumColor($red, $green, $blue)
{
$this->cloudsMaximumColor = floatval($red) . ' ' . floatval($green) . ' ' . floatval($blue);
return $this;
} | php | public function setCloudsMaximumColor($red, $green, $blue)
{
$this->cloudsMaximumColor = floatval($red) . ' ' . floatval($green) . ' ' . floatval($blue);
return $this;
} | [
"public",
"function",
"setCloudsMaximumColor",
"(",
"$",
"red",
",",
"$",
"green",
",",
"$",
"blue",
")",
"{",
"$",
"this",
"->",
"cloudsMaximumColor",
"=",
"floatval",
"(",
"$",
"red",
")",
".",
"' '",
".",
"floatval",
"(",
"$",
"green",
")",
".",
"' '",
".",
"floatval",
"(",
"$",
"blue",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Set the maximum value for the background color range
@api
@param float $red Red color value
@param float $green Green color value
@param float $blue Blue color value
@return static | [
"Set",
"the",
"maximum",
"value",
"for",
"the",
"background",
"color",
"range"
] | train | https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/Stylesheet/Mood.php#L169-L173 |
steeffeen/FancyManiaLinks | FML/Stylesheet/Mood.php | Mood.setLight0Color | public function setLight0Color($red, $green, $blue)
{
$this->light0Color = floatval($red) . ' ' . floatval($green) . ' ' . floatval($blue);
return $this;
} | php | public function setLight0Color($red, $green, $blue)
{
$this->light0Color = floatval($red) . ' ' . floatval($green) . ' ' . floatval($blue);
return $this;
} | [
"public",
"function",
"setLight0Color",
"(",
"$",
"red",
",",
"$",
"green",
",",
"$",
"blue",
")",
"{",
"$",
"this",
"->",
"light0Color",
"=",
"floatval",
"(",
"$",
"red",
")",
".",
"' '",
".",
"floatval",
"(",
"$",
"green",
")",
".",
"' '",
".",
"floatval",
"(",
"$",
"blue",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Set the RGB color of light source 0
@api
@param float $red Red color value
@param float $green Green color value
@param float $blue Blue color value
@return static | [
"Set",
"the",
"RGB",
"color",
"of",
"light",
"source",
"0"
] | train | https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/Stylesheet/Mood.php#L195-L199 |
steeffeen/FancyManiaLinks | FML/Stylesheet/Mood.php | Mood.setLightBallColor | public function setLightBallColor($red, $green, $blue)
{
$this->lightBallColor = floatval($red) . ' ' . floatval($green) . ' ' . floatval($blue);
return $this;
} | php | public function setLightBallColor($red, $green, $blue)
{
$this->lightBallColor = floatval($red) . ' ' . floatval($green) . ' ' . floatval($blue);
return $this;
} | [
"public",
"function",
"setLightBallColor",
"(",
"$",
"red",
",",
"$",
"green",
",",
"$",
"blue",
")",
"{",
"$",
"this",
"->",
"lightBallColor",
"=",
"floatval",
"(",
"$",
"red",
")",
".",
"' '",
".",
"floatval",
"(",
"$",
"green",
")",
".",
"' '",
".",
"floatval",
"(",
"$",
"blue",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Set the light ball color
@api
@param float $red Red color value
@param float $green Green color value
@param float $blue Blue color value
@return static | [
"Set",
"the",
"light",
"ball",
"color"
] | train | https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/Stylesheet/Mood.php#L293-L297 |
steeffeen/FancyManiaLinks | FML/Stylesheet/Mood.php | Mood.setFogColor | public function setFogColor($red, $green, $blue)
{
$this->fogColor = floatval($red) . ' ' . floatval($green) . ' ' . floatval($blue);
return $this;
} | php | public function setFogColor($red, $green, $blue)
{
$this->fogColor = floatval($red) . ' ' . floatval($green) . ' ' . floatval($blue);
return $this;
} | [
"public",
"function",
"setFogColor",
"(",
"$",
"red",
",",
"$",
"green",
",",
"$",
"blue",
")",
"{",
"$",
"this",
"->",
"fogColor",
"=",
"floatval",
"(",
"$",
"red",
")",
".",
"' '",
".",
"floatval",
"(",
"$",
"green",
")",
".",
"' '",
".",
"floatval",
"(",
"$",
"blue",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Set the fog color
@api
@param float $red Red color value
@param float $green Green color value
@param float $blue Blue color value
@return static | [
"Set",
"the",
"fog",
"color"
] | train | https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/Stylesheet/Mood.php#L367-L371 |
steeffeen/FancyManiaLinks | FML/Stylesheet/Mood.php | Mood.setSelfIlluminationColor | public function setSelfIlluminationColor($red, $green, $blue)
{
$this->selfIlluminationColor = floatval($red) . ' ' . floatval($green) . ' ' . floatval($blue);
return $this;
} | php | public function setSelfIlluminationColor($red, $green, $blue)
{
$this->selfIlluminationColor = floatval($red) . ' ' . floatval($green) . ' ' . floatval($blue);
return $this;
} | [
"public",
"function",
"setSelfIlluminationColor",
"(",
"$",
"red",
",",
"$",
"green",
",",
"$",
"blue",
")",
"{",
"$",
"this",
"->",
"selfIlluminationColor",
"=",
"floatval",
"(",
"$",
"red",
")",
".",
"' '",
".",
"floatval",
"(",
"$",
"green",
")",
".",
"' '",
".",
"floatval",
"(",
"$",
"blue",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Set the self illumination color
@api
@param float $red Red color value
@param float $green Green color value
@param float $blue Blue color value
@return static | [
"Set",
"the",
"self",
"illumination",
"color"
] | train | https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/Stylesheet/Mood.php#L393-L397 |
steeffeen/FancyManiaLinks | FML/Stylesheet/Mood.php | Mood.addSkyGradient | public function addSkyGradient($x, $color)
{
$skyGradientKey = new SkyGradientKey($x, $color);
return $this->addSkyGradientKey($skyGradientKey);
} | php | public function addSkyGradient($x, $color)
{
$skyGradientKey = new SkyGradientKey($x, $color);
return $this->addSkyGradientKey($skyGradientKey);
} | [
"public",
"function",
"addSkyGradient",
"(",
"$",
"x",
",",
"$",
"color",
")",
"{",
"$",
"skyGradientKey",
"=",
"new",
"SkyGradientKey",
"(",
"$",
"x",
",",
"$",
"color",
")",
";",
"return",
"$",
"this",
"->",
"addSkyGradientKey",
"(",
"$",
"skyGradientKey",
")",
";",
"}"
] | Add a sky gradient
@api
@param float $x X value
@param string $color Color value
@return static | [
"Add",
"a",
"sky",
"gradient"
] | train | https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/Stylesheet/Mood.php#L455-L459 |
steeffeen/FancyManiaLinks | FML/Stylesheet/Mood.php | Mood.render | public function render(\DOMDocument $domDocument)
{
$domElement = $domDocument->createElement("mood");
if ($this->lightAmbientColor) {
$domElement->setAttribute("LAmbient_LinearRgb", $this->lightAmbientColor);
}
if ($this->cloudsMinimumColor) {
$domElement->setAttribute("CloudsRgbMinLinear", $this->cloudsMinimumColor);
}
if ($this->cloudsMaximumColor) {
$domElement->setAttribute("CloudsRgbMaxLinear", $this->cloudsMaximumColor);
}
if ($this->light0Color) {
$domElement->setAttribute("LDir0_LinearRgb", $this->light0Color);
}
if ($this->light0Intensity != 1.) {
$domElement->setAttribute("LDir0_Intens", $this->light0Intensity);
}
if ($this->light0PhiAngle) {
$domElement->setAttribute("LDir0_DirPhi", $this->light0PhiAngle);
}
if ($this->light0ThetaAngle) {
$domElement->setAttribute("LDir0_DirTheta", $this->light0ThetaAngle);
}
if ($this->lightBallColor) {
$domElement->setAttribute("LBall_LinearRgb", $this->lightBallColor);
}
if ($this->lightBallIntensity != 1.) {
$domElement->setAttribute("LBall_Intens", $this->lightBallIntensity);
}
if ($this->lightBallRadius) {
$domElement->setAttribute("LBall_Radius", $this->lightBallRadius);
}
if ($this->fogColor) {
$domElement->setAttribute("FogColorSrgb", $this->fogColor);
}
if ($this->selfIlluminationColor) {
$domElement->setAttribute("SelfIllumColor", $this->selfIlluminationColor);
}
if ($this->skyGradientScale != 1.) {
$domElement->setAttribute("SkyGradientV_Scale", $this->skyGradientScale);
}
if ($this->skyGradientKeys) {
$skyGradientElement = $domDocument->createElement("skygradient");
$domElement->appendChild($skyGradientElement);
foreach ($this->skyGradientKeys as $skyGradientKey) {
$skyGradientKeyElement = $skyGradientKey->render($domDocument);
$skyGradientElement->appendChild($skyGradientKeyElement);
}
}
return $domElement;
} | php | public function render(\DOMDocument $domDocument)
{
$domElement = $domDocument->createElement("mood");
if ($this->lightAmbientColor) {
$domElement->setAttribute("LAmbient_LinearRgb", $this->lightAmbientColor);
}
if ($this->cloudsMinimumColor) {
$domElement->setAttribute("CloudsRgbMinLinear", $this->cloudsMinimumColor);
}
if ($this->cloudsMaximumColor) {
$domElement->setAttribute("CloudsRgbMaxLinear", $this->cloudsMaximumColor);
}
if ($this->light0Color) {
$domElement->setAttribute("LDir0_LinearRgb", $this->light0Color);
}
if ($this->light0Intensity != 1.) {
$domElement->setAttribute("LDir0_Intens", $this->light0Intensity);
}
if ($this->light0PhiAngle) {
$domElement->setAttribute("LDir0_DirPhi", $this->light0PhiAngle);
}
if ($this->light0ThetaAngle) {
$domElement->setAttribute("LDir0_DirTheta", $this->light0ThetaAngle);
}
if ($this->lightBallColor) {
$domElement->setAttribute("LBall_LinearRgb", $this->lightBallColor);
}
if ($this->lightBallIntensity != 1.) {
$domElement->setAttribute("LBall_Intens", $this->lightBallIntensity);
}
if ($this->lightBallRadius) {
$domElement->setAttribute("LBall_Radius", $this->lightBallRadius);
}
if ($this->fogColor) {
$domElement->setAttribute("FogColorSrgb", $this->fogColor);
}
if ($this->selfIlluminationColor) {
$domElement->setAttribute("SelfIllumColor", $this->selfIlluminationColor);
}
if ($this->skyGradientScale != 1.) {
$domElement->setAttribute("SkyGradientV_Scale", $this->skyGradientScale);
}
if ($this->skyGradientKeys) {
$skyGradientElement = $domDocument->createElement("skygradient");
$domElement->appendChild($skyGradientElement);
foreach ($this->skyGradientKeys as $skyGradientKey) {
$skyGradientKeyElement = $skyGradientKey->render($domDocument);
$skyGradientElement->appendChild($skyGradientKeyElement);
}
}
return $domElement;
} | [
"public",
"function",
"render",
"(",
"\\",
"DOMDocument",
"$",
"domDocument",
")",
"{",
"$",
"domElement",
"=",
"$",
"domDocument",
"->",
"createElement",
"(",
"\"mood\"",
")",
";",
"if",
"(",
"$",
"this",
"->",
"lightAmbientColor",
")",
"{",
"$",
"domElement",
"->",
"setAttribute",
"(",
"\"LAmbient_LinearRgb\"",
",",
"$",
"this",
"->",
"lightAmbientColor",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"cloudsMinimumColor",
")",
"{",
"$",
"domElement",
"->",
"setAttribute",
"(",
"\"CloudsRgbMinLinear\"",
",",
"$",
"this",
"->",
"cloudsMinimumColor",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"cloudsMaximumColor",
")",
"{",
"$",
"domElement",
"->",
"setAttribute",
"(",
"\"CloudsRgbMaxLinear\"",
",",
"$",
"this",
"->",
"cloudsMaximumColor",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"light0Color",
")",
"{",
"$",
"domElement",
"->",
"setAttribute",
"(",
"\"LDir0_LinearRgb\"",
",",
"$",
"this",
"->",
"light0Color",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"light0Intensity",
"!=",
"1.",
")",
"{",
"$",
"domElement",
"->",
"setAttribute",
"(",
"\"LDir0_Intens\"",
",",
"$",
"this",
"->",
"light0Intensity",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"light0PhiAngle",
")",
"{",
"$",
"domElement",
"->",
"setAttribute",
"(",
"\"LDir0_DirPhi\"",
",",
"$",
"this",
"->",
"light0PhiAngle",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"light0ThetaAngle",
")",
"{",
"$",
"domElement",
"->",
"setAttribute",
"(",
"\"LDir0_DirTheta\"",
",",
"$",
"this",
"->",
"light0ThetaAngle",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"lightBallColor",
")",
"{",
"$",
"domElement",
"->",
"setAttribute",
"(",
"\"LBall_LinearRgb\"",
",",
"$",
"this",
"->",
"lightBallColor",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"lightBallIntensity",
"!=",
"1.",
")",
"{",
"$",
"domElement",
"->",
"setAttribute",
"(",
"\"LBall_Intens\"",
",",
"$",
"this",
"->",
"lightBallIntensity",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"lightBallRadius",
")",
"{",
"$",
"domElement",
"->",
"setAttribute",
"(",
"\"LBall_Radius\"",
",",
"$",
"this",
"->",
"lightBallRadius",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"fogColor",
")",
"{",
"$",
"domElement",
"->",
"setAttribute",
"(",
"\"FogColorSrgb\"",
",",
"$",
"this",
"->",
"fogColor",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"selfIlluminationColor",
")",
"{",
"$",
"domElement",
"->",
"setAttribute",
"(",
"\"SelfIllumColor\"",
",",
"$",
"this",
"->",
"selfIlluminationColor",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"skyGradientScale",
"!=",
"1.",
")",
"{",
"$",
"domElement",
"->",
"setAttribute",
"(",
"\"SkyGradientV_Scale\"",
",",
"$",
"this",
"->",
"skyGradientScale",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"skyGradientKeys",
")",
"{",
"$",
"skyGradientElement",
"=",
"$",
"domDocument",
"->",
"createElement",
"(",
"\"skygradient\"",
")",
";",
"$",
"domElement",
"->",
"appendChild",
"(",
"$",
"skyGradientElement",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"skyGradientKeys",
"as",
"$",
"skyGradientKey",
")",
"{",
"$",
"skyGradientKeyElement",
"=",
"$",
"skyGradientKey",
"->",
"render",
"(",
"$",
"domDocument",
")",
";",
"$",
"skyGradientElement",
"->",
"appendChild",
"(",
"$",
"skyGradientKeyElement",
")",
";",
"}",
"}",
"return",
"$",
"domElement",
";",
"}"
] | Render the Mood
@param \DOMDocument $domDocument DOMDocument for which the Mood should be rendered
@return \DOMElement | [
"Render",
"the",
"Mood"
] | train | https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/Stylesheet/Mood.php#L479-L530 |
left-right/center | src/controllers/RowController.php | RowController.index | public function index($table_name, $linked_field=false, $linked_row=false) {
# Get info about the object
$table = config('center.tables.' . $table_name);
//dd($table);
# Trail
if (!$linked_field) Trail::clear();
# Security -- todo hidden?
if (!isset($table->name)) {
return redirect()->action('\LeftRight\Center\Controllers\TableController@index')->with('error', trans('center::site.table_does_not_exist'));
}
# Custom index?
//if ($table->index) return call_user_func($table->index);
# Start query
$rows = DB::table($table->name);
# Table columns
$columns = [];
# Build select statement
$rows->select([$table->name . '.id']);
foreach ($table->list as $field) {
if ($field == $linked_field) continue;
$field = $table->fields->{$field};
if ($field->type == 'checkboxes') {
$rows->addSelect(DB::raw('(SELECT GROUP_CONCAT(' . $field->source . '.' . self::listColumn($field->source) . ' SEPARATOR ", ")
FROM ' . $field->source . '
JOIN ' . $field->name . ' ON ' . $field->source . '.id = ' . $field->name . '.' . self::formatKeyColumn($field->source) . '
WHERE ' . $field->name . '.' . self::formatKeyColumn($table->name) . ' = ' . $table->name . '.id
ORDER BY ' . $field->source . '.' . self::listColumn($field->source) . ') AS ' . $field->name));
} elseif ($field->type == 'image') {
$rows
->leftJoin(config('center.db.files'), $table->name . '.' . $field->name, '=', config('center.db.files') . '.id')
->addSelect(config('center.db.files') . '.url AS ' . $field->name . '_url');
} elseif (in_array($field->type, ['select', 'user'])) {
$rows
->leftJoin($field->source, $field->name, '=', $field->source . '.id')
->addSelect($field->source . '.' . self::listColumn($field->source) . ' AS ' . $field->name);
} else {
//normal, selectable field
$rows->addSelect($table->name . '.' . $field->name);
}
//add to table columns
$columns[] = $field;
}
# Handle group-by fields
$table->nested = false;
if (!empty($table->group_by)) {
if (strpos($table->group_by, '::')) {
list($object, $method) = explode('::', $table->group_by);
if (class_exists($object)) {
//call arbitrary user function
$rows = call_user_func($table->group_by, $rows);
}
} else {
$grouped_table = config('center.tables.' . $table->fields->{$table->group_by}->source);
$grouped_field = self::listColumn($grouped_table->name);
if ($grouped_table->name == $table->name) {
//nested object
$table->nested = true;
} else {
# Include group_by_field in resultset
foreach ($grouped_table->order_by as $order_by => $direction) {
$rows->orderBy($order_by, $direction);
}
$rows->leftJoin($grouped_table->name, $table->name . '.' . $table->fields->{$table->group_by}->name, '=', $grouped_table->name . '.id');
$rows->addSelect($grouped_table->name . '.' . $grouped_field . ' as group');
}
}
}
# If linked, limit scope to just the linked row
if ($linked_field && $linked_row) {
$rows->where($table->name . '.' . $linked_field, $linked_row);
}
# Set the order and direction
foreach ($table->order_by as $order_by => $direction) {
$rows->orderBy($order_by, $direction);
}
# Soft deletes?
if (isset($table->fields->deleted_at)) {
$rows->addSelect($table->name . '.deleted_at');
}
$searching = false;
# Text search?
if ($table->search && Request::has('search')) {
$searching = true;
$rows->where(function($query) use($table) {
foreach ($table->search as $field) {
$query->orWhere($table->name . '.' . $field, 'LIKE', '%' . Request::input('search') . '%');
}
});
}
# Filter search?
foreach ($table->filters as $filter) {
if (Request::has($filter)) {
$searching = true;
$rows->where($table->name . '.' . $filter, Request::input($filter));
}
}
# Run query and save it to a variable
$rows = $rows->paginate(50);
# Set URLs on each instance
foreach ($rows as &$row) {
$row->link = action('\LeftRight\Center\Controllers\RowController@edit', [$table->name, $row->id, $linked_field, $linked_row]);
$row->delete = action('\LeftRight\Center\Controllers\RowController@delete', [$table->name, $row->id]);
}
# If it's a nested object, nest-ify the resultset
if ($table->nested) {
$list = array();
foreach ($rows as &$row) {
$row->children = array();
if (empty($row->{$grouped_field->name})) { //$grouped_field->name is for ex parent_id
$list[] = $row;
} elseif (self::nestedNodeExists($list, $row->{$grouped_field->name}, $row)) {
//attached child to parent node
} else {
//an error occurred; a parent should exist but is not yet present
}
}
$rows = $list;
}
# Search filters for the sidebar
$filters = [];
foreach ($table->filters as $filter) {
if ($table->fields->{$filter}->type == 'us_state') {
$filters[$filter] = ['' => $table->fields->{$filter}->title] + trans('center::site.us_states');;
} elseif ($table->fields->{$filter}->type == 'country') {
$filters[$filter] = ['' => $table->fields->{$filter}->title] + trans('center::site.countries');;
} else {
$related_table = config('center.tables.' . $table->fields->{$filter}->source);
$options = DB::table($related_table->name);
foreach ($related_table->order_by as $column => $direction) {
$options->orderBy($column, $direction);
}
$options->whereIn('id', DB::table($table->name)->distinct()->lists($filter));
$options = $options->lists(self::listColumn($related_table), 'id');
$filters[$filter] = ['' => $related_table->title] + $options;
}
}
$return = compact('table', 'columns', 'rows', 'filters', 'searching', 'linked_field', 'linked_row');
# Return array to edit()
if ($linked_field && $linked_row) return $return;
# Return HTML view
return view('center::rows.index', $return);
} | php | public function index($table_name, $linked_field=false, $linked_row=false) {
# Get info about the object
$table = config('center.tables.' . $table_name);
//dd($table);
# Trail
if (!$linked_field) Trail::clear();
# Security -- todo hidden?
if (!isset($table->name)) {
return redirect()->action('\LeftRight\Center\Controllers\TableController@index')->with('error', trans('center::site.table_does_not_exist'));
}
# Custom index?
//if ($table->index) return call_user_func($table->index);
# Start query
$rows = DB::table($table->name);
# Table columns
$columns = [];
# Build select statement
$rows->select([$table->name . '.id']);
foreach ($table->list as $field) {
if ($field == $linked_field) continue;
$field = $table->fields->{$field};
if ($field->type == 'checkboxes') {
$rows->addSelect(DB::raw('(SELECT GROUP_CONCAT(' . $field->source . '.' . self::listColumn($field->source) . ' SEPARATOR ", ")
FROM ' . $field->source . '
JOIN ' . $field->name . ' ON ' . $field->source . '.id = ' . $field->name . '.' . self::formatKeyColumn($field->source) . '
WHERE ' . $field->name . '.' . self::formatKeyColumn($table->name) . ' = ' . $table->name . '.id
ORDER BY ' . $field->source . '.' . self::listColumn($field->source) . ') AS ' . $field->name));
} elseif ($field->type == 'image') {
$rows
->leftJoin(config('center.db.files'), $table->name . '.' . $field->name, '=', config('center.db.files') . '.id')
->addSelect(config('center.db.files') . '.url AS ' . $field->name . '_url');
} elseif (in_array($field->type, ['select', 'user'])) {
$rows
->leftJoin($field->source, $field->name, '=', $field->source . '.id')
->addSelect($field->source . '.' . self::listColumn($field->source) . ' AS ' . $field->name);
} else {
//normal, selectable field
$rows->addSelect($table->name . '.' . $field->name);
}
//add to table columns
$columns[] = $field;
}
# Handle group-by fields
$table->nested = false;
if (!empty($table->group_by)) {
if (strpos($table->group_by, '::')) {
list($object, $method) = explode('::', $table->group_by);
if (class_exists($object)) {
//call arbitrary user function
$rows = call_user_func($table->group_by, $rows);
}
} else {
$grouped_table = config('center.tables.' . $table->fields->{$table->group_by}->source);
$grouped_field = self::listColumn($grouped_table->name);
if ($grouped_table->name == $table->name) {
//nested object
$table->nested = true;
} else {
# Include group_by_field in resultset
foreach ($grouped_table->order_by as $order_by => $direction) {
$rows->orderBy($order_by, $direction);
}
$rows->leftJoin($grouped_table->name, $table->name . '.' . $table->fields->{$table->group_by}->name, '=', $grouped_table->name . '.id');
$rows->addSelect($grouped_table->name . '.' . $grouped_field . ' as group');
}
}
}
# If linked, limit scope to just the linked row
if ($linked_field && $linked_row) {
$rows->where($table->name . '.' . $linked_field, $linked_row);
}
# Set the order and direction
foreach ($table->order_by as $order_by => $direction) {
$rows->orderBy($order_by, $direction);
}
# Soft deletes?
if (isset($table->fields->deleted_at)) {
$rows->addSelect($table->name . '.deleted_at');
}
$searching = false;
# Text search?
if ($table->search && Request::has('search')) {
$searching = true;
$rows->where(function($query) use($table) {
foreach ($table->search as $field) {
$query->orWhere($table->name . '.' . $field, 'LIKE', '%' . Request::input('search') . '%');
}
});
}
# Filter search?
foreach ($table->filters as $filter) {
if (Request::has($filter)) {
$searching = true;
$rows->where($table->name . '.' . $filter, Request::input($filter));
}
}
# Run query and save it to a variable
$rows = $rows->paginate(50);
# Set URLs on each instance
foreach ($rows as &$row) {
$row->link = action('\LeftRight\Center\Controllers\RowController@edit', [$table->name, $row->id, $linked_field, $linked_row]);
$row->delete = action('\LeftRight\Center\Controllers\RowController@delete', [$table->name, $row->id]);
}
# If it's a nested object, nest-ify the resultset
if ($table->nested) {
$list = array();
foreach ($rows as &$row) {
$row->children = array();
if (empty($row->{$grouped_field->name})) { //$grouped_field->name is for ex parent_id
$list[] = $row;
} elseif (self::nestedNodeExists($list, $row->{$grouped_field->name}, $row)) {
//attached child to parent node
} else {
//an error occurred; a parent should exist but is not yet present
}
}
$rows = $list;
}
# Search filters for the sidebar
$filters = [];
foreach ($table->filters as $filter) {
if ($table->fields->{$filter}->type == 'us_state') {
$filters[$filter] = ['' => $table->fields->{$filter}->title] + trans('center::site.us_states');;
} elseif ($table->fields->{$filter}->type == 'country') {
$filters[$filter] = ['' => $table->fields->{$filter}->title] + trans('center::site.countries');;
} else {
$related_table = config('center.tables.' . $table->fields->{$filter}->source);
$options = DB::table($related_table->name);
foreach ($related_table->order_by as $column => $direction) {
$options->orderBy($column, $direction);
}
$options->whereIn('id', DB::table($table->name)->distinct()->lists($filter));
$options = $options->lists(self::listColumn($related_table), 'id');
$filters[$filter] = ['' => $related_table->title] + $options;
}
}
$return = compact('table', 'columns', 'rows', 'filters', 'searching', 'linked_field', 'linked_row');
# Return array to edit()
if ($linked_field && $linked_row) return $return;
# Return HTML view
return view('center::rows.index', $return);
} | [
"public",
"function",
"index",
"(",
"$",
"table_name",
",",
"$",
"linked_field",
"=",
"false",
",",
"$",
"linked_row",
"=",
"false",
")",
"{",
"# Get info about the object",
"$",
"table",
"=",
"config",
"(",
"'center.tables.'",
".",
"$",
"table_name",
")",
";",
"//dd($table);",
"# Trail",
"if",
"(",
"!",
"$",
"linked_field",
")",
"Trail",
"::",
"clear",
"(",
")",
";",
"# Security -- todo hidden?",
"if",
"(",
"!",
"isset",
"(",
"$",
"table",
"->",
"name",
")",
")",
"{",
"return",
"redirect",
"(",
")",
"->",
"action",
"(",
"'\\LeftRight\\Center\\Controllers\\TableController@index'",
")",
"->",
"with",
"(",
"'error'",
",",
"trans",
"(",
"'center::site.table_does_not_exist'",
")",
")",
";",
"}",
"# Custom index?",
"//if ($table->index) return call_user_func($table->index);",
"# Start query",
"$",
"rows",
"=",
"DB",
"::",
"table",
"(",
"$",
"table",
"->",
"name",
")",
";",
"# Table columns",
"$",
"columns",
"=",
"[",
"]",
";",
"# Build select statement",
"$",
"rows",
"->",
"select",
"(",
"[",
"$",
"table",
"->",
"name",
".",
"'.id'",
"]",
")",
";",
"foreach",
"(",
"$",
"table",
"->",
"list",
"as",
"$",
"field",
")",
"{",
"if",
"(",
"$",
"field",
"==",
"$",
"linked_field",
")",
"continue",
";",
"$",
"field",
"=",
"$",
"table",
"->",
"fields",
"->",
"{",
"$",
"field",
"}",
";",
"if",
"(",
"$",
"field",
"->",
"type",
"==",
"'checkboxes'",
")",
"{",
"$",
"rows",
"->",
"addSelect",
"(",
"DB",
"::",
"raw",
"(",
"'(SELECT GROUP_CONCAT('",
".",
"$",
"field",
"->",
"source",
".",
"'.'",
".",
"self",
"::",
"listColumn",
"(",
"$",
"field",
"->",
"source",
")",
".",
"' SEPARATOR \", \") \n\t\t\t\t\tFROM '",
".",
"$",
"field",
"->",
"source",
".",
"' \n\t\t\t\t\tJOIN '",
".",
"$",
"field",
"->",
"name",
".",
"' ON '",
".",
"$",
"field",
"->",
"source",
".",
"'.id = '",
".",
"$",
"field",
"->",
"name",
".",
"'.'",
".",
"self",
"::",
"formatKeyColumn",
"(",
"$",
"field",
"->",
"source",
")",
".",
"'\n\t\t\t\t\tWHERE '",
".",
"$",
"field",
"->",
"name",
".",
"'.'",
".",
"self",
"::",
"formatKeyColumn",
"(",
"$",
"table",
"->",
"name",
")",
".",
"' = '",
".",
"$",
"table",
"->",
"name",
".",
"'.id \n\t\t\t\t\tORDER BY '",
".",
"$",
"field",
"->",
"source",
".",
"'.'",
".",
"self",
"::",
"listColumn",
"(",
"$",
"field",
"->",
"source",
")",
".",
"') AS '",
".",
"$",
"field",
"->",
"name",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"field",
"->",
"type",
"==",
"'image'",
")",
"{",
"$",
"rows",
"->",
"leftJoin",
"(",
"config",
"(",
"'center.db.files'",
")",
",",
"$",
"table",
"->",
"name",
".",
"'.'",
".",
"$",
"field",
"->",
"name",
",",
"'='",
",",
"config",
"(",
"'center.db.files'",
")",
".",
"'.id'",
")",
"->",
"addSelect",
"(",
"config",
"(",
"'center.db.files'",
")",
".",
"'.url AS '",
".",
"$",
"field",
"->",
"name",
".",
"'_url'",
")",
";",
"}",
"elseif",
"(",
"in_array",
"(",
"$",
"field",
"->",
"type",
",",
"[",
"'select'",
",",
"'user'",
"]",
")",
")",
"{",
"$",
"rows",
"->",
"leftJoin",
"(",
"$",
"field",
"->",
"source",
",",
"$",
"field",
"->",
"name",
",",
"'='",
",",
"$",
"field",
"->",
"source",
".",
"'.id'",
")",
"->",
"addSelect",
"(",
"$",
"field",
"->",
"source",
".",
"'.'",
".",
"self",
"::",
"listColumn",
"(",
"$",
"field",
"->",
"source",
")",
".",
"' AS '",
".",
"$",
"field",
"->",
"name",
")",
";",
"}",
"else",
"{",
"//normal, selectable field",
"$",
"rows",
"->",
"addSelect",
"(",
"$",
"table",
"->",
"name",
".",
"'.'",
".",
"$",
"field",
"->",
"name",
")",
";",
"}",
"//add to table columns",
"$",
"columns",
"[",
"]",
"=",
"$",
"field",
";",
"}",
"# Handle group-by fields",
"$",
"table",
"->",
"nested",
"=",
"false",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"table",
"->",
"group_by",
")",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"table",
"->",
"group_by",
",",
"'::'",
")",
")",
"{",
"list",
"(",
"$",
"object",
",",
"$",
"method",
")",
"=",
"explode",
"(",
"'::'",
",",
"$",
"table",
"->",
"group_by",
")",
";",
"if",
"(",
"class_exists",
"(",
"$",
"object",
")",
")",
"{",
"//call arbitrary user function",
"$",
"rows",
"=",
"call_user_func",
"(",
"$",
"table",
"->",
"group_by",
",",
"$",
"rows",
")",
";",
"}",
"}",
"else",
"{",
"$",
"grouped_table",
"=",
"config",
"(",
"'center.tables.'",
".",
"$",
"table",
"->",
"fields",
"->",
"{",
"$",
"table",
"->",
"group_by",
"}",
"->",
"source",
")",
";",
"$",
"grouped_field",
"=",
"self",
"::",
"listColumn",
"(",
"$",
"grouped_table",
"->",
"name",
")",
";",
"if",
"(",
"$",
"grouped_table",
"->",
"name",
"==",
"$",
"table",
"->",
"name",
")",
"{",
"//nested object",
"$",
"table",
"->",
"nested",
"=",
"true",
";",
"}",
"else",
"{",
"# Include group_by_field in resultset",
"foreach",
"(",
"$",
"grouped_table",
"->",
"order_by",
"as",
"$",
"order_by",
"=>",
"$",
"direction",
")",
"{",
"$",
"rows",
"->",
"orderBy",
"(",
"$",
"order_by",
",",
"$",
"direction",
")",
";",
"}",
"$",
"rows",
"->",
"leftJoin",
"(",
"$",
"grouped_table",
"->",
"name",
",",
"$",
"table",
"->",
"name",
".",
"'.'",
".",
"$",
"table",
"->",
"fields",
"->",
"{",
"$",
"table",
"->",
"group_by",
"}",
"->",
"name",
",",
"'='",
",",
"$",
"grouped_table",
"->",
"name",
".",
"'.id'",
")",
";",
"$",
"rows",
"->",
"addSelect",
"(",
"$",
"grouped_table",
"->",
"name",
".",
"'.'",
".",
"$",
"grouped_field",
".",
"' as group'",
")",
";",
"}",
"}",
"}",
"# If linked, limit scope to just the linked row",
"if",
"(",
"$",
"linked_field",
"&&",
"$",
"linked_row",
")",
"{",
"$",
"rows",
"->",
"where",
"(",
"$",
"table",
"->",
"name",
".",
"'.'",
".",
"$",
"linked_field",
",",
"$",
"linked_row",
")",
";",
"}",
"# Set the order and direction",
"foreach",
"(",
"$",
"table",
"->",
"order_by",
"as",
"$",
"order_by",
"=>",
"$",
"direction",
")",
"{",
"$",
"rows",
"->",
"orderBy",
"(",
"$",
"order_by",
",",
"$",
"direction",
")",
";",
"}",
"# Soft deletes?",
"if",
"(",
"isset",
"(",
"$",
"table",
"->",
"fields",
"->",
"deleted_at",
")",
")",
"{",
"$",
"rows",
"->",
"addSelect",
"(",
"$",
"table",
"->",
"name",
".",
"'.deleted_at'",
")",
";",
"}",
"$",
"searching",
"=",
"false",
";",
"# Text search?",
"if",
"(",
"$",
"table",
"->",
"search",
"&&",
"Request",
"::",
"has",
"(",
"'search'",
")",
")",
"{",
"$",
"searching",
"=",
"true",
";",
"$",
"rows",
"->",
"where",
"(",
"function",
"(",
"$",
"query",
")",
"use",
"(",
"$",
"table",
")",
"{",
"foreach",
"(",
"$",
"table",
"->",
"search",
"as",
"$",
"field",
")",
"{",
"$",
"query",
"->",
"orWhere",
"(",
"$",
"table",
"->",
"name",
".",
"'.'",
".",
"$",
"field",
",",
"'LIKE'",
",",
"'%'",
".",
"Request",
"::",
"input",
"(",
"'search'",
")",
".",
"'%'",
")",
";",
"}",
"}",
")",
";",
"}",
"# Filter search?",
"foreach",
"(",
"$",
"table",
"->",
"filters",
"as",
"$",
"filter",
")",
"{",
"if",
"(",
"Request",
"::",
"has",
"(",
"$",
"filter",
")",
")",
"{",
"$",
"searching",
"=",
"true",
";",
"$",
"rows",
"->",
"where",
"(",
"$",
"table",
"->",
"name",
".",
"'.'",
".",
"$",
"filter",
",",
"Request",
"::",
"input",
"(",
"$",
"filter",
")",
")",
";",
"}",
"}",
"# Run query and save it to a variable",
"$",
"rows",
"=",
"$",
"rows",
"->",
"paginate",
"(",
"50",
")",
";",
"# Set URLs on each instance",
"foreach",
"(",
"$",
"rows",
"as",
"&",
"$",
"row",
")",
"{",
"$",
"row",
"->",
"link",
"=",
"action",
"(",
"'\\LeftRight\\Center\\Controllers\\RowController@edit'",
",",
"[",
"$",
"table",
"->",
"name",
",",
"$",
"row",
"->",
"id",
",",
"$",
"linked_field",
",",
"$",
"linked_row",
"]",
")",
";",
"$",
"row",
"->",
"delete",
"=",
"action",
"(",
"'\\LeftRight\\Center\\Controllers\\RowController@delete'",
",",
"[",
"$",
"table",
"->",
"name",
",",
"$",
"row",
"->",
"id",
"]",
")",
";",
"}",
"# If it's a nested object, nest-ify the resultset",
"if",
"(",
"$",
"table",
"->",
"nested",
")",
"{",
"$",
"list",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"rows",
"as",
"&",
"$",
"row",
")",
"{",
"$",
"row",
"->",
"children",
"=",
"array",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"row",
"->",
"{",
"$",
"grouped_field",
"->",
"name",
"}",
")",
")",
"{",
"//$grouped_field->name is for ex parent_id",
"$",
"list",
"[",
"]",
"=",
"$",
"row",
";",
"}",
"elseif",
"(",
"self",
"::",
"nestedNodeExists",
"(",
"$",
"list",
",",
"$",
"row",
"->",
"{",
"$",
"grouped_field",
"->",
"name",
"}",
",",
"$",
"row",
")",
")",
"{",
"//attached child to parent node",
"}",
"else",
"{",
"//an error occurred; a parent should exist but is not yet present",
"}",
"}",
"$",
"rows",
"=",
"$",
"list",
";",
"}",
"# Search filters for the sidebar",
"$",
"filters",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"table",
"->",
"filters",
"as",
"$",
"filter",
")",
"{",
"if",
"(",
"$",
"table",
"->",
"fields",
"->",
"{",
"$",
"filter",
"}",
"->",
"type",
"==",
"'us_state'",
")",
"{",
"$",
"filters",
"[",
"$",
"filter",
"]",
"=",
"[",
"''",
"=>",
"$",
"table",
"->",
"fields",
"->",
"{",
"$",
"filter",
"}",
"->",
"title",
"]",
"+",
"trans",
"(",
"'center::site.us_states'",
")",
";",
";",
"}",
"elseif",
"(",
"$",
"table",
"->",
"fields",
"->",
"{",
"$",
"filter",
"}",
"->",
"type",
"==",
"'country'",
")",
"{",
"$",
"filters",
"[",
"$",
"filter",
"]",
"=",
"[",
"''",
"=>",
"$",
"table",
"->",
"fields",
"->",
"{",
"$",
"filter",
"}",
"->",
"title",
"]",
"+",
"trans",
"(",
"'center::site.countries'",
")",
";",
";",
"}",
"else",
"{",
"$",
"related_table",
"=",
"config",
"(",
"'center.tables.'",
".",
"$",
"table",
"->",
"fields",
"->",
"{",
"$",
"filter",
"}",
"->",
"source",
")",
";",
"$",
"options",
"=",
"DB",
"::",
"table",
"(",
"$",
"related_table",
"->",
"name",
")",
";",
"foreach",
"(",
"$",
"related_table",
"->",
"order_by",
"as",
"$",
"column",
"=>",
"$",
"direction",
")",
"{",
"$",
"options",
"->",
"orderBy",
"(",
"$",
"column",
",",
"$",
"direction",
")",
";",
"}",
"$",
"options",
"->",
"whereIn",
"(",
"'id'",
",",
"DB",
"::",
"table",
"(",
"$",
"table",
"->",
"name",
")",
"->",
"distinct",
"(",
")",
"->",
"lists",
"(",
"$",
"filter",
")",
")",
";",
"$",
"options",
"=",
"$",
"options",
"->",
"lists",
"(",
"self",
"::",
"listColumn",
"(",
"$",
"related_table",
")",
",",
"'id'",
")",
";",
"$",
"filters",
"[",
"$",
"filter",
"]",
"=",
"[",
"''",
"=>",
"$",
"related_table",
"->",
"title",
"]",
"+",
"$",
"options",
";",
"}",
"}",
"$",
"return",
"=",
"compact",
"(",
"'table'",
",",
"'columns'",
",",
"'rows'",
",",
"'filters'",
",",
"'searching'",
",",
"'linked_field'",
",",
"'linked_row'",
")",
";",
"# Return array to edit()",
"if",
"(",
"$",
"linked_field",
"&&",
"$",
"linked_row",
")",
"return",
"$",
"return",
";",
"# Return HTML view",
"return",
"view",
"(",
"'center::rows.index'",
",",
"$",
"return",
")",
";",
"}"
] | # $linked_field and $linked_row are for when coming from a linked object | [
"#",
"$linked_field",
"and",
"$linked_row",
"are",
"for",
"when",
"coming",
"from",
"a",
"linked",
"object"
] | train | https://github.com/left-right/center/blob/47c225538475ca3e87fa49f31a323b6e6bd4eff2/src/controllers/RowController.php#L32-L196 |
left-right/center | src/controllers/RowController.php | RowController.create | public function create($table, $linked_field=false, $linked_row=false) {
$tables = config('center.tables');
$table = config('center.tables.' . $table);
# Security
if (!isset($table->name)) {
return redirect()->action('\LeftRight\Center\Controllers\TableController@index')->with('error', trans('center::site.table_does_not_exist'));
}
$options = [];
# Add to return stack
Trail::manage();
foreach ($table->fields as $field) {
if (($field->type == 'checkboxes') || ($field->type == 'select')) {
//load options for checkboxes or selects
$field->options = DB::table($tables[$field->source]->name);
foreach ($tables[$field->source]->order_by as $column => $direction) {
$field->options->orderBy($column, $direction);
}
$field->options = $field->options->lists(self::listColumn($field->source), 'id');
//indent nested selects
if ($field->type == 'select' && !empty($related_object->group_by_field)) {
$grouped_field = DB::table(config('center.db.fields'))->where('id', $related_object->group_by_field)->first();
if ($grouped_field->object_id == $grouped_field->related_object_id) {
$field->options = $parents = array();
$options = DB::table($related_object->name)->orderBy($related_object->order_by, $related_object->direction)->get();
foreach ($options as $option) {
if (!empty($option->{$grouped_field->name})) {
//calculate indent
if (in_array($option->{$grouped_field->name}, $parents)) {
$parents = array_slice($parents, 0, array_search($option->{$grouped_field->name}, $parents) + 1);
} else {
$parents[] = $option->{$grouped_field->name};
}
$option->{$related_object->field->name} = str_repeat(' ', count($parents)) . $option->{$related_object->field->name};
} elseif (count($parents)) {
$parents = array();
}
$field->options[$option->id] = $option->{$related_object->field->name};
}
}
}
//select might be nullable
if ($field->type == 'select' && !$field->required) {
$field->options = [''=>''] + $field->options;
}
} elseif ($field->type == 'user') {
$field->options = DB::table(config('center.db.users'))->orderBy('name')->lists('name', 'id');
if (!$field->required) $field->options = [''=>''] + $field->options;
} elseif ($field->type == 'us_state') {
$field->options = trans('center::site.us_states');
if (!$field->required) $field->options = [''=>''] + $field->options;
} elseif ($field->type == 'country') {
$field->options = trans('center::site.countries');
if (!$field->required) $field->options = [''=>''] + $field->options;
} elseif (in_array($field->type, array('image', 'images'))) {
list($field->screen_width, $field->screen_height) = FileController::getImageDimensions($field->width, $field->height);
}
}
return view('center::rows.create', compact('table', 'linked_field', 'linked_row'));
} | php | public function create($table, $linked_field=false, $linked_row=false) {
$tables = config('center.tables');
$table = config('center.tables.' . $table);
# Security
if (!isset($table->name)) {
return redirect()->action('\LeftRight\Center\Controllers\TableController@index')->with('error', trans('center::site.table_does_not_exist'));
}
$options = [];
# Add to return stack
Trail::manage();
foreach ($table->fields as $field) {
if (($field->type == 'checkboxes') || ($field->type == 'select')) {
//load options for checkboxes or selects
$field->options = DB::table($tables[$field->source]->name);
foreach ($tables[$field->source]->order_by as $column => $direction) {
$field->options->orderBy($column, $direction);
}
$field->options = $field->options->lists(self::listColumn($field->source), 'id');
//indent nested selects
if ($field->type == 'select' && !empty($related_object->group_by_field)) {
$grouped_field = DB::table(config('center.db.fields'))->where('id', $related_object->group_by_field)->first();
if ($grouped_field->object_id == $grouped_field->related_object_id) {
$field->options = $parents = array();
$options = DB::table($related_object->name)->orderBy($related_object->order_by, $related_object->direction)->get();
foreach ($options as $option) {
if (!empty($option->{$grouped_field->name})) {
//calculate indent
if (in_array($option->{$grouped_field->name}, $parents)) {
$parents = array_slice($parents, 0, array_search($option->{$grouped_field->name}, $parents) + 1);
} else {
$parents[] = $option->{$grouped_field->name};
}
$option->{$related_object->field->name} = str_repeat(' ', count($parents)) . $option->{$related_object->field->name};
} elseif (count($parents)) {
$parents = array();
}
$field->options[$option->id] = $option->{$related_object->field->name};
}
}
}
//select might be nullable
if ($field->type == 'select' && !$field->required) {
$field->options = [''=>''] + $field->options;
}
} elseif ($field->type == 'user') {
$field->options = DB::table(config('center.db.users'))->orderBy('name')->lists('name', 'id');
if (!$field->required) $field->options = [''=>''] + $field->options;
} elseif ($field->type == 'us_state') {
$field->options = trans('center::site.us_states');
if (!$field->required) $field->options = [''=>''] + $field->options;
} elseif ($field->type == 'country') {
$field->options = trans('center::site.countries');
if (!$field->required) $field->options = [''=>''] + $field->options;
} elseif (in_array($field->type, array('image', 'images'))) {
list($field->screen_width, $field->screen_height) = FileController::getImageDimensions($field->width, $field->height);
}
}
return view('center::rows.create', compact('table', 'linked_field', 'linked_row'));
} | [
"public",
"function",
"create",
"(",
"$",
"table",
",",
"$",
"linked_field",
"=",
"false",
",",
"$",
"linked_row",
"=",
"false",
")",
"{",
"$",
"tables",
"=",
"config",
"(",
"'center.tables'",
")",
";",
"$",
"table",
"=",
"config",
"(",
"'center.tables.'",
".",
"$",
"table",
")",
";",
"# Security",
"if",
"(",
"!",
"isset",
"(",
"$",
"table",
"->",
"name",
")",
")",
"{",
"return",
"redirect",
"(",
")",
"->",
"action",
"(",
"'\\LeftRight\\Center\\Controllers\\TableController@index'",
")",
"->",
"with",
"(",
"'error'",
",",
"trans",
"(",
"'center::site.table_does_not_exist'",
")",
")",
";",
"}",
"$",
"options",
"=",
"[",
"]",
";",
"# Add to return stack",
"Trail",
"::",
"manage",
"(",
")",
";",
"foreach",
"(",
"$",
"table",
"->",
"fields",
"as",
"$",
"field",
")",
"{",
"if",
"(",
"(",
"$",
"field",
"->",
"type",
"==",
"'checkboxes'",
")",
"||",
"(",
"$",
"field",
"->",
"type",
"==",
"'select'",
")",
")",
"{",
"//load options for checkboxes or selects",
"$",
"field",
"->",
"options",
"=",
"DB",
"::",
"table",
"(",
"$",
"tables",
"[",
"$",
"field",
"->",
"source",
"]",
"->",
"name",
")",
";",
"foreach",
"(",
"$",
"tables",
"[",
"$",
"field",
"->",
"source",
"]",
"->",
"order_by",
"as",
"$",
"column",
"=>",
"$",
"direction",
")",
"{",
"$",
"field",
"->",
"options",
"->",
"orderBy",
"(",
"$",
"column",
",",
"$",
"direction",
")",
";",
"}",
"$",
"field",
"->",
"options",
"=",
"$",
"field",
"->",
"options",
"->",
"lists",
"(",
"self",
"::",
"listColumn",
"(",
"$",
"field",
"->",
"source",
")",
",",
"'id'",
")",
";",
"//indent nested selects",
"if",
"(",
"$",
"field",
"->",
"type",
"==",
"'select'",
"&&",
"!",
"empty",
"(",
"$",
"related_object",
"->",
"group_by_field",
")",
")",
"{",
"$",
"grouped_field",
"=",
"DB",
"::",
"table",
"(",
"config",
"(",
"'center.db.fields'",
")",
")",
"->",
"where",
"(",
"'id'",
",",
"$",
"related_object",
"->",
"group_by_field",
")",
"->",
"first",
"(",
")",
";",
"if",
"(",
"$",
"grouped_field",
"->",
"object_id",
"==",
"$",
"grouped_field",
"->",
"related_object_id",
")",
"{",
"$",
"field",
"->",
"options",
"=",
"$",
"parents",
"=",
"array",
"(",
")",
";",
"$",
"options",
"=",
"DB",
"::",
"table",
"(",
"$",
"related_object",
"->",
"name",
")",
"->",
"orderBy",
"(",
"$",
"related_object",
"->",
"order_by",
",",
"$",
"related_object",
"->",
"direction",
")",
"->",
"get",
"(",
")",
";",
"foreach",
"(",
"$",
"options",
"as",
"$",
"option",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"option",
"->",
"{",
"$",
"grouped_field",
"->",
"name",
"}",
")",
")",
"{",
"//calculate indent",
"if",
"(",
"in_array",
"(",
"$",
"option",
"->",
"{",
"$",
"grouped_field",
"->",
"name",
"}",
",",
"$",
"parents",
")",
")",
"{",
"$",
"parents",
"=",
"array_slice",
"(",
"$",
"parents",
",",
"0",
",",
"array_search",
"(",
"$",
"option",
"->",
"{",
"$",
"grouped_field",
"->",
"name",
"}",
",",
"$",
"parents",
")",
"+",
"1",
")",
";",
"}",
"else",
"{",
"$",
"parents",
"[",
"]",
"=",
"$",
"option",
"->",
"{",
"$",
"grouped_field",
"->",
"name",
"}",
";",
"}",
"$",
"option",
"->",
"{",
"$",
"related_object",
"->",
"field",
"->",
"name",
"}",
"=",
"str_repeat",
"(",
"' '",
",",
"count",
"(",
"$",
"parents",
")",
")",
".",
"$",
"option",
"->",
"{",
"$",
"related_object",
"->",
"field",
"->",
"name",
"}",
";",
"}",
"elseif",
"(",
"count",
"(",
"$",
"parents",
")",
")",
"{",
"$",
"parents",
"=",
"array",
"(",
")",
";",
"}",
"$",
"field",
"->",
"options",
"[",
"$",
"option",
"->",
"id",
"]",
"=",
"$",
"option",
"->",
"{",
"$",
"related_object",
"->",
"field",
"->",
"name",
"}",
";",
"}",
"}",
"}",
"//select might be nullable",
"if",
"(",
"$",
"field",
"->",
"type",
"==",
"'select'",
"&&",
"!",
"$",
"field",
"->",
"required",
")",
"{",
"$",
"field",
"->",
"options",
"=",
"[",
"''",
"=>",
"''",
"]",
"+",
"$",
"field",
"->",
"options",
";",
"}",
"}",
"elseif",
"(",
"$",
"field",
"->",
"type",
"==",
"'user'",
")",
"{",
"$",
"field",
"->",
"options",
"=",
"DB",
"::",
"table",
"(",
"config",
"(",
"'center.db.users'",
")",
")",
"->",
"orderBy",
"(",
"'name'",
")",
"->",
"lists",
"(",
"'name'",
",",
"'id'",
")",
";",
"if",
"(",
"!",
"$",
"field",
"->",
"required",
")",
"$",
"field",
"->",
"options",
"=",
"[",
"''",
"=>",
"''",
"]",
"+",
"$",
"field",
"->",
"options",
";",
"}",
"elseif",
"(",
"$",
"field",
"->",
"type",
"==",
"'us_state'",
")",
"{",
"$",
"field",
"->",
"options",
"=",
"trans",
"(",
"'center::site.us_states'",
")",
";",
"if",
"(",
"!",
"$",
"field",
"->",
"required",
")",
"$",
"field",
"->",
"options",
"=",
"[",
"''",
"=>",
"''",
"]",
"+",
"$",
"field",
"->",
"options",
";",
"}",
"elseif",
"(",
"$",
"field",
"->",
"type",
"==",
"'country'",
")",
"{",
"$",
"field",
"->",
"options",
"=",
"trans",
"(",
"'center::site.countries'",
")",
";",
"if",
"(",
"!",
"$",
"field",
"->",
"required",
")",
"$",
"field",
"->",
"options",
"=",
"[",
"''",
"=>",
"''",
"]",
"+",
"$",
"field",
"->",
"options",
";",
"}",
"elseif",
"(",
"in_array",
"(",
"$",
"field",
"->",
"type",
",",
"array",
"(",
"'image'",
",",
"'images'",
")",
")",
")",
"{",
"list",
"(",
"$",
"field",
"->",
"screen_width",
",",
"$",
"field",
"->",
"screen_height",
")",
"=",
"FileController",
"::",
"getImageDimensions",
"(",
"$",
"field",
"->",
"width",
",",
"$",
"field",
"->",
"height",
")",
";",
"}",
"}",
"return",
"view",
"(",
"'center::rows.create'",
",",
"compact",
"(",
"'table'",
",",
"'linked_field'",
",",
"'linked_row'",
")",
")",
";",
"}"
] | show create form for an object instance | [
"show",
"create",
"form",
"for",
"an",
"object",
"instance"
] | train | https://github.com/left-right/center/blob/47c225538475ca3e87fa49f31a323b6e6bd4eff2/src/controllers/RowController.php#L199-L265 |
left-right/center | src/controllers/RowController.php | RowController.store | public function store($table) {
$table = config('center.tables.' . $table);
# Security
if (!isset($table->name)) {
return redirect()->action('\LeftRight\Center\Controllers\TableController@index')->with('error', trans('center::site.table_does_not_exist'));
}
$inserts = self::processColumnsInput($table);
/*validate
$v = Validator::make(Request::all(), [
'email' => 'required|unique:users|max:255',
]);
if ($v->fails()) {
return redirect()->back()->withInput()->withErrors($v->errors());
}*/
//if users table, sent invitation
if ($table->name == config('center.db.users')) {
$password = Str::random(12);
$inserts['password'] = Hash::make($password);
$email = $inserts['email'];
$link = action('\LeftRight\Center\Controllers\TableController@index');
Mail::send('center::emails.welcome', ['email'=>$email, 'password'=>$password, 'link'=>$link], function($message) use ($email) {
$message->to($email)->subject(trans('center::site.welcome_email_subject'));
});
}
//run insert
try {
$row_id = DB::table($table->name)->insertGetId($inserts);
} catch (Exception $e) {
return redirect()->back()->withInput()->with('error', $e->getMessage());
}
//handle any checkboxes, had to wait for row_id
self::processRelationsInput($table, $row_id);
//clean up any abandoned files
FileController::cleanup();
//return to last line in stack or object index
return redirect(Trail::last(action('\LeftRight\Center\Controllers\RowController@index', $table->name)));
} | php | public function store($table) {
$table = config('center.tables.' . $table);
# Security
if (!isset($table->name)) {
return redirect()->action('\LeftRight\Center\Controllers\TableController@index')->with('error', trans('center::site.table_does_not_exist'));
}
$inserts = self::processColumnsInput($table);
/*validate
$v = Validator::make(Request::all(), [
'email' => 'required|unique:users|max:255',
]);
if ($v->fails()) {
return redirect()->back()->withInput()->withErrors($v->errors());
}*/
//if users table, sent invitation
if ($table->name == config('center.db.users')) {
$password = Str::random(12);
$inserts['password'] = Hash::make($password);
$email = $inserts['email'];
$link = action('\LeftRight\Center\Controllers\TableController@index');
Mail::send('center::emails.welcome', ['email'=>$email, 'password'=>$password, 'link'=>$link], function($message) use ($email) {
$message->to($email)->subject(trans('center::site.welcome_email_subject'));
});
}
//run insert
try {
$row_id = DB::table($table->name)->insertGetId($inserts);
} catch (Exception $e) {
return redirect()->back()->withInput()->with('error', $e->getMessage());
}
//handle any checkboxes, had to wait for row_id
self::processRelationsInput($table, $row_id);
//clean up any abandoned files
FileController::cleanup();
//return to last line in stack or object index
return redirect(Trail::last(action('\LeftRight\Center\Controllers\RowController@index', $table->name)));
} | [
"public",
"function",
"store",
"(",
"$",
"table",
")",
"{",
"$",
"table",
"=",
"config",
"(",
"'center.tables.'",
".",
"$",
"table",
")",
";",
"# Security",
"if",
"(",
"!",
"isset",
"(",
"$",
"table",
"->",
"name",
")",
")",
"{",
"return",
"redirect",
"(",
")",
"->",
"action",
"(",
"'\\LeftRight\\Center\\Controllers\\TableController@index'",
")",
"->",
"with",
"(",
"'error'",
",",
"trans",
"(",
"'center::site.table_does_not_exist'",
")",
")",
";",
"}",
"$",
"inserts",
"=",
"self",
"::",
"processColumnsInput",
"(",
"$",
"table",
")",
";",
"/*validate\n\t\t$v = Validator::make(Request::all(), [\n\t\t 'email' => 'required|unique:users|max:255',\n\t\t]);\n\t\t\n\t\tif ($v->fails()) {\n\t\t return redirect()->back()->withInput()->withErrors($v->errors());\n\t\t}*/",
"//if users table, sent invitation",
"if",
"(",
"$",
"table",
"->",
"name",
"==",
"config",
"(",
"'center.db.users'",
")",
")",
"{",
"$",
"password",
"=",
"Str",
"::",
"random",
"(",
"12",
")",
";",
"$",
"inserts",
"[",
"'password'",
"]",
"=",
"Hash",
"::",
"make",
"(",
"$",
"password",
")",
";",
"$",
"email",
"=",
"$",
"inserts",
"[",
"'email'",
"]",
";",
"$",
"link",
"=",
"action",
"(",
"'\\LeftRight\\Center\\Controllers\\TableController@index'",
")",
";",
"Mail",
"::",
"send",
"(",
"'center::emails.welcome'",
",",
"[",
"'email'",
"=>",
"$",
"email",
",",
"'password'",
"=>",
"$",
"password",
",",
"'link'",
"=>",
"$",
"link",
"]",
",",
"function",
"(",
"$",
"message",
")",
"use",
"(",
"$",
"email",
")",
"{",
"$",
"message",
"->",
"to",
"(",
"$",
"email",
")",
"->",
"subject",
"(",
"trans",
"(",
"'center::site.welcome_email_subject'",
")",
")",
";",
"}",
")",
";",
"}",
"//run insert",
"try",
"{",
"$",
"row_id",
"=",
"DB",
"::",
"table",
"(",
"$",
"table",
"->",
"name",
")",
"->",
"insertGetId",
"(",
"$",
"inserts",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"return",
"redirect",
"(",
")",
"->",
"back",
"(",
")",
"->",
"withInput",
"(",
")",
"->",
"with",
"(",
"'error'",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"//handle any checkboxes, had to wait for row_id",
"self",
"::",
"processRelationsInput",
"(",
"$",
"table",
",",
"$",
"row_id",
")",
";",
"//clean up any abandoned files",
"FileController",
"::",
"cleanup",
"(",
")",
";",
"//return to last line in stack or object index",
"return",
"redirect",
"(",
"Trail",
"::",
"last",
"(",
"action",
"(",
"'\\LeftRight\\Center\\Controllers\\RowController@index'",
",",
"$",
"table",
"->",
"name",
")",
")",
")",
";",
"}"
] | save a new object instance to the database | [
"save",
"a",
"new",
"object",
"instance",
"to",
"the",
"database"
] | train | https://github.com/left-right/center/blob/47c225538475ca3e87fa49f31a323b6e6bd4eff2/src/controllers/RowController.php#L268-L313 |
left-right/center | src/controllers/RowController.php | RowController.edit | public function edit($table, $row_id, $linked_field=false, $linked_row=false) {
# Get object / field / whatever infoz
$table = config('center.tables.' . $table);
$tables = config('center.tables');
# Security
if (!isset($table->name)) {
return redirect()->action('\LeftRight\Center\Controllers\TableController@index')->with('error', trans('center::site.table_does_not_exist'));
}
# Retrieve instance/row values
$row = DB::table($table->name)->where('id', $row_id)->first();
# Add to return stack
Trail::manage();
# Format instance values for form
foreach ($table->fields as $field) {
if ($field->type == 'datetime') {
if (!empty($row->{$field->name})) $row->{$field->name} = date('m/d/Y h:i A', strtotime($row->{$field->name}));
} elseif (($field->type == 'checkboxes') || ($field->type == 'select')) {
//load options for checkboxes or selects
$field->options = DB::table($tables[$field->source]->name);
foreach ($tables[$field->source]->order_by as $order_by=>$direction) {
$field->options->orderBy($order_by, $direction);
}
$field->options = $field->options->lists(self::listColumn($field->source), 'id');
//indent nested selects
if ($field->type == 'select' && !empty($related_object->group_by_field)) {
$grouped_field = DB::table(config('center.db.fields'))->where('id', $related_object->group_by_field)->first();
if ($grouped_field->object_id == $grouped_field->related_object_id) {
$field->options = $parents = array();
$options = DB::table($related_object->name)->orderBy($related_object->order_by, $related_object->direction)->get();
foreach ($options as $option) {
if (!empty($option->{$grouped_field->name})) {
//calculate indent
if (in_array($option->{$grouped_field->name}, $parents)) {
$parents = array_slice($parents, 0, array_search($option->{$grouped_field->name}, $parents) + 1);
} else {
$parents[] = $option->{$grouped_field->name};
}
$option->{$related_object->field->name} = str_repeat(' ', count($parents)) . $option->{$related_object->field->name};
} elseif (count($parents)) {
$parents = array();
}
$field->options[$option->id] = $option->{$related_object->field->name};
}
}
}
//select might be nullable
if ($field->type == 'select' && !$field->required) {
$field->options = [''=>''] + $field->options;
}
//get checkbox values todo make a function for consistently getting these checkbox column names
if ($field->type == 'checkboxes') {
$table_key = self::formatKeyColumn($table->name);
$foreign_key = self::formatKeyColumn($field->source);
$row->{$field->name} = DB::table($field->name)->where($table_key, $row->id)->lists($foreign_key);
}
} elseif ($field->type == 'image') {
$row->{$field->name} = DB::table(config('center.db.files'))->where('id', $row->{$field->name})->first();
if (!empty($row->{$field->name}->width) && !empty($row->{$field->name}->height)) {
$field->width = $row->{$field->name}->width;
$field->height = $row->{$field->name}->height;
}
list($field->screen_width, $field->screen_height) = FileController::getImageDimensions($field->width, $field->height);
} elseif ($field->type == 'images') {
$row->{$field->name} = DB::table(config('center.db.files'))->where('field_id', $field->id)->where('instance_id', $row->id)->orderBy('precedence', 'asc')->get();
foreach ($row->{$field->name} as &$image) {
if (!empty($image->width) && !empty($image->height)) {
$image->screen_width = $image->width;
$image->screen_width = $image->height;
}
}
list($field->screen_width, $field->screen_height) = FileController::getImageDimensions($field->width, $field->height);
} elseif ($field->type == 'slug') {
if ($field->required && empty($row->{$field->name}) && $field->related_field_id) {
//slugify related field to populate this one
foreach ($fields as $related_field) {
if ($related_field->id == $field->related_field_id) {
$row->{$field->name} = Str::slug($row->{$related_field->name});
}
}
}
} elseif ($field->type == 'user') {
$field->options = DB::table(config('center.db.users'))->orderBy('name')->lists('name', 'id');
if (!$field->required) $field->options = [''=>''] + $field->options;
} elseif ($field->type == 'us_state') {
$field->options = trans('center::site.us_states');
if (!$field->required) $field->options = [''=>''] + $field->options;
} elseif ($field->type == 'country') {
$field->options = trans('center::site.countries');
if (!$field->required) $field->options = [''=>''] + $field->options;
}
}
// Get linked objects
$links = [];
foreach ($table->links as $table_name => $field_name) {
if ($linked_array = self::index($table_name, $field_name, $row_id)) $links[] = $linked_array;
}
return view('center::rows.edit', compact('table', 'row', 'links', 'linked_field', 'linked_row'));
} | php | public function edit($table, $row_id, $linked_field=false, $linked_row=false) {
# Get object / field / whatever infoz
$table = config('center.tables.' . $table);
$tables = config('center.tables');
# Security
if (!isset($table->name)) {
return redirect()->action('\LeftRight\Center\Controllers\TableController@index')->with('error', trans('center::site.table_does_not_exist'));
}
# Retrieve instance/row values
$row = DB::table($table->name)->where('id', $row_id)->first();
# Add to return stack
Trail::manage();
# Format instance values for form
foreach ($table->fields as $field) {
if ($field->type == 'datetime') {
if (!empty($row->{$field->name})) $row->{$field->name} = date('m/d/Y h:i A', strtotime($row->{$field->name}));
} elseif (($field->type == 'checkboxes') || ($field->type == 'select')) {
//load options for checkboxes or selects
$field->options = DB::table($tables[$field->source]->name);
foreach ($tables[$field->source]->order_by as $order_by=>$direction) {
$field->options->orderBy($order_by, $direction);
}
$field->options = $field->options->lists(self::listColumn($field->source), 'id');
//indent nested selects
if ($field->type == 'select' && !empty($related_object->group_by_field)) {
$grouped_field = DB::table(config('center.db.fields'))->where('id', $related_object->group_by_field)->first();
if ($grouped_field->object_id == $grouped_field->related_object_id) {
$field->options = $parents = array();
$options = DB::table($related_object->name)->orderBy($related_object->order_by, $related_object->direction)->get();
foreach ($options as $option) {
if (!empty($option->{$grouped_field->name})) {
//calculate indent
if (in_array($option->{$grouped_field->name}, $parents)) {
$parents = array_slice($parents, 0, array_search($option->{$grouped_field->name}, $parents) + 1);
} else {
$parents[] = $option->{$grouped_field->name};
}
$option->{$related_object->field->name} = str_repeat(' ', count($parents)) . $option->{$related_object->field->name};
} elseif (count($parents)) {
$parents = array();
}
$field->options[$option->id] = $option->{$related_object->field->name};
}
}
}
//select might be nullable
if ($field->type == 'select' && !$field->required) {
$field->options = [''=>''] + $field->options;
}
//get checkbox values todo make a function for consistently getting these checkbox column names
if ($field->type == 'checkboxes') {
$table_key = self::formatKeyColumn($table->name);
$foreign_key = self::formatKeyColumn($field->source);
$row->{$field->name} = DB::table($field->name)->where($table_key, $row->id)->lists($foreign_key);
}
} elseif ($field->type == 'image') {
$row->{$field->name} = DB::table(config('center.db.files'))->where('id', $row->{$field->name})->first();
if (!empty($row->{$field->name}->width) && !empty($row->{$field->name}->height)) {
$field->width = $row->{$field->name}->width;
$field->height = $row->{$field->name}->height;
}
list($field->screen_width, $field->screen_height) = FileController::getImageDimensions($field->width, $field->height);
} elseif ($field->type == 'images') {
$row->{$field->name} = DB::table(config('center.db.files'))->where('field_id', $field->id)->where('instance_id', $row->id)->orderBy('precedence', 'asc')->get();
foreach ($row->{$field->name} as &$image) {
if (!empty($image->width) && !empty($image->height)) {
$image->screen_width = $image->width;
$image->screen_width = $image->height;
}
}
list($field->screen_width, $field->screen_height) = FileController::getImageDimensions($field->width, $field->height);
} elseif ($field->type == 'slug') {
if ($field->required && empty($row->{$field->name}) && $field->related_field_id) {
//slugify related field to populate this one
foreach ($fields as $related_field) {
if ($related_field->id == $field->related_field_id) {
$row->{$field->name} = Str::slug($row->{$related_field->name});
}
}
}
} elseif ($field->type == 'user') {
$field->options = DB::table(config('center.db.users'))->orderBy('name')->lists('name', 'id');
if (!$field->required) $field->options = [''=>''] + $field->options;
} elseif ($field->type == 'us_state') {
$field->options = trans('center::site.us_states');
if (!$field->required) $field->options = [''=>''] + $field->options;
} elseif ($field->type == 'country') {
$field->options = trans('center::site.countries');
if (!$field->required) $field->options = [''=>''] + $field->options;
}
}
// Get linked objects
$links = [];
foreach ($table->links as $table_name => $field_name) {
if ($linked_array = self::index($table_name, $field_name, $row_id)) $links[] = $linked_array;
}
return view('center::rows.edit', compact('table', 'row', 'links', 'linked_field', 'linked_row'));
} | [
"public",
"function",
"edit",
"(",
"$",
"table",
",",
"$",
"row_id",
",",
"$",
"linked_field",
"=",
"false",
",",
"$",
"linked_row",
"=",
"false",
")",
"{",
"# Get object / field / whatever infoz",
"$",
"table",
"=",
"config",
"(",
"'center.tables.'",
".",
"$",
"table",
")",
";",
"$",
"tables",
"=",
"config",
"(",
"'center.tables'",
")",
";",
"# Security",
"if",
"(",
"!",
"isset",
"(",
"$",
"table",
"->",
"name",
")",
")",
"{",
"return",
"redirect",
"(",
")",
"->",
"action",
"(",
"'\\LeftRight\\Center\\Controllers\\TableController@index'",
")",
"->",
"with",
"(",
"'error'",
",",
"trans",
"(",
"'center::site.table_does_not_exist'",
")",
")",
";",
"}",
"# Retrieve instance/row values",
"$",
"row",
"=",
"DB",
"::",
"table",
"(",
"$",
"table",
"->",
"name",
")",
"->",
"where",
"(",
"'id'",
",",
"$",
"row_id",
")",
"->",
"first",
"(",
")",
";",
"# Add to return stack",
"Trail",
"::",
"manage",
"(",
")",
";",
"# Format instance values for form",
"foreach",
"(",
"$",
"table",
"->",
"fields",
"as",
"$",
"field",
")",
"{",
"if",
"(",
"$",
"field",
"->",
"type",
"==",
"'datetime'",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"row",
"->",
"{",
"$",
"field",
"->",
"name",
"}",
")",
")",
"$",
"row",
"->",
"{",
"$",
"field",
"->",
"name",
"}",
"=",
"date",
"(",
"'m/d/Y h:i A'",
",",
"strtotime",
"(",
"$",
"row",
"->",
"{",
"$",
"field",
"->",
"name",
"}",
")",
")",
";",
"}",
"elseif",
"(",
"(",
"$",
"field",
"->",
"type",
"==",
"'checkboxes'",
")",
"||",
"(",
"$",
"field",
"->",
"type",
"==",
"'select'",
")",
")",
"{",
"//load options for checkboxes or selects",
"$",
"field",
"->",
"options",
"=",
"DB",
"::",
"table",
"(",
"$",
"tables",
"[",
"$",
"field",
"->",
"source",
"]",
"->",
"name",
")",
";",
"foreach",
"(",
"$",
"tables",
"[",
"$",
"field",
"->",
"source",
"]",
"->",
"order_by",
"as",
"$",
"order_by",
"=>",
"$",
"direction",
")",
"{",
"$",
"field",
"->",
"options",
"->",
"orderBy",
"(",
"$",
"order_by",
",",
"$",
"direction",
")",
";",
"}",
"$",
"field",
"->",
"options",
"=",
"$",
"field",
"->",
"options",
"->",
"lists",
"(",
"self",
"::",
"listColumn",
"(",
"$",
"field",
"->",
"source",
")",
",",
"'id'",
")",
";",
"//indent nested selects",
"if",
"(",
"$",
"field",
"->",
"type",
"==",
"'select'",
"&&",
"!",
"empty",
"(",
"$",
"related_object",
"->",
"group_by_field",
")",
")",
"{",
"$",
"grouped_field",
"=",
"DB",
"::",
"table",
"(",
"config",
"(",
"'center.db.fields'",
")",
")",
"->",
"where",
"(",
"'id'",
",",
"$",
"related_object",
"->",
"group_by_field",
")",
"->",
"first",
"(",
")",
";",
"if",
"(",
"$",
"grouped_field",
"->",
"object_id",
"==",
"$",
"grouped_field",
"->",
"related_object_id",
")",
"{",
"$",
"field",
"->",
"options",
"=",
"$",
"parents",
"=",
"array",
"(",
")",
";",
"$",
"options",
"=",
"DB",
"::",
"table",
"(",
"$",
"related_object",
"->",
"name",
")",
"->",
"orderBy",
"(",
"$",
"related_object",
"->",
"order_by",
",",
"$",
"related_object",
"->",
"direction",
")",
"->",
"get",
"(",
")",
";",
"foreach",
"(",
"$",
"options",
"as",
"$",
"option",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"option",
"->",
"{",
"$",
"grouped_field",
"->",
"name",
"}",
")",
")",
"{",
"//calculate indent",
"if",
"(",
"in_array",
"(",
"$",
"option",
"->",
"{",
"$",
"grouped_field",
"->",
"name",
"}",
",",
"$",
"parents",
")",
")",
"{",
"$",
"parents",
"=",
"array_slice",
"(",
"$",
"parents",
",",
"0",
",",
"array_search",
"(",
"$",
"option",
"->",
"{",
"$",
"grouped_field",
"->",
"name",
"}",
",",
"$",
"parents",
")",
"+",
"1",
")",
";",
"}",
"else",
"{",
"$",
"parents",
"[",
"]",
"=",
"$",
"option",
"->",
"{",
"$",
"grouped_field",
"->",
"name",
"}",
";",
"}",
"$",
"option",
"->",
"{",
"$",
"related_object",
"->",
"field",
"->",
"name",
"}",
"=",
"str_repeat",
"(",
"' '",
",",
"count",
"(",
"$",
"parents",
")",
")",
".",
"$",
"option",
"->",
"{",
"$",
"related_object",
"->",
"field",
"->",
"name",
"}",
";",
"}",
"elseif",
"(",
"count",
"(",
"$",
"parents",
")",
")",
"{",
"$",
"parents",
"=",
"array",
"(",
")",
";",
"}",
"$",
"field",
"->",
"options",
"[",
"$",
"option",
"->",
"id",
"]",
"=",
"$",
"option",
"->",
"{",
"$",
"related_object",
"->",
"field",
"->",
"name",
"}",
";",
"}",
"}",
"}",
"//select might be nullable",
"if",
"(",
"$",
"field",
"->",
"type",
"==",
"'select'",
"&&",
"!",
"$",
"field",
"->",
"required",
")",
"{",
"$",
"field",
"->",
"options",
"=",
"[",
"''",
"=>",
"''",
"]",
"+",
"$",
"field",
"->",
"options",
";",
"}",
"//get checkbox values todo make a function for consistently getting these checkbox column names",
"if",
"(",
"$",
"field",
"->",
"type",
"==",
"'checkboxes'",
")",
"{",
"$",
"table_key",
"=",
"self",
"::",
"formatKeyColumn",
"(",
"$",
"table",
"->",
"name",
")",
";",
"$",
"foreign_key",
"=",
"self",
"::",
"formatKeyColumn",
"(",
"$",
"field",
"->",
"source",
")",
";",
"$",
"row",
"->",
"{",
"$",
"field",
"->",
"name",
"}",
"=",
"DB",
"::",
"table",
"(",
"$",
"field",
"->",
"name",
")",
"->",
"where",
"(",
"$",
"table_key",
",",
"$",
"row",
"->",
"id",
")",
"->",
"lists",
"(",
"$",
"foreign_key",
")",
";",
"}",
"}",
"elseif",
"(",
"$",
"field",
"->",
"type",
"==",
"'image'",
")",
"{",
"$",
"row",
"->",
"{",
"$",
"field",
"->",
"name",
"}",
"=",
"DB",
"::",
"table",
"(",
"config",
"(",
"'center.db.files'",
")",
")",
"->",
"where",
"(",
"'id'",
",",
"$",
"row",
"->",
"{",
"$",
"field",
"->",
"name",
"}",
")",
"->",
"first",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"row",
"->",
"{",
"$",
"field",
"->",
"name",
"}",
"->",
"width",
")",
"&&",
"!",
"empty",
"(",
"$",
"row",
"->",
"{",
"$",
"field",
"->",
"name",
"}",
"->",
"height",
")",
")",
"{",
"$",
"field",
"->",
"width",
"=",
"$",
"row",
"->",
"{",
"$",
"field",
"->",
"name",
"}",
"->",
"width",
";",
"$",
"field",
"->",
"height",
"=",
"$",
"row",
"->",
"{",
"$",
"field",
"->",
"name",
"}",
"->",
"height",
";",
"}",
"list",
"(",
"$",
"field",
"->",
"screen_width",
",",
"$",
"field",
"->",
"screen_height",
")",
"=",
"FileController",
"::",
"getImageDimensions",
"(",
"$",
"field",
"->",
"width",
",",
"$",
"field",
"->",
"height",
")",
";",
"}",
"elseif",
"(",
"$",
"field",
"->",
"type",
"==",
"'images'",
")",
"{",
"$",
"row",
"->",
"{",
"$",
"field",
"->",
"name",
"}",
"=",
"DB",
"::",
"table",
"(",
"config",
"(",
"'center.db.files'",
")",
")",
"->",
"where",
"(",
"'field_id'",
",",
"$",
"field",
"->",
"id",
")",
"->",
"where",
"(",
"'instance_id'",
",",
"$",
"row",
"->",
"id",
")",
"->",
"orderBy",
"(",
"'precedence'",
",",
"'asc'",
")",
"->",
"get",
"(",
")",
";",
"foreach",
"(",
"$",
"row",
"->",
"{",
"$",
"field",
"->",
"name",
"}",
"as",
"&",
"$",
"image",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"image",
"->",
"width",
")",
"&&",
"!",
"empty",
"(",
"$",
"image",
"->",
"height",
")",
")",
"{",
"$",
"image",
"->",
"screen_width",
"=",
"$",
"image",
"->",
"width",
";",
"$",
"image",
"->",
"screen_width",
"=",
"$",
"image",
"->",
"height",
";",
"}",
"}",
"list",
"(",
"$",
"field",
"->",
"screen_width",
",",
"$",
"field",
"->",
"screen_height",
")",
"=",
"FileController",
"::",
"getImageDimensions",
"(",
"$",
"field",
"->",
"width",
",",
"$",
"field",
"->",
"height",
")",
";",
"}",
"elseif",
"(",
"$",
"field",
"->",
"type",
"==",
"'slug'",
")",
"{",
"if",
"(",
"$",
"field",
"->",
"required",
"&&",
"empty",
"(",
"$",
"row",
"->",
"{",
"$",
"field",
"->",
"name",
"}",
")",
"&&",
"$",
"field",
"->",
"related_field_id",
")",
"{",
"//slugify related field to populate this one",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"related_field",
")",
"{",
"if",
"(",
"$",
"related_field",
"->",
"id",
"==",
"$",
"field",
"->",
"related_field_id",
")",
"{",
"$",
"row",
"->",
"{",
"$",
"field",
"->",
"name",
"}",
"=",
"Str",
"::",
"slug",
"(",
"$",
"row",
"->",
"{",
"$",
"related_field",
"->",
"name",
"}",
")",
";",
"}",
"}",
"}",
"}",
"elseif",
"(",
"$",
"field",
"->",
"type",
"==",
"'user'",
")",
"{",
"$",
"field",
"->",
"options",
"=",
"DB",
"::",
"table",
"(",
"config",
"(",
"'center.db.users'",
")",
")",
"->",
"orderBy",
"(",
"'name'",
")",
"->",
"lists",
"(",
"'name'",
",",
"'id'",
")",
";",
"if",
"(",
"!",
"$",
"field",
"->",
"required",
")",
"$",
"field",
"->",
"options",
"=",
"[",
"''",
"=>",
"''",
"]",
"+",
"$",
"field",
"->",
"options",
";",
"}",
"elseif",
"(",
"$",
"field",
"->",
"type",
"==",
"'us_state'",
")",
"{",
"$",
"field",
"->",
"options",
"=",
"trans",
"(",
"'center::site.us_states'",
")",
";",
"if",
"(",
"!",
"$",
"field",
"->",
"required",
")",
"$",
"field",
"->",
"options",
"=",
"[",
"''",
"=>",
"''",
"]",
"+",
"$",
"field",
"->",
"options",
";",
"}",
"elseif",
"(",
"$",
"field",
"->",
"type",
"==",
"'country'",
")",
"{",
"$",
"field",
"->",
"options",
"=",
"trans",
"(",
"'center::site.countries'",
")",
";",
"if",
"(",
"!",
"$",
"field",
"->",
"required",
")",
"$",
"field",
"->",
"options",
"=",
"[",
"''",
"=>",
"''",
"]",
"+",
"$",
"field",
"->",
"options",
";",
"}",
"}",
"// Get linked objects",
"$",
"links",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"table",
"->",
"links",
"as",
"$",
"table_name",
"=>",
"$",
"field_name",
")",
"{",
"if",
"(",
"$",
"linked_array",
"=",
"self",
"::",
"index",
"(",
"$",
"table_name",
",",
"$",
"field_name",
",",
"$",
"row_id",
")",
")",
"$",
"links",
"[",
"]",
"=",
"$",
"linked_array",
";",
"}",
"return",
"view",
"(",
"'center::rows.edit'",
",",
"compact",
"(",
"'table'",
",",
"'row'",
",",
"'links'",
",",
"'linked_field'",
",",
"'linked_row'",
")",
")",
";",
"}"
] | show edit form | [
"show",
"edit",
"form"
] | train | https://github.com/left-right/center/blob/47c225538475ca3e87fa49f31a323b6e6bd4eff2/src/controllers/RowController.php#L316-L424 |
left-right/center | src/controllers/RowController.php | RowController.update | public function update($table, $row_id) {
$table = config('center.tables.' . $table);
# Security
if (!isset($table->name)) {
return redirect()->action('\LeftRight\Center\Controllers\TableController@index')->with('error', trans('center::site.table_does_not_exist'));
}
//sanitize and convert input to array
$updates = self::processColumnsInput($table, $row_id);
//run update
try {
DB::table($table->name)->where('id', $row_id)->update($updates);
} catch (Exception $e) {
return redirect()->back()->withInput()->with('error', $e->getMessage());
}
//relations
self::processRelationsInput($table, $row_id);
//clean up abandoned files
FileController::cleanup();
//return to last line in stack or object index
return redirect(Trail::last(action('\LeftRight\Center\Controllers\RowController@index', $table->name)));
} | php | public function update($table, $row_id) {
$table = config('center.tables.' . $table);
# Security
if (!isset($table->name)) {
return redirect()->action('\LeftRight\Center\Controllers\TableController@index')->with('error', trans('center::site.table_does_not_exist'));
}
//sanitize and convert input to array
$updates = self::processColumnsInput($table, $row_id);
//run update
try {
DB::table($table->name)->where('id', $row_id)->update($updates);
} catch (Exception $e) {
return redirect()->back()->withInput()->with('error', $e->getMessage());
}
//relations
self::processRelationsInput($table, $row_id);
//clean up abandoned files
FileController::cleanup();
//return to last line in stack or object index
return redirect(Trail::last(action('\LeftRight\Center\Controllers\RowController@index', $table->name)));
} | [
"public",
"function",
"update",
"(",
"$",
"table",
",",
"$",
"row_id",
")",
"{",
"$",
"table",
"=",
"config",
"(",
"'center.tables.'",
".",
"$",
"table",
")",
";",
"# Security",
"if",
"(",
"!",
"isset",
"(",
"$",
"table",
"->",
"name",
")",
")",
"{",
"return",
"redirect",
"(",
")",
"->",
"action",
"(",
"'\\LeftRight\\Center\\Controllers\\TableController@index'",
")",
"->",
"with",
"(",
"'error'",
",",
"trans",
"(",
"'center::site.table_does_not_exist'",
")",
")",
";",
"}",
"//sanitize and convert input to array",
"$",
"updates",
"=",
"self",
"::",
"processColumnsInput",
"(",
"$",
"table",
",",
"$",
"row_id",
")",
";",
"//run update",
"try",
"{",
"DB",
"::",
"table",
"(",
"$",
"table",
"->",
"name",
")",
"->",
"where",
"(",
"'id'",
",",
"$",
"row_id",
")",
"->",
"update",
"(",
"$",
"updates",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"return",
"redirect",
"(",
")",
"->",
"back",
"(",
")",
"->",
"withInput",
"(",
")",
"->",
"with",
"(",
"'error'",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"//relations",
"self",
"::",
"processRelationsInput",
"(",
"$",
"table",
",",
"$",
"row_id",
")",
";",
"//clean up abandoned files",
"FileController",
"::",
"cleanup",
"(",
")",
";",
"//return to last line in stack or object index",
"return",
"redirect",
"(",
"Trail",
"::",
"last",
"(",
"action",
"(",
"'\\LeftRight\\Center\\Controllers\\RowController@index'",
",",
"$",
"table",
"->",
"name",
")",
")",
")",
";",
"}"
] | # Save edits to database | [
"#",
"Save",
"edits",
"to",
"database"
] | train | https://github.com/left-right/center/blob/47c225538475ca3e87fa49f31a323b6e6bd4eff2/src/controllers/RowController.php#L427-L453 |
left-right/center | src/controllers/RowController.php | RowController.destroy | public function destroy($table, $row_id) {
$table = config('center.tables.' . $table);
# Security
if (!isset($table->name)) {
return redirect()->action('\LeftRight\Center\Controllers\TableController@index')->with('error', trans('center::site.table_does_not_exist'));
}
DB::table($table->name)->where('id', $row_id)->delete();
return Redirect::to(Trail::last(action('\LeftRight\Center\Controllers\RowController@index', $table->name)));
} | php | public function destroy($table, $row_id) {
$table = config('center.tables.' . $table);
# Security
if (!isset($table->name)) {
return redirect()->action('\LeftRight\Center\Controllers\TableController@index')->with('error', trans('center::site.table_does_not_exist'));
}
DB::table($table->name)->where('id', $row_id)->delete();
return Redirect::to(Trail::last(action('\LeftRight\Center\Controllers\RowController@index', $table->name)));
} | [
"public",
"function",
"destroy",
"(",
"$",
"table",
",",
"$",
"row_id",
")",
"{",
"$",
"table",
"=",
"config",
"(",
"'center.tables.'",
".",
"$",
"table",
")",
";",
"# Security",
"if",
"(",
"!",
"isset",
"(",
"$",
"table",
"->",
"name",
")",
")",
"{",
"return",
"redirect",
"(",
")",
"->",
"action",
"(",
"'\\LeftRight\\Center\\Controllers\\TableController@index'",
")",
"->",
"with",
"(",
"'error'",
",",
"trans",
"(",
"'center::site.table_does_not_exist'",
")",
")",
";",
"}",
"DB",
"::",
"table",
"(",
"$",
"table",
"->",
"name",
")",
"->",
"where",
"(",
"'id'",
",",
"$",
"row_id",
")",
"->",
"delete",
"(",
")",
";",
"return",
"Redirect",
"::",
"to",
"(",
"Trail",
"::",
"last",
"(",
"action",
"(",
"'\\LeftRight\\Center\\Controllers\\RowController@index'",
",",
"$",
"table",
"->",
"name",
")",
")",
")",
";",
"}"
] | # Remove object from db - todo check for foreign key constraints | [
"#",
"Remove",
"object",
"from",
"db",
"-",
"todo",
"check",
"for",
"foreign",
"key",
"constraints"
] | train | https://github.com/left-right/center/blob/47c225538475ca3e87fa49f31a323b6e6bd4eff2/src/controllers/RowController.php#L456-L467 |
left-right/center | src/controllers/RowController.php | RowController.reorder | public function reorder($table) {
$table = config('center.tables.' . $table);
# Security
if (!isset($table->name)) {
return;
}
//determine whether nested
$table->nested = false;
if (!empty($table->group_by_field)) {
$grouped_field = DB::table(config('center.db.fields'))->where('id', $table->group_by_field)->first();
if ($grouped_field->related_object_id == $table->id) {
$table->nested = true;
}
}
if ($table->nested) {
$row_ids = explode(',', Request::input('list'));
$precedence = 1;
foreach ($row_ids as $row_id) {
if (!empty($row_id)) {
DB::table($table->name)->where('id', $row_id)->update(['precedence'=>$precedence++]);
}
}
if (Request::has('id') && Request::has('parent_id')) {
DB::table($table->name)->where('id', Request::input('id'))->update([
'parent_id'=>Request::input('parent_id'),
//updated_at, updated_by?
]);
}
return 'done reordering nested';
} else {
$rows = explode('&', Request::input('order'));
$precedence = 1;
foreach ($rows as $row) {
list($garbage, $row_id) = explode('=', $row);
if (!empty($row_id)) {
DB::table($table->name)->where('id', $row_id)->update(['precedence'=>$precedence++]);
}
}
return 'done reordering ' . Request::input('order') . ' instances, linear';
}
} | php | public function reorder($table) {
$table = config('center.tables.' . $table);
# Security
if (!isset($table->name)) {
return;
}
//determine whether nested
$table->nested = false;
if (!empty($table->group_by_field)) {
$grouped_field = DB::table(config('center.db.fields'))->where('id', $table->group_by_field)->first();
if ($grouped_field->related_object_id == $table->id) {
$table->nested = true;
}
}
if ($table->nested) {
$row_ids = explode(',', Request::input('list'));
$precedence = 1;
foreach ($row_ids as $row_id) {
if (!empty($row_id)) {
DB::table($table->name)->where('id', $row_id)->update(['precedence'=>$precedence++]);
}
}
if (Request::has('id') && Request::has('parent_id')) {
DB::table($table->name)->where('id', Request::input('id'))->update([
'parent_id'=>Request::input('parent_id'),
//updated_at, updated_by?
]);
}
return 'done reordering nested';
} else {
$rows = explode('&', Request::input('order'));
$precedence = 1;
foreach ($rows as $row) {
list($garbage, $row_id) = explode('=', $row);
if (!empty($row_id)) {
DB::table($table->name)->where('id', $row_id)->update(['precedence'=>$precedence++]);
}
}
return 'done reordering ' . Request::input('order') . ' instances, linear';
}
} | [
"public",
"function",
"reorder",
"(",
"$",
"table",
")",
"{",
"$",
"table",
"=",
"config",
"(",
"'center.tables.'",
".",
"$",
"table",
")",
";",
"# Security",
"if",
"(",
"!",
"isset",
"(",
"$",
"table",
"->",
"name",
")",
")",
"{",
"return",
";",
"}",
"//determine whether nested",
"$",
"table",
"->",
"nested",
"=",
"false",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"table",
"->",
"group_by_field",
")",
")",
"{",
"$",
"grouped_field",
"=",
"DB",
"::",
"table",
"(",
"config",
"(",
"'center.db.fields'",
")",
")",
"->",
"where",
"(",
"'id'",
",",
"$",
"table",
"->",
"group_by_field",
")",
"->",
"first",
"(",
")",
";",
"if",
"(",
"$",
"grouped_field",
"->",
"related_object_id",
"==",
"$",
"table",
"->",
"id",
")",
"{",
"$",
"table",
"->",
"nested",
"=",
"true",
";",
"}",
"}",
"if",
"(",
"$",
"table",
"->",
"nested",
")",
"{",
"$",
"row_ids",
"=",
"explode",
"(",
"','",
",",
"Request",
"::",
"input",
"(",
"'list'",
")",
")",
";",
"$",
"precedence",
"=",
"1",
";",
"foreach",
"(",
"$",
"row_ids",
"as",
"$",
"row_id",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"row_id",
")",
")",
"{",
"DB",
"::",
"table",
"(",
"$",
"table",
"->",
"name",
")",
"->",
"where",
"(",
"'id'",
",",
"$",
"row_id",
")",
"->",
"update",
"(",
"[",
"'precedence'",
"=>",
"$",
"precedence",
"++",
"]",
")",
";",
"}",
"}",
"if",
"(",
"Request",
"::",
"has",
"(",
"'id'",
")",
"&&",
"Request",
"::",
"has",
"(",
"'parent_id'",
")",
")",
"{",
"DB",
"::",
"table",
"(",
"$",
"table",
"->",
"name",
")",
"->",
"where",
"(",
"'id'",
",",
"Request",
"::",
"input",
"(",
"'id'",
")",
")",
"->",
"update",
"(",
"[",
"'parent_id'",
"=>",
"Request",
"::",
"input",
"(",
"'parent_id'",
")",
",",
"//updated_at, updated_by?",
"]",
")",
";",
"}",
"return",
"'done reordering nested'",
";",
"}",
"else",
"{",
"$",
"rows",
"=",
"explode",
"(",
"'&'",
",",
"Request",
"::",
"input",
"(",
"'order'",
")",
")",
";",
"$",
"precedence",
"=",
"1",
";",
"foreach",
"(",
"$",
"rows",
"as",
"$",
"row",
")",
"{",
"list",
"(",
"$",
"garbage",
",",
"$",
"row_id",
")",
"=",
"explode",
"(",
"'='",
",",
"$",
"row",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"row_id",
")",
")",
"{",
"DB",
"::",
"table",
"(",
"$",
"table",
"->",
"name",
")",
"->",
"where",
"(",
"'id'",
",",
"$",
"row_id",
")",
"->",
"update",
"(",
"[",
"'precedence'",
"=>",
"$",
"precedence",
"++",
"]",
")",
";",
"}",
"}",
"return",
"'done reordering '",
".",
"Request",
"::",
"input",
"(",
"'order'",
")",
".",
"' instances, linear'",
";",
"}",
"}"
] | # Reorder fields by drag-and-drop | [
"#",
"Reorder",
"fields",
"by",
"drag",
"-",
"and",
"-",
"drop"
] | train | https://github.com/left-right/center/blob/47c225538475ca3e87fa49f31a323b6e6bd4eff2/src/controllers/RowController.php#L470-L513 |
left-right/center | src/controllers/RowController.php | RowController.delete | public function delete($table, $row_id) {
$table = config('center.tables.' . $table);
# Security
if (!isset($table->name)) {
return redirect()->action('\LeftRight\Center\Controllers\TableController@index')->with('error', trans('center::site.table_does_not_exist'));
}
//toggle instance with active or inactive
$deleted_at = (Request::input('active') == 1) ? null : new DateTime;
//todo check if updated_at and updated_by exist before updating
DB::table($table->name)->where('id', $row_id)->update([
'deleted_at'=>$deleted_at,
'updated_at'=>new DateTime,
'updated_by'=>Auth::user()->id,
]);
/*update object meta
DB::table(config('center.db.objects'))->where('id', $table->id)->update(array(
'count'=>DB::table($table->name)->whereNull('deleted_at')->count(),
'updated_at'=>new DateTime,
'updated_by'=>Auth::user()->id,
));*/
$updated = DB::table($table->name)->where('id', $row_id)->value('updated_at');
return \LeftRight\Center\Libraries\Dates::relative($updated);
} | php | public function delete($table, $row_id) {
$table = config('center.tables.' . $table);
# Security
if (!isset($table->name)) {
return redirect()->action('\LeftRight\Center\Controllers\TableController@index')->with('error', trans('center::site.table_does_not_exist'));
}
//toggle instance with active or inactive
$deleted_at = (Request::input('active') == 1) ? null : new DateTime;
//todo check if updated_at and updated_by exist before updating
DB::table($table->name)->where('id', $row_id)->update([
'deleted_at'=>$deleted_at,
'updated_at'=>new DateTime,
'updated_by'=>Auth::user()->id,
]);
/*update object meta
DB::table(config('center.db.objects'))->where('id', $table->id)->update(array(
'count'=>DB::table($table->name)->whereNull('deleted_at')->count(),
'updated_at'=>new DateTime,
'updated_by'=>Auth::user()->id,
));*/
$updated = DB::table($table->name)->where('id', $row_id)->value('updated_at');
return \LeftRight\Center\Libraries\Dates::relative($updated);
} | [
"public",
"function",
"delete",
"(",
"$",
"table",
",",
"$",
"row_id",
")",
"{",
"$",
"table",
"=",
"config",
"(",
"'center.tables.'",
".",
"$",
"table",
")",
";",
"# Security",
"if",
"(",
"!",
"isset",
"(",
"$",
"table",
"->",
"name",
")",
")",
"{",
"return",
"redirect",
"(",
")",
"->",
"action",
"(",
"'\\LeftRight\\Center\\Controllers\\TableController@index'",
")",
"->",
"with",
"(",
"'error'",
",",
"trans",
"(",
"'center::site.table_does_not_exist'",
")",
")",
";",
"}",
"//toggle instance with active or inactive",
"$",
"deleted_at",
"=",
"(",
"Request",
"::",
"input",
"(",
"'active'",
")",
"==",
"1",
")",
"?",
"null",
":",
"new",
"DateTime",
";",
"//todo check if updated_at and updated_by exist before updating",
"DB",
"::",
"table",
"(",
"$",
"table",
"->",
"name",
")",
"->",
"where",
"(",
"'id'",
",",
"$",
"row_id",
")",
"->",
"update",
"(",
"[",
"'deleted_at'",
"=>",
"$",
"deleted_at",
",",
"'updated_at'",
"=>",
"new",
"DateTime",
",",
"'updated_by'",
"=>",
"Auth",
"::",
"user",
"(",
")",
"->",
"id",
",",
"]",
")",
";",
"/*update object meta\n\t\tDB::table(config('center.db.objects'))->where('id', $table->id)->update(array(\n\t\t\t'count'=>DB::table($table->name)->whereNull('deleted_at')->count(),\n\t\t\t'updated_at'=>new DateTime,\n\t\t\t'updated_by'=>Auth::user()->id,\n\t\t));*/",
"$",
"updated",
"=",
"DB",
"::",
"table",
"(",
"$",
"table",
"->",
"name",
")",
"->",
"where",
"(",
"'id'",
",",
"$",
"row_id",
")",
"->",
"value",
"(",
"'updated_at'",
")",
";",
"return",
"\\",
"LeftRight",
"\\",
"Center",
"\\",
"Libraries",
"\\",
"Dates",
"::",
"relative",
"(",
"$",
"updated",
")",
";",
"}"
] | # Soft delete | [
"#",
"Soft",
"delete"
] | train | https://github.com/left-right/center/blob/47c225538475ca3e87fa49f31a323b6e6bd4eff2/src/controllers/RowController.php#L516-L545 |
left-right/center | src/controllers/RowController.php | RowController.processColumnsInput | private static function processColumnsInput($table, $row_id=false) {
//metadata
$return = [];
if (property_exists($table->fields, 'updated_at')) $return['updated_at'] = new DateTime;
if (property_exists($table->fields, 'updated_by')) $return['updated_by'] = Auth::user()->id;
if (!$row_id) {
if (property_exists($table->fields, 'created_at')) $return['created_at'] = new DateTime;
if (property_exists($table->fields, 'created_by')) $return['created_by'] = Auth::user()->id;
if (property_exists($table->fields, 'precedence')) $return['precedence'] = DB::table($table->name)->max('precedence') + 1;
}
//loop through the fields
foreach ($table->fields as $field) {
if ($field->hidden || in_array($field->type, self::$relation_field_types)) continue;
//always trim whitespace
$return[$field->name] = trim(Request::input($field->name));
//first decide whether value is null
if ($field->type == 'checkbox') {
$return[$field->name] = !empty($return[$field->name]); //checkboxes are true or false, never null
} elseif ($field->type != 'slug' && empty($return[$field->name]) && ($return[$field->name] !== '0') && !$field->required) {
$return[$field->name] = null;
} else {
if ($field->type == 'date') {
$return[$field->name] = date('Y-m-d', strtotime($return[$field->name]));
} elseif ($field->type == 'datetime') {
$return[$field->name] = date('Y-m-d H:i:s', strtotime($return[$field->name]));
} elseif ($field->type == 'image') {
if ($row_id) {
# Unset any old file associations (will get cleaned up later)
DB::table(config('center.db.files'))
->where('table', $table->name)
->where('field', $field->name)
->where('row_id', $row_id)
->update(['row_id'=>null]);
}
} elseif ($field->type == 'phone') {
$return[$field->name] = preg_replace('/[^0-9]/', '', $return[$field->name]);
} elseif ($field->type == 'slug') {
//determine where slug is coming from
if (Request::input($field->name) !== null) { //Request::has() will return false on empty string
$value = Request::input($field->name);
} elseif (Request::has($table->fields->{$field->name}->source)) {
$value = Request::input($table->fields->{$field->name}->source);
} else {
$value = date('Y-m-d');
}
//get other values to check uniqueness
if ($row_id) {
$uniques = DB::table($table->name)->where('id', '<>', $row_id)->lists($field->name);
} else {
$uniques = DB::table($table->name)->lists($field->name);
}
//add unique, formatted slug to the insert batch
$return[$field->name] = Slug::make($value, $uniques);
} elseif ($field->type == 'time') {
$return[$field->name] = date('H:i:s', strtotime($return[$field->name]));
}
}
}
return $return;
} | php | private static function processColumnsInput($table, $row_id=false) {
//metadata
$return = [];
if (property_exists($table->fields, 'updated_at')) $return['updated_at'] = new DateTime;
if (property_exists($table->fields, 'updated_by')) $return['updated_by'] = Auth::user()->id;
if (!$row_id) {
if (property_exists($table->fields, 'created_at')) $return['created_at'] = new DateTime;
if (property_exists($table->fields, 'created_by')) $return['created_by'] = Auth::user()->id;
if (property_exists($table->fields, 'precedence')) $return['precedence'] = DB::table($table->name)->max('precedence') + 1;
}
//loop through the fields
foreach ($table->fields as $field) {
if ($field->hidden || in_array($field->type, self::$relation_field_types)) continue;
//always trim whitespace
$return[$field->name] = trim(Request::input($field->name));
//first decide whether value is null
if ($field->type == 'checkbox') {
$return[$field->name] = !empty($return[$field->name]); //checkboxes are true or false, never null
} elseif ($field->type != 'slug' && empty($return[$field->name]) && ($return[$field->name] !== '0') && !$field->required) {
$return[$field->name] = null;
} else {
if ($field->type == 'date') {
$return[$field->name] = date('Y-m-d', strtotime($return[$field->name]));
} elseif ($field->type == 'datetime') {
$return[$field->name] = date('Y-m-d H:i:s', strtotime($return[$field->name]));
} elseif ($field->type == 'image') {
if ($row_id) {
# Unset any old file associations (will get cleaned up later)
DB::table(config('center.db.files'))
->where('table', $table->name)
->where('field', $field->name)
->where('row_id', $row_id)
->update(['row_id'=>null]);
}
} elseif ($field->type == 'phone') {
$return[$field->name] = preg_replace('/[^0-9]/', '', $return[$field->name]);
} elseif ($field->type == 'slug') {
//determine where slug is coming from
if (Request::input($field->name) !== null) { //Request::has() will return false on empty string
$value = Request::input($field->name);
} elseif (Request::has($table->fields->{$field->name}->source)) {
$value = Request::input($table->fields->{$field->name}->source);
} else {
$value = date('Y-m-d');
}
//get other values to check uniqueness
if ($row_id) {
$uniques = DB::table($table->name)->where('id', '<>', $row_id)->lists($field->name);
} else {
$uniques = DB::table($table->name)->lists($field->name);
}
//add unique, formatted slug to the insert batch
$return[$field->name] = Slug::make($value, $uniques);
} elseif ($field->type == 'time') {
$return[$field->name] = date('H:i:s', strtotime($return[$field->name]));
}
}
}
return $return;
} | [
"private",
"static",
"function",
"processColumnsInput",
"(",
"$",
"table",
",",
"$",
"row_id",
"=",
"false",
")",
"{",
"//metadata",
"$",
"return",
"=",
"[",
"]",
";",
"if",
"(",
"property_exists",
"(",
"$",
"table",
"->",
"fields",
",",
"'updated_at'",
")",
")",
"$",
"return",
"[",
"'updated_at'",
"]",
"=",
"new",
"DateTime",
";",
"if",
"(",
"property_exists",
"(",
"$",
"table",
"->",
"fields",
",",
"'updated_by'",
")",
")",
"$",
"return",
"[",
"'updated_by'",
"]",
"=",
"Auth",
"::",
"user",
"(",
")",
"->",
"id",
";",
"if",
"(",
"!",
"$",
"row_id",
")",
"{",
"if",
"(",
"property_exists",
"(",
"$",
"table",
"->",
"fields",
",",
"'created_at'",
")",
")",
"$",
"return",
"[",
"'created_at'",
"]",
"=",
"new",
"DateTime",
";",
"if",
"(",
"property_exists",
"(",
"$",
"table",
"->",
"fields",
",",
"'created_by'",
")",
")",
"$",
"return",
"[",
"'created_by'",
"]",
"=",
"Auth",
"::",
"user",
"(",
")",
"->",
"id",
";",
"if",
"(",
"property_exists",
"(",
"$",
"table",
"->",
"fields",
",",
"'precedence'",
")",
")",
"$",
"return",
"[",
"'precedence'",
"]",
"=",
"DB",
"::",
"table",
"(",
"$",
"table",
"->",
"name",
")",
"->",
"max",
"(",
"'precedence'",
")",
"+",
"1",
";",
"}",
"//loop through the fields",
"foreach",
"(",
"$",
"table",
"->",
"fields",
"as",
"$",
"field",
")",
"{",
"if",
"(",
"$",
"field",
"->",
"hidden",
"||",
"in_array",
"(",
"$",
"field",
"->",
"type",
",",
"self",
"::",
"$",
"relation_field_types",
")",
")",
"continue",
";",
"//always trim whitespace",
"$",
"return",
"[",
"$",
"field",
"->",
"name",
"]",
"=",
"trim",
"(",
"Request",
"::",
"input",
"(",
"$",
"field",
"->",
"name",
")",
")",
";",
"//first decide whether value is null",
"if",
"(",
"$",
"field",
"->",
"type",
"==",
"'checkbox'",
")",
"{",
"$",
"return",
"[",
"$",
"field",
"->",
"name",
"]",
"=",
"!",
"empty",
"(",
"$",
"return",
"[",
"$",
"field",
"->",
"name",
"]",
")",
";",
"//checkboxes are true or false, never null",
"}",
"elseif",
"(",
"$",
"field",
"->",
"type",
"!=",
"'slug'",
"&&",
"empty",
"(",
"$",
"return",
"[",
"$",
"field",
"->",
"name",
"]",
")",
"&&",
"(",
"$",
"return",
"[",
"$",
"field",
"->",
"name",
"]",
"!==",
"'0'",
")",
"&&",
"!",
"$",
"field",
"->",
"required",
")",
"{",
"$",
"return",
"[",
"$",
"field",
"->",
"name",
"]",
"=",
"null",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"field",
"->",
"type",
"==",
"'date'",
")",
"{",
"$",
"return",
"[",
"$",
"field",
"->",
"name",
"]",
"=",
"date",
"(",
"'Y-m-d'",
",",
"strtotime",
"(",
"$",
"return",
"[",
"$",
"field",
"->",
"name",
"]",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"field",
"->",
"type",
"==",
"'datetime'",
")",
"{",
"$",
"return",
"[",
"$",
"field",
"->",
"name",
"]",
"=",
"date",
"(",
"'Y-m-d H:i:s'",
",",
"strtotime",
"(",
"$",
"return",
"[",
"$",
"field",
"->",
"name",
"]",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"field",
"->",
"type",
"==",
"'image'",
")",
"{",
"if",
"(",
"$",
"row_id",
")",
"{",
"# Unset any old file associations (will get cleaned up later)",
"DB",
"::",
"table",
"(",
"config",
"(",
"'center.db.files'",
")",
")",
"->",
"where",
"(",
"'table'",
",",
"$",
"table",
"->",
"name",
")",
"->",
"where",
"(",
"'field'",
",",
"$",
"field",
"->",
"name",
")",
"->",
"where",
"(",
"'row_id'",
",",
"$",
"row_id",
")",
"->",
"update",
"(",
"[",
"'row_id'",
"=>",
"null",
"]",
")",
";",
"}",
"}",
"elseif",
"(",
"$",
"field",
"->",
"type",
"==",
"'phone'",
")",
"{",
"$",
"return",
"[",
"$",
"field",
"->",
"name",
"]",
"=",
"preg_replace",
"(",
"'/[^0-9]/'",
",",
"''",
",",
"$",
"return",
"[",
"$",
"field",
"->",
"name",
"]",
")",
";",
"}",
"elseif",
"(",
"$",
"field",
"->",
"type",
"==",
"'slug'",
")",
"{",
"//determine where slug is coming from",
"if",
"(",
"Request",
"::",
"input",
"(",
"$",
"field",
"->",
"name",
")",
"!==",
"null",
")",
"{",
"//Request::has() will return false on empty string",
"$",
"value",
"=",
"Request",
"::",
"input",
"(",
"$",
"field",
"->",
"name",
")",
";",
"}",
"elseif",
"(",
"Request",
"::",
"has",
"(",
"$",
"table",
"->",
"fields",
"->",
"{",
"$",
"field",
"->",
"name",
"}",
"->",
"source",
")",
")",
"{",
"$",
"value",
"=",
"Request",
"::",
"input",
"(",
"$",
"table",
"->",
"fields",
"->",
"{",
"$",
"field",
"->",
"name",
"}",
"->",
"source",
")",
";",
"}",
"else",
"{",
"$",
"value",
"=",
"date",
"(",
"'Y-m-d'",
")",
";",
"}",
"//get other values to check uniqueness",
"if",
"(",
"$",
"row_id",
")",
"{",
"$",
"uniques",
"=",
"DB",
"::",
"table",
"(",
"$",
"table",
"->",
"name",
")",
"->",
"where",
"(",
"'id'",
",",
"'<>'",
",",
"$",
"row_id",
")",
"->",
"lists",
"(",
"$",
"field",
"->",
"name",
")",
";",
"}",
"else",
"{",
"$",
"uniques",
"=",
"DB",
"::",
"table",
"(",
"$",
"table",
"->",
"name",
")",
"->",
"lists",
"(",
"$",
"field",
"->",
"name",
")",
";",
"}",
"//add unique, formatted slug to the insert batch",
"$",
"return",
"[",
"$",
"field",
"->",
"name",
"]",
"=",
"Slug",
"::",
"make",
"(",
"$",
"value",
",",
"$",
"uniques",
")",
";",
"}",
"elseif",
"(",
"$",
"field",
"->",
"type",
"==",
"'time'",
")",
"{",
"$",
"return",
"[",
"$",
"field",
"->",
"name",
"]",
"=",
"date",
"(",
"'H:i:s'",
",",
"strtotime",
"(",
"$",
"return",
"[",
"$",
"field",
"->",
"name",
"]",
")",
")",
";",
"}",
"}",
"}",
"return",
"$",
"return",
";",
"}"
] | # Process Column Input | [
"#",
"Process",
"Column",
"Input"
] | train | https://github.com/left-right/center/blob/47c225538475ca3e87fa49f31a323b6e6bd4eff2/src/controllers/RowController.php#L548-L634 |
left-right/center | src/controllers/RowController.php | RowController.processRelationsInput | private static function processRelationsInput($table, $row_id) {
foreach ($table->fields as $field) {
if ($field->type == 'checkboxes') {
# Figure out schema
$object_column = self::formatKeyColumn($table->name);
$remote_column = self::formatKeyColumn($field->source);
# Clear old values
DB::table($field->name)->where($object_column, $row_id)->delete();
# Loop through and save all the checkboxes
if (Request::has($field->name)) {
foreach (Request::input($field->name) as $related_id) {
DB::table($field->name)->insert([
$object_column=>$row_id,
$remote_column=>$related_id,
]);
}
}
} elseif ($field->type == 'image') {
# Capture the uploaded file by setting the reverse-lookup
DB::table(config('center.db.files'))
->where('id', Request::input($field->name))
->update(['row_id'=>$row_id]);
} elseif ($field->type == 'images') {
# Unset any old file associations (will get cleaned up after this loop)
DB::table(config('center.db.files'))
->where('table', $table->name)
->where('field', $field->name)
->where('row_id', $row_id)
->update(['row_id' => null]);
# Create new associations
$file_ids = explode(',', Request::input($field->name));
$precedence = 0;
foreach ($file_ids as $file_id) {
DB::table(config('center.db.files'))
->where('id', $file_id)
->update([
'row_id' => $row_id,
'precedence' => ++$precedence,
]);
}
}
}
} | php | private static function processRelationsInput($table, $row_id) {
foreach ($table->fields as $field) {
if ($field->type == 'checkboxes') {
# Figure out schema
$object_column = self::formatKeyColumn($table->name);
$remote_column = self::formatKeyColumn($field->source);
# Clear old values
DB::table($field->name)->where($object_column, $row_id)->delete();
# Loop through and save all the checkboxes
if (Request::has($field->name)) {
foreach (Request::input($field->name) as $related_id) {
DB::table($field->name)->insert([
$object_column=>$row_id,
$remote_column=>$related_id,
]);
}
}
} elseif ($field->type == 'image') {
# Capture the uploaded file by setting the reverse-lookup
DB::table(config('center.db.files'))
->where('id', Request::input($field->name))
->update(['row_id'=>$row_id]);
} elseif ($field->type == 'images') {
# Unset any old file associations (will get cleaned up after this loop)
DB::table(config('center.db.files'))
->where('table', $table->name)
->where('field', $field->name)
->where('row_id', $row_id)
->update(['row_id' => null]);
# Create new associations
$file_ids = explode(',', Request::input($field->name));
$precedence = 0;
foreach ($file_ids as $file_id) {
DB::table(config('center.db.files'))
->where('id', $file_id)
->update([
'row_id' => $row_id,
'precedence' => ++$precedence,
]);
}
}
}
} | [
"private",
"static",
"function",
"processRelationsInput",
"(",
"$",
"table",
",",
"$",
"row_id",
")",
"{",
"foreach",
"(",
"$",
"table",
"->",
"fields",
"as",
"$",
"field",
")",
"{",
"if",
"(",
"$",
"field",
"->",
"type",
"==",
"'checkboxes'",
")",
"{",
"# Figure out schema",
"$",
"object_column",
"=",
"self",
"::",
"formatKeyColumn",
"(",
"$",
"table",
"->",
"name",
")",
";",
"$",
"remote_column",
"=",
"self",
"::",
"formatKeyColumn",
"(",
"$",
"field",
"->",
"source",
")",
";",
"# Clear old values",
"DB",
"::",
"table",
"(",
"$",
"field",
"->",
"name",
")",
"->",
"where",
"(",
"$",
"object_column",
",",
"$",
"row_id",
")",
"->",
"delete",
"(",
")",
";",
"# Loop through and save all the checkboxes",
"if",
"(",
"Request",
"::",
"has",
"(",
"$",
"field",
"->",
"name",
")",
")",
"{",
"foreach",
"(",
"Request",
"::",
"input",
"(",
"$",
"field",
"->",
"name",
")",
"as",
"$",
"related_id",
")",
"{",
"DB",
"::",
"table",
"(",
"$",
"field",
"->",
"name",
")",
"->",
"insert",
"(",
"[",
"$",
"object_column",
"=>",
"$",
"row_id",
",",
"$",
"remote_column",
"=>",
"$",
"related_id",
",",
"]",
")",
";",
"}",
"}",
"}",
"elseif",
"(",
"$",
"field",
"->",
"type",
"==",
"'image'",
")",
"{",
"# Capture the uploaded file by setting the reverse-lookup",
"DB",
"::",
"table",
"(",
"config",
"(",
"'center.db.files'",
")",
")",
"->",
"where",
"(",
"'id'",
",",
"Request",
"::",
"input",
"(",
"$",
"field",
"->",
"name",
")",
")",
"->",
"update",
"(",
"[",
"'row_id'",
"=>",
"$",
"row_id",
"]",
")",
";",
"}",
"elseif",
"(",
"$",
"field",
"->",
"type",
"==",
"'images'",
")",
"{",
"# Unset any old file associations (will get cleaned up after this loop)",
"DB",
"::",
"table",
"(",
"config",
"(",
"'center.db.files'",
")",
")",
"->",
"where",
"(",
"'table'",
",",
"$",
"table",
"->",
"name",
")",
"->",
"where",
"(",
"'field'",
",",
"$",
"field",
"->",
"name",
")",
"->",
"where",
"(",
"'row_id'",
",",
"$",
"row_id",
")",
"->",
"update",
"(",
"[",
"'row_id'",
"=>",
"null",
"]",
")",
";",
"# Create new associations",
"$",
"file_ids",
"=",
"explode",
"(",
"','",
",",
"Request",
"::",
"input",
"(",
"$",
"field",
"->",
"name",
")",
")",
";",
"$",
"precedence",
"=",
"0",
";",
"foreach",
"(",
"$",
"file_ids",
"as",
"$",
"file_id",
")",
"{",
"DB",
"::",
"table",
"(",
"config",
"(",
"'center.db.files'",
")",
")",
"->",
"where",
"(",
"'id'",
",",
"$",
"file_id",
")",
"->",
"update",
"(",
"[",
"'row_id'",
"=>",
"$",
"row_id",
",",
"'precedence'",
"=>",
"++",
"$",
"precedence",
",",
"]",
")",
";",
"}",
"}",
"}",
"}"
] | run relationship updates on input (used by store and update) | [
"run",
"relationship",
"updates",
"on",
"input",
"(",
"used",
"by",
"store",
"and",
"update",
")"
] | train | https://github.com/left-right/center/blob/47c225538475ca3e87fa49f31a323b6e6bd4eff2/src/controllers/RowController.php#L637-L689 |
left-right/center | src/controllers/RowController.php | RowController.nestedNodeExists | private function nestedNodeExists(&$array, $parent_id, $child) {
foreach ($array as &$a) {
if ($a->id == $parent_id) {
$a->children[] = $child;
return true;
} elseif (count($a->children) && self::nestedNodeExists($a->children, $parent_id, $child)) {
return true;
}
}
return false;
} | php | private function nestedNodeExists(&$array, $parent_id, $child) {
foreach ($array as &$a) {
if ($a->id == $parent_id) {
$a->children[] = $child;
return true;
} elseif (count($a->children) && self::nestedNodeExists($a->children, $parent_id, $child)) {
return true;
}
}
return false;
} | [
"private",
"function",
"nestedNodeExists",
"(",
"&",
"$",
"array",
",",
"$",
"parent_id",
",",
"$",
"child",
")",
"{",
"foreach",
"(",
"$",
"array",
"as",
"&",
"$",
"a",
")",
"{",
"if",
"(",
"$",
"a",
"->",
"id",
"==",
"$",
"parent_id",
")",
"{",
"$",
"a",
"->",
"children",
"[",
"]",
"=",
"$",
"child",
";",
"return",
"true",
";",
"}",
"elseif",
"(",
"count",
"(",
"$",
"a",
"->",
"children",
")",
"&&",
"self",
"::",
"nestedNodeExists",
"(",
"$",
"a",
"->",
"children",
",",
"$",
"parent_id",
",",
"$",
"child",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | # Recursively assemble nested tree | [
"#",
"Recursively",
"assemble",
"nested",
"tree"
] | train | https://github.com/left-right/center/blob/47c225538475ca3e87fa49f31a323b6e6bd4eff2/src/controllers/RowController.php#L692-L702 |
left-right/center | src/controllers/RowController.php | RowController.listColumn | public static function listColumn($table) {
if (is_string($table)) $table = config('center.tables.' . $table);
$fields = !empty($table->list) ? $table->list : array_keys((array) $table->fields);
foreach ($fields as $field) {
if ($table->fields->{$field}->type == 'string') return $field;
}
} | php | public static function listColumn($table) {
if (is_string($table)) $table = config('center.tables.' . $table);
$fields = !empty($table->list) ? $table->list : array_keys((array) $table->fields);
foreach ($fields as $field) {
if ($table->fields->{$field}->type == 'string') return $field;
}
} | [
"public",
"static",
"function",
"listColumn",
"(",
"$",
"table",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"table",
")",
")",
"$",
"table",
"=",
"config",
"(",
"'center.tables.'",
".",
"$",
"table",
")",
";",
"$",
"fields",
"=",
"!",
"empty",
"(",
"$",
"table",
"->",
"list",
")",
"?",
"$",
"table",
"->",
"list",
":",
"array_keys",
"(",
"(",
"array",
")",
"$",
"table",
"->",
"fields",
")",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"field",
")",
"{",
"if",
"(",
"$",
"table",
"->",
"fields",
"->",
"{",
"$",
"field",
"}",
"->",
"type",
"==",
"'string'",
")",
"return",
"$",
"field",
";",
"}",
"}"
] | get the first text field column name | [
"get",
"the",
"first",
"text",
"field",
"column",
"name"
] | train | https://github.com/left-right/center/blob/47c225538475ca3e87fa49f31a323b6e6bd4eff2/src/controllers/RowController.php#L705-L711 |
left-right/center | src/controllers/RowController.php | RowController.table | public static function table($table, $columns, $rows) {
if (count($rows)) {
$return = new Table;
$return->rows($rows);
foreach ($columns as $column) {
$return->column($column->name, $column->type, $column->title);
}
if (isset($table->fields->deleted_at)) $return->deletable();
if (array_keys($table->order_by)[0] == $table->name . '.precedence') $return->draggable(action('\LeftRight\Center\Controllers\RowController@reorder', $table->name));
if (!empty($table->group_by)) $return->groupBy('group');
return $return->draw($table->name);
}
} | php | public static function table($table, $columns, $rows) {
if (count($rows)) {
$return = new Table;
$return->rows($rows);
foreach ($columns as $column) {
$return->column($column->name, $column->type, $column->title);
}
if (isset($table->fields->deleted_at)) $return->deletable();
if (array_keys($table->order_by)[0] == $table->name . '.precedence') $return->draggable(action('\LeftRight\Center\Controllers\RowController@reorder', $table->name));
if (!empty($table->group_by)) $return->groupBy('group');
return $return->draw($table->name);
}
} | [
"public",
"static",
"function",
"table",
"(",
"$",
"table",
",",
"$",
"columns",
",",
"$",
"rows",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"rows",
")",
")",
"{",
"$",
"return",
"=",
"new",
"Table",
";",
"$",
"return",
"->",
"rows",
"(",
"$",
"rows",
")",
";",
"foreach",
"(",
"$",
"columns",
"as",
"$",
"column",
")",
"{",
"$",
"return",
"->",
"column",
"(",
"$",
"column",
"->",
"name",
",",
"$",
"column",
"->",
"type",
",",
"$",
"column",
"->",
"title",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"table",
"->",
"fields",
"->",
"deleted_at",
")",
")",
"$",
"return",
"->",
"deletable",
"(",
")",
";",
"if",
"(",
"array_keys",
"(",
"$",
"table",
"->",
"order_by",
")",
"[",
"0",
"]",
"==",
"$",
"table",
"->",
"name",
".",
"'.precedence'",
")",
"$",
"return",
"->",
"draggable",
"(",
"action",
"(",
"'\\LeftRight\\Center\\Controllers\\RowController@reorder'",
",",
"$",
"table",
"->",
"name",
")",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"table",
"->",
"group_by",
")",
")",
"$",
"return",
"->",
"groupBy",
"(",
"'group'",
")",
";",
"return",
"$",
"return",
"->",
"draw",
"(",
"$",
"table",
"->",
"name",
")",
";",
"}",
"}"
] | # Draw an instance table, used both by index and by edit > linked | [
"#",
"Draw",
"an",
"instance",
"table",
"used",
"both",
"by",
"index",
"and",
"by",
"edit",
">",
"linked"
] | train | https://github.com/left-right/center/blob/47c225538475ca3e87fa49f31a323b6e6bd4eff2/src/controllers/RowController.php#L725-L737 |
left-right/center | src/controllers/RowController.php | RowController.pdf | public static function pdf($table, $row_id) {
# Get object / field / whatever infoz
$table = config('center.tables.' . $table);
# Security
if (!isset($table->name)) {
return redirect()->action('\LeftRight\Center\Controllers\TableController@index')->with('error', trans('center::site.table_does_not_exist'));
}
# Retrieve instance/row values
$row = DB::table($table->name)->where('id', $row_id)->first();
# Output PDF to the browser
return PDF::loadView('center::rows.pdf', compact('table', 'row'))
->setPaper('letter', 'portrait')
->stream($table->name . '-' . $row->id . '.pdf');
} | php | public static function pdf($table, $row_id) {
# Get object / field / whatever infoz
$table = config('center.tables.' . $table);
# Security
if (!isset($table->name)) {
return redirect()->action('\LeftRight\Center\Controllers\TableController@index')->with('error', trans('center::site.table_does_not_exist'));
}
# Retrieve instance/row values
$row = DB::table($table->name)->where('id', $row_id)->first();
# Output PDF to the browser
return PDF::loadView('center::rows.pdf', compact('table', 'row'))
->setPaper('letter', 'portrait')
->stream($table->name . '-' . $row->id . '.pdf');
} | [
"public",
"static",
"function",
"pdf",
"(",
"$",
"table",
",",
"$",
"row_id",
")",
"{",
"# Get object / field / whatever infoz",
"$",
"table",
"=",
"config",
"(",
"'center.tables.'",
".",
"$",
"table",
")",
";",
"# Security",
"if",
"(",
"!",
"isset",
"(",
"$",
"table",
"->",
"name",
")",
")",
"{",
"return",
"redirect",
"(",
")",
"->",
"action",
"(",
"'\\LeftRight\\Center\\Controllers\\TableController@index'",
")",
"->",
"with",
"(",
"'error'",
",",
"trans",
"(",
"'center::site.table_does_not_exist'",
")",
")",
";",
"}",
"# Retrieve instance/row values",
"$",
"row",
"=",
"DB",
"::",
"table",
"(",
"$",
"table",
"->",
"name",
")",
"->",
"where",
"(",
"'id'",
",",
"$",
"row_id",
")",
"->",
"first",
"(",
")",
";",
"# Output PDF to the browser",
"return",
"PDF",
"::",
"loadView",
"(",
"'center::rows.pdf'",
",",
"compact",
"(",
"'table'",
",",
"'row'",
")",
")",
"->",
"setPaper",
"(",
"'letter'",
",",
"'portrait'",
")",
"->",
"stream",
"(",
"$",
"table",
"->",
"name",
".",
"'-'",
".",
"$",
"row",
"->",
"id",
".",
"'.pdf'",
")",
";",
"}"
] | # Display a PDF for an instance | [
"#",
"Display",
"a",
"PDF",
"for",
"an",
"instance"
] | train | https://github.com/left-right/center/blob/47c225538475ca3e87fa49f31a323b6e6bd4eff2/src/controllers/RowController.php#L740-L757 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.