コード例 #1
0
ファイル: BaseModel.php プロジェクト: samrahman/providence
 /**
  * Returns change log for currently loaded row in displayable HTML format
  */
 public function getChangeLogForDisplay($ps_css_id = null)
 {
     $o_log = new ApplicationChangeLog();
     return $o_log->getChangeLogForRowForDisplay($this, $ps_css_id);
 }
コード例 #2
0
ファイル: SearchResult.php プロジェクト: kai-iak/providence
 /**
  * 
  */
 public function prefetchChangeLogData($ps_tablename, $pn_start, $pn_num_rows)
 {
     if (sizeof($va_row_ids = $this->getRowIDsToPrefetch($pn_start, $pn_num_rows)) == 0) {
         return false;
     }
     $vs_key = caMakeCacheKeyFromOptions(array_merge($va_row_ids, array('_table' => $ps_tablename)));
     if (self::$s_timestamp_cache['fetched'][$vs_key]) {
         return true;
     }
     $o_log = new ApplicationChangeLog();
     if (!is_array(self::$s_timestamp_cache['created_on'][$ps_tablename])) {
         self::$s_timestamp_cache['created_on'][$ps_tablename] = array();
     }
     self::$s_timestamp_cache['created_on'][$ps_tablename] += $o_log->getCreatedOnTimestampsForIDs($ps_tablename, $va_row_ids);
     if (!is_array(self::$s_timestamp_cache['last_changed'][$ps_tablename])) {
         self::$s_timestamp_cache['last_changed'][$ps_tablename] = array();
     }
     self::$s_timestamp_cache['last_changed'][$ps_tablename] += $o_log->getLastChangeTimestampsForIDs($ps_tablename, $va_row_ids);
     self::$s_timestamp_cache['fetched'][$vs_key] = true;
     return true;
 }
コード例 #3
0
 /**
  * Responds to the two main List verbs, includes resumption and limiting.
  *
  * @param string $verb OAI-PMH verb for the request
  * @param string $metadataPrefix Metadata prefix
  * @param int $cursor Offset in response to begin output at
  * @param mixed $set Optional set argument
  * @param string $from Optional from date argument
  * @param string $until Optional until date argument
  * @uses createResumptionToken()
  */
 private function listResponse($oaiData, $verb, $metadataPrefix, $cursor, $set, $from, $until)
 {
     $listLimit = $this->_listLimit;
     $o_dm = Datamodel::load();
     // by this point, the mapping code was checked to be valid
     $t_instance = $o_dm->getInstanceByTableName($this->table, true);
     $vs_pk = $t_instance->primaryKey();
     $va_access_values = caGetUserAccessValues($this->opo_request, $this->opa_provider_info);
     $vb_show_deleted = (bool) $this->opa_provider_info['show_deleted'];
     $vb_dont_enforce_access_settings = (bool) $this->opa_provider_info['dont_enforce_access_settings'];
     $vb_dont_cache = (bool) $this->opa_provider_info['dont_cache'];
     $vs_table = $t_instance->tableName();
     if (!($o_search = caGetSearchInstance($vs_table))) {
         $this->throwError(self::OAI_ERR_BAD_ARGUMENT);
         return;
     }
     // Construct date range for from/until if defined
     $o_tep = new TimeExpressionParser();
     $o_lang_settings = $o_tep->getLanguageSettings();
     $vs_conj = array_shift($o_lang_settings->getList("rangeConjunctions"));
     $vs_range = $from && $until ? "{$from} {$vs_conj} {$until}" : '';
     if ($set && $this->opa_provider_info['setFacet']) {
         $o_browse = caGetBrowseInstance($this->table);
         if (($vs_query = $this->opa_provider_info['query']) && $vs_query != "*") {
             $o_browse->addCriteria("_search", $vs_query);
         }
         $o_browse->addCriteria($this->opa_provider_info['setFacet'], $set);
         $o_browse->execute(array('showDeleted' => $vb_show_deleted, 'no_cache' => $vb_dont_cache, 'limitToModifiedOn' => $vs_range, 'checkAccess' => $vb_dont_enforce_access_settings ? null : $va_access_values));
         $qr_res = $o_browse->getResults();
     } else {
         $qr_res = $o_search->search(strlen($this->opa_provider_info['query']) ? $this->opa_provider_info['query'] : "*", array('no_cache' => $vb_dont_cache, 'limitToModifiedOn' => $vs_range, 'showDeleted' => $vb_show_deleted, 'checkAccess' => $vb_dont_enforce_access_settings ? null : $va_access_values));
     }
     if (!$qr_res) {
         $this->throwError(self::OAI_ERR_NO_RECORDS_MATCH, _t('Query failed'));
         return;
     }
     $rows = $qr_res->numHits();
     if (count($qr_res->numHits()) == 0) {
         $this->throwError(self::OAI_ERR_NO_RECORDS_MATCH, _t('No records match the given criteria'));
     } else {
         $verbElement = $oaiData->createElement($verb);
         $oaiData->documentElement->appendChild($verbElement);
         $t_change_log = new ApplicationChangeLog();
         if ($vb_show_deleted) {
             // get list of deleted records
             $va_deleted_items = array();
             $qr_res->seek($cursor);
             $vn_c = 0;
             $va_get_deleted_timestamps_for = array();
             while ($qr_res->nextHit()) {
                 if ((bool) $qr_res->get("{$vs_table}.deleted")) {
                     $va_deleted_items[$vs_pk_val = (int) $qr_res->get("{$vs_table}.{$vs_pk}")] = true;
                     $va_get_deleted_timestamps_for[$vs_pk_val] = true;
                 } else {
                     $vn_access = (int) $qr_res->get("{$vs_table}.access");
                     if (!in_array($vn_access, $va_access_values)) {
                         $va_deleted_items[(int) $qr_res->get("{$vs_table}.{$vs_pk}")] = true;
                     }
                 }
                 $vn_c++;
                 if ($vn_c >= $listLimit) {
                     break;
                 }
             }
             $qr_res->seek(0);
             $va_deleted_timestamps = $t_change_log->getDeleteOnTimestampsForIDs($vs_table, array_keys($va_get_deleted_timestamps_for));
         }
         // Export data using metadata mapping
         $va_items = ca_data_exporters::exportRecordsFromSearchResultToArray($this->getMappingCode(), $qr_res, array('start' => $cursor, 'limit' => $listLimit));
         if (is_array($va_items) && sizeof($va_items)) {
             $va_timestamps = $t_change_log->getLastChangeTimestampsForIDs($vs_table, array_keys($va_items));
             foreach ($va_items as $vn_id => $vs_item_xml) {
                 if ($vb_show_deleted && $va_deleted_items[$vn_id]) {
                     $headerData = array('identifier' => OaiIdentifier::itemToOaiId($vn_id), 'datestamp' => self::unixToUtc($va_deleted_timestamps[$vn_id]['timestamp'] ? $va_deleted_timestamps[$vn_id]['timestamp'] : $va_timestamps[$vn_id]['timestamp']));
                     if ($verb == 'ListIdentifiers') {
                         $header = $this->createElementWithChildren($oaiData, $verbElement, 'header', $headerData);
                         $header->setAttribute("status", "deleted");
                     } else {
                         $recordElement = $verbElement->appendChild($oaiData->createElement('record'));
                         $header = $this->createElementWithChildren($oaiData, $recordElement, 'header', $headerData);
                         $header->setAttribute("status", "deleted");
                     }
                 } else {
                     $headerData = array('identifier' => OaiIdentifier::itemToOaiId($vn_id), 'datestamp' => self::unixToUtc($va_timestamps[$vn_id]['timestamp']));
                     if ($verb == 'ListIdentifiers') {
                         $this->createElementWithChildren($oaiData, $verbElement, 'header', $headerData);
                     } else {
                         $recordElement = $verbElement->appendChild($oaiData->createElement('record'));
                         $this->createElementWithChildren($oaiData, $recordElement, 'header', $headerData);
                         $metadataElement = $oaiData->createElement('metadata');
                         $o_doc_src = DomDocument::loadXML($vs_item_xml);
                         if ($o_doc_src) {
                             // just in case the xml fails to load through DomDocument for some reason (e.g. a bad mapping or very weird characters)
                             $metadataElement->appendChild($oaiData->importNode($o_doc_src->documentElement, true));
                         }
                         $recordElement->appendChild($metadataElement);
                     }
                 }
             }
         }
         if ($rows > $cursor + $listLimit) {
             $token = $this->createResumptionToken($verb, $metadataPrefix, $cursor + $listLimit, $set, $from, $until);
             $tokenElement = $oaiData->createElement('resumptionToken', $token['key']);
             $tokenElement->setAttribute('expirationDate', self::unixToUtc($token['expiration']));
             $tokenElement->setAttribute('completeListSize', $rows);
             $tokenElement->setAttribute('cursor', $cursor);
             $verbElement->appendChild($tokenElement);
         } else {
             if ($cursor != 0) {
                 $tokenElement = $this->oaiData->createElement('resumptionToken');
                 $verbElement->appendChild($tokenElement);
             }
         }
     }
 }
コード例 #4
0
ファイル: SearchResult.php プロジェクト: ffarago/pawtucket2
 /**
  * 
  */
 public function prefetchChangeLogData($ps_tablename, $pn_start, $pn_num_rows)
 {
     if (sizeof($va_row_ids = $this->getRowIDsToPrefetch($ps_tablename, $pn_start, $pn_num_rows)) == 0) {
         return false;
     }
     $vs_key = md5($ps_tablename . '/' . print_r($va_row_ids, true));
     if ($this->opa_timestamp_cache['fetched'][$vs_key]) {
         return true;
     }
     $o_log = new ApplicationChangeLog();
     if (!is_array($this->opa_timestamp_cache['created_on'][$ps_tablename])) {
         $this->opa_timestamp_cache['created_on'][$ps_tablename] = array();
     }
     $this->opa_timestamp_cache['created_on'][$ps_tablename] += $o_log->getCreatedOnTimestampsForIDs($ps_tablename, $va_row_ids);
     if (!is_array($this->opa_timestamp_cache['last_changed'][$ps_tablename])) {
         $this->opa_timestamp_cache['last_changed'][$ps_tablename] = array();
     }
     $this->opa_timestamp_cache['last_changed'][$ps_tablename] += $o_log->getLastChangeTimestampsForIDs($ps_tablename, $va_row_ids);
     $this->opa_timestamp_cache['fetched'][$vs_key] = true;
     return true;
 }
コード例 #5
0
 /**
  * 
  */
 public function getDeletions()
 {
     //if (!is_object($t_entity = $this->_checkEntity())) { return $t_entity; }
     //$vn_id = $t_entity->getPrimaryKey();
     $t_object = new ca_objects();
     //$va_data = array('id' => $vn_id);
     $from = $this->opo_request->getParameter('from', pString);
     $until = $this->opo_request->getParameter('until', pString);
     if (!$until) {
         $until = date('c');
     }
     $vs_range = $from && $until ? self::utcToDb($from) . ' to ' . self::utcToDb($until) : null;
     $o_tep = new TimeExpressionParser();
     $vb_parsed_date = false;
     if ($vs_range) {
         if ($vb_parsed_date = $o_tep->parse($vs_range)) {
             $va_range = $o_tep->getUnixTimestamps();
         }
     }
     $o_log = new ApplicationChangeLog();
     // $va_log = $o_log->getChangeLogForRow($t_entity, array('range' => $va_range, 'changeType' => 'D'));
     $va_log = $o_log->getDeletions('ca_objects', array('range' => $va_range));
     $va_data['deletions'] = $va_log;
     //
     //         foreach($va_log as $vs_key => $va_log_item) {
     //         	foreach($va_log_item as $vn_i => $va_log) {
     //         		if (!is_array($va_log['changes'])) { continue; }
     //         		foreach($va_log['changes'] as $vn_j => $va_change) {
     //         			$va_data[$va_change['table_name']][] = array(
     //         				'datetime' => $va_log['datetime'],
     //         				'row_id' => $va_change['row_id'],
     //         				'description' => $va_change['description'],
     //         				'idno' => $va_change['idno']
     //         			);
     //         		}
     //         	}
     //         }
     //
     return $this->makeResponse($va_data);
 }
コード例 #6
0
 /**
  *
  */
 public function getWatchedItems($pn_user_id, $pn_table_num = null)
 {
     require_once __CA_LIB_DIR__ . '/core/ApplicationChangeLog.php';
     if (!$pn_user_id) {
         return null;
     }
     $t_changelog = new ApplicationChangeLog();
     $o_db = $this->getDb();
     $o_dm = $this->getAppDatamodel();
     $sql = "";
     $va_items = array();
     if ($pn_table_num) {
         $sql = " AND table_num = {$pn_table_num}";
     }
     $q_watched_items = $o_db->query("\n\t\t\tSELECT watch_id, row_id, table_num \n\t\t\tFROM ca_watch_list \n\t\t\tWHERE \n\t\t\t\tuser_id = ? {$sql} \n\t\t\tORDER BY watch_id DESC", $pn_user_id);
     if ($q_watched_items->numRows() > 0) {
         while ($q_watched_items->nextRow()) {
             $t_item_table = $o_dm->getInstanceByTableNum($q_watched_items->get("table_num"), true);
             if ($t_item_table->hasField('deleted') && $t_item_table->get('deleted') == 1) {
                 continue;
             }
             $t_item_table->load($q_watched_items->get("row_id"));
             $va_items[] = array("watch_id" => $q_watched_items->get("watch_id"), "row_id" => $q_watched_items->get("row_id"), "table_num" => $q_watched_items->get("table_num"), "table_name" => $t_item_table->TableName(), "displayName" => $t_item_table->getLabelForDisplay(), "idno" => $t_item_table->get("idno"), "item_type" => $t_item_table->getProperty('NAME_SINGULAR'), "primary_key" => $t_item_table->getPrimaryKey(), "change_log" => $t_changelog->getChangeLogForRowForDisplay($t_item_table));
         }
     }
     return $va_items;
 }