Design and Analysis of Collection and Cataloguing System

The core of an acquisition and editing system is nothing more than writing, auditing and publishing these basic processes. Handling this part properly, a collection and editing system should be about the same.

Writing, auditing, publishing. From a programming point of view, they are actually events one by one. Audit is an event, publication is an event, cancellation is an event, recommendation is an event. These events change the state of the article.

First of all, it's a text class. Simplify it. An id represents the unique identity and a status identifies the status of the article.

class ArticleModel
    public $id;
    public $status;

Second, this should be event-driven, so define interfaces and abstract classes

interface IArticleEvent{
    public function action(ArticleModel $articelModel);

abstract class ArticleEvent implements IArticleEvent{    
    const SaveArticle = 1;
    const SubmitArticle = 2;
    //First audit
    const FirstReviewArticle = 4;
    //Second audit
    const SecondReviewArticle = 8;
    const PublishArticle = 16;
    //A Recommendation
    const ARecommendArticle = 32;
    //B Recommendation
    const BRecommendArticle = 64;

    public $event_name;
    public $created_at;
    public $created_by;

    public function __construct($event_name,$created_at,$created_by){
        $this->event_name = $event_name;
        $this->created_by = $created_at;
        $this->created_by = $created_by;

    public abstract function action(ArticleModel $articelModel);

In general, the state is best expressed in two-level system 1, 2, 4, 6, 8.. This one is no different from 1, 2, 3, 4, and the other is that it can represent accumulation, 1 + 2 + 4 = 7.
The process here is to save status - > submit status - > first audit status - > second audit status - > release status - > (A recommendation status, B recommendation status).
Here status can be very flexible, either 1, 2, 4, 8. It can also be state addition, for example, the article is A recommended state 1 + 2 + 4 + 8 + 16 + 32 = 63. At the same time, recommendation A is also recommendation B, which is 127. The article cancels A recommendation, which is 95, and the publishing status is 31.

Finally, it is the realization of events. Here we simply implement three events. Submission, A Recommendation and Cancellation of A Recommendation

class PublishArticleEvent extends ArticleEvent {

    public function action(ArticleModel $articelModel)
        $status = $articelModel->status + ArticleEvent::PublishArticle;
        echo "Successful submission status ".$status;

class ARecommendArticle extends ArticleEvent

    public function action(ArticleModel $articelModel)
        $status = $articelModel->status + ArticleEvent::ARecommendArticle;
        echo "A Recommended articles enter B Recommendations (articles can be both submission status and A Recommendation status) ". $status;

class CancelARecommendArticle extends ArticleEvent
    public function action(ArticleModel $articelModel)
        $status = $articelModel->status - ArticleEvent::ARecommendArticle;
        echo "cancel A Selected successful articles returned to submission status ".$status;

At present, the process is relatively simple, that is, simple addition and subtraction. You can also deal with sql statements and so on here.

This is event-driven, consistent with the single principle and the open-close principle. The code will be flexible, the extension will be convenient, and the process control code and the event code will be separated.
For example, implement the general logging method function log() in Article. Under a particular class, override the log method. Used to record more detailed log information.
For example, add a third audit to the process and an event Third ArticleReview Event to add this class to the process control code.
Cancellation of A recommendation event requires not only the cancellation of A recommendation, but also the cancellation of A publication. Then add a new event, or just modify a single event.
Change the above requirements again. A department can cancel recommendation and publication at the same time, B department can only cancel recommendation. So add a new event.

This can basically make him feel bad about himself, and I'm really full of breath.

Tags: PHP Programming SQL

Posted on Fri, 30 Aug 2019 01:02:07 -0700 by digitalmustache