File: D:/HostingSpaces/SBogers10/beat-the-barn.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 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 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;
}
}