ill look through these 😊 just little improvements now, https://torrenttrader.uk/post/user?id=1 & https://torrenttrader.uk/comment/user?id=1
i did the comments & forum post and ill post them for a example of mvc - using this as a guide you can build stuff pretty quick
need to add sql & replace app/helpers_general_helper with https://github.com/M-jay84/M-BiTsy/blob/main/M-BiTsy/app/helpers/general_helper.php - added a function to tidy up a bit & sort ratio, avatar etc which i used for comments & forum which ill re-use everywhere
added new sql
first re-write model function - i only try use 1 query each page to get info from database - not always possible but makes life easier
app/models/Comments.php
second write the controller (page) this is where we sort the data and send to view eg $_GET or query results
rewrite user function in app/controllers/users/Comment.php
Third make a view - this is where we go through the data sent from controller placing it into html
rewrite app/views/user/comment
here it is on github the user comments https://github.com/M-jay84/M-BiTsy/commit/0a2d20a3064fd1f0c2936e7ca8e66a489f1c49c0 and user forum post https://github.com/M-jay84/M-BiTsy/commit/82d00a4b0c58dabc1fc6d9ddfde8a07535fb5ba1
debug your own
the best way to build is printing out the data so in controller print out the data from the model make sure you have everything you want
so before you start you plan on what you need and then in the controller we check the data been sent to the view
here is example of the data sent to view for users comments - once you've got your model data its so easy hopefully 🤣 making it user friendly is something i;m more aware of
i did the comments & forum post and ill post them for a example of mvc - using this as a guide you can build stuff pretty quick
need to add sql & replace app/helpers_general_helper with https://github.com/M-jay84/M-BiTsy/blob/main/M-BiTsy/app/helpers/general_helper.php - added a function to tidy up a bit & sort ratio, avatar etc which i used for comments & forum which ill re-use everywhere
added new sql
ALTER TABLE `comments` ADD `type` VARCHAR(11) DEFAULT NULL;first re-write model function - i only try use 1 query each page to get info from database - not always possible but makes life easier
app/models/Comments.php
public static function join($id, $limit)
{
$row = DB::run("SELECT comments.id, comments.type, comments.news, comments.torrent, text, user, comments.added, avatar,
signature, username, users.title, class, uploaded, downloaded, privacy, donated,
news.title as newstitle,
torrents.name as torrenttitle
FROM comments
LEFT JOIN users
ON comments.user = users.id
LEFT JOIN news
ON comments.news = news.id
LEFT JOIN torrents
ON comments.torrent = torrents.id
WHERE user = $id ORDER BY comments.id $limit")->fetchAll();
return $row;
}second write the controller (page) this is where we sort the data and send to view eg $_GET or query results
rewrite user function in app/controllers/users/Comment.php
public function user()
{
// Get Id
$id = (int) Input::get("id");
// Run Some Checks
if (!isset($id) || !$id) {
Redirect::autolink(URLROOT, Lang::T("ERROR"));
}
// Count For Pager
$count = DB::column('comments', 'count(*)', ['user' => $id]);
list($pager, $limit) = Pagination::pager(20, $count, URLROOT . "/comment/user?id=$id&");
// Grab All Data
$row = Comments::join($id, $limit);
//echo '<pre>'.print_r($row, true).'</pre>';
// Check If Data Returned
if (!$row) {
Redirect::autolink(URLROOT, "User has not posted any comments");
}
// Send Sorted Data
$data = [
'title' => Lang::T("Search Users Comments"),
'id' => $id,
'res' => $row,
'pager' => $pager,
];
View::render('comment/user', $data, 'user');
}Third make a view - this is where we go through the data sent from controller placing it into html
rewrite app/views/user/comment
<p class="text-center"><a href='<?php echo URLROOT ?>/profile?id=<?php echo $data['id'] ?>'>Go To Profile</a></p>
<?php
foreach ($data['res'] as $row) {
// Quick Function To Tidy Results
$user = userpostdetails($row); ?>
<div class="container">
<div class="row ttborder">
<div class="col-2 d-none d-sm-block"> <?php
if (Users::get('edit_users') == 'no' && $user['privacylevel'] == 'strong') {
print('<td align="left" width="180"><center><small><a href="' . URLROOT . '/profile?id=' . $row['id'] . '"><b>' . $user['postername'] . '</b></a><br /><i>' . $user['title'] . '</i><img width="80" height="80" src="' . $user['avatar'] . '" alt="" /><br />Uploaded: ---<br />Downloaded: ---<br />Ratio: ' . get_ratio_color('---') . '</small><br /><br /><a href="' . URLROOT . '/profile?id=' . $row["user"] . '"><i class="fa fa-user tticon" title="Profile"></i></a> <a href="' . URLROOT . '/message/create?id=' . $row["user"] . '"><i class="fa fa-comment" title="Send PM"></i></a></center></td>');
} else {
print('<td align="left" width="180"><center><small><a href="' . URLROOT . '/profile?id=' . $row['id'] . '"><b>' . $user['postername'] . '</b></a><br /><i>' . $user['title'] . '</i><img width="80" height="80" src="' . $user['avatar'] . '" alt="" /><br />Uploaded: ' . $user['useruploaded'] . '<br />Downloaded: ' . $user['userdownloaded'] . '<br />Ratio: ' . get_ratio_color($user['userratio']) . '</small><br /><a href="' . URLROOT . '/profile?id=' . $row["user"] . '"><i class="fa fa-user" title="Profile"></i></a> <a href="/message/create?id=' . $row["user"] . '"><i class="fa fa-comment" title="Send PM"></i></a></center></td>');
} ?>
</div>
<div class="col-10">
<a href="<?php echo URLROOT ?>/topic?topicid=<?php echo $row['topicid'] ?>"><b><?php echo $row['subject'] ?></b></a> Posted: <?php echo date("d-m-Y \\a\\t H:i:s", TimeDate::utc_to_tz_time($row["added"])) ?><a id="comment<?php echo $row["id"] ?>"></a> in <a href="<?php echo URLROOT ?>/forum/view&forumid=<?php echo $row['forumid'] ?>"><b><?php echo $row['name'] ?></b></a>
<p class="float-end"><?php echo $user['edit'] . $user['delete'] ?><a href="<?php echo URLROOT ?>/report/forum?forumid=<?php echo $row['topicid'] ?>&forumpost=<?php echo $row['id'] ?>"><i class="fa fa-flag" title='Report' aria-hidden="true"></i></a></p>
<hr />
<?php echo $user['commenttext'] ?>
<hr />
<?php echo $user['usersignature'] ?>
</div>
</div><br>
</div> <?php
}
print($data['pager']);here it is on github the user comments https://github.com/M-jay84/M-BiTsy/commit/0a2d20a3064fd1f0c2936e7ca8e66a489f1c49c0 and user forum post https://github.com/M-jay84/M-BiTsy/commit/82d00a4b0c58dabc1fc6d9ddfde8a07535fb5ba1
debug your own
the best way to build is printing out the data so in controller print out the data from the model make sure you have everything you want
// Grab All Data
$row = Comments::join($id, $limit);
echo '<pre>'.print_r($row, true).'</pre>';so before you start you plan on what you need and then in the controller we check the data been sent to the view
View::render('comment/user', $data, 'user');
echo '<pre>'.print_r($data, true).'</pre>';here is example of the data sent to view for users comments - once you've got your model data its so easy hopefully 🤣 making it user friendly is something i;m more aware of
[title] => Search Users Comments
[id] => 1
[res] => Array
(
[0] => Array
(
[id] => 2
[type] => forum
[news] => 0
[torrent] => 28
[text] => jntrhjrh
[user] => 1
[added] => 2022-03-26 17:29:50
[avatar] =>
[signature] =>
[username] => M-jay
[title] =>
[class] => 7
[uploaded] => 524288000
[downloaded] => 1073741824
[privacy] => normal
[donated] => 0
[newstitle] =>
[torrenttitle] => MP3-daily-2022-March-17-Vocal
)
Last edited by M-jay
on 2022-03-27 06:32:30
on 2022-03-27 06:32:30