Skip to content

Commit

Permalink
Issue #20 - first pass setting decision for a post
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbingwide committed Mar 17, 2018
1 parent 15636bd commit bfdb038
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 7 deletions.
42 changes: 41 additions & 1 deletion admin/class-oik-block-editor-opinion.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ class oik_block_editor_opinion {
* Advice on what to do
*/
public $choice_of_action;


public function __construct( $preferred_editor='A', $mandatory=false, $level="P", $observation="", $choice_of_action="" ) {
$this->set_preferred_editor( $preferred_editor );
Expand Down Expand Up @@ -115,6 +114,47 @@ public function get_mandatory() {
return $mandatory;
}


/**
*
* Current | Next opinion | New current | Notes
* ------- | ------------ | ----------- | -------
* AO | AO | AO
* AM |
* BO |
* BM |
* CO |
* CM |
*/
public function consider( $current_decision ) {
$decisions = array( "AOAM" => "AM"
, "AOBM" => "BM"
, "AOCM" => "CM"
, "AMBM" => "BM"
, "AMCM" => "CM"
, "BOAO" => "AO"
, "BOAM" => "AM"
, "BOBM" => "BM"
, "BOCO" => "AO"
, "BOCM" => "CM"
, "BMAM" => "BM"
, "BMCM" => "CM" // Oops
, "COAO" => "AO"
, "COAM" => "AM"
, "COBO" => "AO"
, "COBM" => "BM"
, "COCM" => "CM"
, "CMAM" => "CM" // Oops
, "CMBM" => "CM" // Oops
);
$next_opinion = $this->get_preferred_editor();
$next_opinion .= $this->get_mandatory();

$new_decision = bw_array_get( $decisions, $current_decision . $next_opinion, $current_decision );

return $new_decision;
}

public function report() {
$row = array();
$row[] = $this->get_preferred_editor();
Expand Down
51 changes: 50 additions & 1 deletion admin/class-oik-block-editor-opinions.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,62 @@ public function add_opinions( $opinions ) {
/**
* Considers the opinions to come to a decision
*
* It shouldn't matter at which level the opinion is set
* but it does matter which opinion has precedence.
* We'll consider the "opinion" as two chars combining the Editor and Mandatory fields
* Initial opinion is 'AO'. There are 36 combinations.
*
*/
public function consider_opinions() {
$decision = 'C';
$decision = 'AO';
foreach ( $this->opinions as $opinion ) {
$decision = $opinion->consider( $decision );
}
return $decision;
}

public function report_summary() {
$decision = $this->consider_opinions();
echo "Decision: $decision" . PHP_EOL;
}

/**
* Implements the decision of the considered opinions
*
* Do we need to fetch the current decision?
*
* @param object $post the post object that's been analysed in context
*
*/
public function implement_decision( $post ) {
$decision = $this->consider_opinions();
$current_decision = $this->get_current_decision( $post );
$this->update_decision( $post, $decision );
}

/**
* Fetch the current decision
*
* If not set then we'll need to determine it
* If it is, then we'll just re-determine it
*/

public function get_current_decision( $post ) {
$decision = get_post_meta( $post->ID, "_oik_block_editor", true );
if ( !$decision ) {
$decision = "AO";
}
return $decision;
}

public function update_decision( $post, $decision ) {
update_post_meta( $post->ID, "_oik_block_editor", $decision );

}



/**
* Gathers the opinions at Site level
*
Expand Down
6 changes: 3 additions & 3 deletions oik-block-opinions.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,11 @@ function oik_block_options_validate_post_type( $post_type ) {
*/
function oik_block_opinions_post_type( $post_type ) {
$opinions = oik_block_editor_opinions::instance();

$opinions->gather_site_opinions();
$opinions->gather_post_type_opinions( $post_type );
$opinions->gather_all_post_opinions( $post_type );
$opinions->report();
//$opinions->report_summary();

$opinions->report_summary();
}


Expand All @@ -101,6 +99,8 @@ function oik_block_opinions_post( $post, $post_type ) {
$opinions->gather_post_type_opinions( $post_type );
$opinions->gather_post_opinions( $post );
$opinions->report();
$opinions->report_summary();
$opinions->implement_decision( $post );
}

function oik_block_prepare_opinions() {
Expand Down
4 changes: 2 additions & 2 deletions opinions/class-oik-block-type-opinions.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ public function supports_editor() {
public function show_in_rest() {
if ( $this->post_type_object->show_in_rest ) {
$this->can_edit = true;
return new oik_block_editor_opinion( 'A', false, 'T', "REST API not enabled" );
return new oik_block_editor_opinion( 'A', false, 'T', "REST API enabled." );
} else {
$this->can_edit = false;
return new oik_block_editor_opinion( 'C', true, 'T', "REST API not enabled", "Set show_in_rest true to enable the Block editor" );
return new oik_block_editor_opinion( 'C', true, 'T', "REST API not enabled.", "Set show_in_rest true to enable the Block editor" );
}
}

Expand Down

0 comments on commit bfdb038

Please sign in to comment.