Skip to content

Commit

Permalink
Merge pull request #146 from Extendy/feat/115tagscloud
Browse files Browse the repository at this point in the history
feat: ability to view the tags cloud on a separate page #115
  • Loading branch information
mshannaq authored Feb 29, 2024
2 parents 36b8747 + d0eac6e commit 6e27a6c
Show file tree
Hide file tree
Showing 9 changed files with 538 additions and 270 deletions.
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

0 comments on commit 6e27a6c

Please sign in to comment.