Add related posts see BT#12723

pull/2487/head
jmontoyaa 9 years ago
parent 6fc9149c74
commit 4a3f5d0046
  1. 2
      main/cron/import_csv.php
  2. 11
      plugin/studentfollowup/Entity/CarePost.php
  3. 27
      plugin/studentfollowup/post.php
  4. 54
      plugin/studentfollowup/view/post.html.twig
  5. 4
      plugin/studentfollowup/view/posts.html.twig

@ -2141,11 +2141,9 @@ class ImportCsv
$criteria = [
'externalCareId' => $row['External_care_id']
];
var_dump($criteria);
$post = $em->getRepository('ChamiloPluginBundle:StudentFollowUp\CarePost')->findOneBy($criteria);
if (empty($post)) {
var_dump('empty');
$post = new CarePost();
}

@ -7,8 +7,14 @@ use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\ORM\Mapping as ORM;
/**
*
* CarePost
*
* When installing the plugin, this fill will be move inside:
* src/Chamilo/PluginBundle/Entity/StudentFollowUp/
* in order that Chamilo/Doctrine register it before using
*
*
* @ORM\Table(name="sfu_post")
* @ORM\Entity
* @Gedmo\Tree(type="nested")
@ -106,7 +112,7 @@ class CarePost
/**
* @ORM\OneToMany(targetEntity="CarePost", mappedBy="parent")
* @ORM\OrderBy({"lft" = "ASC"})
* @ORM\OrderBy({"createdAt" = "DESC"})
*/
private $children;
@ -420,7 +426,4 @@ class CarePost
return $this;
}
}

@ -2,7 +2,7 @@
/* For licensing terms, see /license.txt */
use Doctrine\Common\Collections\Criteria;
use Doctrine\ORM\Tools\Pagination\Paginator;
use Chamilo\PluginBundle\Entity\StudentFollowUp\CarePost;
require_once __DIR__.'/../../main/inc/global.inc.php';
@ -40,12 +40,35 @@ $qb
->addCriteria($criteria)
->setMaxResults(1)
;
$query = $qb->getQuery();
/** @var CarePost $post */
$post = $query->getOneOrNullResult();
// Get related posts (post with same parent)
$relatedPosts = [];
if ($post && !empty($post->getParent())) {
$qb = $em->createQueryBuilder();
$criteria = Criteria::create();
if ($showPrivate == false) {
$criteria->andWhere(Criteria::expr()->eq('private', false));
}
$criteria->andWhere(Criteria::expr()->eq('parent', $post->getParent()));
$criteria->andWhere(Criteria::expr()->neq('id', $post->getId()));
$qb
->select('p')
->from('ChamiloPluginBundle:StudentFollowUp\CarePost', 'p')
->addCriteria($criteria)
->orderBy('p.createdAt', 'desc')
;
$query = $qb->getQuery();
$relatedPosts = $query->getResult();
}
$tpl = new Template($plugin->get_lang('plugin_title'));
$tpl->assign('post', $post);
$tpl->assign('related_posts', $relatedPosts);
$url = api_get_path(WEB_PLUGIN_PATH).'/studentfollowup/post.php?student_id='.$studentId;
$tpl->assign('post_url', $url);
$tpl->assign(

@ -1,4 +1,4 @@
{% macro post_template(post, information_icon, post_url, current_url) %}
{% macro post_template(type, post, information_icon, post_url, current_url, related_posts) %}
{% if post %}
<h2>{{ post.title }}</h2>
<p>{{ post.content }}</p>
@ -22,29 +22,45 @@
{% set countElements = post.hasParent + post.children.count %}
{% if countElements %}
{% if countElements > 1%}
<p>{{ information_icon }} + {{ countElements }}</p>
<a href="{{ post_url }}&post_id={{ post.id }}">
{% if countElements > 1 %}
{{ information_icon }} + {{ countElements }}
{% else %}
<p>{{ information_icon }} </p>
{{ information_icon }}
{% endif %}
{% endif %}
{% if post.parent %}
<h3>Parent</h3>
<a href="{{ post_url }}&post_id={{ post.parent.id }}">
{{ post.parent.title }}
</a>
{% endif %}
{% if post.children.count %}
<h3>Children</h3>
{% for child in post.children %}
<p>
<a href="{{ post_url }}&post_id={{ child.id }}">
{{ child.title }}
{% if type == 'all' %}
{% if post.parent %}
<h3>Parent</h3>
<a href="{{ post_url }}&post_id={{ post.parent.id }}">
{{ post.parent.title }}
</a>
</p>
{% endfor %}
{% endif %}
{% if post.children.count %}
<h3>Children</h3>
{% for child in post.children %}
<p>
<a href="{{ post_url }}&post_id={{ child.id }}">
{{ child.title }}
</a>
</p>
{% endfor %}
{% endif %}
{% if related_posts %}
<h3>Related</h3>
{% for post in related_posts %}
<p>
<a href="{{ post_url }}&post_id={{ post.id }}">
{{ post.title }}
</a>
</p>
{% endfor %}
{% endif %}
{% endif %}
{% endif %}
{% endmacro %}
@ -55,4 +71,4 @@
{{ back_link }}
</div>
<h1>Care detail view</h1>
{{ template.post_template(post, information_icon, post_url, current_url) }}
{{ template.post_template('all', post, information_icon, post_url, current_url, related_posts) }}

@ -3,9 +3,7 @@
<h1>Care detail view</h1>
{% if posts %}
{% for post in posts %}
{{ template.post_template(post, information_icon, post_url, current_url) }}
{{ template.post_template('simple', post, information_icon, post_url, current_url) }}
{% endfor %}
<div>
{{ pagination }}

Loading…
Cancel
Save