Example #1
0
 public function callbackDelete()
 {
     $this->comment = new \Phpmvc\Comment\Comment();
     $this->comment->setDI($this->di);
     $deleted = $this->comment->delete($this->id);
     if (is_numeric($this->pagekey)) {
         $this->question = new \Anax\Question\Question();
         $this->question->setDI($this->di);
         $question = $this->question->findQuestion(null, $this->pagekey);
         $comments = $question[0]->getProperties()['comments'];
         $this->question->customUpdate('question', array('comments' => $comments - 1), 'id = ' . $this->pagekey);
     } else {
         $this->news = new \Anax\News\News();
         $this->news->setDI($this->di);
         $news = $this->news->findNews($this->pagekey);
         $comments = $news[0]->getProperties()['comments'];
         $articleid = $news[0]->getProperties()['id'];
         $this->news->customUpdate('news', array('comments' => $comments - 1), 'id = ' . $articleid);
     }
     if ($deleted) {
         $user = new \Anax\Users\User();
         $user->setDI($this->di);
         $user = $user->find($_SESSION['user']->id);
         $xp = $user->getProperties()['xp'];
         $user->update(array('xp' => $xp - 2));
         return true;
     } else {
         return false;
     }
 }
Example #2
0
 public function callbackDelete()
 {
     $this->answer = new \Anax\Answer\Answer();
     $this->answer->setDI($this->di);
     $deleted = $this->answer->delete($this->id);
     $this->question = new \Anax\Question\Question();
     $this->question->setDI($this->di);
     $question = $this->question->findQuestion(null, $this->pagekey);
     $answers = $question[0]->getProperties()['answers'];
     $this->question->customUpdate('question', array('answers' => $answers - 1), 'id = ' . $this->pagekey);
     if ($deleted) {
         $user = new \Anax\Users\User();
         $user->setDI($this->di);
         $user = $user->find($_SESSION['user']->id);
         $xp = $user->getProperties()['xp'];
         $user->update(array('xp' => $xp - 4));
         return true;
     } else {
         return false;
     }
 }
Example #3
0
 public function callbackDelete()
 {
     $this->question = new \Anax\Question\Question();
     $this->question->setDI($this->di);
     $deleted = $this->question->delete($this->id);
     if ($deleted) {
         $this->redirect = 'question';
         // Also delete all comments and answers related to this question
         $this->answer = new \Anax\Answer\Answer();
         $this->answer->setDI($this->di);
         $answers = $this->answer->findAll($this->id);
         var_dump($answers);
         foreach ($answers as $id => $answer) {
             $this->answer->delete($answer->id);
         }
         $this->comment = new \Phpmvc\Comment\Comment();
         $this->comment->setDI($this->di);
         $comments = $this->comment->findAll($this->id);
         foreach ($comments as $id => $comment) {
             $this->comment->delete($comment->id);
         }
         // Update User reputation
         $user = new \Anax\Users\User();
         $user->setDI($this->di);
         $user = $user->find($_SESSION['user']->id);
         $xp = $user->getProperties()['xp'];
         $user->update(array('xp' => $xp - 5));
         // Update number of tags
         $oldtags = explode(',', $this->tagslug);
         $this->tag = new \Anax\Question\Tag();
         $this->tag->setDI($this->di);
         foreach ($oldtags as $key => $val) {
             $tag = $this->tag->findTag($val);
             $questions = $tag[0]->getProperties()['questions'];
             $tagid = $tag[0]->getProperties()['id'];
             $this->tag->customUpdate('tag', array('questions' => $questions - 1), 'id = ' . $tagid);
         }
         return true;
     } else {
         return false;
     }
 }
Example #4
0
 /**
  * Construct.
  *
  */
 public function __construct()
 {
     parent::__construct();
     require ANAX_APP_PATH . 'config/error_reporting.php';
     $this->setShared('response', '\\Anax\\Response\\CResponseBasic');
     $this->setShared('validate', '\\Anax\\Validate\\CValidate');
     $this->setShared('flash', '\\Anax\\Flash\\CFlashBasic');
     $this->set('route', '\\Anax\\Route\\CRouteBasic');
     $this->set('view', '\\Anax\\View\\CViewBasic');
     $this->set('form', '\\Mos\\HTMLForm\\CForm');
     $this->set('ErrorController', function () {
         $controller = new \Anax\MVC\ErrorController();
         $controller->setDI($this);
         return $controller;
     });
     $this->setShared('log', function () {
         $log = new \Anax\Log\CLogger();
         $log->setContext('development');
         return $log;
     });
     $this->setShared('request', function () {
         $request = new \Anax\Request\CRequestBasic();
         $request->init();
         return $request;
     });
     $this->setShared('url', function () {
         $url = new \Anax\Url\CUrl();
         $url->setSiteUrl($this->request->getSiteUrl());
         $url->setBaseUrl($this->request->getBaseUrl());
         $url->setStaticSiteUrl($this->request->getSiteUrl());
         $url->setStaticBaseUrl($this->request->getBaseUrl());
         $url->setScriptName($this->request->getScriptName());
         $url->setUrlType($url::URL_APPEND);
         return $url;
     });
     $this->setShared('views', function () {
         $views = new \Anax\View\CViewContainerBasic();
         $views->setBasePath(ANAX_APP_PATH . 'view');
         $views->setFileSuffix('.tpl.php');
         $views->setDI($this);
         return $views;
     });
     $this->setShared('db', function () {
         $db = new \Mos\Database\CDatabaseBasic();
         $db->setOptions(require ANAX_APP_PATH . 'config/config_mysql.php');
         $db->connect();
         return $db;
     });
     $this->setShared('router', function () {
         $router = new \Anax\Route\CRouterBasic();
         $router->setDI($this);
         $router->addInternal('403', function () {
             $this->dispatcher->forward(['controller' => 'error', 'action' => 'statusCode', 'params' => ['code' => 403, 'message' => "HTTP Status Code 403: This is a forbidden route."]]);
         })->setName('403');
         $router->addInternal('404', function () {
             $this->dispatcher->forward(['controller' => 'error', 'action' => 'statusCode', 'params' => ['code' => 404, 'message' => "HTTP Status Code 404: This route is not found."]]);
             $this->dispatcher->forward(['controller' => 'error', 'action' => 'displayValidRoutes']);
         })->setName('404');
         $router->addInternal('500', function () {
             $this->dispatcher->forward(['controller' => 'error', 'action' => 'statusCode', 'params' => ['code' => 500, 'message' => "HTTP Status Code 500: There was an internal server or processing error."]]);
         })->setName('500');
         return $router;
     });
     $this->setShared('dispatcher', function () {
         $dispatcher = new \Anax\MVC\CDispatcherBasic();
         $dispatcher->setDI($this);
         return $dispatcher;
     });
     $this->setShared('session', function () {
         $session = new \Anax\Session\CSession();
         $session->configure(ANAX_APP_PATH . 'config/session.php');
         $session->name();
         $session->start();
         return $session;
     });
     $this->setShared('theme', function () {
         $themeEngine = new \Anax\ThemeEngine\CThemeBasic();
         $themeEngine->setDI($this);
         $themeEngine->configure(ANAX_APP_PATH . 'config/theme.php');
         return $themeEngine;
     });
     $this->setShared('navbar', function () {
         $navbar = new \Anax\Navigation\CNavbar();
         $navbar->setDI($this);
         $navbar->configure(ANAX_APP_PATH . 'config/navbar.php');
         return $navbar;
     });
     $this->setShared('user', function () {
         $user = new \Anax\Users\User();
         $user->setDI($this);
         return $user;
     });
     $this->set('fileContent', function () {
         $fc = new \Anax\Content\CFileContent();
         $fc->setBasePath(ANAX_APP_PATH . 'content/');
         return $fc;
     });
     $this->setShared('textFilter', function () {
         $filter = new \Anax\Content\CTextFilter();
         $filter->setDI($this);
         $filter->configure(ANAX_APP_PATH . 'config/text_filter.php');
         return $filter;
     });
 }
Example #5
0
 public function callbackDelete()
 {
     $this->news = new \Anax\News\News();
     $this->news->setDI($this->di);
     $deleted = $this->news->delete($this->id);
     if ($deleted) {
         $this->redirect = 'news';
         // Also delete all comments related to this article
         $this->comment = new \Phpmvc\Comment\Comment();
         $this->comment->setDI($this->di);
         $comments = $this->comment->findAll($this->id);
         foreach ($comments as $id => $comment) {
             $this->comment->delete($comment->id);
         }
         // Update User reputation
         $user = new \Anax\Users\User();
         $user->setDI($this->di);
         $user = $user->find($_SESSION['user']->id);
         $xp = $user->getProperties()['xp'];
         $user->update(array('xp' => $xp - 15));
         // Update number of tags
         $oldtags = explode(',', $this->tagslug);
         $this->tag = new \Anax\News\Tag();
         $this->tag->setDI($this->di);
         foreach ($oldtags as $key => $val) {
             $tag = $this->tag->findTag($val);
             $news = $tag[0]->getProperties()['news'];
             $tagid = $tag[0]->getProperties()['id'];
             $this->tag->customUpdate('newstag', array('news' => $news - 1), 'id = ' . $tagid);
         }
         return true;
     } else {
         return false;
     }
 }