victorjonsson / Arlima

Article List Manager - Wordpress plugin suitable for online newspapers that's in need of a fully customizable front page
28 stars 16 forks source link

Refactor the "list factory" #65

Open victorjonsson opened 9 years ago

victorjonsson commented 9 years ago

The class Arlima_ListFactory does a lot of stuff. If we want to adhere to the single responsibility principle we should separate this class into three different classes.

Arlima_ListRepository — CRUD operations for the lists.

Arlima_VersionRepository — CRUD operations for the list versions.

Arlima_ScheduledVersionRepository — CRUD operations for scheduled list versions (extends VersionRepository).

Arlima_ListBuilder — Class that can create a list object, following a set of instructions.

Example on using the list builder:

$list = Arlima_List::builder()
          ->id(323) # list id
          ->slug( 'my-list' ) # can be used instead of id()
          ->import( $url )  # can be used instead of id() or slug()      
          ->loadVersion(1234) # load articles belonging to version 1234
          ->loadLatestVersion() # load latest published version
          ->loadScheduledVersion(1234) # load articles from a scheduled version
          ->loadPreview() # load latest preview version
          ->includeFuturePosts()
          ->build();

I have looked through the current list factory and placed its functions in one of the repositories

Arlima_ListRepository extends Arlima_AbstractRepositoryDB {
   save()
   load( $id_or_slug )
   updated()
   delete()
   getListId( $slug )
   loadListSlugs()
}

Arlima_VersionRepository extends Arlima_AbstractRepositoryDB {
   save($articles, $list_id, $preview=false)
   loadVersions($limit=5) // get array with list versions, each version containing the articles
   loadInfo() // Array with info about all saved versions array( array(verisonID, authorID, date), ... )
   updateArticlePublishDate( $post )
   updateArticle(...)
   getLatestArticle($post_id);
   loadListVersionsByPostId($post_id)
   removeOldVersions($list_id, $num_versions_to_keep=10)
}

Arlima_ScheduledVersionRepository extends Arlima_VersionRepository {
   saveScheduledVersion($articles, $list_id, $date)
   ...
}

Arlima_AbstractRepositoryDB {  
    get_result()
    db_table()
    install()
    uninstall()
}
victorjonsson commented 9 years ago

Added some documentation to Server-side, in depth