layout = $layout;
$this->show_comments = $show_comments;
$this->proposal_id = $pid;
$this->type = $amend_type;
return true;
}
private function headers($current, $previous, $lines, $layout, $original, $amendment){
static $show_id = 0;
$diff = false;
if($current->getId() != ''){
$diff = true;
}
if ( $current->getOrder2() != $previous->getOrder2() || $current->getTitle2_status()!= $previous->getTitle2_status())
{
//we have moved to next 'title2' section
$layout->echoln('
');
$lines++;
$layout->echoln(' ('.$original['paragraph'].') | ');
if ($diff) {
$layout->echoln('()');
}
$layout->echoln(' | ');
if ($amendment!=NULL ){
$layout->echoln('()');
}
$layout->echoln(' |
');
$lines++;
}
elseif ( $current->getArticle() != $previous->getArticle() || $current->getArticle_title() != $previous->getArticle_title() || $current->getArticle_Title_status()!= $previous->getArticle_Title_status())
{
//we have moved to next article
$show_id++;
$txt = '');
$lines++;
$layout->echoln(' ('.$original['paragraph'].') | ');
if ($diff) {
$layout->echoln('()');
}
$layout->echoln(' | ');
if ($amendment!=NULL){
$layout->echoln('()');
}
$layout->echoln(' |
');
$lines++;
}
elseif ($current->getParagraph() != $previous->getParagraph() || $current->getParagraph_status()!= $previous->getParagraph_status())
{
//we have moved to next paragraph
$layout->echoln(' ('.$original['paragraph'].') | ');
if ($diff) {
$layout->echoln('()');
}
$layout->echoln(' | ');
if ($amendment!=NULL ){
$layout->echoln('()');
}
$layout->echoln(' |
');
$lines++;
}
$ret = array($lines, $show_id);
return $ret;
}
private function Area($layout, $model, $lines, $original, $previous, $show_comments, $amendment){
$ret = $this->headers($model, $previous, $lines, $layout, $original, $amendment);
$lines = $ret[0];
$show_id = $ret[1];
$ordered = array("\r\n", "\n", "\r");
$replace = '
';
$layout->echoln(''.$original['sentence'].''.$original['sentence_text'].' | ');
if ($model->getId() != NULL){
$layout->echoln(' ');
$layout->echoln('');
$layout->echoln('');
}
$layout->echoln(' | ');
$amendLink =' ');
$amendLink .= '&aid='.$amendment['id'];
}
if ($this->type != NULL){
$amendLink.='">Amend';
$layout->echoln($amendLink);
}
$layout->echoln(' |
');
if ($show_comments && $model->getJc_comment()!=NULL){
$layout->echoln(' | JC Comment: '.$model->getJc_comment().' | |
');
$layout->echoln('');
}
$lines++;
return $lines;
}
public function display($sentences, $proposals_sentences, $amendments){
$layout = $this->layout;
$layout->echoln('');
$layout->echoln('');
$layout->echoln('
Click on article titles to show/hide them
');
$layout->echoln('Original | Proposal | Amendments |
');
//display title
foreach ($sentences as $sentence) {
//check if modified version exists
$ps = NULL;
foreach ($proposals_sentences as $prs){
if($prs['sentence_id'] == $sentence['id']){
$ps = $prs;
break;
}
}
$amendment = NULL;
foreach($amendments as $am){
if($sentence['id'] == $am['sentence_id']){
$amendment = $am; //keep only the latest amendment
}
}
$layout->echoln(''.$sentence['title'].' | ');
if ($ps !=NULL){
$layout->echoln('');
}
$layout->echoln(' | ');
if ($amendment != NULL){
$layout->echoln('');
}
$layout->echoln(' |
');
break;
}
$empty= new Proposals_sentences('');
$previous = $empty;
$empty_array = array(
'title2'=>' ',
'article'=>' ',
'article_title'=>' ',
'paragraph'=>' ',
'sentence'=>' ',
'sentence_text'=>' '
);
$lines = 2;
foreach ($sentences as $sentence) {
//check if edited text exists
$later = array();
$modified = NULL;
$amendment = NULL;
foreach($proposals_sentences as $prop_s){
if ($prop_s['sentence_id'] == $sentence['id']){
//an edited version of this sentence exists
//simple edited text
if($prop_s['change_type']=='Edit'){
$modified = new Proposals_sentences($prop_s);
}
elseif($prop_s['change_type']=='Delete'){
$modified = new Proposals_sentences($prop_s);
}
elseif($prop_s['change_type']=='New_^'){
//display the inserted sentence
$ps = new Proposals_sentences($prop_s);
$amendment = NULL;
foreach($amendments as $am){
if($ps->getId() == $am['proposals_sentence_id']){
$amendment = $am;
}
}
$lines = $this->Area($layout, $ps, $lines, $empty_array, $previous, $this->show_comments, $amendment);
$previous = $ps;
}
elseif($prop_s['change_type']=='New_v'){
//display later
$later []=$prop_s;
}
}
}
if ($modified!=NULL){
$amendment = NULL;
foreach($amendments as $am){
if($modified->getId() == $am['proposals_sentence_id']){
$amendment = $am;
}
}
$lines = $this->Area($layout, $modified, $lines, $sentence, $previous, $this->show_comments, $amendment);
$previous = $modified;
}
else{
//display original cia sentence
$ps = new Proposals_sentences('');
$ps->copy_from_cia_array($sentence);
$ps->setProposal_id($this->proposal_id);
$ps->setChange_type('Edit');
$amendment = NULL;
foreach($amendments as $am){
if($sentence['id'] == $am['sentence_id'] && $am['proposals_sentence_id'] == -1){
$amendment = $am;
}
}
$lines = $this->Area($layout, $ps, $lines, $sentence, $previous, $this->show_comments, $amendment);
$previous = $ps;
}
foreach($later as $later_s){
//display the inserted sentence
$ps = new Proposals_sentences($later_s);
$amendment = NULL;
foreach($amendments as $am){
if($ps->getId() == $am['proposals_sentence_id']){
$amendment = $am;
}
}
$lines = $this->Area($layout, $ps, $lines, $empty_array, $previous, $this->show_comments, $amendment);
$previous = $ps;
}
}
$layout->echoln('
');
return true;
}
public function display1Col($sentences, $proposals_sentences, $amendments){
$layout = $this->layout;
$layout->echoln('');
$layout->echoln('');
$layout->echoln('');
//display title
foreach ($sentences as $sentence) {
//check if modified version exists
$ps = NULL;
foreach ($proposals_sentences as $prs){
if($prs['sentence_id'] == $sentence['id']){
$ps = $prs;
break;
}
}
$amendment = NULL;
if ($ps !=NULL){
$layout->echoln('');
}else{
$layout->echoln(''.$sentence['title']);
}
$layout->echoln(' | ');
$layout->echoln('');
break;
}
$empty= new Proposals_sentences('');
$previous = $empty;
$empty_array = array(
'title2'=>' ',
'article'=>' ',
'article_title'=>' ',
'paragraph'=>' ',
'sentence'=>' ',
'sentence_text'=>' '
);
$lines = 2;
foreach ($sentences as $sentence) {
//check if edited text exists
$later = array();
$modified = NULL;
$amendment = NULL;
foreach($proposals_sentences as $prop_s){
if ($prop_s['sentence_id'] == $sentence['id']){
//an edited version of this sentence exists
//simple edited text
if($prop_s['change_type']=='Edit'){
$modified = new Proposals_sentences($prop_s);
}
elseif($prop_s['change_type']=='Delete'){
$modified = new Proposals_sentences($prop_s);
}
elseif($prop_s['change_type']=='New_^'){
//display the inserted sentence
$ps = new Proposals_sentences($prop_s);
foreach($amendments as $am){
if($ps->getId() == $am['proposals_sentence_id']){
$amendment = $am;
}
}
$lines = $this->Area1Col($layout, $ps, $lines, $empty_array, $previous, $this->show_comments, $amendment);
$previous = $ps;
}
elseif($prop_s['change_type']=='New_v'){
//display later
$later []=$prop_s;
}
}
}
if ($modified!=NULL){
$amendment = NULL;
foreach($amendments as $am){
if($modified->getId() == $am['proposals_sentence_id']){
$amendment = $am;
}
}
$lines = $this->Area1Col($layout, $modified, $lines, $sentence, $previous, $this->show_comments, $amendment);
$previous = $modified;
}
else{
//display original cia sentence
$ps = new Proposals_sentences('');
$ps->copy_from_cia_array($sentence);
$ps->setProposal_id($this->proposal_id);
$ps->setChange_type('Edit');
$amendment = NULL;
foreach($amendments as $am){
if($sentence['id'] == $am['sentence_id'] && $am['proposals_sentence_id'] == -1){
$amendment = $am;
}
}
$lines = $this->Area1Col($layout, $ps, $lines, $sentence, $previous, $this->show_comments, $amendment);
$previous = $ps;
}
foreach($later as $later_s){
//display the inserted sentence
$ps = new Proposals_sentences($later_s);
$amendment = NULL;
foreach($amendments as $am){
if($ps->getId() == $am['proposals_sentence_id']){
$amendment = $am;
}
}
$lines = $this->Area1Col($layout, $ps, $lines, $empty_array, $previous, $this->show_comments, $amendment);
$previous = $ps;
}
}
$layout->echoln(' |
');
return true;
}
private function Area1Col($layout, $model, $lines, $original, $previous, $show_comments, $amendment){
$ret = $this->headers1Col($model, $previous, $lines, $layout, $original, $amendment);
$lines = $ret[0];
$show_id = $ret[1];
$ordered = array("\r\n", "\n", "\r");
$replace = '
';
if ($model->getId() != NULL){
$layout->echoln(' ');
$layout->echoln('');
$layout->echoln(' |
');
}else{
$layout->echoln(''.$original['sentence'].''.$original['sentence_text'].' | ');
}
$lines++;
return $lines;
}
private function headers1Col($current, $previous, $lines, $layout, $original, $amendment){
static $show_id = 0;
$diff = false;
if($current->getId() != ''){
$diff = true;
}
if ( $current->getOrder2() != $previous->getOrder2() || $current->getTitle2_status()!= $previous->getTitle2_status())
{
//we have moved to next 'title2' section
if ($diff) {
$layout->echoln(' |
');
}else{
$layout->echoln(' |
'.$original['title2'].'');
}
$layout->echoln(' |
');
$lines++;
$show_id++;
if ($diff) {
$layout->echoln(' Article : ');
$layout->echoln('');
}else{
$layout->echoln(' |
Article '.$original['article'].': '.$original['article_title'].'');
}
$layout->echoln(' |
');
$layout->echoln('');
$lines++;
if ($diff) {
$layout->echoln('()');
}else{
$layout->echoln(' |
('.$original['paragraph'].')');
}
$layout->echoln(' |
');
$lines++;
}
elseif ( $current->getArticle() != $previous->getArticle() || $current->getArticle_title() != $previous->getArticle_title() || $current->getArticle_Title_status()!= $previous->getArticle_Title_status())
{
//we have moved to next article
$show_id++;
$txt = ' ';
if ($original['article'] > 0){
$txt .= 'Article '.$original['article'].': ';
}
$txt .= $original['article_title'].'';
if ($diff) {
$layout->echoln(' |
Article : ');
$layout->echoln('');
}else{
$layout->echoln($txt);
}
$layout->echoln(' |
');
$lines++;
if ($diff) {
$layout->echoln('()');
}
else{
$layout->echoln(' |
('.$original['paragraph'].')');
}
$layout->echoln(' |
');
$lines++;
}
elseif ($current->getParagraph() != $previous->getParagraph() || $current->getParagraph_status()!= $previous->getParagraph_status())
{
//we have moved to next paragraph
if ($diff) {
$layout->echoln('()');
}else{
$layout->echoln(' |
('.$original['paragraph'].')');
}
$layout->echoln(' |
');
$lines++;
}
$ret = array($lines, $show_id);
return $ret;
}
}