@@ -228,10 +228,41 @@ protected function reverseCastFromType($data, int $type)
228228
229229 return $ data ;
230230 }
231+
232+ /**
233+ * Best effort guess of datatype
234+ *
235+ * @param $data
236+ * @return int
237+ */
238+ protected function guessType ($ data )
239+ {
240+ if ($ data instanceof \DateTime) {
241+ return MetadataAttributeTypes::TYPE_DATE ;
242+ }
243+
244+ if (is_int ($ data )) {
245+ return MetadataAttributeTypes::TYPE_INTEGER ;
246+ }
247+
248+ if (is_float ($ data )) {
249+ return MetadataAttributeTypes::TYPE_DECIMAL ;
250+ }
251+
252+ if (is_bool ($ data )) {
253+ return MetadataAttributeTypes::TYPE_BOOLEAN ;
254+ }
255+
256+ if (is_array ($ data )) {
257+ return MetadataAttributeTypes::TYPE_ARRAY ;
258+ }
259+
260+ return MetadataAttributeTypes::TYPE_TEXT ;
261+ }
231262}
232263
233264/**
234- * Class AbstractMetadataRecord
265+ * Class MetadataAttributeTypes
235266 * @package codelathe\fccloudapi
236267 */
237268final class MetadataAttributeTypes
@@ -2733,6 +2764,8 @@ protected function doChunkedUpload($url, $filechunkpath, $filename) {
27332764 }
27342765
27352766class CloudAPI extends APICore {
2767+
2768+ use MetadataAttributeTypeCasterTrait;
27362769
27372770 public function __construct ($ SERVER_URL , $ debug = false ) {
27382771 parent ::__construct ($ SERVER_URL , $ debug );
@@ -4619,6 +4652,100 @@ public function getMetadataValues(string $fullPath)
46194652
46204653 return $ collection ;
46214654 }
4655+
4656+ /**
4657+ * Get metadata sets for search
4658+ *
4659+ * @param string $fullPath
4660+ * @return Collection|null
4661+ */
4662+ public function getMetadataSetsForSearch (string $ fullPath ): ?Collection
4663+ {
4664+ $ this ->startTimer ();
4665+ $ response = $ this ->doPOST ("{$ this ->server_url }/core/getmetadatasetsforsearch " , http_build_query ([
4666+ 'fullpath ' => $ fullPath
4667+ ]));
4668+ $ collection = new Collection ($ response , 'metadataset ' , MetadataSetRecord::class);
4669+ $ this ->stopTimer ();
4670+
4671+ return $ collection ;
4672+ }
4673+
4674+ /**
4675+ * Add specified metadata set to file object
4676+ *
4677+ * @param string $fullPath
4678+ * @param string $setId
4679+ * @return CommandRecord|null
4680+ */
4681+ public function addSetToFileObject (string $ fullPath , string $ setId ): ?CommandRecord
4682+ {
4683+ $ this ->startTimer ();
4684+ $ response = $ this ->doPOST ("{$ this ->server_url }/core/addsettofileobject " , http_build_query ([
4685+ 'fullpath ' => $ fullPath ,
4686+ 'setid ' => $ setId ,
4687+ ]));
4688+ $ collection = new Collection ($ response , 'command ' , CommandRecord::class);
4689+ $ records = $ collection ->getRecords ();
4690+ $ record = $ collection ->getNumberOfRecords () > 0 ? reset ($ records ) : null ;
4691+ $ this ->stopTimer ();
4692+
4693+ return $ record ;
4694+ }
4695+
4696+ /**
4697+ * Remove specified metadata set from file object
4698+ *
4699+ * @param string $fullPath
4700+ * @param string $setId
4701+ * @return CommandRecord|null
4702+ */
4703+ public function removeSetFromFileObject (string $ fullPath , string $ setId ): ?CommandRecord
4704+ {
4705+ $ this ->startTimer ();
4706+ $ response = $ this ->doPOST ("{$ this ->server_url }/core/removesetfromfileobject " , http_build_query ([
4707+ 'fullpath ' => $ fullPath ,
4708+ 'setid ' => $ setId ,
4709+ ]));
4710+ $ collection = new Collection ($ response , 'command ' , CommandRecord::class);
4711+ $ records = $ collection ->getRecords ();
4712+ $ record = $ collection ->getNumberOfRecords () > 0 ? reset ($ records ) : null ;
4713+ $ this ->stopTimer ();
4714+
4715+ return $ record ;
4716+ }
4717+
4718+ /**
4719+ * Update attribute values of a file object's metadata
4720+ *
4721+ * @param string $setId
4722+ * @param string $fullPath
4723+ * @param array $attributes
4724+ * @return CommandRecord|null
4725+ */
4726+ public function saveAttributeValues (string $ fullPath , string $ setId , array $ attributes ): ?CommandRecord
4727+ {
4728+ $ this ->startTimer ();
4729+ $ args = [
4730+ 'fullpath ' => $ fullPath ,
4731+ 'setid ' => $ setId ,
4732+ ];
4733+
4734+ foreach ($ attributes as $ i => $ attribute ) {
4735+ $ args ["attribute {$ i }_attributeid " ] = $ attribute ['attributeid ' ];
4736+ $ args ["attribute {$ i }_value " ] = $ this ->reverseCastFromType ($ attribute ['value ' ], $ this ->guessType ($ attribute ['value ' ]));
4737+ }
4738+
4739+ $ args ['attributes_total ' ] = count ($ attributes );
4740+
4741+ $ response = $ this ->doPOST ("{$ this ->server_url }/core/saveattributevalues " , http_build_query ($ args ));
4742+ $ collection = new Collection ($ response , 'command ' , CommandRecord::class);
4743+ $ records = $ collection ->getRecords ();
4744+ $ record = $ collection ->getNumberOfRecords () > 0 ? reset ($ records ) : null ;
4745+ $ this ->stopTimer ();
4746+
4747+ return $ record ;
4748+ }
46224749
46234750 public function getUITranslations () {
46244751 $ this ->startTimer ();
0 commit comments