Skip to content

Commit

Permalink
[NF] Search for usernames
Browse files Browse the repository at this point in the history
  • Loading branch information
barryo committed Feb 19, 2014
1 parent 3122dcc commit 94e137d
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 2 deletions.
25 changes: 25 additions & 0 deletions application/Repositories/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,29 @@ public function getGroupsByIds( $ids )

return $data;
}



/**
* Find contacts by username
*
* Will support a username starts / ends with as it uses LIKE
*
* @param string $username The username to search for
* @return \Entities\Contact[] Matching contacts
*/
public function findByUsername( $username )
{
return $this->getEntityManager()->createQuery(
"SELECT c
FROM \\Entities\\Contact c
LEFT JOIN c.User u
WHERE u.username LIKE :username"
)
->setParameter( 'username', $username )
->getResult();
}

}
7 changes: 6 additions & 1 deletion application/controllers/SearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function doAction()
$this->view->type = 'ipv6';
$this->processIPSearch( $this->getD2R( '\\Entities\\IPv6Address' )->findVlanInterfaces( $search ) );
}
else if( preg_match( '/^as(\d+)$/', strtolower( $search ), $matches ) )
else if( preg_match( '/^as(\d+)$/', strtolower( $search ), $matches ) || preg_match( '/^(\d+)$/', $search, $matches ) )
{
$this->view->type = 'asn';
$this->view->results = $this->getD2R( '\\Entities\\Customer' )->findByASN( $matches[1] );
Expand All @@ -70,6 +70,11 @@ public function doAction()
$this->view->type = 'asmacro';
$this->view->results = $this->getD2R( '\\Entities\\Customer' )->findByASMacro( $search );
}
else if( preg_match( '/^@([a-zA-Z0-9]+)$/', $search, $matches ) )
{
$this->view->type = 'username';
$this->view->results = $this->getD2R( '\\Entities\\Contact' )->findByUsername( $matches[1] . '%' );
}
}

private function processMACSearch( $search )
Expand Down
6 changes: 5 additions & 1 deletion application/views/menu.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,11 @@
</dd>
<dt>AS Number / Macro</dt>
<dd>
Enter ASN <code>asXXX</code> and AS macro as <code>as-XXX</code>
Enter ASN as <code>XXX</code> or <code>asXXX</code> and AS macro as <code>as-XXX</code>
</dd>
<dt>Usernames</dt>
<dd>
Find usernames <em>starting with</em> <code>xxx</code> by entering <code>@xxx</code>
</dd>
</dl>
</div>
Expand Down
49 changes: 49 additions & 0 deletions application/views/search/contacts.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@

<div class="row-fluid">
<div class="span11 offset1">

<table class="table">

<thead>
<tr>
<th>Name</th>
<th>E-Mail</th>
<th>Username (history)</th>
<th>Customer</th>
<th>Created</th>
</tr>
</thead>
<tbody>
{foreach $results as $contact}

<tr>
<td>
<a href="{genUrl controller="contact" action="edit" id=$contact->getId() cid=$contact->getCustomer()->getId()}">
{$contact->getName()}
</a>
</td>
<td>
{$contact->getEmail()}
</td>
<td>
<a href="{genUrl controller="login-history" action="list" uid=$contact->getUser()->getId() limit=1}">
{$contact->getUser()->getUsername()}
</a>
</td>
<td>
<a href="{genUrl controller="customer" action="overview" id=$contact->getCustomer()->getId()}">
{$contact->getCustomer()->getName()}
</a>
</td>
<td>
{$contact->getCreated()->format( 'Y-m-d H:i:s' )}
</td>
</tr>

{/foreach}
</tbody>

</table>

</div>
</div>
8 changes: 8 additions & 0 deletions application/views/search/do.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
</div>
</div>

{if $type = 'username'}

{tmplinclude file='search/contacts.phtml'}

{else}

{foreach $results as $cust}
<div class="row-fluid">
<div class="span11 offset1">
Expand Down Expand Up @@ -55,6 +61,8 @@

{/if}

{/if}


<div class="row-fluid">

Expand Down

0 comments on commit 94e137d

Please sign in to comment.