|
@@ -529,3 +529,79 @@ function tripal_jbrowse_mgmt_get_track_types() {
|
|
|
'XYPlot',
|
|
|
];
|
|
|
}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Save properties for a given instance.
|
|
|
+ *
|
|
|
+ * @param $id
|
|
|
+ * The instance ID that properties should be associated with.
|
|
|
+ * @param $data
|
|
|
+ * An array of properties where each is
|
|
|
+ * key: property_type, value: property value.
|
|
|
+ */
|
|
|
+function tripal_jbrowse_mgmt_save_instance_properties($id, $data) {
|
|
|
+
|
|
|
+ // For each property...
|
|
|
+ foreach ($data as $type => $value) {
|
|
|
+ tripal_jbrowse_mgmt_save_instance_property($id, $type, $value);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Save the details for a specific property of a given instance.
|
|
|
+ *
|
|
|
+ * @param $id
|
|
|
+ * The instance ID that properties should be associated with.
|
|
|
+ * @param $type
|
|
|
+ * The name of the property type to be saved.
|
|
|
+ * @param $value
|
|
|
+ * The value of the property to be saved.
|
|
|
+ */
|
|
|
+function tripal_jbrowse_mgmt_save_instance_property($id, $type, $value) {
|
|
|
+
|
|
|
+ // Check to see if the property already exists.
|
|
|
+ $result = db_select('tripal_jbrowse_mgmt_instanceprop', 'p')
|
|
|
+ ->fields('p', ['value'])
|
|
|
+ ->condition('instance_id', $id)
|
|
|
+ ->condition('property_type', $type)
|
|
|
+ ->execute()->fetchObject();
|
|
|
+
|
|
|
+ // If the property doesn't already exist then insert it.
|
|
|
+ if (empty($result)) {
|
|
|
+ return db_insert('tripal_jbrowse_mgmt_instanceprop')
|
|
|
+ ->fields([
|
|
|
+ 'instance_id' => $id,
|
|
|
+ 'property_type' => $type,
|
|
|
+ 'value' => $value,
|
|
|
+ ])->execute();
|
|
|
+ }
|
|
|
+ // Otherwise, we need to update it.
|
|
|
+ else {
|
|
|
+ return db_update('tripal_jbrowse_mgmt_instanceprop')
|
|
|
+ ->fields([
|
|
|
+ 'value' => $value,
|
|
|
+ ])
|
|
|
+ ->condition('instance_id', $id)
|
|
|
+ ->condition('property_type', $type)
|
|
|
+ ->execute();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Retrieves the value for a given instance property.
|
|
|
+ *
|
|
|
+ * @param $id
|
|
|
+ * The instance ID.
|
|
|
+ * @param $type
|
|
|
+ * The name of the property type.
|
|
|
+ * @return
|
|
|
+ * The value of the property for a given instance.
|
|
|
+ */
|
|
|
+function tripal_jbrowse_mgmt_get_instance_property($id, $type) {
|
|
|
+ return db_select('tripal_jbrowse_mgmt_instanceprop', 'p')
|
|
|
+ ->fields('p', ['value'])
|
|
|
+ ->condition('instance_id', $id)
|
|
|
+ ->condition('property_type', $type)
|
|
|
+ ->execute()->fetchField();
|
|
|
+}
|