Equivalent to $modx->getDocument in YAMS - modx

I am converting an old mono-lingual site to a multi-lingual site with YAMS. I have a snippet including articles based on ID
$doc = $modx->getDocument($fromId, '*', 1); // Search published first.
Is there equivalent using YAMS? Like this where the language is based on current article?
$doc $modx-yamsGetDocument($fromId, '*', 1);
Any tips would be greatly appreciated!

I'm not familiar with YAMS, but it looks like you need to run the YAMS snippet from within your code.
You should be able to do something like this:
$result = $modx->runSnippet('YAMS', array(
'docid' => $fromId,
// other parameters here
));
Consult the YAMS snippet documentation for a list of parameters to include.

I did this workaround, hope it helps somebody:
If you manage to bring the id of the language you could do this call:
$modx->runSnippet("getField", array('docid'=>$id_of_the_document,'field' =>'pagetitle_'.$lang));

Related

How to find all documents in couchDB using ektrop library

I have gone through all the blogs available for the ektrop library and also the source code of the library.I have found that get(class obj,String id) function is available but If I use this function then only one document will be returned according to the id given.So I want to read all the changed documents present in the bucket.How Can I achieve this.Thanks in advance any help would be appreciable.
You are probably looking for the _all_docs endpoint.
ViewQuery q = new ViewQuery().allDocs().includeDocs(true);
List<Sofa> bulkLoaded = db.queryView(q, Sofa.class);
You can find more detailed information in the api
Hello all I have got the answer the question asked by me above.Here is the steps by which you can get the all documents or simply the result of _changes API is used.
Integrate the Ektorp library into your project.
Use the follwing code to get the all document.
HttpClient httpClient = new StdHttpClient.Builder()
.url("http://localhost:5984/")
.build();
CouchDbInstance dbInstance = new StdCouchDbInstance(httpClient);
CouchDbConnector db = new StdCouchDbConnector("my_database", dbInstance);
ChangesCommand.Builder builder = new ChangesCommand.Builder();
ChangesCommand changesCommand =builder.build() ;
List<DocumentChange> documentChangeList=db.changes(changesCommand);
for(int i=0;i<documentChangeList.size()-1;i++) {
System.out.println(documentChangeList.get(i).getId());
}

DocumentDB Replace not Working

I recently realized that DocumentDB supports stand alone update operations via ReplaceDocumentAsync.
I've replaced the Upsert operation below with the Replace operation.
var result = _client
.UpsertDocumentAsync(_collectionUri, docObject)
.Result;
So this is now:
var result = _client
.ReplaceDocumentAsnyc(_collectionUri, docObject)
.Result;
However, now I get the exception:
Microsoft.Azure.Documents.BadRequestException : ResourceType Document is unexpected.
ActivityId: b1b2fd71-3029-4d0d-bd5d-87d8d0a2fc95
No idea why, upsert and replace are of the same vein and the object is the same that worked for upsert, so I would expect it to work without problems.
All help appreciated.
Thanks
Update: Have tried to implement this using the SelfLink approach, and it works for Replace, but selflink does not work with Upsert. The behavior is quite confusing. I don't like that I have to build a self link in code using string concatenation.
I'm afraid that building the selflink with string concatenation is your only option here because ReplaceDocument(...) requires a link to the document. You show a link to the collection in your example. It won't suck the id out and find the document as you might wish.
The NPM module, documentdb-utils, has library functions for building these links but it's just using string concatenation. I have seen an equivalent library for .NET but I can't remember where. Maybe it was in an Azure example or even in the SDK now.
You can build a document link for a replace using the UriFactory helper class:
var result = _client
.ReplaceDocumentAsync(UriFactory.CreateDocumentUri(databaseId, collectionId, docObject.Id), docObject)
.Result;
Unfortunately it's not very intuitive, as Larry has already pointed out, but a replace expects a document to already be there, while an upsert is what it says on the tin. Two different use-cases, I would say.
In order to update a document, you need to provide the Collection Uri. If you provide the Document Uri it returns the following:
ResourceType Document is unexpected.
Maybe the _collectionUri is a Document Uri, the assignment should look like this:
_collectionUri = UriFactory.CreateDocumentCollectionUri(DatabaseName, CollectionName);

Searching by related model field

I know there are plenty of topics on this but I searched&tried so many and it is still not working.
I have tables: Team and Worker. Any worker can be assigned to a Team. So at the Workers Manager I want to search Workers also by Team name.
I got the column etc. but when I type part of team name - search starts but the written text dissappears and search doesn't care about the field. I checked the AJAX call with Firebug and there is a field called teamName (I added public field to my Worker model class). But when I print_r criteria in my search method - there is no condition.
How is that possible? How can I perform the searching by related field?
EDIT (my serach() method):
public function dsearch()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('idWorker',$this->idWorker);
$criteria->compare('idLeaderType',$this->idLeaderType);
$criteria->compare('t.idTeam',$this->idTeam);
$criteria->compare('idVoip',$this->idVoip);
$criteria->compare('workLogin',$this->workLogin,true);
$criteria->compare('workPass',$this->workPass,true);
$criteria->compare('name',$this->name,true);
$criteria->compare('surname',$this->surname,true);
$criteria->compare('madeCalls',$this->madeCalls);
$criteria->compare('deleted',$this->deleted);
$criteria->compare('liveChanges',$this->liveChanges);
$criteria->compare('confirmer',$this->confirmer);
$criteria->compare('oldWorkerNum',$this->oldWorkerNum);
$criteria->compare('idDepart',$this->idDepart);
$criteria->compare('Team.name', $this->teamName, true);
$criteria->with=array('Team');
$criteria->together = true;
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
Use the mergeWith: Hope it works.
if($merge!==null){
$criteria->mergeWith($merge);
}
Reference:http://www.yiiframework.com/doc/api/1.1/CDbCriteria#mergeWith-detail
I found usefull extension to do that:
http://www.yiiframework.com/extension/relatedsearchbehavior/
I couldnt get it to work somehow. I downloaded new version and now its fine.
It works pretty well. Thanks for your time though.

Kohana 3.1 ORM - Conditional Parameters

I am trying to achieve a very simple goal, however it does not seem to be working. I wish to use Kohana's ORM and conditionally add certain parameters.
For instance:
$query = ORM::factory('user')
->where('foo', '=', 'bar');
if (isset($some_var))
$query->where('field', '=', $some_var);
$query->find_all();
One would think this should work, but all I get from $query is a big fat nothing. Any suggestions I would greatly appreciate! Thanks.
EDIT:
The simple example on this Kohana page even shows a similar query:
http://kohanaframework.org/3.1/guide/orm/examples/simple
...But even when I create a 'user' model instance and then try to find_all() in a separate statement, I get nothing.
This works:
$query = ORM::factory('user')->find_all();
This doesn't work:
$query = ORM::factory('user');
$query->find_all();
Possible bug??
In your example that works, you are assigning the value returned from find_all() to $query. While in the example that is not working, you are not assigning the value returned by find_all() at all.
kohana framework
$query = ORM::factory('user');
$result = $query->find_all();
// you may now loop over $result
When you look over the api, you will see that find() and find_all() work differently.
Your code is perfectly fine, as ORM::where method returns ORM object, so there is no problem with method chaining. You should look for the errors in other place (perhaps your $some_var is set but may be empty, therefore your condition may look different then expected). I'd try with this small change:
if (!empty($some_var))
$query->where('field', '=', $some_var);

How to handle unused Managed Metadata Terms without a WssId?

The Problem
We upload (large amounts of) files to SharePoint using FrontPage RPC (put documents call). As far as we've been able to find out, setting the value of taxonomy fields through this protocol requires their WssId.
The problem is that unless terms have been explicitly used before on a listitem, they don´t seem to have a WSS ID. This causes uploading documents with previously unused metadata terms to fail.
The Code
The call TaxonomyField.GetWssIdsOfTerm in the code snippet below simply doesn´t return an ID for those terms.
SPSite site = new SPSite( "http://some.site.com/foo/bar" );
SPWeb web = site.OpenWeb();
TaxonomySession session = new TaxonomySession( site );
TermStore termStore = session.TermStores[new Guid( "3ead46e7-6bb2-4a54-8cf5-497fc7229697" )];
TermSet termSet = termStore.GetTermSet( new Guid( "f21ac592-5e51-49d0-88a8-50be7682de55" ) );
Guid termId = new Guid( "a40d53ed-a017-4fcd-a2f3-4c709272eee4" );
int[] wssIds = TaxonomyField.GetWssIdsOfTerm( site, termStore.Id, termSet.Id, termId, false, 1);
foreach( int wssId in wssIds )
{
Console.WriteLine( wssId );
}
We also tried querying the taxonomy hidden list directly, with similar results.
The Cry For Help
Both confirmation and advice on how to tackle this would be appreciated. I see three possible routes to a solution:
Change the way we are uploading, either by uploading the terms in a different way, or by switching to a different protocol.
Query for the metadata WssIds in a different way. One that works for unused terms.
Write/find a tool to preresolve WssIds for all terms. Suggestions on how to do this elegantly are most welcome.
setting the WssID value to -1 should help you. I had similar problem (copying documents containing metadata fields) between two different web applications. I've spent many hours on solving strange metadata issues. In the end, setting the value to -1 have solved all my issues. Even if the GetWssIdsOfTerm returns a value, I've used -1 and it works correctly.
Probably there is some background logic that will tak care of the WssId.
Radek

Resources