Esempio n. 1
0
 function execute($param, $post)
 {
     try {
         if (count($param) > 0) {
             if ($param[0] == "act") {
                 $obj = json_decode($post["json"]);
                 if ($obj->Action == "delete") {
                     $guids = array();
                     foreach ($obj->Notes as $note) {
                         $guids[] = $note->Guid;
                     }
                     return ReturnBoolean($this->deleteNotes($obj->NoteTakerGuid, $obj->NoteCollectionGuid, $guids));
                 } else {
                     if ($obj->Action == "addorupdate") {
                         $newNotes = array();
                         $updateNotes = array();
                         $listId = $this->getNoteCollectionId($obj->NoteTakerGuid, $obj->NoteCollectionGuid);
                         if ($listId !== false) {
                             foreach ($obj->Notes as $note) {
                                 $existingNote = GetSingleByCondition("Notes", array("Guid" => $note->Guid, "NoteCollectionId" => $listId));
                                 if ($existingNote == null) {
                                     $newnote = new Note();
                                     $newnote->NoteCollectionId = $listId;
                                     $newnote->Guid = $note->Guid;
                                     $newnote->Content = $note->Content;
                                     $newnote->Description = $note->Description;
                                     $newnote->CreateTime = ConvertToDatabaseDateTime($note->CreateTime);
                                     $newnote->IsCompleted = $note->IsCompleted;
                                     $newNotes[] = $newnote;
                                 } else {
                                     $existingNote->Content = $note->Content;
                                     $existingNote->Description = $note->Description;
                                     $existingNote->CreateTime = ConvertToDatabaseDateTime($note->CreateTime);
                                     $existingNote->IsCompleted = $note->IsCompleted;
                                     $updateNotes[] = $existingNote;
                                 }
                             }
                             $res = InsertAll($newNotes);
                             $res &= UpdateAll($updateNotes);
                             return ReturnBoolean($res == 1);
                         }
                         return ReturnBoolean(false);
                     } else {
                         if ($obj->Action == "get") {
                             $listId = $this->getNoteCollectionId($obj->NoteTakerGuid, $obj->NoteCollectionGuid);
                             if ($listId !== false) {
                                 $notes = GetAllByCondition("Notes", array("NoteCollectionId" => $listId));
                                 $resp = new NoteResponse();
                                 foreach ($notes as $note) {
                                     $resp->Notes[] = new NoteEntity($note);
                                 }
                                 return ReturnJson($resp);
                             }
                             return ReturnBoolean(false);
                         } else {
                             return ReturnError(LINK_INVALID);
                         }
                     }
                 }
             }
         }
         return ReturnError(LINK_INVALID);
     } catch (\Exception $ex) {
         return ReturnError("Exception occured: " . $ex->getMessage());
     }
 }
 function execute($param, $post)
 {
     try {
         if (count($param) > 0) {
             if ($param[0] == "act") {
                 $obj = json_decode($post["json"]);
                 if ($obj->Action == "delete") {
                     $guids = array();
                     foreach ($obj->NoteCollections as $collection) {
                         $guids[] = $collection->Guid;
                     }
                     return ReturnBoolean($this->deleteNoteCollections($obj->NoteTakerGuid, $guids));
                 } else {
                     if ($obj->Action == "addorupdate") {
                         $newCollections = array();
                         $updateCollections = array();
                         $taker = $this->tryAddNoteTaker($obj->NoteTakerGuid);
                         if ($taker !== false) {
                             $existingCollections = $this->getNoteCollections($obj->NoteTakerGuid);
                             foreach ($obj->NoteCollections as $collection) {
                                 $found = false;
                                 foreach ($existingCollections as $existingCollection) {
                                     if ($existingCollection->Guid == $collection->Guid) {
                                         $found = $existingCollection;
                                     }
                                 }
                                 if ($found == false) {
                                     $newCollection = new NoteCollection();
                                     $newCollection->Guid = $collection->Guid;
                                     $newCollection->CreateTime = ConvertToDatabaseDateTime($collection->CreateTime);
                                     $newCollection->Name = $collection->Name;
                                     $newCollections[] = $newCollection;
                                 } else {
                                     $found->Name = $collection->Name;
                                     $found->CreateTime = ConvertToDatabaseDateTime($collection->CreateTime);
                                     $updateCollections[] = $found;
                                 }
                             }
                             return ReturnBoolean($this->addNoteCollections($obj->NoteTakerGuid, $newCollections) && UpdateAll($updateCollections));
                         }
                         return ReturnBoolean(false);
                     } else {
                         if ($obj->Action == "get") {
                             $collections = $this->getNoteCollections($obj->NoteTakerGuid);
                             if ($collections !== false) {
                                 $resp = new NoteCollectionResponse();
                                 foreach ($collections as $collection) {
                                     $resp->NoteCollections[] = new NoteCollectionEntity($collection);
                                 }
                                 return ReturnJson($resp);
                             }
                             return ReturnBoolean(false);
                         } else {
                             return ReturnError(LINK_INVALID);
                         }
                     }
                 }
             }
         }
         return ReturnError(LINK_INVALID);
     } catch (\Exception $ex) {
         return ReturnError("Exception occured: " . $ex->getMessage());
     }
 }