Last active
December 14, 2015 21:19
-
-
Save aqualad/5150499 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* * | |
* Usage: | |
* CrmEmployees :: getUsers(); | |
*/ | |
public static function getUsers($userid=null, $cols=null) | |
{ | |
$valid_columns = array( | |
'UID'=>1, | |
'FirstName'=>1, | |
'LastName'=>1, | |
'Company'=>1, | |
'Phone'=>1, | |
'Email'=>1, | |
'Country'=>1, | |
'State'=>1, | |
'Zip'=>1, | |
'City'=>1, | |
'Address'=>1 | |
); | |
if(is_null($userid)) | |
{ | |
$auth = Auth::get(); | |
$userid = $auth['UserID']; | |
} | |
if(empty($cols) || is_null($cols) || !is_array($cols)) | |
{ | |
$cols = array('UID'); | |
} | |
else | |
{ | |
$i = 0; | |
foreach($cols as $column) | |
{ | |
if(empty($valid_columns[$column])) | |
unset($cols[$i]); | |
else | |
$cols[$i] = db::escape($column); | |
$i++; | |
} | |
} | |
$cols = implode(',',$cols); | |
$prefix = db::prefix(); | |
$sql = "SELECT a.EntityType, a.EntityID, Name, d.ID, $cols | |
FROM ".db::prefix('crm_useraccess')." a | |
JOIN ( | |
SELECT concat(b.`FirstName`, ' ', b.`LastName`) as Name, ID, $cols FROM ".db::prefix('crm_employees')." b | |
UNION | |
SELECT concat(c.`FirstName`, ' ', c.`LastName`) as Name, ID, $cols FROM ".db::prefix('crm_clients')." c | |
) d ON a.EntityID=d.ID | |
WHERE a.UserID={$userid} | |
ORDER BY a.EntityType ASC"; | |
return db::query($sql); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment