File: D:/HostingSpaces/SBogers10/momsecurity.komma.nl/database/factories/ComponentFaker.php
<?php
use App\Buttons\Models\Button;
use App\Components\Component;
use App\Components\ComponentTypes;
use App\Components\Types\FeaturedServices;
use App\Components\Types\Testimonials;
use App\Servicepoints\Models\Servicepoint;
use App\Services\Models\Service;
use App\Testimonials\Models\Testimonial;
use Illuminate\Support\Str;
use Faker\Provider\Base;
use Komma\KMS\Components\Component\ComponentSaveState;
use Komma\KMS\Components\ComponentArea\ComponentAreaService;
class ComponentFaker extends Base
{
/**
* @return ComponentSaveState
*/
private static function contentPersonalSaveState() {
/** @var Servicepoint $servicePoint */
$servicePoint = Servicepoint::inRandomOrder()->first();
$button = Button::first();
return (new ComponentSaveState())
->setId(0)
->setVersion(ComponentAreaService::SAVE_VERSION)
->setComponentTypeId(ComponentTypes::CONTENT_PERSONAL)
->setData([
"ComponentArea|dynamic_group_sections|C0|contentHeader|nl" => "Inspireren om te groeien",
"ComponentArea|dynamic_group_sections|C0|contentDescription|nl" => "<p>Van kraakhelder concept tot krachtige website: Komma realiseert totaaloplossingen voor ondernemers met groeiplannen. Wij zijn een pain-in-the-ass bij brainstormsessies, maar overdonderen je ook met nieuwe ideeën om het maximale uit je bedrijf te halen. Met onze digitale roots en een gezonde portie boerenverstand blijven we je verrassen. Nu én in de toekomst, want we zijn niet van de eenmalige avontuurtjes. Een komma is geen punt.</p>",
"ComponentArea|dynamic_group_sections|C0|contentButtons|nl" => "1",
"ComponentArea|dynamic_group_sections|C0|servicePointHeader|nl" => "Benieuwd? Neem contact op!",
"ComponentArea|dynamic_group_sections|C0|servicepoints|nl" => "".($servicePoint->id ?? "")."",
"ComponentArea|dynamic_group_sections|C0|servicePointButtons|nl" => "".($button->id ?? "").""
]);
}
/**
* @return ComponentSaveState
*/
private static function textSaveState() {
return (new ComponentSaveState())
->setId(0)
->setVersion(ComponentAreaService::SAVE_VERSION)
->setComponentTypeId(ComponentTypes::TEXT)
->setData([
"ComponentArea|dynamic_group_sections|C0|text|nl" => "<h2>Dit is een heading voor het tekst component</h2><p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Animi, aspernatur blanditiis consequuntur delectus deserunt, dolorem dolores ea enim eos et iure maxime numquam odit omnis quis quo, rerum sapiente sequi tempore voluptatibus. Aliquam consequatur cum dolore eum, exercitationem possimus provident quam quod sint soluta temporibus tenetur, veritatis. Accusamus aliquid atque eius eum molestias mollitia possimus reprehenderit! Consectetur doloremque odio quod?</p>"
]);
}
/**
* @return ComponentSaveState
*/
private static function doubleTextSaveState() {
return (new ComponentSaveState())
->setId(0)
->setVersion(ComponentAreaService::SAVE_VERSION)
->setComponentTypeId(ComponentTypes::DOUBLE_TEXT)
->setData([
"ComponentArea|dynamic_group_sections|C0|left|nl" => "<h2>Dit is de tekst voor de linkerkant.</h2><p>Asperiores est ex molestias. Accusamus architecto autem cupiditate doloremque eius itaque libero magni odio odit repellendus soluta, voluptas, voluptates voluptatum? Numquam, vero!</p>",
"ComponentArea|dynamic_group_sections|C0|right|nl" => "<h2>Dit is de tekst voor de rechterkant.</h2><p>Culpa dolorem hic ipsam magni, sapiente sunt voluptate voluptatibus. Accusamus aspernatur autem culpa doloremque dolorum laboriosam, perferendis placeat quis unde? Consectetur, corporis culpa dolore ex expedita hic ipsum itaque magnam modi molestias natus nulla officia possimus quas quia quod unde veniam veritatis?</p>"
]);
}
/**
* @return ComponentSaveState
*/
private static function imageSaveState() {
//Warning the image document does not exist. It is fake
return (new ComponentSaveState())
->setId(0)
->setVersion(ComponentAreaService::SAVE_VERSION)
->setComponentTypeId(ComponentTypes::IMAGE)
->setData([
"ComponentArea|dynamic_group_sections|C0|caption|nl" => "Onderschrift van afbeelding",
"ComponentArea|dynamic_group_sections|C0|image|nl" => "",
]);
}
/**
* @return ComponentSaveState
*/
private static function doubleImageSaveState() {
//Warning the image document does not exist. It is fake
return (new ComponentSaveState())
->setId(0)
->setVersion(ComponentAreaService::SAVE_VERSION)
->setComponentTypeId(ComponentTypes::DOUBLE_IMAGE)
->setData([
"ComponentArea|dynamic_group_sections|C0|image_one|nl" => "",
"ComponentArea|dynamic_group_sections|C0|image_two|nl" => "",
"ComponentArea|dynamic_group_sections|C0|reversed|nl" => "0"
]);
}
/**
* @return ComponentSaveState
*/
private static function videoSaveState() {
return (new ComponentSaveState())
->setId(0)
->setVersion(ComponentAreaService::SAVE_VERSION)
->setComponentTypeId(ComponentTypes::VIDEO)
->setData([
"ComponentArea|dynamic_group_sections|C0|video|nl_video_id" => "uBdfduMtaz0",
"ComponentArea|dynamic_group_sections|C0|video|nl_autoplay" => "on",
"ComponentArea|dynamic_group_sections|C0|video|nl" => "0,uBdfduMtaz0"
]);
}
/**
* @return ComponentSaveState
*/
private static function quoteSaveState() {
return (new ComponentSaveState())
->setId(0)
->setVersion(ComponentAreaService::SAVE_VERSION)
->setComponentTypeId(ComponentTypes::QUOTE)
->setData([
"ComponentArea|dynamic_group_sections|C0|text|nl" => "All my life, I always wanted to be somebody. <br>Now I see that I should have been more specific",
"ComponentArea|dynamic_group_sections|C0|title|nl" => "Jane Wagner",
"ComponentArea|dynamic_group_sections|C0|subtitle|nl" => "The Search For Intelligent Life In The Universe",
"ComponentArea|dynamic_group_sections|C0|image|nl" => "",
]);
}
/**
* @return ComponentSaveState
*/
private static function tabsSaveState() {
return (new ComponentSaveState())
->setId(0)
->setVersion(ComponentAreaService::SAVE_VERSION)
->setComponentTypeId(ComponentTypes::TABS)
->setData([
"ComponentArea|dynamic_group_sections|C0|label_1|nl" => "Praktische info",
"ComponentArea|dynamic_group_sections|C0|text_1|nl" => "<p>Phasellus consectetuer vestibulum elit. Nunc sed turpis. Cras sagittis. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos hymenaeos. Praesent porttitor, nulla vitae posuere iaculis, arcu nisl dignissim dolor, a pretium mi sem ut ipsum. Donec vitae orci sed dolor rutrum auctor. Maecenas nec odio et ante tincidunt tempus. Phasellus tempus.</p>",
"ComponentArea|dynamic_group_sections|C0|label_2|nl" => "Programma",
"ComponentArea|dynamic_group_sections|C0|text_2|nl" => "<p>Fusce vulputate eleifend sapien. Nulla consequat massa quis enim. Fusce ac felis sit amet ligula pharetra condimentum. Ut varius tincidunt libero. Pellentesque libero tortor, tincidunt et, tincidunt eget, semper nec, quam. Proin viverra, ligula sit amet ultrices semper, ligula arcu tristique sapien, a accumsan nisi mauris ac eros. Nulla porta dolor.</p>",
"ComponentArea|dynamic_group_sections|C0|label_3|nl" => "Certificaat",
"ComponentArea|dynamic_group_sections|C0|text_3|nl" => "<p>Aenean commodo ligula eget dolor. Morbi mollis tellus ac sapien. Cras varius. Nunc sed turpis. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Phasellus a est. Cras risus ipsum, faucibus ut, ullamcorper id, varius ac, leo. Phasellus volutpat, metus eget egestas mollis, lacus lacus blandit dui, id egestas quam mauris ut lacus.</p>",
"ComponentArea|dynamic_group_sections|C0|label_4|nl" => "",
"ComponentArea|dynamic_group_sections|C0|text_4|nl" => ""
]);
}
/**
* @return ComponentSaveState
*/
private static function textImageSaveState() {
return (new ComponentSaveState())
->setId(0)
->setVersion(ComponentAreaService::SAVE_VERSION)
->setComponentTypeId(ComponentTypes::TEXT_IMAGE)
->setData([
"ComponentArea|dynamic_group_sections|C0|text|nl" => "<h2>Vestibulum purus quam scelerisque ut</h2><p>Mollis sed nonummy id, metus. In auctor lobortis lacus. Fusce neque. Suspendisse enim turpis, dictum sed, iaculis a, condimentum nec, nisi. Nullam tincidunt adipiscing enim. Vestibulum volutpat pretium libero. In dui magna, posuere eget, vestibulum et, tempor auctor, justo. Vivamus elementum semper nisi. Curabitur suscipit suscipit tellus. Fusce fermentum odio nec arcu. Ut non enim eleifend felis pretium feugiat.</p>",
"ComponentArea|dynamic_group_sections|C0|image|nl" => "",
"ComponentArea|dynamic_group_sections|C0|caption|nl" => "Beautiful image",
"ComponentArea|dynamic_group_sections|C0|reversed|nl" => "1"
]);
}
/**
* @return ComponentSaveState
*/
private static function featuredServicesSaveState() {
/** @var featuredServices $services */
$featuredServicesQuery = Service::with('translation')->where('lft', '!=', 1)->take(3);
$featuredServicesIDString = $featuredServicesQuery->get()->reduce(function($carry, Service $featuredServicesQuery) {
return ($carry == null) ? (string)$featuredServicesQuery->id : $carry . ',' . $featuredServicesQuery->id;
});
$button = Button::first();
return (new ComponentSaveState())
->setId(0)
->setVersion(ComponentAreaService::SAVE_VERSION)
->setComponentTypeId(ComponentTypes::FEATURED_SERVICES)
->setData([
"ComponentArea|dynamic_group_sections|C0|featuredServicesHeader|nl" => "Geselecteerde diensten",
"ComponentArea|dynamic_group_sections|C0|featuredServices|nl" => "".($featuredServicesIDString ?? "")."",
"ComponentArea|dynamic_group_sections|C0|featuredServicesButtons|nl" => "".($button->id ?? "").""
]);
}
/**
* @return ComponentSaveState
*/
private static function testimonialsSaveState() {
/** @var testimonials $testimonials */
$testimonialsQuery = Testimonial::with('translation')->take(2);
$testimonialsIDString = $testimonialsQuery->get()->reduce(function($carry, Testimonial $testimonialsQuery) {
return ($carry == null) ? (string)$testimonialsQuery->id : $carry . ',' . $testimonialsQuery->id;
});
$button = Button::first();
return (new ComponentSaveState())
->setId(0)
->setVersion(ComponentAreaService::SAVE_VERSION)
->setComponentTypeId(ComponentTypes::TESTIMONIALS)
->setData([
"ComponentArea|dynamic_group_sections|C0|testimonialsHeader|nl" => "Hoor het van onze klanten",
"ComponentArea|dynamic_group_sections|C0|testimonials|nl" => "".($testimonialsIDString ?? "")."",
"ComponentArea|dynamic_group_sections|C0|testimonialsButtons|nl" => "".($button->id ?? "")."",
]);
}
/**
* Get a component sample
*
* @param int $componentType
* @return Component
*/
public static function componentOfType(int $componentType): Component
{
//Get sample save state for a certain component type
if(!in_array($componentType, ComponentTypes::getAsArray())) throw new InvalidArgumentException('The given component type number was not a value of the '.ComponentTypes::class.'');
$componentTypeEnumName = array_search($componentType, ComponentTypes::getAsArray(), true);
$methodName = Str::camel(strtolower($componentTypeEnumName)).'SaveState';
if(!method_exists(self::class, $methodName)) throw new RuntimeException('There must be a method called '.$methodName.'. But it did not exist.');
/** @var ComponentSaveState $saveState */
$saveState = call_user_func([self::class, $methodName]);
//Create a component and return it.
$component = new Component([
'component_area_id' => 0,
'component_type_id' => $saveState->getComponentTypeId(),
'sort_order' => 0,
'version' => $saveState->getVersion(),
'data' => json_encode($saveState->getData()),
]);
return $component;
}
}