private function getStatsQuery(Journal $journal) { $filter = new Term(); $filter->setTerm('journalUsers.journal.id', $journal->getId()); $filterQuery = new Query\Filtered(); $filterQuery->setFilter($filter); $query = new Query($filterQuery); $titleAggregation = new Terms('title'); $titleAggregation->setField('title'); $query->addAggregation($titleAggregation); $genderAggregation = new Terms('gender'); $genderAggregation->setField('gender'); $query->addAggregation($genderAggregation); $query->setSize(0); return $query; }
private function getStatsQuery(Journal $journal) { $filter = new Term(); $filter->setTerm('journal.id', $journal->getId()); $filterQuery = new Filtered(); $filterQuery->setFilter($filter); $query = new Query($filterQuery); $dateHistogram = new DateHistogram('dateHistogram', 'created', 'month'); $dateHistogram->setFormat("YYYY-MM-dd"); $query->addAggregation($dateHistogram); $genderAggregation = new Terms('language'); $genderAggregation->setField('locale'); $query->addAggregation($genderAggregation); $query->setSize(0); return $query; }
/** * @param Journal $journal * @return bool|Journal */ public function setSelectedJournal(Journal $journal = null) { if ($journal) { $this->session->set('selectedJournalId', $journal->getId()); return $journal; } $token = $this->tokenStorage->getToken(); if ($token instanceof AnonymousToken) { return false; } $user = $token->getUser(); // set first journal if found /** @var JournalRepository $journalRepo */ $journalRepo = $this->em->getRepository('OjsJournalBundle:Journal'); $journal = $journalRepo->findOneByUser($user); if (!$journal instanceof Journal) { return false; } $this->session->set('selectedJournalId', $journal->getId()); return $journal; }
/** * Creates a form to edit a ArticleFile entity. * @param ArticleFile $entity The entity * @param Journal $journal * @param Article $article * @return Form The form */ private function createEditForm(ArticleFile $entity, Journal $journal, Article $article) { $form = $this->createForm(new ArticleFileType(), $entity, ['action' => $this->generateUrl('ojs_journal_article_file_update', ['id' => $entity->getId(), 'journalId' => $journal->getId(), 'articleId' => $article->getId()]), 'method' => 'PUT']); return $form; }
/** * Creates a form to create a Section entity. * * @param Section $entity * @param Journal $journal * @return Form */ private function createCreateForm(Section $entity, Journal $journal) { $form = $this->createForm(new SectionType(), $entity, array('action' => $this->generateUrl('ojs_journal_section_create', ['journalId' => $journal->getId()]), 'method' => 'POST')); $form->add('submit', 'submit', array('label' => 'Create')); return $form; }
private function createEditForm(Article $article, Journal $journal, $locales, $defaultLocale) { $event = new TypeEvent(new ArticleSubmissionType()); $this->get('event_dispatcher')->dispatch(ArticleEvents::INIT_SUBMIT_FORM, $event); $form = $this->createForm($event->getType(), $article, array('action' => $this->generateUrl('ojs_journal_submission_edit', array('journalId' => $journal->getId(), 'id' => $article->getId())), 'method' => 'POST', 'locales' => $locales, 'default_locale' => $defaultLocale, 'citationTypes' => array_keys($this->container->getParameter('citation_types'))))->add('save', 'submit', array('label' => 'save', 'attr' => array('class' => 'btn-block'))); return $form; }
/** * Just get journal's last issue id * @param Journal $journal * @return integer */ public function getLastIssueId($journal) { $q = $this->_em->createQuery('SELECT i FROM OjsJournalBundle:Issue i WHERE i.journalId =:j ' . 'AND i.datePublished IS NOT NULL ORDER BY i.datePublished DESC')->setMaxResults(1)->setParameter('j', $journal->getId()); try { $issue = $q->getOneOrNullResult(); return $issue; } catch (NoResultException $e) { return false; } return false; }
/** * Returns an array of article download statistics which can be displayed in a table * * @param array $dates * @param Journal|null $journal * @return array */ public function generateArticleFileDownloadsData($dates = null, Journal $journal = null) { $whereDate = ''; if ($dates) { $today = $dates[0]; $lastMonthToday = end($dates); $whereDate = "AND statistic.date BETWEEN '" . $lastMonthToday . "' AND '" . $today . "' "; } $journalWhereQuery = ' '; if ($journal) { $journalWhereQuery = 'AND article.journal_id = ' . $journal->getId() . ' '; } $sql = "SELECT article_file.title, SUM(statistic.download) as sum_download, article_file.id FROM statistic " . "join article_file on statistic.article_file_id = article_file.id " . "join article on article_file.article_id = article.id " . "WHERE article_file_id IS NOT NULL " . $whereDate . $journalWhereQuery . "group by article_file_id ,article_file.title, article_file.id " . "ORDER BY sum_download DESC " . "LIMIT 20 "; $rsm = new ResultSetMapping(); $rsm->addScalarResult('title', 'title'); $rsm->addScalarResult('sum_download', 'download'); $rsm->addScalarResult('id', 'id'); $query = $this->manager->createNativeQuery($sql, $rsm); $results = $query->getResult(); return $results; }
/** * Creates a form to add Member to Board entity. * * @param BoardMember $entity * @param Board $board * @param Journal $journal * @return Form */ private function createAddMemberForm(BoardMember $entity, Board $board, Journal $journal) { $form = $this->createForm(new BoardMemberType(), $entity, array('action' => $this->generateUrl('ojs_journal_board_member_add', array('boardId' => $board->getId(), 'journalId' => $journal->getId())), 'method' => 'PUT')); return $form; }
/** * Imports the journal with given ID * @param int $id Journal's ID * @return array New IDs as keys, old IDs as values * @throws Exception * @throws \Doctrine\DBAL\DBALException */ public function importJournal($id) { $this->consoleOutput->writeln("Importing the journal..."); $journalSql = "SELECT path, primary_locale FROM journals WHERE journal_id = :id LIMIT 1"; $journalStatement = $this->dbalConnection->prepare($journalSql); $journalStatement->bindValue('id', $id); $journalStatement->execute(); $settingsSql = "SELECT locale, setting_name, setting_value FROM journal_settings WHERE journal_id = :id"; $settingsStatement = $this->dbalConnection->prepare($settingsSql); $settingsStatement->bindValue('id', $id); $settingsStatement->execute(); $pkpJournal = $journalStatement->fetch(); $pkpSettings = $settingsStatement->fetchAll(); $primaryLocale = $pkpJournal['primary_locale']; $languageCode = mb_substr($primaryLocale, 0, 2, 'UTF-8'); !$pkpJournal && die('Journal not found.' . PHP_EOL); $this->consoleOutput->writeln("Reading journal settings..."); foreach ($pkpSettings as $setting) { $locale = !empty($setting['locale']) ? mb_substr($setting['locale'], 0, 2, 'UTF-8') : $languageCode; $name = $setting['setting_name']; $value = $setting['setting_value']; $this->settings[$locale][$name] = $value; } $this->journal = new Journal(); $this->journal->setStatus(1); $this->journal->setSlug($pkpJournal['path']); // Fill translatable fields in all available languages except the primary one foreach ($this->settings as $fieldLocale => $fields) { if ($fieldLocale === $languageCode) { // We will fill fields of the primary language later. continue; } $this->journal->setCurrentLocale(mb_substr($fieldLocale, 0, 2, 'UTF-8')); !empty($fields['title']) ? $this->journal->setTitle($fields['title']) : $this->journal->setTitle('Unknown Journal'); !empty($fields['description']) ? $this->journal->setDescription($fields['description']) : $this->journal->setDescription('-'); } $this->journal->setCurrentLocale($languageCode); // Fill fields for the primary language !empty($this->settings[$languageCode]['title']) ? $this->journal->setTitle($this->settings[$languageCode]['title']) : $this->journal->setTitle('Unknown Journal'); !empty($this->settings[$languageCode]['description']) ? $this->journal->setDescription($this->settings[$languageCode]['description']) : $this->journal->setDescription('-'); !empty($this->settings[$languageCode]['journalPageFooter']) ? $this->journal->setFooterText($this->settings[$languageCode]['journalPageFooter']) : $this->journal->setFooterText(null); !empty($this->settings[$languageCode]['printIssn']) && count($this->settings[$languageCode]['printIssn']) == 9 ? $this->journal->setIssn($this->settings[$languageCode]['printIssn']) : $this->journal->setIssn(''); !empty($this->settings[$languageCode]['onlineIssn']) && count($this->settings[$languageCode]['onlineIssn']) == 9 ? $this->journal->setEissn($this->settings[$languageCode]['onlineIssn']) : $this->journal->setEissn(''); $date = sprintf('%d-01-01 00:00:00', !empty($this->settings[$languageCode]['initialYear']) ? $this->settings[$languageCode]['initialYear'] : '2015'); $this->journal->setFounded(DateTime::createFromFormat('Y-m-d H:i:s', $date)); // Set view and download counts !empty($this->settings[$languageCode]['total_views']) ? $this->journal->setViewCount($this->settings[$languageCode]['total_views']) : $this->journal->setViewCount(0); !empty($this->settings[$languageCode]['total_downloads']) ? $this->journal->setDownloadCount($this->settings[$languageCode]['total_downloads']) : $this->journal->setDownloadCount(0); !empty($this->settings[$languageCode]['homeHeaderTitleImage']) ? $header = unserialize($this->settings[$languageCode]['homeHeaderTitleImage']) : ($header = null); if ($header) { $baseDir = '/../web/uploads/journal/imported/'; $croppedBaseDir = '/../web/uploads/journal/croped/imported/'; $headerPath = $id . '/' . $header['uploadName']; $pendingDownload = new PendingDownload(); $pendingDownload->setSource('public/journals/' . $headerPath)->setTarget($baseDir . $headerPath)->setTag('journal-header'); $croppedPendingDownload = new PendingDownload(); $croppedPendingDownload->setSource('public/journals/' . $headerPath)->setTarget($croppedBaseDir . $headerPath)->setTag('journal-header'); $history = $this->em->getRepository(FileHistory::class)->findOneBy(['fileName' => 'imported/' . $headerPath]); if (!$history) { $history = new FileHistory(); $history->setFileName('imported/' . $headerPath); $history->setOriginalName('imported/' . $headerPath); $history->setType('journal'); } $this->em->persist($croppedPendingDownload); $this->em->persist($pendingDownload); $this->em->persist($history); $this->journal->setHeader('imported/' . $headerPath); } $subjects = $this->importSubjects($languageCode); foreach ($subjects as $subject) { $this->journal->addSubject($subject); } // Set publisher !empty($this->settings[$languageCode]['publisherInstitution']) ? $this->importAndSetPublisher($this->settings[$languageCode]['publisherInstitution'], $languageCode) : $this->journal->setPublisher($this->getUnknownPublisher($languageCode)); // Use existing languages or create if needed $language = $this->em->getRepository('OjsJournalBundle:Lang')->findOneBy(['code' => $languageCode]); $this->journal->setMandatoryLang($language ? $language : $this->createLanguage($languageCode)); $this->journal->addLanguage($language ? $language : $this->createLanguage($languageCode)); $this->importContacts($languageCode); $this->importSubmissionChecklist($languageCode); $this->consoleOutput->writeln("Read journal's settings."); $this->em->beginTransaction(); // Outer transaction try { $this->em->beginTransaction(); // Inner transaction $this->em->persist($this->journal); $this->em->flush(); $this->em->commit(); } catch (Exception $exception) { $this->em->rollback(); throw $exception; } $this->consoleOutput->writeln("Imported journal #" . $id); // Those below also create their own inner transactions $createdSections = $this->sectionImporter->importJournalSections($id, $this->journal->getId()); $createdIssues = $this->issueImporter->importJournalIssues($id, $this->journal->getId(), $createdSections); $this->articleImporter->importJournalArticles($id, $this->journal->getId(), $createdIssues, $createdSections); $this->journalPageImporter->importPages($id, $this->journal->getId()); $createdBoards = $this->boardImporter->importBoards($id, $this->journal->getId()); foreach ($createdBoards as $oldBoardId => $newBoardId) { $this->boardMemberImporter->importBoardMembers($oldBoardId, $newBoardId); } $this->importAboutPage(); $map = new ImportMap($id, $this->journal->getId(), Journal::class); $this->em->persist($map); $this->em->flush(); $this->em->commit(); return ['new' => $this->journal->getId(), 'old' => $id]; }
/** * @param $journal * @return array */ public function journalStats(Journal $journal) { $object_view = $this->dm->getRepository('OjsAnalyticsBundle:ObjectViews'); $journal_stats = $object_view->findBy(['entity' => 'journal', 'objectId' => $journal->getId()]); $groupped_journal_stats = []; $counted_article_stats = []; foreach ($journal_stats as $js) { /** @var ObjectViews $js */ $dateKey = $js->getLogDate()->format('d-M-Y'); $groupped_journal_stats[$dateKey] = isset($groupped_journal_stats[$dateKey]) ? $groupped_journal_stats[$dateKey] + 1 : 1; foreach ($journal->getArticles() as $article) { $article_stats = $object_view->findBy(['entity' => 'article', 'objectId' => $article->getId()]); foreach ($article_stats as $article_stat) { if ($article_stat->getLogDate()->format('d-M-Y') == $dateKey && !in_array($article_stat->getId(), $counted_article_stats)) { $counted_article_stats[] = $article_stat->getId(); $groupped_journal_stats[$dateKey] = isset($groupped_journal_stats[$dateKey]) ? $groupped_journal_stats[$dateKey] + 1 : 1; } } } } ksort($groupped_journal_stats); return $groupped_journal_stats; }
/** * @param Design $entity * @param Journal $journal * @return Form */ private function createEditForm(Design $entity, Journal $journal) { $form = $this->createForm(new DesignType(), $entity, array('action' => $this->generateUrl('ojs_journal_design_update', ['journalId' => $journal->getId(), 'id' => $entity->getId()]), 'method' => 'PUT')); $form->add('submit', 'submit', array('label' => 'Update')); return $form; }
public function journalBlocks(Journal $journal) { return $this->findBy(['objectType' => 'journal', 'objectId' => $journal->getId()], ['block_order' => 'asc']); }