/**
  * @see GridFeature::saveSequence()
  */
 function saveSequence($args)
 {
     $request =& $args['request'];
     $grid =& $args['grid'];
     import('lib.pkp.classes.core.JSONManager');
     $jsonManager = new JSONManager();
     $data = $jsonManager->decode($request->getUserVar('data'));
     $gridElements = $grid->getGridDataElements($request);
     $firstSeqValue = $grid->getRowDataElementSequence(reset($gridElements));
     foreach ($gridElements as $rowId => $element) {
         $rowPosition = array_search($rowId, $data);
         $newSequence = $firstSeqValue + $rowPosition;
         $currentSequence = $grid->getRowDataElementSequence($element);
         if ($newSequence != $currentSequence) {
             $grid->saveRowDataElementSequence($request, $rowId, $element, $newSequence);
         }
     }
 }
Пример #2
0
 /**
  * Construct a JSON string to use for AJAX communication
  * @return string
  */
 function getString()
 {
     // Construct an associative array that contains all information we require.
     $jsonObject = array('status' => $this->getStatus(), 'content' => $this->getContent(), 'elementId' => $this->getElementId());
     if (is_array($this->getAdditionalAttributes())) {
         foreach ($this->getAdditionalAttributes() as $key => $value) {
             $jsonObject[$key] = $value;
         }
     }
     if (is_array($this->getEvent())) {
         $jsonObject['event'] = $this->getEvent();
     }
     // Encode the object.
     import('lib.pkp.classes.core.JSONManager');
     $jsonManager = new JSONManager();
     return $jsonManager->encode($jsonObject);
 }
 /**
  *
  * @param $journal Journal
  * @param $articles array
  * @return boolean
  */
 function _exportArticles($journal, &$articles)
 {
     if (!isset($articles) || count($articles) == 0) {
         return false;
     }
     $plugin = $this->_plugin;
     $journalPath = $journal->getPath();
     $journalId = $journal->getId();
     $payload = '';
     foreach ($articles as $article) {
         $doi = $article->getPubId('doi');
         $publishedDate = date('Y-m-d', strtotime($article->getDatePublished()));
         $title = preg_replace('/s+/', ' ', $article->getLocalizedTitle());
         if ($doi && $publishedDate && $title) {
             $payload .= "{$doi} {$publishedDate} {$title}\n";
         }
     }
     $depositUrl = $this->_depositUrl;
     $apiKey = $plugin->getSetting($journalId, 'apiKey');
     if (!$apiKey) {
         $this->addExecutionLogEntry(__('plugins.generic.alm.senderTask.warning.noApiKey', array('path' => $journalPath)), SCHEDULED_TASK_MESSAGE_TYPE_WARNING);
     }
     $params = array('api_key' => $apiKey, 'payload' => $payload);
     $jsonManager = new JSONManager();
     if ($payload && $depositUrl && $apiKey) {
         $webServiceRequest = new WebServiceRequest($depositUrl, $params, 'POST');
         // Configure and call the web service
         $webService = new WebService();
         $result = $webService->call($webServiceRequest);
         if ($result) {
             $resultDecoded = $jsonManager->decode($result);
         }
         if (is_null($result)) {
             $this->addExecutionLogEntry(__('plugins.generic.alm.senderTask.error.noServerResponse', array('path' => $journalPath)), SCHEDULED_TASK_MESSAGE_TYPE_ERROR);
         }
         if ($resultDecoded && isset($resultDecoded->success) && isset($resultDecoded->count) && $resultDecoded->count == count($articles)) {
             return true;
         } else {
             $this->addExecutionLogEntry(__('plugins.generic.alm.senderTask.error.returnError', array('error' => $result, 'articlesNumber' => count($articles), 'payload' => $payload)), SCHEDULED_TASK_MESSAGE_TYPE_ERROR);
         }
     }
     return false;
 }
 /**
  * This method checks the CrossRef APIs and checks if deposits have been successful
  * @param $request Request
  * @param $journal Journal The journal associated with the deposit
  * @param $article Article The article getting deposited
  */
 function updateDepositStatus(&$request, &$journal, $article)
 {
     $articleDao =& DAORegistry::getDAO('ArticleDAO');
     /* @var $articleDao ArticleDAO */
     import('lib.pkp.classes.core.JSONManager');
     $jsonManager = new JSONManager();
     // Prepare HTTP session.
     $curlCh = curl_init();
     curl_setopt($curlCh, CURLOPT_RETURNTRANSFER, true);
     $username = $this->getSetting($journal->getId(), 'username');
     $password = $this->getSetting($journal->getId(), 'password');
     curl_setopt($curlCh, CURLOPT_USERPWD, "{$username}:{$password}");
     $doi = urlencode($article->getPubId('doi'));
     $params = 'filter=doi:' . $doi;
     curl_setopt($curlCh, CURLOPT_URL, CROSSREF_API_URL . (strpos(CROSSREF_API_URL, '?') === false ? '?' : '&') . $params);
     // try to fetch from the new API
     $response = curl_exec($curlCh);
     // try the new API with the filter completed (should only return successes)
     if ($response && curl_getinfo($curlCh, CURLINFO_HTTP_CODE) == CROSSREF_API_RESPONSE_OK) {
         $response = $jsonManager->decode($response);
         $pastDeposits = array();
         foreach ($response->message->items as $item) {
             $pastDeposits[strtotime($item->{'submitted-at'})] = $item->status;
             if ($item->status == 'completed') {
                 $articleDao->updateSetting($article->getId(), $this->getDepositStatusSettingName(), 'completed', 'string');
                 $this->markRegistered($request, $article);
                 return true;
             }
             if ($item->status == 'failed') {
                 $articleDao->updateSetting($article->getId(), $this->getDepositStatusSettingName(), 'failed', 'string');
             } elseif ($item->status == 'submitted') {
                 $articleDao->updateSetting($article->getId(), $this->getDepositStatusSettingName(), 'submitted', 'string');
             }
         }
         // if there have been past attempts, save the most recent one's status for display to user
         if (count($pastDeposits) > 0) {
             $lastStatus = $pastDeposits[max(array_keys($pastDeposits))];
             $articleDao->updateSetting($article->getId(), $this->getDepositStatusSettingName(), $lastStatus, 'string');
         }
     }
     // now try the old crossref API and just search for the DOI
     curl_setopt($curlCh, CURLOPT_URL, CROSSREF_SEARCH_API . (strpos(CROSSREF_SEARCH_API, '?') === false ? '?' : '&') . 'q=' . $doi);
     $response = curl_exec($curlCh);
     if ($response && curl_getinfo($curlCh, CURLINFO_HTTP_CODE) == CROSSREF_API_RESPONSE_OK) {
         $response = $jsonManager->decode($response);
         if (count($response) > 0) {
             // inventing a new status "found" for when we find it in the search API (as opposed to deposit API)
             $articleDao->updateSetting($article->getId(), $this->getDepositStatusSettingName(), 'found', 'string');
             $this->markRegistered($request, $article);
             return true;
         }
     }
     curl_close($curlCh);
     return false;
 }
 /**
  * @see GridFeature::saveSequence()
  */
 function saveSequence($args)
 {
     $request =& $args['request'];
     $grid =& $args['grid'];
     import('lib.pkp.classes.core.JSONManager');
     $jsonManager = new JSONManager();
     $data = $jsonManager->decode($request->getUserVar('data'));
     $gridCategoryElements = $grid->getGridDataElements($request);
     if ($this->getType() != ORDER_CATEGORY_GRID_CATEGORIES_ROWS_ONLY) {
         $categoriesData = array();
         foreach ($data as $categoryData) {
             $categoriesData[] = $categoryData->categoryId;
         }
         // Save categories sequence.
         $firstSeqValue = $grid->getCategoryDataElementSequence(reset($gridCategoryElements));
         foreach ($gridCategoryElements as $rowId => $element) {
             $rowPosition = array_search($rowId, $categoriesData);
             $newSequence = $firstSeqValue + $rowPosition;
             $currentSequence = $grid->getCategoryDataElementSequence($element);
             if ($newSequence != $currentSequence) {
                 $grid->saveCategoryDataElementSequence($element, $newSequence);
             }
         }
     }
     // Save rows sequence, if this grid has also orderable rows inside each category.
     $this->_saveRowsInCategoriesSequence($grid, $gridCategoryElements, $data);
 }
Пример #6
0
 /**
  * Unpack data to save using an external handler.
  * @param $data String (the json encoded data from the listbuilder itself)
  * @param $deletionCallback array callback to be used for each deleted element
  * @param $insertionCallback array callback to be used for each updated element
  * @param $updateCallback array callback to be used for each updated element
  */
 function unpack(&$request, $data, $deletionCallback = null, $insertionCallback = null, $updateCallback = null)
 {
     // Set some defaults
     // N.B. if this class is called statically, then $this is not set to Listbuilder, but to your calling class.
     if (!$deletionCallback) {
         $deletionCallback = array(&$this, 'deleteEntry');
     }
     if (!$insertionCallback) {
         $insertionCallback = array(&$this, 'insertEntry');
     }
     if (!$updateCallback) {
         $updateCallback = array(&$this, 'updateEntry');
     }
     import('lib.pkp.classes.core.JSONManager');
     $jsonManager = new JSONManager();
     $data = $jsonManager->decode($data);
     // Handle deletions
     if (isset($data->deletions)) {
         foreach (explode(' ', trim($data->deletions)) as $rowId) {
             call_user_func($deletionCallback, $request, $rowId, $data->numberOfRows);
         }
     }
     // Handle changes and insertions
     if (isset($data->changes)) {
         foreach ($data->changes as $entry) {
             // Get the row ID, if any, from submitted data
             if (isset($entry->rowId)) {
                 $rowId = $entry->rowId;
                 unset($entry->rowId);
             } else {
                 $rowId = null;
             }
             // $entry should now contain only submitted modified or new rows.
             // Go through each and unpack the data in prep for application.
             $changes = array();
             foreach ($entry as $key => $value) {
                 // Match the column name and localization data, if any.
                 if (!preg_match('/^newRowId\\[([a-zA-Z]+)\\](\\[([a-z][a-z]_[A-Z][A-Z])\\])?$/', $key, $matches)) {
                     assert(false);
                 }
                 // Get the column name
                 $column = $matches[1];
                 // If this is a multilingual input, fetch $locale; otherwise null
                 $locale = isset($matches[3]) ? $matches[3] : null;
                 if ($locale) {
                     $changes[$column][$locale] = $value;
                 } else {
                     $changes[$column] = $value;
                 }
             }
             // $changes should now contain e.g.:
             // array ('localizedColumnName' => array('en_US' => 'englishValue'),
             // 'nonLocalizedColumnName' => 'someNonLocalizedValue');
             if (is_null($rowId)) {
                 call_user_func($insertionCallback, $request, $changes);
             } else {
                 call_user_func($updateCallback, $request, $rowId, $changes);
             }
         }
     }
 }
Пример #7
0
 /**
  * Build the required article information for the
  * metrics visualization.
  * @param $article PublishedArticle
  * @return string JSON response
  */
 function _buildRequiredArticleInfoJson($article)
 {
     if ($article->getDatePublished()) {
         $datePublished = $article->getDatePublished();
     } else {
         // Sometimes there is no article getDatePublished, so fallback on the issue's
         $issueDao =& DAORegistry::getDAO('IssueDAO');
         /* @var $issueDao IssueDAO */
         $issue =& $issueDao->getIssueByArticleId($article->getId(), $article->getJournalId());
         $datePublished = $issue->getDatePublished();
     }
     $response = array(array('publication_date' => date('c', strtotime($datePublished)), 'doi' => $article->getPubId('doi'), 'title' => $article->getLocalizedTitle(), 'sources' => array()));
     $jsonManager = new JSONManager();
     return $jsonManager->encode($response);
 }
} else {
    if ($IS_UPDATE_NEWS) {
        $debug .= "IS_UPDATE_NEWS";
        $query_output = $wdj_mysql_interface->updateNewsByNewsId_V2($MEETING_ID, $NEWS_ID, $NEWS_TITLE, $NEWS_CONTENTS);
        array_push($result->query_output_arr, $query_output);
    } else {
        if ($IS_DELETE_NEWS && $NEWS_ID > 0) {
            $debug .= "IS_DELETE_NEWS";
            $query_output = $wdj_mysql_interface->deleteNewsByNewsId($NEWS_ID);
            array_push($result->query_output_arr, $query_output);
        } else {
            if ($IS_UPDATE_TABLE_ROW_ORDER_ON_NEWS) {
                $debug .= "IS_UPDATE_TABLE_ROW_ORDER_ON_NEWS";
                // 열의 순서를 변경합니다.
                // REFACTOR ME - 중복되고 있는 구조
                $news_table_row_info_arr = JSONManager::get_json_obj($NEWS_TABLE_ROW_INFO_ARR_JSON_STR);
                for ($idx = 0; $idx < count($news_table_row_info_arr); $idx++) {
                    $cur_news_row_info = $news_table_row_info_arr[$idx];
                    $cur_news_id = intval($cur_news_row_info->__news_id);
                    $cur_order_num = intval($cur_news_row_info->__ORDER_NUM);
                    $query_output = $wdj_mysql_interface->updateNewsByNewsId_V2($MEETING_ID, $cur_news_id, null, null, $cur_order_num);
                    array_push($result->query_output_arr, $query_output);
                }
            }
        }
    }
}
//     dMMMMMP dMP dMP dMMMMMP .aMMMb  dMP dMP dMMMMMMP dMP dMP dMP dMMMMMP         dMMMMMMMMb  dMMMMMP dMMMMMMMMb  dMMMMb  dMMMMMP dMMMMb  .dMMMb
//    dMP     dMK.dMP dMP     dMP"VMP dMP dMP    dMP   amr dMP dMP dMP             dMP"dMP"dMP dMP     dMP"dMP"dMP dMP"dMP dMP     dMP.dMP dMP" VP
//   dMMMP   .dMMMK" dMMMP   dMP     dMP dMP    dMP   dMP dMP dMP dMMMP           dMP dMP dMP dMMMP   dMP dMP dMP dMMMMK" dMMMP   dMMMMK"  VMMMb
//  dMP     dMP"AMF dMP     dMP.aMP dMP.aMP    dMP   dMP  YMvAP" dMP             dMP dMP dMP dMP     dMP dMP dMP dMP.aMF dMP     dMP"AMF dP .dMP