Quantcast

%LDAP% macro evaluation

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

%LDAP% macro evaluation

Alan
Hello,

I'm creating a NewLdapUserTemplate topic to create user topics
automatically with the NewUserPlugin.

In it, I use the %LDAP% macro this way:

%LDAP{"(sAMAccountName=%EXPAND{$percntUSERINFO{format="$username"}$percnt}%)"
  clear="$cn,$mail,$telephoneNumber,$title,$l,$thumbnailPhoto"
  blob="thumbnailPhoto"
  limit="1"
  format="<img style='height:auto; height:320px;' src='$thumbnailPhoto' />
    <h1>$cn</h1>
    <table class='foswikiLayoutTable'>
      <tr><th>%MAKETEXT{"E-mail"}%:</th>
          <td> $mail </td></tr>
      <tr><th>%MAKETEXT{"Telephone"}%:</th>
          <td> $telephoneNumber </td></tr>
      <tr><th>%MAKETEXT{"Title"}%:</th>
          <td> $title </td></tr>
      <tr><th>%MAKETEXT{"Location"}%:</th>
          <td> $l </td></tr>
    </table>
    $percntCLEAR$percnt"
}%

This works.  But some users don't have a thumbnailPhoto.  For these
cases I want to replace the picture with a default one, like this:

<img src='%IF{"$thumbnailPhoto=''" then="defaultUser.png"
else="$thumbnailPhoto"}%' />

But it doesn't work.

Using this expression with the %CALC% macro:
thumbnail: ->$thumbnailPhoto<- length: ->%CALC{"$LENGTH($thumbnailPhoto)"}%<-

I get this when there is a picture:
thumbnail: ->/pub/System/LdapContrib/blobs/799d832cbf716cebc2b09df38d3917a4<-
length: ->15<-

And this when there is none:
thumbnail: -><- length: ->15<-

What am I doing wrong here?

------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/NeoTech
_______________________________________________
Foswiki-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/foswiki-discuss
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: %LDAP% macro evaluation

Leila Pearson
I had the same problem and wound up working around it by doing two LDAP queries like this:

<div class="foswikiProfileInfo">
%LDAP{"&(sAMAccountName=%USERINFO{"%BASETOPIC%" format="$username"}%)(thumbnailPhoto=*)" 
  clear="$mail,$telephoneNumber,$thumbnailPhoto"
  blob="thumbnailPhoto"
  limit="1"
  format="<div class='foswikiImage foswikiLeft'><img alt='user photo' src='$thumbnailPhoto' height='100' /></div>
    <h1>$cn</h1>
    <table class='foswikiLayoutTable'>
      <tr><td> $mail </td></tr>
      <tr><td> $telephoneNumber </td></tr>
    </table>
    $percntCLEAR$percnt"
}% 
%LDAP{"&(sAMAccountName=%USERINFO{"%BASETOPIC%" format="$username"}%)(!(thumbnailPhoto=*))" 
  clear="$mail,$telephoneNumber"
  limit="1"
  format="<div class='foswikiImage foswikiLeft'><img alt='generic user photo' src='%PUBURLPATH%/%SYSTEMWEB%/MetaCommentPlugin/nobody.gif' height='100' /></div>
    <h1>$cn</h1>
    <table class='foswikiLayoutTable'>
      <tr><td> $mail </td></tr>
      <tr><td> $telephoneNumber </td></tr>
    </table>
    $percntCLEAR$percnt"
}% 
</div>
This works, but I would have preferred a single query solution.

Leila

On Thu, Apr 17, 2014 at 8:30 PM, Alan <[hidden email]> wrote:
Hello,

I'm creating a NewLdapUserTemplate topic to create user topics
automatically with the NewUserPlugin.

In it, I use the %LDAP% macro this way:

%LDAP{"(sAMAccountName=%EXPAND{$percntUSERINFO{format="$username"}$percnt}%)"
  clear="$cn,$mail,$telephoneNumber,$title,$l,$thumbnailPhoto"
  blob="thumbnailPhoto"
  limit="1"
  format="<img style='height:auto; height:320px;' src='$thumbnailPhoto' />
    <h1>$cn</h1>
    <table class='foswikiLayoutTable'>
      <tr><th>%MAKETEXT{"E-mail"}%:</th>
          <td> $mail </td></tr>
      <tr><th>%MAKETEXT{"Telephone"}%:</th>
          <td> $telephoneNumber </td></tr>
      <tr><th>%MAKETEXT{"Title"}%:</th>
          <td> $title </td></tr>
      <tr><th>%MAKETEXT{"Location"}%:</th>
          <td> $l </td></tr>
    </table>
    $percntCLEAR$percnt"
}%

This works.  But some users don't have a thumbnailPhoto.  For these
cases I want to replace the picture with a default one, like this:

<img src='%IF{"$thumbnailPhoto=''" then="defaultUser.png"
else="$thumbnailPhoto"}%' />

But it doesn't work.

Using this expression with the %CALC% macro:
thumbnail: ->$thumbnailPhoto<- length: ->%CALC{"$LENGTH($thumbnailPhoto)"}%<-

I get this when there is a picture:
thumbnail: ->/pub/System/LdapContrib/blobs/799d832cbf716cebc2b09df38d3917a4<-
length: ->15<-

And this when there is none:
thumbnail: -><- length: ->15<-

What am I doing wrong here?

------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/NeoTech
_______________________________________________
Foswiki-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/foswiki-discuss


------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/NeoTech
_______________________________________________
Foswiki-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/foswiki-discuss
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: %LDAP% macro evaluation

Michael Daum-2
In reply to this post by Alan
On Friday 18 April 2014 12:30:57 Alan wrote:

> Hello,
>
> I'm creating a NewLdapUserTemplate topic to create user topics
> automatically with the NewUserPlugin.
>
> In it, I use the %LDAP% macro this way:
>
> %LDAP{"(sAMAccountName=%EXPAND{$percntUSERINFO{format="$username"}$percnt}%)"
>   clear="$cn,$mail,$telephoneNumber,$title,$l,$thumbnailPhoto"
>   blob="thumbnailPhoto"
>   limit="1"
>   format="<img style='height:auto; height:320px;' src='$thumbnailPhoto' />
>     <h1>$cn</h1>
>     <table class='foswikiLayoutTable'>
>       <tr><th>%MAKETEXT{"E-mail"}%:</th>
>           <td> $mail </td></tr>
>       <tr><th>%MAKETEXT{"Telephone"}%:</th>
>           <td> $telephoneNumber </td></tr>
>       <tr><th>%MAKETEXT{"Title"}%:</th>
>           <td> $title </td></tr>
>       <tr><th>%MAKETEXT{"Location"}%:</th>
>           <td> $l </td></tr>
>     </table>
>     $percntCLEAR$percnt"
> }%
>
> This works.  But some users don't have a thumbnailPhoto.  For these
> cases I want to replace the picture with a default one, like this:
>
> <img src='%IF{"$thumbnailPhoto=''" then="defaultUser.png"
> else="$thumbnailPhoto"}%' />
>
> But it doesn't work.

All TML is evaluated left-to-right-inside-out. So your %IF is expanded _before_ the %LDAP had a chance to replace $thumbnailPhoto with a result from the query.

Try this

%LDAP{
   ...
   clear="$thumbnailPhoto"
   ...
  format="..... <img src='$percntIF{\" '$thumbnailPhot'='' \"  then=\"defaultUser.png\" else=\"$thumbnailPhoto\"}$percnt\"' /> ...."

}%


Michael.

--
-- Michael Daum Consulting
-- Wissensmanagement und Intranet-Technologie
-- http://michaeldaumconsulting.com
-- Tel: +49 (0)40 21 99 27 51

------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/NeoTech
_______________________________________________
Foswiki-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/foswiki-discuss
Loading...