public function SaveSubjectAction() { $request = Project::getRequest(); $article_model = new ArticleModel(); if (count($article_model->loadByParentId(0, array(ARTICLE_COMPETITION_STATUS::NEW_ARTICLE), Project::getUser()->getDbUser()->id)) < 5) { $article_model->title = $request->title; $article_model->articles_tree_id = $request->parent_id; $article_model->user_id = Project::getUser()->getDbUser()->id; $article_model->rate_status = ARTICLE_COMPETITION_STATUS::NEW_ARTICLE; $article_model->creation_date = date("Y-m-d H:i:s"); $article_model->save(); } Project::getResponse()->redirect($request->createUrl('Article', 'CompetitionCatalog')); }
public function VerifyCompetitionAction() { $article_competition_model = new ArticleCompetitionModel(); $endCompetition = $article_competition_model->selectEndCompetition(); $article_model = new ArticleModel(); $article_vote_model = new ArticleVoteModel(); $winnerArticleId = 0; if (count($endCompetition) > 0) { foreach ($endCompetition as $comp) { $articles = $article_model->loadByParentId($comp['article_tree_id']); $max = 0; foreach ($articles as $article) { $r = $article_vote_model->rateByArticleId($article['id']); if ($max < $r['rate']) { $max = $r['rate']; $winnerArticleId = $article['id']; } } $article_model->load($winnerArticleId); $article_model->rate_status = ARTICLE_RATE_STATUS::WINNER; $article_model->save(); $article_competition_model->delete($comp['id']); } } }