demo.posthook.php 911 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. /**
  3. * A demo postHook for doing faceted search
  4. */
  5. $c = $modx->newQuery('modUser');
  6. $c->innerJoin('modUserProfile', 'Profile');
  7. $c->where(array(
  8. 'username:LIKE' => '%' . $search . '%',
  9. 'OR:Profile.fullname:LIKE' => '%' . $search . '%',
  10. 'OR:Profile.email:LIKE' => '%' . $search . '%',
  11. ));
  12. $count = $modx->getCount('modUser', $c);
  13. $c->select(array(
  14. 'modUser.*',
  15. 'Profile.fullname',
  16. 'Profile.email',
  17. ));
  18. $c->limit($limit,$offset);
  19. $users = $modx->getCollection('modUser', $c);
  20. $results = array();
  21. foreach ($users as $user) {
  22. $results[] = array(
  23. 'pagetitle' => $user->get('fullname'),
  24. 'longtitle' => $user->get('email'),
  25. 'link' => $modx->makeUrl(10, '',
  26. array(
  27. 'user' => $user->get('id'),
  28. )
  29. ),
  30. 'excerpt' => '',
  31. );
  32. }
  33. $hook->addFacet('people', $results, $count);
  34. return true;