Skip to content

Commit

Permalink
Merge pull request #2 from Jadens-arc/capsules
Browse files Browse the repository at this point in the history
rebranded to capsules
  • Loading branch information
Jadens-arc committed Feb 15, 2023
2 parents 05f3731 + a745d78 commit 2b3bf75
Show file tree
Hide file tree
Showing 14 changed files with 63 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
use Symfony\Component\Routing\Generator\UrlGenerator;
use Symfony\Component\Security\Core\User\UserInterface;

class EssayController extends AbstractController
class CapsuleController extends AbstractController
{

#[Route('/essay/share/{id}', name: 'app_share_essay')]
#[Route('/capsule/share/{id}', name: 'app_share_capsule')]
public function share(Request $request, ManagerRegistry $doctrine, $id): Response
{
$post = $doctrine->getRepository(Post::class)->findOneBy(['id' => $id]);
Expand All @@ -32,12 +32,12 @@ public function share(Request $request, ManagerRegistry $doctrine, $id): Respons
$output,
$code
);
return $this->render('essay/share.html.twig',
['post' => $filename, 'url' => $this->generateUrl("app_view_essay", ["id" => $id], UrlGenerator::ABSOLUTE_URL) ]);
return $this->render('capsule/share.html.twig',
['post' => $filename, 'url' => $this->generateUrl("app_view_capsule", ["id" => $id], UrlGenerator::ABSOLUTE_URL) ]);
}

#[Route('/essay/edit/{id}', name: 'app_new_essay')]
public function newEssay(Request $request, ManagerRegistry $doctrine, UserInterface $user, $id): Response
#[Route('/capsule/edit/{id}', name: 'app_new_capsule')]
public function newCapsule(Request $request, ManagerRegistry $doctrine, UserInterface $user, $id): Response
{
$post = new Post();
$post->setCreator($user);
Expand Down Expand Up @@ -102,10 +102,10 @@ public function newEssay(Request $request, ManagerRegistry $doctrine, UserInterf
return $this->redirectToRoute('app_embargo');
}
}
return $this->renderForm('essay/new.html.twig', ["form"=>$form]);
return $this->renderForm('capsule/new.html.twig', ["form"=>$form]);
}

#[Route('/essay/delete/{id}', name: 'app_delete_essay')]
#[Route('/capsule/delete/{id}', name: 'app_delete_capsule')]
public function delete(Request $request, ManagerRegistry $doctrine, UserInterface $user, $id): Response
{
$em = $doctrine->getManager();
Expand All @@ -129,7 +129,7 @@ public function delete(Request $request, ManagerRegistry $doctrine, UserInterfac
return $this->redirectToRoute('app_homepage');
}

#[Route('/essay/post_draft/{id}', name: 'app_essay_post_draft')]
#[Route('/capsule/post_draft/{id}', name: 'app_capsule_post_draft')]
public function postDraft(Request $request, ManagerRegistry $doctrine, UserInterface $user, $id): Response {
$em = $doctrine->getManager();
$post = $doctrine->getRepository(Post::class)->find($id);
Expand All @@ -148,22 +148,27 @@ public function postDraft(Request $request, ManagerRegistry $doctrine, UserInter
}
}

#[Route('/essay/{id}', name: 'app_view_essay')]
#[Route('/capsule/{id}', name: 'app_view_capsule')]
public function index(Request $request, ManagerRegistry $doctrine, $id): Response
{

$currentDate = new DateTime();
$currentDate->modify("-3 day");
$currentDate = $currentDate->format('Y-m-d H:i:s');

$post = $doctrine
->getManager()
->createQuery("SELECT p FROM App\Entity\Post p WHERE p.id = $id AND p.creationDate < '$currentDate'")
->getResult();
$post = $doctrine->getRepository(Post::class)
->createQueryBuilder('p')
->where('p.id = :id')
->setParameter("id", $id)
->andWhere('p.creationDate < :currentDate')
->setParameter("currentDate", $currentDate)
->getQuery()
->getResult()
;

if (!$post) {
return $this->redirect('/');
}
return $this->renderForm('essay/index.html.twig', ["post" => $post[0]]);
return $this->renderForm('capsule/index.html.twig', ["post" => $post[0]]);
}
}
31 changes: 18 additions & 13 deletions src/Controller/HomepageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,32 @@ public function index(Request $request, ManagerRegistry $doctrine): Response
$currentDate = $currentDate->format('Y-m-d H:i:s');

$searchQuery = $request->query->get('q');
$query = "SELECT p FROM App\Entity\Post p WHERE p.creationDate < '$currentDate'";
$querySort = "ORDER BY p.creationDate DESC";


$qb = $doctrine->getRepository(Post::class)
->createQueryBuilder('p');

if ($searchQuery) { // if user is searching
$rawSearch = substr($searchQuery, 1); // remove @ and #
if (strpos($searchQuery, "#") !== false) { // searching for hashtags
$query .= "AND p.tags like '%$rawSearch%' $querySort";
}elseif (strpos($searchQuery, "@") !== false) { // searching for usernames
$query .= " AND (p.content like '% $searchQuery %' OR p.creatorUsername = '$rawSearch') $querySort";
}else { // just searching by content and title
$query .= " AND (p.content like '% $searchQuery %' OR p.title like '% $searchQuery %') $querySort";
$qb->where("p.tags like :search")
->setParameter('search', $rawSearch);
} elseif (strpos($searchQuery, "@") !== false) { // searching for usernames
$qb->where("p.creator.username like :username")
->setParameter('username', $rawSearch);
} else { // just searching by content and title
$qb->where("p.content like :search")
->orWhere("p.title like :search")
->setParameter('search', "%".$searchQuery."%");
}
} else { // if user is not searching
$query .= $querySort;
}

$posts = $doctrine
->getManager()
->createQuery($query)
->getResult();
$qb->andWhere('p.creationDate < :currentDate')
->setParameter('currentDate', $currentDate)
->orderBy('p.creationDate', 'DESC')
;

$posts = $qb->getQuery()->getResult();
return $this->render('homepage/index.html.twig', ["title" => "Latest...", "posts"=>$posts]);
}

Expand Down
2 changes: 1 addition & 1 deletion templates/admin/posts.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<td>{{ row.title }}</td>
<td>{{ row.creationDate.format('Y-m-d H:i:s') }}<td>
<td>
<a class="btn btn-danger" href="{{ path('app_delete_essay', {'id': row.id}) }}">Delete</a>
<a class="btn btn-danger" href="{{ path('app_delete_capsule', {'id': row.id}) }}">Delete</a>
</td>
</tr>
{% endfor %}
Expand Down
4 changes: 2 additions & 2 deletions templates/base.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
<a class="nav-link" href="{{ path('app_subscriptions') }}">Subscriptions</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{ path('app_new_essay', {id: "new"}) }}">New Essay</a>
<a class="nav-link" href="{{ path('app_new_capsule', {id: "new"}) }}">New Capsule</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{ path('app_drafts') }}">Drafts</a>
Expand Down Expand Up @@ -90,7 +90,7 @@
<form class="d-flex" type="search" method="get" action="/">
<input
class="form-control me-2"
placeholder="Search Essays"
placeholder="Search Capsules"
id="searchInput"
name="q"
value="{{ app.request.query.get('q') }}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</div>
</div>
<div class="d-flex flex-row justify-content-between">
<a href="/essay/share/{{ post.id }}">
<a href="/capsule/share/{{ post.id }}">
<img src="/brands/instagram.svg" style="margin-left:20px; width: 1rem;" alt="">
</a>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{% extends "base.html.twig" %}
{% block title %}| New Essay{% endblock %}
{% block title %}| New Capsule{% endblock %}
{% block content %}
<h1>New Essay</h1>
<h1>New Capsule</h1>
<div class="alert alert-secondary">
<span>All essays go through a 3-day embargo. After they leave the embargo they cannot be deleted. <a
<span>All capsules go through a 3-day embargo. After they leave the embargo they cannot be deleted. <a
href="{{ path('app_about') }}">Learn more here</a></span>
</div>
{{ form_start(form) }}
Expand Down Expand Up @@ -46,7 +46,7 @@

{{ form_row(form._token) }}
{{ form_widget(form.submit, {'attr': {'class': 'btn btn-primary mb-3'}}) }}
<button id="saveToDrafts" class="btn btn-secondary mb-3" formaction="{{ path('app_new_essay', {id: "new"}) }}?isDraft=true">Save to Drafts</button>
<button id="saveToDrafts" class="btn btn-secondary mb-3" formaction="{{ path('app_new_capsule', {id: "new"}) }}?isDraft=true">Save to Drafts</button>
{{ form_end(form, {render_rest: false}) }}
{% endblock %}

Expand Down
File renamed without changes.
10 changes: 5 additions & 5 deletions templates/essays.html.twig → templates/capsules.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@
{% endif %}
{% for post in posts %}
<div class="card" id="{{ post.id }}" style="margin: 20px 0; overflow: visible">
<h6 class="card-header" style="cursor: pointer" onclick="window.location='{{ path('app_view_essay', {'id': post.id}) }}'">
<h6 class="card-header" style="cursor: pointer" onclick="window.location='{{ path('app_view_capsule', {'id': post.id}) }}'">
<div class="col-sm d-flex flex-row" style="flex-grow: 1">
{% if (app.user and is_granted('ROLE_ADMIN')) or not post.creationDate or ("-3 days"|date("Y-m-d H:i:s") < post.creationDate.format('Y-m-d H:i:s')) %}
<a href="{{ path('app_delete_essay', {'id': post.id}) }}">
<a href="{{ path('app_delete_capsule', {'id': post.id}) }}">
<img class="icon" alt="Trash can" src="{{ asset('regular/trash-can.svg') }}" style="margin-right:20px; width: 1rem;">
</a>
{% endif %}
{% if post.creationDate %}
<a href="{{ path('app_share_essay', {'id': post.id}) }}">
<a href="{{ path('app_share_capsule', {'id': post.id}) }}">
<img class="icon" alt="Instagram Logo" src="{{ asset('brands/instagram.svg') }}" style="margin-right:20px; width: 1rem;">
</a>
{% else %}
<a href="{{ path('app_essay_post_draft', {'id': post.id}) }}">
<a href="{{ path('app_capsule_post_draft', {'id': post.id}) }}">
<img class="icon" alt="share" src="{{ asset('regular/share-from-square.svg') }}" style="margin-right:20px; width: 1rem;">
</a>
<a href="{{ path('app_new_essay', {'id': post.id}) }}">
<a href="{{ path('app_new_capsule', {'id': post.id}) }}">
<img class="icon" alt="share" src="{{ asset('regular/pen-to-square.svg') }}" style="margin-right:20px; width: 1rem;">
</a>
{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion templates/embargo/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
<h3 class="text-muted text-center">Nothing yet :( Just be thoughtful about what you write</h3
{% endif %}

{% include 'essays.html.twig' %}
{% include 'capsules.html.twig' %}
{% endblock %}
2 changes: 1 addition & 1 deletion templates/homepage/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
</div>
{% endif %}
<h1>{{ title }}</h1>
{% include 'essays.html.twig' %}
{% include 'capsules.html.twig' %}
{% endblock %}
6 changes: 3 additions & 3 deletions templates/settings/about.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
<div class="mb-5 col-sm">
<h3 class="text-muted">How it Works</h3>
<p>Opium isn't a publisher, but it is a platform for you to share your own work.</p>
<p>Essays are meant to be a form of creative expression. Don't feel forced to try to prove a point.</p>
<p>Each essay you post goes through a 3-day embargo. This is an intentional choice not a technical limitation.</p>
<p>Capsules are meant to be a form of creative expression. Don't feel forced to try to prove a point.</p>
<p>Each capsule you post goes through a 3-day embargo. This is an intentional choice not a technical limitation.</p>
<p>We strongly encourage you to think through your post in that time period.</p>
<ul>
<li>Does it address everything you wanted it to</li>
Expand All @@ -41,7 +41,7 @@
<ul>
<li>Copyrighted material</li>
<li>Leaked confidential documents</li>
<li>Essays that aim to directly insight violence</li>
<li>Capsules that aim to directly insight violence</li>
<li>The other creep stuff that y’all come up with</li>
</ul>
<li>Only one account per user/entity</li>
Expand Down
2 changes: 1 addition & 1 deletion templates/user_favorites/subscriptions.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
</a>
{% endfor %}
</div>
{% include 'essays.html.twig' %}
{% include 'capsules.html.twig' %}
{% endblock %}
2 changes: 1 addition & 1 deletion templates/writer/drafts.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
{% if not posts %}
<h3 class="text-muted text-center">Nothing yet :( go write something</h3
{% endif %}
{% include 'essays.html.twig' %}
{% include 'capsules.html.twig' %}
{% endblock %}
10 changes: 5 additions & 5 deletions templates/writer/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,22 @@
<hr>
{% if not posts %}
{% if app.user and app.user.username == writer.username %}
<h3 class="text-muted text-center">No Essays :( Why don't you write something</h3>
<h3 class="text-muted text-center">No Capsules:( Why don't you write something</h3>
{% else %}
<h3 class="text-muted text-center">Who ever runs this account is antisocial</h3>
{% endif %}
{% else %}
{% if app.user and app.user.username == writer.username %}
<h2 class="h2 text-muted">Your Essays</h2>
<h2 class="h2 text-muted">Your Capsules</h2>
{% else %}
{% if writer.displayName|last == 's' %}
<h2 class="h2 text-muted">{{ writer.displayName }}' Essays</h2>
<h2 class="h2 text-muted">{{ writer.displayName }}' Capsules</h2>
{% else %}
<h2 class="h2 text-muted">{{ writer.displayName }}'s Essays</h2>
<h2 class="h2 text-muted">{{ writer.displayName }}'s Capsules</h2>
{% endif %}
{% endif %}
{% endif %}

{% include 'essays.html.twig' %}
{% include 'capsules.html.twig' %}
{% endblock %}

0 comments on commit 2b3bf75

Please sign in to comment.