diff --git a/create.php b/create.php new file mode 100644 index 0000000..b8054c1 --- /dev/null +++ b/create.php @@ -0,0 +1,78 @@ + + + + + + + + Add New Section + + + + + +
+

Add New Section

+
+
+ + +
+
+ +
+ +
+ +
+
+ + +
+ +
+
+ + + + + + + diff --git a/crud.php b/crud.php new file mode 100644 index 0000000..c91bf8b --- /dev/null +++ b/crud.php @@ -0,0 +1,47 @@ +query('SELECT * FROM sections'); + return $stmt->fetchAll(PDO::FETCH_ASSOC); +} + +function getSectionById(PDO $pdo, int $id): ?array +{ + $stmt = $pdo->prepare('SELECT * FROM sections WHERE id = ?'); + $stmt->execute([$id]); + return $stmt->fetch(PDO::FETCH_ASSOC); +} + +function createSection(PDO $pdo, string $title, string $description, string $image): bool +{ + try { + $stmt = $pdo->prepare('INSERT INTO sections (title, description, image) VALUES (?, ?, ?)'); + return $stmt->execute([$title, $description, $image]); + } catch (Exception $e) { + echo "Error while creating section: " . $e->getMessage(); + return false; + } +} + +function updateSection(PDO $pdo, int $id, string $title, string $description, string $image): bool +{ + try { + $stmt = $pdo->prepare('UPDATE sections SET title = ?, description = ?, image = ? WHERE id = ?'); + return $stmt->execute([$title, $description, $image, $id]); + } catch (Exception $e) { + echo "Error while updating section: " . $e->getMessage(); + return false; + } +} + +function deleteSection(PDO $pdo, int $id): bool +{ + try { + $stmt = $pdo->prepare('DELETE FROM sections WHERE id = ?'); + return $stmt->execute([$id]); + } catch (Exception $e) { + echo "Error while deleting section: " . $e->getMessage(); + return false; + } +} \ No newline at end of file diff --git a/css/style.css b/css/style.css new file mode 100644 index 0000000..7ad91c8 --- /dev/null +++ b/css/style.css @@ -0,0 +1,64 @@ +body { + background-color: #1b2e42; + color: white; + font-family: 'Arial', sans-serif; +} + +.container-fluid { + padding: 50px 0; +} + +#tabs-column { + background-color: #ffffff; + border-right: 1px solid #ccc; + padding: 20px; +} + +#tabs-column .nav-link { + color: #333; + font-size: 18px; + margin-bottom: 10px; + background-color: #f7f7f7; + border-radius: 5px; + text-align: left; +} + +#tabs-column .nav-link.active { + background-color: #007bff; + color: #fff; +} + +#sectionContent .content-slider { + background-color: #2ca3d9; + padding: 40px; + border-radius: 5px; +} + +#image-column img { + width: 100%; + border-radius: 5px; +} + +/* Mobile view styles */ +@media (max-width: 768px) { + #tabs-column { + background-color: transparent; + border: none; + } + + #tabs-column .nav-link { + font-size: 16px; + } + + #image-column { + display: none; + } + + .content-slider { + background-image: url('../images/mobile-background.jpg'); /* Change the background for mobile */ + background-size: cover; + background-position: center; + color: white; + } + +} \ No newline at end of file diff --git a/db_config.php b/db_config.php new file mode 100644 index 0000000..c9e2a26 --- /dev/null +++ b/db_config.php @@ -0,0 +1,14 @@ +setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); +} catch (PDOException $e) { + die("Could not connect to the database: " . $e->getMessage()); +} \ No newline at end of file diff --git a/delete.php b/delete.php new file mode 100644 index 0000000..2f67b82 --- /dev/null +++ b/delete.php @@ -0,0 +1,8 @@ + + + + + + + + + Edit Section + + + + + +
+

Edit Section

+
+
+ + +
+
+ + +
+
+ + +
+ +
+
+ + + + + + + \ No newline at end of file diff --git a/fetch_sections.php b/fetch_sections.php new file mode 100644 index 0000000..7ed72de --- /dev/null +++ b/fetch_sections.php @@ -0,0 +1,12 @@ +query($query); + +$sections = array(); +while ($row = $result->fetch_assoc()) { + $sections[] = $row; +} + +echo json_encode($sections); diff --git "a/images/DALL\302\267E 2024-09-16 09.00.20 - A colorful cartoon scene featuring a playful forest with animated animals such as a smiling bear, a dancing rabbit, and a cheerful bird singing on a t.webp" "b/images/DALL\302\267E 2024-09-16 09.00.20 - A colorful cartoon scene featuring a playful forest with animated animals such as a smiling bear, a dancing rabbit, and a cheerful bird singing on a t.webp" new file mode 100644 index 0000000..a2e68ec Binary files /dev/null and "b/images/DALL\302\267E 2024-09-16 09.00.20 - A colorful cartoon scene featuring a playful forest with animated animals such as a smiling bear, a dancing rabbit, and a cheerful bird singing on a t.webp" differ diff --git "a/images/DALL\302\267E 2024-09-16 09.00.24 - A colorful cartoon scene for a kids' song titled 'Dancing in the Jungle', featuring cheerful animals like a monkey, a tiger, and a parrot dancing in a.webp" "b/images/DALL\302\267E 2024-09-16 09.00.24 - A colorful cartoon scene for a kids' song titled 'Dancing in the Jungle', featuring cheerful animals like a monkey, a tiger, and a parrot dancing in a.webp" new file mode 100644 index 0000000..290c069 Binary files /dev/null and "b/images/DALL\302\267E 2024-09-16 09.00.24 - A colorful cartoon scene for a kids' song titled 'Dancing in the Jungle', featuring cheerful animals like a monkey, a tiger, and a parrot dancing in a.webp" differ diff --git a/images/communication-infrastructure.jpg b/images/communication-infrastructure.jpg new file mode 100644 index 0000000..4e657ed Binary files /dev/null and b/images/communication-infrastructure.jpg differ diff --git a/images/digital-learning.jpg b/images/digital-learning.jpg new file mode 100644 index 0000000..755171f Binary files /dev/null and b/images/digital-learning.jpg differ diff --git a/images/image-placeholder.jpg b/images/image-placeholder.jpg new file mode 100644 index 0000000..a8d4354 Binary files /dev/null and b/images/image-placeholder.jpg differ diff --git a/images/technology-solutions.jpg b/images/technology-solutions.jpg new file mode 100644 index 0000000..51b3b5b Binary files /dev/null and b/images/technology-solutions.jpg differ diff --git a/index.php b/index.php new file mode 100644 index 0000000..89ffdf1 --- /dev/null +++ b/index.php @@ -0,0 +1,142 @@ + PDO::ERRMODE_EXCEPTION, + PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, + PDO::ATTR_EMULATE_PREPARES => false, +]; + +try { + $pdo = new PDO($dsn, $user, $pass, $options); +} catch (PDOException $e) { + echo "Connection failed: " . $e->getMessage(); + exit; +} + +// Include CRUD operations +include 'crud.php'; + +// Fetch sections +$sections = getSections($pdo); + +// Set default values +$defaultImage = 'images/image-placeholder.jpg'; + +// Fallback for the first section +$firstSection = !empty($sections) ? $sections[0] : [ + 'title' => 'DelphianLogic in Action', + 'description' => [], // Assuming description is an array now + 'image' => $defaultImage +]; +?> + + + + + + + <?php echo htmlspecialchars($firstSection['title']); ?> + + + + + +
+ Add New Section +
+ +
+ +
+ +
+
+ + $section): ?> +
+ +
+ + +

No sections found.

+ +
+
+ +
+ <?php echo htmlspecialchars($firstSection['title']); ?> Image +
+
+
+ + + + + + + + + + diff --git a/js/script.js b/js/script.js new file mode 100644 index 0000000..34ca875 --- /dev/null +++ b/js/script.js @@ -0,0 +1,18 @@ +$('#editModal').on('show.bs.modal', function (event) { + var button = $(event.relatedTarget); // Button that triggered the modal + var id = button.data('id'); // Extract info from data-* attributes + var title = button.data('title'); + var description = button.data('description'); + var image = button.data('image'); + + // Update the modal's content + var modal = $(this); + modal.find('#editId').val(id); + modal.find('#editTitle').val(title); + modal.find('#editDescription').val(description); + if (image) { + modal.find('#editImagePreview').attr('src', image).show(); + } else { + modal.find('#editImagePreview').hide(); + } +}); diff --git a/question.md b/question.md new file mode 100644 index 0000000..b9b6c84 --- /dev/null +++ b/question.md @@ -0,0 +1,50 @@ + +# Answers to Technical Questions + +### 1. How long did you spend on the coding test? What would you add to your solution if you had more time? +I spent approximately 2-3 hours on the coding test. If I had more time, I would focus on the following enhancements: +- **Refactor Code:** Improve code modularity and readability, ensuring clean architecture with proper separation of concerns. +- **Error Handling:** Add more comprehensive error handling and edge-case coverage to ensure robustness. +- **Performance Optimization:** Fine-tune any performance bottlenecks that could arise when handling larger datasets or more complex computations. +- **Unit Tests:** Increase test coverage with more unit tests to validate edge cases and scenarios. +- **Documentation:** Add detailed comments and documentation to make the code easier to understand and maintain. + +### 2. How would you track down a performance issue in production? Have you ever had to do this? +Yes, I have had to track down performance issues in production. My approach typically involves the following steps: +- **Monitor Logs:** I would first analyze logs (using tools like ELK stack, Graylog, or Splunk) to identify unusual patterns or slow queries. +- **Profiling:** Use profiling tools such as New Relic, Blackfire, or Xdebug to pinpoint the slow sections of code, database queries, or API calls. +- **Database Optimization:** I would check database queries for inefficiencies such as missing indexes, slow joins, or large datasets causing delays. +- **Caching:** Review and optimize the use of caching layers (e.g., Redis, Memcached) to reduce unnecessary processing. +- **Load Testing:** Use load testing tools like Apache JMeter or k6 to simulate high traffic and observe where the bottlenecks appear. +- **Code Review:** Conduct code reviews to check for inefficient algorithms or resource-heavy operations. + +### 3. Please describe yourself using JSON. + +```json +{ + "name": "Full Stack Developer", + "experience": "2+ years in Laravel and Full Stack Development", + "skills": [ + "PHP", + "Laravel", + "JavaScript", + "React.js", + "Node.js", + "MySQL", + "Docker", + "Microservices" + ], + "interests": [ + "Web Development", + "API Design", + "Cloud", + "Open Source Contributions" + ], + "current_focus": "Building microservices with Docker and KrakenD", + "education": "Master of Computer Application, VIT Chennai", + "goals": [ + "Enhance microservices architecture skills", + "Explore more opportunities in full-stack development", + "Contribute to open-source projects" + ] +}