예제 #1
0
/** 適切にinsertMeatadataEventを行う
 * repository         item
 * is_deleted==0  &&  public    : isCreate ? ME_CREATED : ME_MODIFIED;
 * is_deleted==0  &&  nonpublic : ME_DELETED
 * is_deleted!=0  &&  public    : ME_CREATED
 * is_deleted!=0  &&  nonpubic  : -
 * 
 */
function insertMetadataEventAuto($iid, $isCreate = false)
{
    global $xoopsDB;
    $status = array();
    $res = xnp_get_item_status($iid, $status);
    if ($res != RES_OK) {
        if ($res == RES_NO_SUCH_ITEM) {
            $status['is_deleted'] = 1;
        } else {
            return $res;
        }
    }
    //guestからアクセスできるか?(/Publicをゲストに公開する設定が有効,且つ/Publicに属するアイテムか?)
    $value = '';
    if (($res = xnp_get_config_value(XNP_CONFIG_PUBLIC_ITEM_TARGET_USER_KEY, $value)) != RES_OK) {
        return $res;
    }
    if ($value != XNP_CONFIG_PUBLIC_ITEM_TARGET_USER_ALL) {
        $isPublic = false;
    } else {
        $sql = "SELECT * FROM " . $xoopsDB->prefix("xoonips_index") . " AS tx, " . $xoopsDB->prefix("xoonips_index_item_link") . " AS tlink" . " WHERE tlink.item_id={$iid}" . " AND tlink.index_id=tx.index_id" . " AND tlink.certify_state=" . CERTIFIED . " AND tx.open_level=" . OL_PUBLIC;
        $result = $xoopsDB->query($sql);
        if ($result) {
            $isPublic = $xoopsDB->getRowsNum($result) > 0;
        } else {
            $isPublic = false;
        }
    }
    if ($status['is_deleted'] == 0) {
        if ($isPublic) {
            $me = $isCreate ? ME_CREATED : ME_MODIFIED;
        } else {
            $me = ME_DELETED;
        }
    } else {
        if ($isPublic) {
            $me = ME_CREATED;
        } else {
            _xnpal_setLastErrorString("");
            return RES_OK;
        }
    }
    $res = _xnpal_insertMetadataEvent($me, $iid);
    if ($res == RES_OK) {
        _xnpal_setLastErrorString("");
    }
    return $res;
}
 function oaipmh_header($identifier, $index_tree_list)
 {
     global $xoopsDB;
     $xconfig_handler =& xoonips_getormhandler('xoonips', 'config');
     $parsed = $identifier;
     $lines = array();
     $status = array();
     if (xnp_get_item_status($parsed['item_id'], $status) == RES_OK) {
         $datestamp = max($status['created_timestamp'], $status['modified_timestamp'], $status['deleted_timestamp']);
         if ($status['is_deleted'] == 1) {
             $lines[] = "<header status=\"deleted\">";
         } else {
             $lines[] = "<header>";
         }
         $nijc_code = $xconfig_handler->getValue('repository_nijc_code');
         $basic_info = xnpGetItemBasicInfo($parsed['item_id']);
         $id_str = "";
         if ($basic_info && $basic_info['doi'] != "") {
             if (!empty($nijc_code)) {
                 $id_str = "{$nijc_code}:" . XNP_CONFIG_DOI_FIELD_PARAM_NAME . "/" . $basic_info['doi'];
             }
         }
         if ($id_str == "") {
             $id_str = $nijc_code . "/" . $parsed['item_type_id'] . "." . $parsed['item_id'];
         }
         $lines[] = "<identifier>{$id_str}</identifier>";
         $lines[] = "<datestamp>" . gmdate("Y-m-d\\TH:i:s\\Z", $datestamp) . "</datestamp>";
         $sql = "SELECT link.index_id FROM " . $xoopsDB->prefix('xoonips_index_item_link') . " as link LEFT JOIN " . $xoopsDB->prefix('xoonips_index') . " as idx on link.index_id=idx.index_id " . " WHERE link.item_id=" . intval($parsed['item_id']) . " AND open_level=" . OL_PUBLIC;
         $result = $xoopsDB->query($sql);
         if ($result) {
             while (list($xid) = $xoopsDB->fetchRow($result)) {
                 // echo "xid=$xid\n";
                 $xid_path = explode(",", $index_tree_list[$xid]['id_fullpath']);
                 $lines[] = "<setSpec>index" . implode(":index", $xid_path) . "</setSpec>";
             }
         }
         $lines[] = "<setSpec>" . $parsed['item_type_name'] . "</setSpec>";
         $lines[] = "</header>";
         return implode("\n", $lines);
     }
 }