public function __construct() { $objectType = $this->objectType; $this->ObjectType = ucwords($objectType); $this->objectTypePlural = \Zotero\DataObjectUtilities::getObjectTypePlural($objectType); $this->ObjectTypePlural = ucwords($this->objectTypePlural); $this->objectsClass = "Zotero_" . $this->ObjectTypePlural; $this->dataTypes = array_merge($this->dataTypes, $this->dataTypesExtended); $this->markAllDataTypeLoadStates(false); $this->clearChanged(); }
public static function init() { if (!self::$objectType) { throw new Exception('self::$objectType must be set before calling Zotero_DataObjects initializer'); } self::$ObjectType = ucwords(self::$objectType); self::$objectTypePlural = \Zotero\DataObjectUtilities::getObjectTypePlural(self::$objectType); self::$ObjectTypePlural = ucwords(self::$objectTypePlural); self::$idColumn = self::$objectType . "ID"; self::$table = isset(self::$_table) ? self::$_table : self::$objectTypePlural; self::$ObjectClass = "Zotero_" . self::$objectType; self::$primaryFields = array_keys(self::$primaryDataSQLParts); self::$primaryDataSQLFrom = " " . (isset(self::$_primaryDataSQLFrom) ? self::$_primaryDataSQLFrom : "FROM " . self::$table . " O") . " " . self::$primaryDataSQLWhere; }
protected function handleObjectWrite($objectType, $obj = null) { if (!is_object($obj) && !is_null($obj)) { throw new Exception('$obj must be a data object or null'); } $objectTypePlural = \Zotero\DataObjectUtilities::getObjectTypePlural($objectType); $objectsClassName = "Zotero_" . ucwords($objectTypePlural); $json = !empty($this->body) ? $this->jsonDecode($this->body) : false; $objectVersionValidated = $this->checkSingleObjectWriteVersion($objectType, $obj, $json); $this->libraryVersion = Zotero_Libraries::getUpdatedVersion($this->objectLibraryID); // Update item if ($this->method == 'PUT' || $this->method == 'PATCH') { if ($this->apiVersion < 2) { $this->allowMethods(['PUT']); } if (!$obj) { $className = "Zotero_" . ucwords($objectType); $obj = new $className(); $obj->libraryID = $this->objectLibraryID; $obj->key = $this->objectKey; } if ($objectType == 'item') { $changed = Zotero_Items::updateFromJSON($obj, $json, null, $this->queryParams, $this->userID, $objectVersionValidated ? 0 : 2, $this->method == 'PATCH'); } else { $changed = $objectsClassName::updateFromJSON($obj, $json, $this->queryParams, $this->userID, $objectVersionValidated ? 0 : 2, $this->method == 'PATCH'); } // If not updated, return the original library version if (!$changed) { $this->libraryVersion = Zotero_Libraries::getOriginalVersion($this->objectLibraryID); } if ($cacheKey = $this->getWriteTokenCacheKey()) { Z_Core::$MC->set($cacheKey, true, $this->writeTokenCacheTime); } } else { if ($this->method == 'DELETE') { $objectsClassName::delete($this->objectLibraryID, $this->objectKey); } else { throw new Exception("Unexpected method {$this->method}"); } } if ($this->apiVersion >= 2 || $this->method == 'DELETE') { $this->e204(); } return $obj; }