Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Course Article Page #452

Open
wants to merge 71 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 65 commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
20753c6
Course Article Page
PolinaShneider Apr 5, 2018
578bf7e
Update course articles
PolinaShneider Apr 7, 2018
46661bc
Merge branch 'master' into course-design
PolinaShneider Apr 12, 2018
92c35fe
Update course article
PolinaShneider Apr 12, 2018
0e5dede
Make course title both toggleable and clickable
PolinaShneider Apr 12, 2018
fd57fef
Merge branch 'master' of https://github.com/codex-team/codex into cou…
PolinaShneider Apr 18, 2018
4d58954
Add submodule
PolinaShneider Apr 18, 2018
f783cce
update migrations
talyguryn Apr 19, 2018
2451ed5
Merge branch 'articles-redesign' into course-design
talyguryn Apr 19, 2018
f60140b
Add courses progress state
PolinaShneider Apr 26, 2018
d9af702
Minor design update
PolinaShneider May 23, 2018
87a0e3c
Update
PolinaShneider May 25, 2018
2211d65
Update styles
PolinaShneider May 25, 2018
708cb68
Fix margins
PolinaShneider May 26, 2018
9958547
Return back
PolinaShneider May 26, 2018
2663249
Update cover styles
PolinaShneider May 27, 2018
c449a33
Quick fix
PolinaShneider May 27, 2018
401bd89
Get rid of height hardcode
PolinaShneider May 27, 2018
d232315
Rearrange styles
PolinaShneider May 27, 2018
1bf58ab
Quick font fix
PolinaShneider May 27, 2018
4a5c9ea
Zvuchit kak zadacha
PolinaShneider May 27, 2018
d7f564f
Add comments
PolinaShneider May 27, 2018
dc38095
Remove gray entirely
PolinaShneider May 27, 2018
6be9908
Merge branch 'master' of https://github.com/codex-team/codex into cou…
PolinaShneider May 28, 2018
8cc8386
Course in feed
PolinaShneider May 29, 2018
10dc77d
Update courses
PolinaShneider Jun 1, 2018
f23f0c9
Minor fix
PolinaShneider Jun 1, 2018
7e4fc4a
Add course page
PolinaShneider Jun 1, 2018
a8a10fc
Fix courses appearance
PolinaShneider Jun 4, 2018
2272aa7
Update font-size
PolinaShneider Jun 4, 2018
d61d17d
Update hover colors
PolinaShneider Jun 4, 2018
153c10b
Backend for course in feed
PolinaShneider Jun 4, 2018
fb2d980
Add check for courses without articles
PolinaShneider Jun 4, 2018
dfda9e6
One more check for courses without articles
PolinaShneider Jun 4, 2018
4bf9c66
Check for courses articles in feed
PolinaShneider Jun 4, 2018
063eafa
Fix for a single course item in feed
PolinaShneider Jun 4, 2018
17c0120
Improve padding
PolinaShneider Jun 4, 2018
b855948
Update templates
PolinaShneider Jun 4, 2018
467b686
Rename some classes and other minor fixes
PolinaShneider Jun 4, 2018
6f52ee6
Some upds
PolinaShneider Jun 4, 2018
5220317
Model update
PolinaShneider Jun 5, 2018
6970f5c
Remove hardcode
PolinaShneider Jun 5, 2018
79a2d78
Remove margin before description
PolinaShneider Jun 5, 2018
a59e526
Update margin
PolinaShneider Jun 5, 2018
a145f9e
Change margin again
PolinaShneider Jun 5, 2018
182c628
Update Model + sum small bugfixes
PolinaShneider Jun 5, 2018
203e52c
Remove extra addEventListener
PolinaShneider Jun 5, 2018
8c92086
Merge branch 'master' into course-design
talyguryn Jun 7, 2018
2bbc4df
use dt_publish top arrange items
talyguryn Jun 8, 2018
a6d5552
Revert "use dt_publish top arrange items"
talyguryn Jun 8, 2018
bf263dc
Update templates and some bug fixes
PolinaShneider Jun 8, 2018
e978608
Update courses
PolinaShneider Jun 8, 2018
c1dac14
Add comments
PolinaShneider Jun 9, 2018
97541c3
webpack 4
talyguryn Jun 12, 2018
fbe70cb
fix links to articles
talyguryn Jun 12, 2018
0faa975
fix transport
talyguryn Jun 13, 2018
a884934
Resolve merge conflicts
PolinaShneider Nov 19, 2018
ebe6c03
Merge branch 'master' of https://github.com/codex-team/codex into cou…
PolinaShneider Nov 21, 2018
a48651b
Temporarily remove caching
PolinaShneider Nov 21, 2018
c6be3fd
Removing extra stuff
PolinaShneider Nov 24, 2018
67bf79a
For debugging purposes
PolinaShneider Nov 24, 2018
e356bf3
Remove debugging stuff
PolinaShneider Nov 24, 2018
379d502
Fix cache
n0str Nov 25, 2018
13455e8
Merge branch 'master' of https://github.com/codex-team/codex into cou…
PolinaShneider Nov 25, 2018
c4c16e5
Fix dt_update for courses
PolinaShneider Nov 25, 2018
1246c08
Fix comments
PolinaShneider Nov 27, 2018
38c2a1f
Improve coments once more
PolinaShneider Nov 27, 2018
b9f0cbe
Alter article $isNotInCourse check
PolinaShneider Nov 27, 2018
2512f24
Return usage of feed
PolinaShneider Nov 27, 2018
2160f5e
Update hawk link
PolinaShneider Nov 27, 2018
fa2159d
Merge branch 'master' of https://github.com/codex-team/codex into cou…
PolinaShneider Feb 11, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions www/application/classes/Controller/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,27 @@ public function scripts_resetArticlesTimeline()
$articles[$key] = $article;
}

$courses = Model_Courses::getActiveCourses();

/** rebuld array*/
foreach ($courses as $key => $value) {
$course = array(
'id' => $courses[$key]->id,
'dt_create' => $courses[$key]->dt_publish,
);
$courses[$key] = $course;
}

// #TODO add to $feed array with courses later
$feed = new Model_Feed_Articles('article');
$feed->clear();
$feed->init($articles);
$feed_articles = new Model_Feed_Articles('article');
$feed_courses = new Model_Feed_Articles('course');

$feed_articles->clear();
$feed_courses->clear();

$feed_articles->init($articles);
$feed_courses->init($courses);

return 'Articles timeline was successfully updated';
return 'Articles and Courses timeline was successfully updated';
}
}
58 changes: 50 additions & 8 deletions www/application/classes/Controller/Articles/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,53 @@ public function action_show()
*/
public function getFeed()
{
$cacheKey = LANG . ':articles-feed';
$cached = $this->memcache->get($cacheKey);

if ($cached) {
return $cached;
}

$articles = new Model_Article();
$article_items = $articles->getActiveArticles($clearCache=true);

$courses = new Model_Courses();
$course_items = $courses->getActiveCourses(false, true);

/**
* Prepare Feed model
* Prepare feed items array
*/
$feed = new Model_Feed_Articles();
$feed_items = [];
$do_not_add_these_articles_to_feed = [];

/**
* Get all published articles
* Add course articles to feed items
*/
$feed_items = $feed->get();
foreach ($course_items as $course) {
$feed_items[$course->dt_publish] = $course;
$coauthorship = new Model_Coauthors($course->id);
$course->coauthor = Model_User::get($coauthorship->user_id);

foreach ($course->course_articles as $article) {
$do_not_add_these_articles_to_feed[] = $article->id;
}
}

/**
* Add articles to feed items if they weren't added as part of course
*/
foreach ($article_items as $article) {
if (in_array($article->id, $do_not_add_these_articles_to_feed)) {
continue;
}

$feed_items[$article->dt_publish] = $article;
$coauthorship = new Model_Coauthors($article->id);
$article->coauthor = Model_User::get($coauthorship->user_id);
}

ksort($feed_items);
$feed_items = array_reverse($feed_items);

/**
* List of published articles ids
Expand Down Expand Up @@ -175,6 +213,8 @@ public function getFeed()
}
}

$this->memcache->set($cacheKey, $feed_items);

return $feed_items;
}

Expand Down Expand Up @@ -227,10 +267,12 @@ private function getArticlesFromCourse($articleId, $courseId)
* search in array of article ids the position of current article
*/
$counter = 0;
$position = 0;

foreach ($course_articles as $articles) {
$articleList[] = Model_Article::get($articles['article_id']);
$articleList[] = Model_Article::get($articles->id);

if ($articles['article_id'] == $articleId) {
if ($articles->id == $articleId) {
$position = $counter;
}

Expand All @@ -242,14 +284,14 @@ private function getArticlesFromCourse($articleId, $courseId)
* If next or previous article exists, then we send it to view
*/
if ($position + 1 < count($course_articles)) {
$nextArticleId = $course_articles[$position + 1]['article_id'];
$nextArticleId = $course_articles[$position + 1]->id;
$nextArticle = Model_Article::get($nextArticleId);

$this->view["nextArticle"] = $nextArticle;
}

if ($position - 1 >= 0) {
$previousArticleId = $course_articles[$position - 1]['article_id'];
$previousArticleId = $course_articles[$position - 1]->id;
$previousArticle = Model_Article::get($previousArticleId);

$this->view["previousArticle"] = $previousArticle;
Expand Down
8 changes: 7 additions & 1 deletion www/application/classes/Controller/Articles/Modify.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,9 @@ public function action_save()
$courses_to_delete = array_diff($current_courses, $courses_ids);
$courses_to_add = array_diff($courses_ids, $current_courses);

Model_Courses::deleteArticles($article->id, $courses_to_delete);
if ($courses_to_delete) {
Model_Courses::deleteArticles($article->id, $courses_to_delete);
}

foreach ($courses_to_add as $course_id) {
Model_Courses::addArticle($article->id, $course_id);
Expand All @@ -238,6 +240,10 @@ public function action_save()
$recentArticlesFeed->remove($article->id);
}

// Очистка кэша фидов
$this->memcache->delete('en:articles-feed');
$this->memcache->delete('ru:articles-feed');

// Если поле uri пустое, то редиректить на обычный роут /article/id
$redirect = ($uri) ? '/' . $article->uri : '/article/' . $article->id;

Expand Down
9 changes: 8 additions & 1 deletion www/application/classes/Controller/Courses/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,25 @@ class Controller_Courses_Index extends Controller_Base_preDispatch
public function action_show()
{
$courseId = $this->request->param('id') ?: $this->request->query('id');
$isAlias = $this->request->query('id');

$course = Model_Courses::get($courseId);

if ($course->id == 0) {
throw new HTTP_Exception_404();
}

if (!empty($courseId)) {
if ($course->uri && !$isAlias) {
$this->redirect($course->uri);
}
}

$this->view["course"] = $course;

$this->title = $course->title;
$this->description = $course->description;

$this->template->content = View::factory('templates/courses/course', $this->view);
}
}
}
3 changes: 3 additions & 0 deletions www/application/classes/Controller/Courses/Modify.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ public function action_save()
} else {
$insertedId = $course->insert();
$course->uri = Model_Aliases::addAlias($alias, Aliases_Controller::COURSE, $insertedId);
// If course is published right after creation set 'dt_publish' immediately
$course->dt_publish = $course->is_published ? date('Y-m-d H:i:s') : null;
$course->update();
}

if ($course->is_published && !$course->is_removed) {
Expand Down
92 changes: 82 additions & 10 deletions www/application/classes/Model/Courses.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class Model_Courses extends Model
public $description;
public $cover;
public $is_big_cover;
public $course_articles = [];
public $course_authors = [];
public $dt_publish;
public $dt_create;
public $dt_update;
Expand Down Expand Up @@ -83,6 +85,9 @@ private function fillByRow($course_row)
}
}

$this->course_articles = self::getArticles($this->id);
$this->course_authors = $this->getUniqueCourseAuthors();

return $this;
}

Expand Down Expand Up @@ -182,7 +187,7 @@ public static function deleteArticles($article_id, $courses_ids = 0)
{
$deleteQuery = Dao_CoursesArticles::delete()->where('article_id', '=', $article_id);

if (!$courses_ids) {
if ($courses_ids === 0) {
return $deleteQuery->execute();
}

Expand Down Expand Up @@ -215,13 +220,32 @@ public static function get($id = 0, $needClearCache = false)
}

/**
* Получить все активные (опубликованные и не удалённые курсы) в порядке убывания ID.
* Return
* a) All published courses to output them on Article editing page
* b) All published courses, containing at least one Article to show in feed
*
* @return Model_Courses[] - array of Model_Courses
*/
public static function getActiveCourses($clearCache = false)
public static function getActiveCourses($clearCache = false, $excludeCoursesWithoutArticles = false)
{
return Model_Courses::getCourses(false, false, !$clearCache ? Date::MINUTE * 5 : null);
}
$active_courses = Model_Courses::getCourses(false, false, !$clearCache ? Date::MINUTE * 5 : null);
$courses_with_articles = array();

if ($excludeCoursesWithoutArticles) {

foreach ($active_courses as $course) {
if (self::getArticles($course->id)) {
$courses_with_articles[] = $course;
}
}

return $courses_with_articles;

} else {
return $active_courses;
}

}

/**
* Получить все неудалённые курсы в порядке убывания ID.
Expand Down Expand Up @@ -284,17 +308,65 @@ private static function rowsToModels($course_rows)
}

/**
* Получить id статей, входящих в курс
*
* @param $course_id
* @return bool|object
* Get Articles from Course
* @param [int] $courseId - ID of Course
* @return Model_Article[] - Array of Articles
*/
public static function getArticles($course_id)
{
if (!$course_id) {
return false;
}

return Dao_CoursesArticles::select('article_id')->where('course_id', '=', $course_id)->execute();
$articles_ids = Dao_CoursesArticles::select('article_id')->where('course_id', '=', $course_id)->execute();

/** $articleList - empty array. Needs to fill by article ids */
$articleList = array();

/**
* If Course has Articles
*/
if ($articles_ids) {
foreach ($articles_ids as $article) {
$course_article = Model_Article::get($article['article_id']);

/**
* Show only published Articles in Course
*/
if ($course_article->is_published) {
$articleList[] = $course_article;
}
}
/** Get Articles with Coauthors to display on Course Page */
foreach ($articleList as $article) {
$coauthorship = new Model_Coauthors($article->id);
$article->coauthor = Model_User::get($coauthorship->user_id);
}
}

return $articleList;
}

/**
* Return unique article authors from the Course
* @param Model_Article[] - Articles included in specific Course
* @return Model_User[] - Array of unique Course authors
*/
public function getUniqueCourseAuthors()
{
$course_articles = self::getArticles($this->id);
$course_authors_ids = array();
$course_authors = array();

foreach ($course_articles as $article) {
$author_id = $article->author->id;

if (!in_array($author_id, $course_authors_ids))
{
$course_authors_ids[] = $author_id;
$course_authors[] = Model_User::get($author_id);
}
}
return $course_authors;
}
}
1 change: 1 addition & 0 deletions www/application/config/system-aliases.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
'',
'ajax',
'admin',
'ajax',
'article',
'articles',
'auth',
Expand Down
2 changes: 1 addition & 1 deletion www/application/views/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<link rel="apple-touch-icon-precomposed" sizes="180x180" href="/apple-touch-icon-180x180.png" />

<? if (!empty($_SERVER['HAWK_TOKEN'])): ?>
<script src="https://cdn.rawgit.com/codex-team/hawk.client/5f545116/hawk.js" onload="hawk.init('<?= $_SERVER['HAWK_TOKEN'] ?>')"></script>
<script src="https://cdn.rawgit.com/codex-team/hawk.javascript/master/hawk.js" onload="hawk.init({token: '<?= $_SERVER['HAWK_TOKEN'] ?>', revision: <?= filemtime('public/build/bundle.js') ?>})"></script>
<? endif; ?>

</head>
Expand Down
Loading