Skip to content

Commit d4793c6

Browse files
authored
Merge pull request #513 from topcoder-platform/issues-479
Issues-479: Watch functionality changes
2 parents adf7ed6 + f242e53 commit d4793c6

File tree

16 files changed

+473
-33
lines changed

16 files changed

+473
-33
lines changed

config/vanilla/bootstrap.before.php

Lines changed: 77 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,46 @@ function dateUpdated($row, $wrap = null) {
327327
}
328328
}
329329

330+
if (!function_exists('watchIcon')) {
331+
/**
332+
*
333+
* Writes the Watch/watching icon
334+
*
335+
* @param int $categoryID
336+
* @return string
337+
*/
338+
function watchIcon($hasWatched = false) {
339+
if($hasWatched) {
340+
$icon = <<<EOT
341+
<svg width="21px" height="14px" viewBox="0 0 21 14" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
342+
<title>C37BD87D-4683-4407-B623-A16FF477E263</title>
343+
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
344+
<g id="02-Challenge-Forums" transform="translate(-1261.000000, -328.000000)" fill="#0AB88A" fill-rule="nonzero">
345+
<path d="M1271.08333,328 C1266.5,328 1262.58583,330.850833 1261,334.875 C1262.58583,338.899167 1266.5,341.75 1271.08333,341.75 C1275.66667,341.75 1279.58083,338.899167 1281.16667,334.875 C1279.58083,330.850833 1275.66667,328 1271.08333,328 Z M1271.08333,339.458333 C1268.55333,339.458333 1266.5,337.405 1266.5,334.875 C1266.5,332.345 1268.55333,330.291667 1271.08333,330.291667 C1273.61333,330.291667 1275.66667,332.345 1275.66667,334.875 C1275.66667,337.405 1273.61333,339.458333 1271.08333,339.458333 Z M1271.08333,332.125 C1269.56167,332.125 1268.33333,333.353333 1268.33333,334.875 C1268.33333,336.396667 1269.56167,337.625 1271.08333,337.625 C1272.605,337.625 1273.83333,336.396667 1273.83333,334.875 C1273.83333,333.353333 1272.605,332.125 1271.08333,332.125 Z" id="Shape"></path>
346+
</g>
347+
</g>
348+
</svg>
349+
EOT;
350+
} else {
351+
$icon = <<<EOT
352+
<svg width="22px" height="22px" viewBox="0 0 22 22" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
353+
<title>A8A8C574-0B97-4F46-826B-9E3C5F919266</title>
354+
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
355+
<g id="02-Challenge-Forums" transform="translate(-1260.000000, -594.000000)">
356+
<g id="watch-icon" transform="translate(1260.000000, 594.000000)">
357+
<polygon id="Path" points="0 0 22 0 22 22 0 22"></polygon>
358+
<path d="M11,6.41666667 C14.4741667,6.41666667 17.5725,8.36916667 19.085,11.4583333 C17.5725,14.5475 14.4741667,16.5 11,16.5 C7.52583333,16.5 4.4275,14.5475 2.915,11.4583333 C4.4275,8.36916667 7.52583333,6.41666667 11,6.41666667 M11,4.58333333 C6.41666667,4.58333333 2.5025,7.43416667 0.916666667,11.4583333 C2.5025,15.4825 6.41666667,18.3333333 11,18.3333333 C15.5833333,18.3333333 19.4975,15.4825 21.0833333,11.4583333 C19.4975,7.43416667 15.5833333,4.58333333 11,4.58333333 Z M11,9.16666667 C12.265,9.16666667 13.2916667,10.1933333 13.2916667,11.4583333 C13.2916667,12.7233333 12.265,13.75 11,13.75 C9.735,13.75 8.70833333,12.7233333 8.70833333,11.4583333 C8.70833333,10.1933333 9.735,9.16666667 11,9.16666667 M11,7.33333333 C8.72666667,7.33333333 6.875,9.185 6.875,11.4583333 C6.875,13.7316667 8.72666667,15.5833333 11,15.5833333 C13.2733333,15.5833333 15.125,13.7316667 15.125,11.4583333 C15.125,9.185 13.2733333,7.33333333 11,7.33333333 Z" id="Shape" fill="#555555" fill-rule="nonzero"></path>
359+
</g>
360+
</g>
361+
</g>
362+
</svg>
363+
EOT;
364+
}
365+
366+
return $icon;
367+
}
368+
}
369+
330370
if (!function_exists('watchButton')) {
331371
/**
332372
*
@@ -335,27 +375,25 @@ function dateUpdated($row, $wrap = null) {
335375
* @param int $categoryID
336376
* @return string
337377
*/
338-
function watchButton($categoryID) {
378+
function watchButton($category) {
339379
$output = ' ';
340380
$userID = Gdn::session()->UserID;
341-
$category = CategoryModel::categories($categoryID);
381+
if(is_numeric($category)) {
382+
$category = CategoryModel::categories($category);
383+
}
342384

343-
if ($userID && $category && $category['DisplayAs'] == 'Discussions') {
385+
//if ($userID && $category && $category['DisplayAs'] == 'Discussions') {
386+
if ($userID && $category) {
344387
$categoryModel = new CategoryModel();
388+
$categoryID= val('CategoryID', $category);
345389
$hasWatched = $categoryModel->hasWatched($categoryID, $userID);
346-
$iconTitle = t('Watch');
347-
$icon = <<<EOT
348-
<svg xmlns="http://www.w3.org/2000/svg" class="watchButton-icon" viewBox="0 0 16 16" aria-hidden="true">
349-
<title>{$iconTitle}</title>
350-
<path d="M7.568,14.317a.842.842,0,0,1-1.684,0,4.21,4.21,0,0,0-4.21-4.21h0a.843.843,0,0,1,0-1.685A5.9,5.9,0,0,1,7.568,14.317Zm4.21,0a.842.842,0,0,1-1.684,0A8.421,8.421,0,0,0,1.673,5.9h0a.842.842,0,0,1,0-1.684,10.1,10.1,0,0,1,10.105,10.1Zm4.211,0a.842.842,0,0,1-1.684,0A12.633,12.633,0,0,0,1.673,1.683.842.842,0,0,1,1.673,0,14.315,14.315,0,0,1,15.989,14.315ZM1.673,16a1.684,1.684,0,1,1,1.684-1.684h0A1.684,1.684,0,0,1,1.673,16Z" transform="translate(0.011 0.001)" style="fill: currentColor;"/>
351-
</svg>
352-
EOT;
353390

354-
$text = $hasWatched ? t('Watching') : t('Watch');
391+
$icon = watchIcon($hasWatched);
392+
$text = $hasWatched ? t('Stop watching the category') : t('Watch the category');
355393
$output .= anchor(
356-
$icon . $text,
394+
$icon,
357395
$hasWatched ? "/category/watched/{$categoryID}/" . Gdn::session()->transientKey() : "/category/watch/{$categoryID}/" . Gdn::session()->transientKey(),
358-
'Hijack watchButton' . ($hasWatched ? ' TextColor isWatching' : ''),
396+
'Hijack watchButton' . ($hasWatched ? ' isWatching' : ''),
359397
['title' => $text, 'aria-pressed' => $hasWatched ? 'true' : 'false', 'role' => 'button', 'tabindex' => '0']
360398
);
361399
}
@@ -806,6 +844,32 @@ function myDraftsMenuItem($CountDrafts) {
806844
}
807845
}
808846

847+
if (!function_exists('myWatchingMenuItem')) {
848+
/**
849+
*
850+
*
851+
* @param $CountBookmarks
852+
* @return string
853+
*/
854+
function myWatchingMenuItem($CountWatches) {
855+
if (!Gdn::session()->isValid()) {
856+
return '';
857+
}
858+
$watching = t('Watching');
859+
$watching .= FilterCountString($CountWatches, '/watching');
860+
$cssClass = 'MyWatching';
861+
Logger::event(
862+
'topcoder_plugin',
863+
Logger::DEBUG,
864+
'myWatchingMenuItem:'.Gdn::controller()->RequestMethod,
865+
[]
866+
);
867+
$cssClass .= Gdn::controller()->ControllerName == 'watchingcontroller' ? ' Active' : '';
868+
$cssClass .= $CountWatches == 0 ? ' hidden': '';
869+
return sprintf('<li id="MyWatching" class="%s">%s</li>', $cssClass, anchor(sprite('SpBookmarks').$watching, '/watching'));
870+
}
871+
}
872+
809873
if(!function_exists('writeInlineDiscussionOptions')) {
810874
function writeInlineDiscussionOptions($discussionRow) {
811875
$discussionID = val('DiscussionID', $discussionRow);

config/vanilla/bootstrap.early.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,4 +152,17 @@
152152
->column('DateExpires', 'datetime')
153153
->set(false, false);
154154
}
155+
156+
// FIX: https://github.com/topcoder-platform/forums/issues/479
157+
if(!Gdn::structure()->table('User')->columnExists('CountWatchedCategories')) {
158+
Gdn::structure()->table('User')
159+
->column('CountWatchedCategories', 'int', null)
160+
->set(false, false);
161+
162+
// Set count of WatchedCategories for users
163+
Gdn::sql()->query('update GDN_User u set u.CountWatchedCategories = (
164+
select count(c.CategoryID) from GDN_Category c, (select distinct CAST(SUBSTRING_INDEX(um.Name, ".", -1) as UNSIGNED) as CategoryID from GDN_UserMeta um
165+
where um.Name LIKE "Preferences.%" AND UserID = u.UserID and Value = 1) ws where ws.CategoryID = c.CategoryID)');
166+
167+
}
155168
}

0 commit comments

Comments
 (0)