function create() { if ($this->_user['id'] == 2 || $this->_user['id'] == 1) { $this->set('alert', '1'); } else { $this->set('alert', '0'); } if (isset($_POST['submit'])) { $brand = $_POST['brand']; $br = new Brand(); $br->description = $brand['text']; $br->image = $brand['image']; $br->url = $brand['url']; $br->deck_id = $brand['deck']; $br->create(); $deck = new Deck(); $deck->id = $brand['deck']; $deck->title = $deck->getTitle(); $deck->slug_title = $deck->sluggify($deck->title); header('Location: deck/' . $brand['deck'] . '_' . $deck->slug_title); } else { } }
public function getLastDeck($id) { $deck_id = $this->dbGetOne('SELECT deck_revision_id FROM deck_content WHERE item_id=:id LIMIT 1', array('id' => $id)); $deck = new Deck(); $deck->id = $deck_id; $deck->title = $deck->getTitle(); $deck->slug_title = $deck->sluggify($deck->title); return $deck; }
public function getFollowedDecks() { $this->initConnection(); $res = array(); $res_array = $this->dbQuery('SELECT * FROM subscription WHERE item_type="deck" AND user_id=:id', array('id' => $this->id)); foreach ($res_array as $row) { $deck = new Deck(); $deck->deck_id = $row['item_id']; $deck->id = $deck->getLastRevisionID(); $title = $deck->getTitle(); $deck->title = $deck->shortenTitle($title); $res[] = $deck; } return $res; }
public function getAllTranslations($slide_rev_id = 0) { $this->initConnection(); $result = array(); $complete_result = array(); $language_ids = array(); $node = array(); $slide_translations = array(); $node['id'] = $this->deck_id; $node['language'] = $this->getLanguage(); $node['last'] = $this->id; $node['slug_title'] = $this->slug_title; $result = $this->getTranslatedTo(true); foreach ($result as $lang) { $language_ids[] = $lang['language']['id']; } if (!in_array($node['language']['id'], $language_ids)) { $language_ids[] = $node['language']['id']; $result[] = $node; } $visited = array(); foreach ($result as $node) { $visited[] = $node['id']; } $parent = $this->translated_from; while ($parent) { $parent_deck = new Deck(); $parent_deck->id = $this->getTranslatedFromRevision(); $parent_deck->deck_id = $parent; $parent_deck->language = $parent_deck->getLanguage(); $parent_deck->translated_from = $parent_deck->getTranslatedFrom(); $parent_deck->title = $parent_deck->getTitle(); $parent_deck->slug_title = $parent_deck->sluggify($parent_deck->title); if (!in_array($parent_deck->language['id'], $language_ids)) { $parent_arr = array(); $parent_arr['id'] = $parent; $parent_arr['language'] = $parent_deck->language; $parent_arr['first'] = $parent_deck->id; $parent_arr['last'] = $parent_deck->getLastRevisionID(); $parent_arr['slug_title'] = $parent_deck->slug_title; $result[] = $parent_arr; $language_ids[] = $parent_arr['language']['id']; } foreach ($parent_deck->getTranslatedTo(true) as $node) { if (!in_array($node['id'], $visited) && !in_array($node['language']['id'], $language_ids)) { $visited[] = $node['id']; $result[] = $node; $language_ids[] = $node['language']['id']; } } $parent = $parent_deck->translated_from; } if ($slide_rev_id) { $slide = new Slide(); $slide->createFromID($slide_rev_id); $slide_translations = $slide->getAllTranslations(); foreach ($result as $node) { $language = $node['language']['id']; $deck = new Deck(); $deck->createFromID($node['last']); foreach ($slide_translations as $slide) { if ($slide['language']['id'] == $language) { $slide_all_revisions = new Slide(); $slide_all_revisions->slide_id = $slide['id']; $all_revisions = array(); $all_revisions = $slide_all_revisions->getThisSlideRevisions(); foreach ($all_revisions as $slide_rev) { if ($deck->isSlideIn($slide_rev['id'])) { $node['slide'] = $deck->getSlidePropertiesById($slide_rev['id']); $node['slideLink'] = $node['slide']['link']; } } $complete_result[] = $node; } } } } else { foreach ($result as $node) { $deck = new Deck(); $node['slide'] = $deck->getSlidePropertiesById(0); $complete_result[] = $node; } } return $complete_result; }
function item() { $item_id = $_GET['id']; $item_type = $_GET['type']; $item_user = @$_GET['user']; $redirect_link = ""; $hash = ""; switch ($item_type) { case 'slide': $slide = new Slide(); $slide->createFromID($item_id); if (isset($item_user)) { $last_revision = $slide->getLastRevisionID($item_user); } else { $last_revision = $slide->last_revision_id; } $slide2 = new Slide(); $slide2->createFromID($last_revision); $slide_usage = $slide2->getUsage(); if (is_array($slide_usage) && count($slide_usage) == 1) { $hash = 'tree-' . $slide_usage[0]->id . '-slide-' . $slide2->id . '-' . $slide2->getPosition() . '-view'; $parent_deck = $slide2->getLastOuterParent($slide_usage[0]->id); $deck = new Deck(); $deck->id = $parent_deck; $deck->title = $deck->getTitle(); $deck->slug_title = $deck->sluggify($deck->title); $redirect_link = BASE_PATH . 'deck/' . $parent_deck . '_' . $deck->slug_title . '#' . $hash; } else { $redirect_link = BASE_PATH . 'slide/' . $last_revision; } break; case 'deck': $deck = new Deck(); $deck->createFromID($item_id); if (isset($item_user)) { $last_revision = $deck->getLastRevisionID($item_user); } else { $last_revision = $deck->last_revision_id; } $deck_for_title = new Deck(); $deck_for_title->id = $last_revision; $deck_for_title->title = $deck_for_title->getTitle(); $deck_for_title->slug_title = $deck_for_title->sluggify($deck->title); $deck2 = new Deck(); $deck2->createFromID($last_revision); $deck_usage = $deck2->getUsage(); if (is_array($deck_usage) && count($deck_usage) == 1) { $hash = 'tree-' . $deck_usage[0]->id . '-deck-' . $deck2->id . '-' . $deck2->getPosition() . '-view'; $parent_deck = $deck2->getLastOuterParent($deck_usage[0]->id); $deck_for_title = new Deck(); $deck_for_title->id = $parent_deck; $deck_for_title->title = $deck->getTitle(); $deck_for_title->slug_title = $deck->sluggify($deck->title); $redirect_link = BASE_PATH . 'deck/' . $parent_deck . '_' . $deck_for_title->slug_title . '#' . $hash; } else { $redirect_link = BASE_PATH . 'deck/' . $last_revision . '_' . $deck_for_title->slug_title; } break; } header('Location: ' . $redirect_link); }
public function getAnswerTest($user_id = false, $deck_revision_id = false, $start, $end, $keywords = '') { if ($user_id != false || $deck_revision_id != false) { $this->initConnection(); $activities = array(); $result = array(); if ($user_id) { $user = new User(); $user->id = $user_id; $user->getUsername(); if (strlen($keywords)) { $result = $this->dbQuery('SELECT max(testing.max_points) AS max_p, testing.item_id, testing.timestamp, wiki_app FROM testing INNER JOIN deck_revision ON testing.item_id = deck_revision.id WHERE testing.user_id=:user_id AND testing.type="auto" AND testing.max_points IS NOT NULL AND MATCH (deck_revision.title) AGAINST (\'' . $keywords . '*\' IN BOOLEAN MODE) GROUP BY testing.attempt_id', array('user_id' => $user_id)); } else { $result = $this->dbQuery('SELECT max(max_points) AS max_p, item_id, timestamp, wiki_app FROM testing WHERE user_id=:user_id AND type="auto" AND max_points IS NOT NULL AND DATE(timestamp) >= DATE("' . $start . '") AND DATE(timestamp) < DATE("' . $end . '") GROUP BY attempt_id', array('user_id' => $user_id)); } if (count($result)) { foreach ($result as $row) { $test = new Deck(); $test->id = $row['item_id']; $test->title = $test->getTitle(); if ($test->title == "") { $test->title = "Untitled"; } $test->slug_title = $test->sluggify($test->title); $text = array(); $text['wiki_app'] = $row['wiki_app']; $text['max_points'] = $row['max_p']; $text['score'] = round($row['wiki_app'] / $row['max_p'] * 100, 2) . '%'; $activity = new Activity($row['timestamp'], $user, 'answered_test', $test, $text); $activities[] = $activity; } } } else { $result = $this->dbQuery('SELECT * FROM testing WHERE item_id=:deck_revision_id AND DATE(timestamp) >= DATE("' . $start . '") AND DATE(timestamp) < DATE("' . $end . '")', array('deck_revision_id' => $deck_revision_id)); $test = new Deck(); $test->id = $deck_revision_id; $test->title = $test->getTitle(); if ($test->title == "") { $test->title = "Untitled"; } $test->slug_title = $test->sluggify($test->title); if (count($result)) { foreach ($result as $row) { $activity = new Activity($row['timestamp'], $row['user_id'], 'answered_test', $test, 'with points ' . $row['wiki_app'] . '/' . $row['max_points']); $activities[] = $activity; } } } if (count($activities)) { foreach ($activities as $activity) { $this->activities[] = $activity; } } } }
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; }