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

feat: ability to view the tags cloud on a separate page #115 #146

Merged
merged 1 commit into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions app/Config/Routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
$routes->post('del/(:num)', 'Url::delUrl/$1', ['filter' => 'session']); // json del url
});

$routes->group('urltags', static function ($routes) {
$routes->get('/', 'Urltags::index', ['as' => 'url-tags', 'filter' => 'session']);
});

// Users
$routes->group('users', static function ($routes) {
$routes->get('/', 'Users::index', ['filter' => 'session']);
Expand Down
38 changes: 38 additions & 0 deletions app/Controllers/Urltags.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace App\Controllers;

use App\Models\UrltagsModel;
use CodeIgniter\Controller;
use CodeIgniter\I18n\Time;

class Urltags extends Controller
{
public function __construct()
{
}

public function index()
{
// permissions need to access this page is url.access
if (! auth()->user()->can('url.access')) {
return smarty_permission_error();
}

$urltagsModel = new UrltagsModel();
$tags = $urltagsModel->getTagsWithUrlCount();

// Format the created_at datetime field
foreach ($tags as &$tag) {
// Convert to Time object
$createdAt = Time::createFromFormat('Y-m-d H:i:s', $tag['created_at']);

// Format as desired (e.g., 'F j, Y, g:i a')
$tag['created_at'] = lang('Common.CreatedAt') . ' ' . $createdAt->format('F j, Y, g:i a');
}

$data['tags'] = $tags;

return view(smarty_view('url/tags'), $data);
}
}
2 changes: 2 additions & 0 deletions app/Language/ar/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@
'MyURLsHitCountAllTime' => 'اجمالي زيارات روابطي',
'MyURLsHitCountThisMonth' => 'زيارات روابطي هذا الشهر',
'MyURLsHitCountToday' => 'زيارات روابطي اليوم',

'CreatedAt' => 'في تاريخ',
];
3 changes: 3 additions & 0 deletions app/Language/ar/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,7 @@
'ThisMonth' => 'هذا الشهر',
'AllTime' => 'كل الوقت',
'MyUrls' => 'روابطي',

'TagsCloud' => 'سحابة هاشتاق الروابط',
'TagCreator' => 'منشئ الهاشتاق',
];
2 changes: 2 additions & 0 deletions app/Language/en/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@
'MyURLsHitCountAllTime' => 'Total visits of my URLs',
'MyURLsHitCountThisMonth' => 'My URLs visits this month',
'MyURLsHitCountToday' => 'My URLs visits today',

'CreatedAt' => 'At',
];
3 changes: 3 additions & 0 deletions app/Language/en/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,7 @@
'ThisMonth' => 'This Month',
'AllTime' => 'All Time',
'MyUrls' => 'My URLs',

'TagsCloud' => 'URL Tags Cloud',
'TagCreator' => 'Tag Creator',
];
14 changes: 14 additions & 0 deletions app/Models/UrlTagsModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,18 @@ public function findTagNo(string $tag, int $userId, bool $shared = false)

return $this->countAllResults();
}

/**
* This function return tags cloud with url count for each tag
*/
public function getTagsWithUrlCount()
{
return $this->db->table($this->table)
->select('urltags.*, COUNT(urltagsdata.url_id) AS url_count, users.username AS creator_username')
->join('urltagsdata', 'urltags.tag_id = urltagsdata.tag_id', 'left')
->join('users', 'urltags.tag_user_id = users.id', 'left')
->groupBy('urltags.tag_id')
->get()
->getResultArray();
}
}
Loading