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

Add user statistics #3

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open

Add user statistics #3

wants to merge 10 commits into from

Conversation

bdgregg
Copy link

@bdgregg bdgregg commented Jun 7, 2021

No description provided.

Copy link
Member

@ctgraham ctgraham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lots of good stuff here. Comments are the output of our group code review this morning.

*/
class UserStatistics extends Model
{
/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove getStatistics() in favor of get()

*
* @return Statistic.
*/
public function getStatistic($typeCode,$categoryCode)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirm whether multiple Statistics can really exist across a single type/category combination.

Also, compare with similar method signatures in codetables, identifiers, etc. In codetables, for example, there is a pattern of:

// get a single entry
$client->codetable->get( $code );
// get all:
$client->codetable->getCodeTables( );

Is this typical? If so, should this look like:

// get one
$user->Statistics->get( $type, $category );
// get all
$user->Statistics->getAll( );

* @param string $note free text description of the statistic.
* @param string $segment_type either "Internal" or "External"
*/
public function addStatisticRaw($typeCode,$typeDesc,$categoryCode,$categoryDesc,$segment_type = 'External' ,$note = '')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested refactor:
addStatistic() adds the values unchecked (in line with the fact that such invalid data can exist in Alma

But add a Statistics->Statistic->validate() method, and Statistics->validate() method to confirm the statistics against actual codetables.

Warning: this has substantial implications for the Lazy Load approach, and for caching of codetables.

* @param string $segmentType either ("Internal" or "External")
* @param string $note
*/
public function addStatistic($typeCode,$categoryCode,$segmentType = 'External',$note = '')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the context of Statistics, since it looks like we will be filling out the Statistic class as well, an add() method should probably take a Statistic object, rather than a set of parameters.

*/
public function removeAllStatistics()
{
foreach($this->data->user_statistic as $key => $row) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should simply be:

$this->data-user_statistic = array();

* @param string $segmentType ("Internal" or "External")
* @param string $note
*/
public function updateStatistic($fromTypeCode,$fromCategoryCode,$toTypeCode,$toCategoryCode,$segmentType = "External" ,$note = '')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The update method is better as a member of Statistic rather than Statistics.

* @param string $typeCode
* @return Array of Statistics.
*/
public function getStatsByTypeCode($typeCode)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lots of helper methods here, mostly performing various formulations of array searches. These can be attractive in an SDK, but one argument against them is that if we write them, we are also responsible to write tests for them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants