Skip to content

Commit

Permalink
fix sections API, article translate url
Browse files Browse the repository at this point in the history
  • Loading branch information
takeit committed Mar 9, 2015
1 parent 6973425 commit 804a13f
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 83 deletions.
96 changes: 47 additions & 49 deletions newscoop/admin-files/libs/ArticleList/ArticleList.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
* @license http://www.gnu.org/licenses/gpl.txt
* @link http://www.sourcefabric.org
*/

require_once dirname(__FILE__) . '/../BaseList/BaseList.php';
require_once WWW_DIR . '/classes/GeoMap.php';
require_once dirname(__FILE__).'/../BaseList/BaseList.php';
require_once WWW_DIR.'/classes/GeoMap.php';

/**
* Article list component
Expand Down Expand Up @@ -41,18 +40,18 @@ class ArticleList extends BaseList
protected $orderBy = array();

/** @var bool */
protected static $renderFilters = FALSE;
protected static $renderFilters = false;

/** @var bool */
protected static $renderActions = FALSE;
protected static $renderActions = false;

/** @var string */
protected static $lastId = NULL;
protected static $lastId = null;

/**
* @param bool $randomId
*/
public function __construct($randomId = FALSE)
public function __construct($randomId = false)
{
parent::__construct();

Expand All @@ -69,7 +68,7 @@ public function __construct($randomId = FALSE)

// column titles
$this->cols = array(
'Number' => NULL,
'Number' => null,
'Language' => $translator->trans('Language'),
'Order' => $translator->trans('Order'),
'Name' => $translator->trans('Title', array(), 'api'),
Expand All @@ -91,7 +90,7 @@ public function __construct($randomId = FALSE)
'PublishDate' => $translator->trans('Publish Date', array(), 'library'),
'LastModified' => $translator->trans('Last Modified', array(), 'articles'),
'Preview' => $translator->trans('Preview'),
'Translate' => $translator->trans('Translate')
'Translate' => $translator->trans('Translate'),
);
}

Expand All @@ -102,7 +101,7 @@ public function __construct($randomId = FALSE)
*/
public function setPublication($publication)
{
$this->publication = is_null($publication) ? NULL : (int) $publication;
$this->publication = is_null($publication) ? null : (int) $publication;

return $this;
}
Expand All @@ -114,7 +113,7 @@ public function setPublication($publication)
*/
public function setIssue($issue)
{
$this->issue = is_null($issue) ? NULL : (int) $issue;
$this->issue = is_null($issue) ? null : (int) $issue;

return $this;
}
Expand All @@ -126,7 +125,7 @@ public function setIssue($issue)
*/
public function setSection($section)
{
$this->section = is_null($section) ? NULL : (int) $section;
$this->section = is_null($section) ? null : (int) $section;

return $this;
}
Expand Down Expand Up @@ -210,8 +209,8 @@ public function renderFilters()
{
$this->beforeRender();

include dirname(__FILE__) . '/filters.php';
self::$renderFilters = TRUE;
include dirname(__FILE__).'/filters.php';
self::$renderFilters = true;

return $this;
}
Expand All @@ -224,8 +223,8 @@ public function renderActions()
{
$this->beforeRender();

include dirname(__FILE__) . '/actions.php';
self::$renderActions = TRUE;
include dirname(__FILE__).'/actions.php';
self::$renderActions = true;

return $this;
}
Expand All @@ -238,9 +237,9 @@ public function render()
{
$this->beforeRender();

include dirname(__FILE__) . '/table.php';
self::$renderTable = TRUE;
echo '</div><!-- /#list-' . $this->id . ' -->';
include dirname(__FILE__).'/table.php';
self::$renderTable = true;
echo '</div><!-- /#list-'.$this->id.' -->';

return $this;
}
Expand All @@ -256,11 +255,12 @@ public function processItem($article)
$translator = \Zend_Registry::get('container')->getService('translator');
$editorService = \Zend_Registry::get('container')->getService('newscoop.editor');
$articleLink = $editorService->getLink($article);
$articleLinkParamsTranslate = $articleLinkParams.'&amp;f_action=translate&amp;f_action_workflow=' . $article->getWorkflowStatus()
. '&amp;f_article_code=' . $article->getArticleNumber() . '_' . $article->getLanguageId();
$previewLink = $Campsite['WEBSITE_URL'].'/admin/articles/preview.php' . $editorService->getLinkParameters($article);
$articleLinkParams = $editorService->getLinkParameters($article);
$articleLinkParamsTranslate = $articleLinkParams.'&amp;f_action=translate&amp;f_action_workflow='.$article->getWorkflowStatus()
.'&amp;f_article_code='.$article->getArticleNumber().'_'.$article->getLanguageId();
$previewLink = $Campsite['WEBSITE_URL'].'/admin/articles/preview.php'.$editorService->getLinkParameters($article);
$htmlPreviewLink = '<a href="'.$previewLink.'" target="_blank" title="'.$translator->trans('Preview').'">'.$translator->trans('Preview').'</a>';
$translateLink = $Campsite['WEBSITE_URL'].'/admin/articles/translate.php' . $articleLinkParamsTranslate;
$translateLink = $Campsite['WEBSITE_URL'].'/admin/articles/translate.php'.$articleLinkParamsTranslate;
$htmlTranslateLink = '<a href="'.$translateLink.'" target="_blank" title="'.$translator->trans('Translate').'">'.$translator->trans('Translate').'</a>';

$lockInfo = '';
Expand All @@ -273,12 +273,12 @@ public function processItem($article)
'$1' => htmlspecialchars($lockUser->getRealName()),
'$2' => htmlspecialchars($lockUser->getUserName()),
'$3' => $timeDiff['hours'],
'$4' => $timeDiff['minutes']), 'articles');
'$4' => $timeDiff['minutes'], ), 'articles');
} else {
$lockInfo = $translator->trans('The article has been locked by $1 ($2) $3 minute(s) ago.', array(
'$1' => htmlspecialchars($lockUser->getRealName()),
'$2' => htmlspecialchars($lockUser->getUserName()),
'$3' => $timeDiff['minutes']), 'articles');
'$3' => $timeDiff['minutes'], ), 'articles');
}
if ($article->getLockedByUser() != $g_user->getUserId()) {
$lockHighlight = true;
Expand Down Expand Up @@ -324,10 +324,10 @@ public function processItem($article)
$article->getLanguageId(),
$article->getOrder(),
sprintf('%s <a href="%s" title="%s %s">%s</a>',
$article->isLocked() ? '<span class="ui-icon ui-icon-locked' . (!$lockHighlight ? ' current-user' : '' ) . '" title="' . $lockInfo . '"></span>' : '',
$article->isLocked() ? '<span class="ui-icon ui-icon-locked'.(!$lockHighlight ? ' current-user' : '').'" title="'.$lockInfo.'"></span>' : '',
$articleLink,
$translator->trans('Edit'), htmlspecialchars($article->getName() . " ({$article->getLanguageName()})"),
htmlspecialchars($article->getName() . (empty($_REQUEST['language']) ? " ({$language->getCode()})" : ''))), // /sprintf
$translator->trans('Edit'), htmlspecialchars($article->getName()." ({$article->getLanguageName()})"),
htmlspecialchars($article->getName().(empty($_REQUEST['language']) ? " ({$language->getCode()})" : ''))), // /sprintf
htmlspecialchars($article->getSection()->getName()),
$article->getWebcode(),
htmlspecialchars($tmpArticleType->getDisplayName()),
Expand All @@ -340,13 +340,13 @@ public function processItem($article)
$topicsNo,
$commentsNo,
(int) $article->getReads(),
Geo_Map::GetArticleMapId($article) != NULL ? $translator->trans('Yes') : $translator->trans('No'),
Geo_Map::GetArticleMapId($article) != null ? $translator->trans('Yes') : $translator->trans('No'),
(int) sizeof(Geo_Map::GetLocationsByArticle($article)),
$article->getCreationDate(),
$article->getPublishDate(),
$article->getLastModified(),
$htmlPreviewLink,
$htmlTranslateLink
$htmlTranslateLink,
);
}

Expand All @@ -360,17 +360,16 @@ public function doData()
$_REQUEST[$arg['name']] = $arg['value'];
}

return require_once dirname(__FILE__) . '/do_data.php';
return require_once dirname(__FILE__).'/do_data.php';
}

public function getFilterIssues()
{

global $ADMIN_DIR, $g_user;
require_once $GLOBALS['g_campsiteDir'] . '/classes/Publication.php';
require_once $GLOBALS['g_campsiteDir'] . '/classes/Issue.php';
require_once $GLOBALS['g_campsiteDir'] . '/classes/Section.php';
require_once $GLOBALS['g_campsiteDir'] . '/classes/Author.php';
require_once $GLOBALS['g_campsiteDir'].'/classes/Publication.php';
require_once $GLOBALS['g_campsiteDir'].'/classes/Issue.php';
require_once $GLOBALS['g_campsiteDir'].'/classes/Section.php';
require_once $GLOBALS['g_campsiteDir'].'/classes/Author.php';
$translator = \Zend_Registry::get('container')->getService('translator');

foreach ($_REQUEST['args'] as $arg) {
Expand All @@ -380,13 +379,13 @@ public function getFilterIssues()
if ($_REQUEST['publication'] > 0) {
$publication = $_REQUEST['publication'];
} else {
$publication = NULL;
$publication = null;
}

if ($_REQUEST['language'] > 0) {
$language = $_REQUEST['language'];
} else {
$language = NULL;
$language = null;
}

$newIssues = array();
Expand All @@ -402,17 +401,16 @@ public function getFilterIssues()
$returns['menuItemTitle'] = $menuIssueTitle;

return json_encode($returns);

}

public function getFilterSections()
{
$translator = \Zend_Registry::get('container')->getService('translator');
global $ADMIN_DIR, $g_user;
require_once $GLOBALS['g_campsiteDir'] . '/classes/Publication.php';
require_once $GLOBALS['g_campsiteDir'] . '/classes/Issue.php';
require_once $GLOBALS['g_campsiteDir'] . '/classes/Section.php';
require_once $GLOBALS['g_campsiteDir'] . '/classes/Author.php';
require_once $GLOBALS['g_campsiteDir'].'/classes/Publication.php';
require_once $GLOBALS['g_campsiteDir'].'/classes/Issue.php';
require_once $GLOBALS['g_campsiteDir'].'/classes/Section.php';
require_once $GLOBALS['g_campsiteDir'].'/classes/Author.php';

foreach ($_REQUEST['args'] as $arg) {
$_REQUEST[$arg['name']] = $arg['value'];
Expand All @@ -421,18 +419,18 @@ public function getFilterSections()
if ($_REQUEST['publication'] > 0) {
$publication = $_REQUEST['publication'];
} else {
$publication = NULL;
$publication = null;
}

$language = NULL;
$language = null;
if ($_REQUEST['issue'] > 0) {
$issueArray = explode("_",$_REQUEST['issue']);
$issueArray = explode("_", $_REQUEST['issue']);
$issue = $issueArray[1];
if (isset($issueArray[2])) {
$language = $issueArray[2];
}
} else {
$issue = NULL;
$issue = null;
}

if ($_REQUEST['language'] > 0) {
Expand Down Expand Up @@ -480,7 +478,7 @@ public static function doAction($f_action, $f_items, $f_params = array())
$f_target = '';
}

return require_once dirname(__FILE__) . '/do_action.php';
return require_once dirname(__FILE__).'/do_action.php';
}

/**
Expand All @@ -493,7 +491,7 @@ public static function doOrder($f_order, $f_language)
{
global $ADMIN_DIR;

return require_once dirname(__FILE__) . '/do_order.php';
return require_once dirname(__FILE__).'/do_order.php';
}

/**
Expand Down
25 changes: 15 additions & 10 deletions newscoop/library/Newscoop/Entity/Repository/IssueRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,23 @@ public function getLatestByPublication($publicationId, $maxResults = 1, $leftJoi
return $query->getQuery();
}

public function getByPublicationAndNumberAndLanguage($publication, $number, $language)
public function getByPublicationAndNumberAndLanguage($publication, $number = null, $language = null)
{
$issue = $this->createQueryBuilder('i')
->andWhere('i.publication = :publication')
->setParameter('publication', $publication)
->andWhere('i.number = :number')
->setParameter('number', $number)
->andWhere('i.language = :language')
->setParameter('language', $language)
->getQuery();
$queryBuilder = $this->createQueryBuilder('i')
->where('i.publication = :publication')
->setParameter('publication', $publication);

if ($number) {
$queryBuilder->andWhere('i.number = :number')
->setParameter('number', $number);
}

if ($language) {
$queryBuilder->andWhere('i.language = :language')
->setParameter('language', $language);
}

return $issue;
return $queryBuilder->getQuery();
}

public function getIssuesCountForPublication($publicationId)
Expand Down
23 changes: 13 additions & 10 deletions newscoop/library/Newscoop/Entity/Repository/SectionRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@
* @copyright 2011 Sourcefabric o.p.s.
* @license http://www.gnu.org/licenses/gpl.txt
*/

namespace Newscoop\Entity\Repository;

use Doctrine\ORM\EntityRepository,
Newscoop\Entity\Publication,
Newscoop\Entity\Subscription;
use Doctrine\ORM\EntityRepository;
use Newscoop\Entity\Publication;
use Newscoop\Entity\Subscription;

/**
* Section repository
*/
class SectionRepository extends EntityRepository
{
public function getSections($publication, $issue = false, $language = false)
public function getSections($publication, $issue = null, $language = null)
{
$em = $this->getEntityManager();
$queryBuilder = $em->getRepository('Newscoop\Entity\Section')
Expand All @@ -29,6 +28,11 @@ public function getSections($publication, $issue = false, $language = false)
->setParameter('issue', $issue);
}

if ($language) {
$queryBuilder->andWhere('s.language = :language')
->setParameter('language', $language);
}

$countQueryBuilder = clone $queryBuilder;
$countQueryBuilder->select('count(s)');

Expand All @@ -54,9 +58,9 @@ public function getSectionsCountForPublication($publicationId)
/**
* Get list of publication sections
*
* @param Newscoop\Entity\Publication $publication
* @param Newscoop\Entity\Subscription $subscription;
* @param bool $groupByLanguage
* @param Newscoop\Entity\Publication $publication
* @param Newscoop\Entity\Subscription $subscription;
* @param bool $groupByLanguage
* @return array
*/
public function getAvailableSections(Publication $publication, Subscription $subscription, $groupByLanguage = false)
Expand Down Expand Up @@ -108,7 +112,7 @@ public function findSectionByArticle($article)
));

if ($issue === null) {
return null;
return;
}

$section = $em->getRepository('Newscoop\Entity\Section')
Expand All @@ -122,4 +126,3 @@ public function findSectionByArticle($article)
return $section;
}
}

Loading

0 comments on commit 804a13f

Please sign in to comment.