Esempio n. 1
0
 function findIdBySlug2($slugs)
 {
     App::import('Model', 'Forumbranch');
     $branch = new Forumbranch();
     $out = array("Forum" => null, "Topic" => null);
     if (empty($slugs)) {
         return $out;
     }
     $topic_slug = $slugs[count($slugs) - 1];
     $this->contain();
     $topic_id = $this->find('first', array('conditions' => array('Forumtopic.is_deleted <> 1', 'Forumtopic.slug' => $topic_slug)));
     if (!empty($topic_id)) {
         $out['Topic'] = $topic_id['Forumtopic']['id'];
     }
     if (!empty($out['Topic'])) {
         unset($slugs[count($slugs) - 1]);
     }
     $forum_slug = $slugs[count($slugs) - 1];
     $branch->contain();
     $forumbranch = $branch->find('first', array('conditions' => array('Forumbranch.is_deleted <> 1', 'Forumbranch.slug' => $forum_slug)));
     if (!empty($forumbranch)) {
         $out['Forum'] = $forumbranch['Forumbranch']['id'];
     }
     return $out;
 }
Esempio n. 2
0
 function _deletePost($post_id = null)
 {
     $post_id = (int) $post_id;
     if (!$post_id) {
         return false;
     }
     $time_now = date("Y-m-d H:i:s", time());
     $this->id = $post_id;
     $forumtopic_id = $this->field('forumtopic_id');
     $this->Forumtopic->recursive = 0;
     $result = $this->Forumtopic->read(null, $forumtopic_id);
     if (!$result['Forumtopic']['repliescounter']) {
         $this->Forumtopic->_deleteTopic($forumtopic_id);
         return false;
     }
     $this->query("\n\t\t\t\t\t\t\tUPDATE `forumposts`\n\t\t\t\t\t\t\tSET `deleted` = '{$time_now}', is_deleted = 1\n\t\t\t\t\t\t\tWHERE `forumposts`.`id` = {$post_id}");
     $this->query("\n\t\t\t\t\t\t\tUPDATE `forumtopics`\n\t\t\t\t\t\t\tSET `repliescounter` = `repliescounter` - 1\n\t\t\t\t\t\t\tWHERE `forumtopics`.`id` = " . $result['Forumtopic']['id']);
     //Change only if topic have this lastpost id
     if ($result['Forumtopic']['lastpost_id'] == $post_id) {
         $lastpost_id = $this->query("\tSELECT max(id) AS lastpost_id\n\t\t\t\t\t\t\t\t\t\t\tFROM forumposts\n\t\t\t\t\t\t\t\t\t\t\tWHERE \tforumtopic_id = " . $forumtopic_id . "\n\t\t\t\t\t\t\t\t\t\t\t\tAND\tis_deleted <> 1 ");
         $lastpost_id = $lastpost_id[0][0]['lastpost_id'];
         $this->query("\n\t\t\t\t\t\t\t\tUPDATE `forumtopics`\n\t\t\t\t\t\t\t\tSET   `lastpost_id` = " . $lastpost_id . "\n\t\t\t\t\t\t\t\tWHERE `forumtopics`.`id` = " . $result['Forumtopic']['id']);
     }
     if (!class_exists('Forumbranch')) {
         App::import('Model', 'Forumbranch');
     }
     $forumbranch = new Forumbranch();
     $forumbranch->update_branch_parents($result['Forumtopic']['forumbranch_id'], null, 1);
     $forumbranch->update_lastpostID($result['Forumtopic']['forumbranch_id'], $post_id);
     return true;
 }
 function generate_last_post_url_for_branch($forumtopic_slug, $lft, $rght)
 {
     $objBranch = new Forumbranch();
     $forum_path = $objBranch->getBranchSlugTree($lft, $rght);
     if (empty($forum_path)) {
         return "";
     }
     $slugs = array();
     foreach ($forum_path as $index => $branch) {
         $slugs[$index] = $branch['Forumbranch']['slug'];
     }
     array_push($slugs, $forumtopic_slug);
     return implode("/", $slugs);
 }