public static function getGroupsByUser($db = null, $user_id)
 {
     $peer_object = new DinklyUserGroup();
     if ($db == null) {
         $db = self::fetchDB();
     }
     $query = $peer_object->getSelectQuery() . " where dinkly_user_id = " . $db->quote($user_id);
     $user_group_joins = self::getCollection($peer_object, $query, $db);
     if ($user_group_joins != array()) {
         $group_ids = array();
         foreach ($user_group_joins as $group_join) {
             $group_ids[] = $group_join->getDinklyGroupId();
         }
         $groups = DinklyGroupCollection::getByArrayOfIds($group_ids, $db);
         if ($groups != array()) {
             return $groups;
         }
     }
     return false;
 }
 public function validateGroupPost($post_array)
 {
     if (isset($post_array['name'])) {
         //Just in case the js validation didn't already catch it
         if ($post_array['name'] == "") {
             $this->errors[] = "Name cannot be blank.";
         }
         //Check the name for uniqueness
         if (!DinklyGroupCollection::isUniqueName($post_array['name']) && $post_array['name'] != $this->group->getName()) {
             $this->errors[] = "Name already in use, please try another.";
         }
         //Check the abbreviation for uniqueness
         if (!DinklyGroupCollection::isUniqueAbbreviation($post_array['abbreviation']) && $post_array['abbreviation'] != $this->group->getAbbreviation()) {
             $this->errors[] = "Abbreviation already in use, please try another.";
         }
         //Check for whitespace in the abbreviation
         if (stristr($post_array['abbreviation'], ' ')) {
             $this->errors[] = "Abbreviation cannot contain whitespace.";
         }
         //Make sure that the abbreviation is also alphanumeric, without funky symbols
         $valid_symbols = array('-', '_');
         if (!ctype_alnum(str_replace($valid_symbols, '', $post_array['abbreviation']))) {
             $this->errors[] = "Abbreviation must be alphanumeric. Underscores and dashes are allowed.";
         }
         //Duh
         if ($post_array['abbreviation'] == "") {
             $this->errors[] = "Abbreviation cannot be blank.";
         }
         //Update group (don't worry, we don't save unless everything is valid)
         $this->group->setName($post_array['name']);
         $this->group->setAbbreviation($post_array['abbreviation']);
         $this->group->setDescription($post_array['description']);
     }
 }