function deck()
 {
     $deck_id = $_GET['id'];
     $deck = new Deck();
     $deck->createFromIDLite($deck_id);
     $deck->last_revision_id = $deck->getLastRevisionID();
     $usage = $deck->getUsage();
     $deck->comments = $deck->getComments();
     $translations = $deck->getTranslatedTo();
     $this->set('deck', $deck);
     $this->set('translations', $translations);
     $this->set('usage', $usage);
     $this->set('page_title', $deck->title . ' - SlideWiki');
     $this->set('page_keywords', join(',', $deck->getTags($deck->id)));
 }
Exemple #2
0
 public function getUsageExceptUser($user_id, $ignore_owner = 0)
 {
     $user = new User();
     $user->createFromID($user_id);
     if (!$ignore_owner) {
         $ignore_list = array($user_id);
     } else {
         //ignore the usage by owner
         $ignore_list = array($user_id, $this->owner->id);
     }
     $res = array();
     $query = $this->dbQuery('SELECT deck_content.item_id, deck_content.deck_revision_id FROM deck_content WHERE item_type="slide" AND item_id = :item_id', array('item_id' => $this->id));
     # deck_revision.id - revision id of the deck
     # deck_revision.user_id - owner of this deck revision
     # deck_revision.title - title of this deck revision
     # users.username - username of the owner
     /*$this->dbQuery ( 'SELECT deck_revision.id, deck_revision.title, deck_revision.user_id, users.username
       FROM deck_content INNER JOIN deck_revision ON(deck_revision_id=deck_revision.id) INNER JOIN users ON(deck_revision.user_id=users.id)
       WHERE item_type="slide" AND item_id=' . $this->id . ' GROUP BY deck_revision.id ORDER BY deck_revision.timestamp DESC' );*/
     foreach ($query as $row) {
         $deck = new Deck();
         $deck->createFromIDLite($row['deck_revision_id']);
         if (!in_array($deck->owner->id, $ignore_list)) {
             array_push($res, $deck);
         }
     }
     if (empty($res)) {
         $res = "Not used!";
     }
     return $res;
 }
 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!";
             }
         }
     }
 }
Exemple #4
0
 public function getEditorDecks()
 {
     $result = array();
     $e_decks_ids = $this->dbQuery('SELECT DISTINCT * FROM user_group WHERE user_id=:user_id AND category="editor" ORDER BY timestamp DESC', array('user_id' => $this->id));
     foreach ($e_decks_ids as $row) {
         $n = new Deck();
         $n->createFromIDLite($row['deck_revision_id']);
         if ($n->title) {
             $result[] = $n;
         }
     }
     return $result;
 }
Exemple #5
0
 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;
 }
Exemple #6
0
 function getAllDeckContributions()
 {
     $user_id = $_GET['id'];
     $user = new User();
     $user->createFromID($user_id);
     $user->email = $user->getEmail();
     $editoreddecks = $user->getEditorDecks();
     $owndecks = array();
     foreach ($user->getContributedDecks() as $c) {
         $n = new Deck();
         $n->createFromIDLite($c);
         $owndecks[] = $n;
     }
     $this->set('editoreddecks', $editoreddecks);
     $this->set('owndecks', $owndecks);
     $this->set('profile', $user);
     $this->set('page_title', $user->username . ' - List of all contributed decks');
 }
Exemple #7
0
 function style()
 {
     $deckid = $_GET['deck'];
     $styleid = isset($_GET['id']) ? $_GET['id'] : 1;
     $response = 0;
     $deck = new Deck();
     $deck->createFromIDLite($deckid);
     //show error if deck does not exist
     if (!isset($deck->deck_id)) {
         header('Location: ' . BASE_PATH . 'error/404');
         die;
     }
     $slides = $deck->getSlidesFull();
     $deck->slides = $slides;
     $style = new Style();
     $style->createFromID($styleid);
     //show error if style does not exist
     if (!isset($style->name)) {
         header('Location: ' . BASE_PATH . 'error/404');
         die;
     }
     $styles = $style->getAll();
     //$this->set ( 'user', $current_user );
     $this->set('response', $response);
     $this->set('deck', $deck);
     $this->set('styleObj', $style);
     $this->set('styles', $styles);
     $this->set('page_title', "SlideWiki Style - " . $style->name);
 }
Exemple #8
0
 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;
 }