Exemplo n.º 1
0
 /**
  * retrieve users from the database
  *
  * @param object $criteria {@link icms_db_criteria_Element} conditions to be met
  * @param bool $id_as_key use the UID as key for the array?
  * @return array array of {@link icms_member_user_Object} objects
  */
 public function getObjects($criteria = NULL, $id_as_key = FALSE)
 {
     $ret = array();
     $limit = $start = 0;
     $sql = "SELECT * FROM " . $this->db->prefix('users');
     if (isset($criteria) && is_subclass_of($criteria, 'icms_db_criteria_Element')) {
         $sql .= " " . $criteria->renderWhere();
         if ($criteria->getSort() != '') {
             $sql .= " ORDER BY " . $criteria->getSort() . " " . $criteria->getOrder();
         }
         $limit = $criteria->getLimit();
         $start = $criteria->getStart();
     }
     $result = $this->db->query($sql, $limit, $start);
     if (!$result) {
         return $ret;
     }
     while ($myrow = $this->db->fetchArray($result)) {
         $user = new icms_member_user_Object();
         $user->assignVars($myrow);
         if (!$id_as_key) {
             $ret[] =& $user;
         } else {
             $ret[$myrow['uid']] =& $user;
         }
         unset($user);
     }
     return $ret;
 }
Exemplo n.º 2
0
 /**
  * Get a list of users belonging to certain groups and matching criteria
  * Temporary solution
  *
  * @param int $groups IDs of groups
  * @param object $criteria {@link icms_db_criteria_Element} object
  * @param bool $asobject return the users as objects?
  * @param bool $id_as_key use the UID as key for the array if $asobject is TRUE
  * @return array Array of {@link icms_member_user_Object} objects (if $asobject is TRUE)
  * or of associative arrays matching the record structure in the database.
  */
 public function getUsersByGroupLink($groups, $criteria = null, $asobject = false, $id_as_key = false)
 {
     $ret = array();
     $select = $asobject ? "u.*" : "u.uid";
     $sql[] = "\tSELECT DISTINCT {$select} " . "\tFROM " . icms::$xoopsDB->prefix("users") . " AS u" . " LEFT JOIN " . icms::$xoopsDB->prefix("groups_users_link") . " AS m ON m.uid = u.uid" . "\tWHERE 1 = '1'";
     if (!empty($groups)) {
         $sql[] = "m.groupid IN (" . implode(", ", $groups) . ")";
     }
     $limit = $start = 0;
     if (isset($criteria) && is_subclass_of($criteria, 'icms_db_criteria_Element')) {
         $sql_criteria = $criteria->render();
         if ($criteria->getSort() != '') {
             $sql_criteria .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder();
         }
         $limit = $criteria->getLimit();
         $start = $criteria->getStart();
         if ($sql_criteria) {
             $sql[] = $sql_criteria;
         }
     }
     $sql_string = implode(" AND ", array_filter($sql));
     if (!($result = icms::$xoopsDB->query($sql_string, $limit, $start))) {
         return $ret;
     }
     while ($myrow = icms::$xoopsDB->fetchArray($result)) {
         if ($asobject) {
             $user = new icms_member_user_Object();
             $user->assignVars($myrow);
             if (!$id_as_key) {
                 $ret[] =& $user;
             } else {
                 $ret[$myrow['uid']] =& $user;
             }
             unset($user);
         } else {
             $ret[] = $myrow['uid'];
         }
     }
     return $ret;
 }