function reportDeckChanges() { //$this->_template->disableHeader(); //$this->_template->disableFooter(); $this->_noRender = true; $id = $_GET['deck']; $deck = new Deck(); $deck->createFromIDLite($id); // revision id $deck2 = new Deck(); $deck2->id = $deck->getPreviousRevisionID(); if ($deck2->id != NULL) { $deck2->createFromIDLite($deck2->id); $deck->content = $deck->fetchDeckContentLite(); $deck2->content = $deck2->fetchDeckContentLite(); $deck_count = count($deck->content); $deck2_count = count($deck2->content); //var_dump($deck->content); //var_dump($deck2->content); if ($deck_count > $deck2_count) { echo $deck_count - $deck2_count . " slide(s) added to the deck."; } elseif ($deck_count < $deck2_count) { echo $deck2_count - $deck_count . " slide(s) removed from the deck."; } else { $flag = 0; $changes = array(); foreach ($deck->content as $index => $val) { if ($val->id != $deck2->content[$index]->id) { $flag++; array_push($changes, array($index, $deck2->content[$index]->id, $val->id)); } } if ($flag) { echo "Content of the following " . $flag . " slide(s) has been modified:<br>"; echo "<ol>"; foreach ($changes as $v) { echo "<li>"; echo "<a href='slide/" . $v[1] . "' target='_blank'>Slide</a> at position <b>" . ($v[0] + 1) . "</b> <a href='slide/" . $v[2] . "' target='_blank'>changed</a> (<small><a style='color:#888855;' target='_blank' href='?url=compare/reportSlideChanges&slide=" . $v[2] . "&compareTo=" . $v[1] . "'>details</a></small>)."; echo "</li>"; } echo "</ol>"; } else { echo "Just a copy of the previous revision!"; } } } }
public function getFullDeckStream($deck_revision_id, $month, $filter = false, $portion) { if (!$month) { $month = date("Y-m"); $month .= '-01'; } $end = date($month); //1st day of current month $start = $end; switch ($portion) { default: break; case '1': $end_str = strtotime($end . ' +1 month '); //last day of current month $end = date('Y-m-d', $end_str); //last day of month $start_str = strtotime($end . ' -7 day'); //last weak $start = date('Y-m-d', $start_str); break; case '2': $end_str = strtotime($end . ' +1 month -7 day'); $end = date('Y-m-d', $end_str); $start_str = strtotime($end . ' -7 day'); $start = date('Y-m-d', $start_str); break; case '3': $end_str = strtotime($end . '+1 month -14 day'); $end = date('Y-m-d', $end_str); $start_str = strtotime($end . ' -7 day'); $start = date('Y-m-d', $start_str); break; case '4': $end_str = strtotime($end . '+1 month -21 day'); $end = date('Y-m-d', $end_str); $start_str = strtotime($month); $start = date('Y-m-d', $start_str); break; } if ($filter == false) { $filter_array = array('1', '1', '1', '1'); } else { $filter_array = explode(',', $filter); } $filter_array[0] = '1'; $deck = new Deck(); $deck->id = $deck_revision_id; $deck->deck_id = $deck->getBasicID(); $deck->content = $deck->fetchDeckContentLite(); $this->createForDeck($deck->deck_id, $start, $filter_array, $end); foreach ($deck->content as $item) { if (get_class($item) == 'Deck') { if ($filter == false) { $filter_array = array('1', '1', '1', '1'); } else { $filter_array = explode(',', $filter); } $filter_array[0] = '1'; $this->getFullDeckStream($item->id, $month, $filter, $portion); } else { if ($filter == false) { $filter_array = array('1', '1', '1', '1'); } else { $filter_array = explode(',', $filter); } $this->getSlideStream($item->id, $month, $filter, $portion); } } }
public function fetchDeckContentLite() { $this->initConnection(); $deck = null; $slide = null; $res = array(); // get content $deckContent = $this->dbQuery('SELECT * FROM deck_content WHERE deck_revision_id=:id ORDER BY position', array('id' => $this->id)); /*if (! $deckContent) die ( "error querying db for deck content: " . mysql_error () );*/ // parse content foreach ($deckContent as $item) { // if it's deck if ($item['item_type'] == 'deck') { $deck = new Deck(); $deck->createFromIDLite($item['item_id']); $deck->content = $deck->fetchDeckContentLite(); $deck->position = $item['position']; $res[] = $deck; } else { $slide = new Slide(); $slide->createFromIDLite($item['item_id']); $slide->position = $item['position']; $slide->deck = new Deck(); $slide->deck->id = $item['deck_revision_id']; $slide->deck->title = $slide->deck->getTitle(); $slide->deck->slug_title = $slide->sluggify($slide->deck->title); $res[] = $slide; } } return $res; }
function handleChange($changes) { //we store new deck revs to prevent duplicate rev creation in case we have changed two items of a deck $new_deck_revs = array(); //result of change applied to each change item $items = array(); $should_refresh_nodes = array(); //create user who has made the change $user = new User(); $user->createFromID($changes['user_id']); foreach ($changes['items'] as $change) { //get the path to the root $nested_decks = $this->getNestedDecks($change['item_id']); //get the target deck of change if (count($nested_decks) == 1) { //root node is selected $target_deck_id = $this->root_id; } else { $target_deck_id = $nested_decks[0]; } //create target deck object $target_deck = new Deck(); $target_deck->createFromIDLite($target_deck_id); $target_deck->content = $target_deck->fetchDeckContentLite(); //check if we need to create new revisions if (!@$new_deck_revs[$target_deck->id] && $this->needNewRevision($user->id, $target_deck)) { $target_deck->user = $user; $new_deck_revs[$target_deck_id] = $target_deck->commit($target_deck_id); $i = 1; while (@$nested_decks[$i] && (int) $nested_decks[$i] != 0) { $tmp_deck = new Deck(); if (@$new_deck_revs[$nested_decks[$i]]) { $tmp_deck->createFromIDLite($new_deck_revs[$nested_decks[$i]]); $tmp_deck->content = $tmp_deck->fetchDeckContentLite(); } else { $tmp_deck->createFromIDLite($nested_decks[$i]); $tmp_deck->content = $tmp_deck->fetchDeckContentLite(); } if (!@$new_deck_revs[$tmp_deck->id] && $this->needNewRevision($user->id, $tmp_deck)) { $tmp_deck->user = $user; $new_deck_revs[$nested_decks[$i]] = $tmp_deck->commit($tmp_deck->id); } else { $should_refresh_nodes[] = $tmp_deck->id; } if (@$new_deck_revs[$nested_decks[$i - 1]]) { //we should update deck content $tmp_deck->replaceContentWith($new_deck_revs[$nested_decks[$i - 1]], $nested_decks[$i - 1], 'deck'); } else { //we do not need to iterate more break; } $i++; } } else { //stop refreshing here $should_refresh_nodes[] = $target_deck_id; } //check if target node is changed to a new revision if (count($nested_decks) == 1) { //root node is selected $target_deck_id = @$new_deck_revs[$this->root_id] ? $new_deck_revs[$this->root_id] : $this->root_id; } else { $target_deck_id = @$new_deck_revs[$nested_decks[0]] ? $new_deck_revs[$nested_decks[0]] : $nested_decks[0]; } //contains the id of leave deck whether it has a new revision or not $items[] = array('target_deck_id' => $target_deck_id); } $output = array(); $output['items'] = $items; $output['refresh_nodes'] = $should_refresh_nodes; $output['new_deck_revs'] = $new_deck_revs; if (@$new_deck_revs[$this->root_id]) { //root node has changed! $this->root_id = $new_deck_revs[$this->root_id]; $output['root_changed'] = $this->root_id; $deck_for_title = new Deck(); $deck_for_title->id = $this->root_id; $deck_for_title->title = $deck_for_title->getTitle(); $deck_for_title->slug_title = $deck_for_title->sluggify($deck_for_title->title); $output['slug_title'] = $deck_for_title->slug_title; } else { //no change in root node $output['root_changed'] = 0; } return $output; }