-
Notifications
You must be signed in to change notification settings - Fork 141
Modify per-language user list page to make it easier to find active native speakers #3217
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
base: dev
Are you sure you want to change the base?
Modify per-language user list page to make it easier to find active native speakers #3217
Conversation
…ecent sentence timestamp, and added icon to for_language page indicating users who have contributed within the past week
…o their language rating
|
It looks like the CI is failing because the Fyi, this PR includes a script |
|
To fix the CI, you can edit the fixture file To run the tests locally, you can run To add the new column, we used to create migration scripts in The table definition in |
| if ($userLevel < 0) { | ||
| return; | ||
| } | ||
| $this->update_user_last_contribution($userId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CakePHP offers a mechanism to perform some action on every creation or update of a model: the afterSave callback. Have a look at the afterSave() method in UsersTable.php or SentencesTable.php. You could call update_user_last_contribution() from there instead. The advantage is that:
- you call it only once, instead of calling it from every controller action potentially involved in sentence creation/update
- it is easier to write unit tests
381943a to
eb08f82
Compare
…e class, which is called in afterSave in the SentencesTable class
eb08f82 to
ee88b10
Compare
|
Thanks for the pointers! The unit tests are now passing, and I moved |
It does sound like this approach would accomplish what I was looking for. In any case, if you move your changes over to dev, let me know, and I'll check it out there. Thanks! |
docs/database/updates/2025-10-13.sql
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file can be removed now.
| public function change() | ||
| { | ||
| $table = $this->table('users'); | ||
| $table->addColumn('last_contribution', 'integer', [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better to use the datetime type rather than integer. This will let CakePHP automatically interpret it as a datetime, providing type check and datetime calculation methods. Using integer also makes your implementation vulnerable to the year 2038 bug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. I only used the integer type in order to be consistent with the last_time_active field.
|
|
||
| public function updateLastContribution($userId) | ||
| { | ||
| if ($this->exists(["Users.id" => $userId])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use the following pattern instead:
use Cake\Datasource\Exception\RecordNotFoundException;
try {
$user = $this->get($userId);
} catch (RecordNotFoundException $e) {
}The benefit is that only one SQL SELECT request is performed (at get()) instead of two (both at exists() and get()).
src/Template/Users/for_language.ctp
Outdated
| ) | ||
| ); | ||
| if ($timeSinceLastActivity < 604800) { /* Add a calendar icon for users who have been active within the past week */ | ||
| echo '<md-icon class="material-icons user-recently-active-icon" aria-label="comment" title="Active this week">comment</md-icon>'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are two problems with this icon.
- The text Active this week is not translatable, you can use
__("Active this week")to make it so. Also wrap withh()to avoid any quote returned by__()to mess up with your markup. - The HTML title attribute should be avoided because of its accessibility concerns. You can use
<md-tooltip>instead, see the documentation and search around the codebase for some usage more examples.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. I re-ran generate_pot.sh as well to update the localization files... let me know if you see any issues with this.
| public function change() | ||
| { | ||
| $table = $this->table('users'); | ||
| $table->addColumn('last_contribution', 'integer', [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That’s really not a big deal, but the position of the last_contribution column is different here than what you specified in the fixtures. The migration script adds the column as the last position, unless specified with the option after, e.g. 'after' => 'last_time_active'.
You can use cake migrations rollback and cake migrations migrate to re-run the migration, and check how the table looks with desc users; in the mysql shell.
src/Template/Users/for_language.ctp
Outdated
| ) | ||
| ); | ||
| if ($timeSinceLastActivity < 604800) { /* Add a calendar icon for users who have been active within the past week */ | ||
| echo '<md-icon class="material-icons user-recently-active-icon" aria-label="comment" title="Active this week">comment</md-icon>'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The wording Active this week is not entirely accurate, because it really is Active within the last 7 days. This week could be interpreted as between Monday and today (or Sunday and today depending on which day you start your weeks on).
Maybe I am being too picky and most people will interpret it correctly. Feel free to ignore this comment if you don’t think it’s a real problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I think "active within the past week" will be clearer.
|
I think only two pieces are missing to get this PR ready.
|
…rather than int type
…_time_active column
2db80c4 to
af44a98
Compare
af44a98 to
d731e13
Compare
|
Okay, I've taken care of the following:
I'm currently struggling with the unit tests but haven't made much progress. I'll keep playing around with them, but if you want to merge and add the unit tests yourself I won't complain. :-) |
… a new sentence is posted
|
Okay, I was actually able to add a unit test testing this new functionality. In its current state, the test just posts two sentences as |
fixes #3075
/users/for_language/XXX) to users who have been active within the past weekThis should make it easier to find the most active / likely-to-respond users in a given language on Tatoeba. See this former PR for further discussion.
It would be nice to get some feedback from @alanfgh on whether this would meet his need. Alternatively, perhaps this could get rolled out to the dev instance of Tatoeba and we could ask alanfgh to try it out.