patternphpMinor
Social application with users and sessions
Viewed 0 times
socialapplicationwithanduserssessions
Problem
I work with a legacy application. This is my attempt to add some sanity in an new feature I want to add.
It's a social application with users, sessions etc. The entire application is run in a procedural fashion. It still uses MySQL, so once this feature is complete, upgrading to PDO will be my next project.
```
class Groups {
protected $_db;
protected $member_id;
protected $group_id,
$group_title,
$group_about,
$group_join_us,
$group_contact,
$group_rss_url,
$group_rss_post_limit,
$group_privacy;
protected $group_super_admin;
protected $group_approve_status,
$group_approve_date;
protected $group_meta_title,
$group_meta_description,
$group_meta_keywords;
public function __construct($db, $member_id) {
$this->_db = $db;
$this->member_id = $member_id;
}
/**
* Set the group title
*
* @param str $group_id
*
*/
public function set_group_id($group_id) {
$this->group_id = $group_id;
}
/**
* Set the group title
*
* @param int $group_id
*
*/
public function get_group_id() {
return $this->group_id;
}
/**
* Set the group title
*
* @param str $group_id
*
*/
public function set_group_title($group_title) {
$this->group_title = $group_title;
}
/**
* get the group title
*
* @return int $group_id
*
*/
public function get_group_title() {
return $this->group_title;
}
/**
* Set the group about
*
* @param str $group_id
*
*/
public function set_group_about($group_about) {
$this->group_about = $group_about;
}
/**
* Get the group abo
It's a social application with users, sessions etc. The entire application is run in a procedural fashion. It still uses MySQL, so once this feature is complete, upgrading to PDO will be my next project.
```
class Groups {
protected $_db;
protected $member_id;
protected $group_id,
$group_title,
$group_about,
$group_join_us,
$group_contact,
$group_rss_url,
$group_rss_post_limit,
$group_privacy;
protected $group_super_admin;
protected $group_approve_status,
$group_approve_date;
protected $group_meta_title,
$group_meta_description,
$group_meta_keywords;
public function __construct($db, $member_id) {
$this->_db = $db;
$this->member_id = $member_id;
}
/**
* Set the group title
*
* @param str $group_id
*
*/
public function set_group_id($group_id) {
$this->group_id = $group_id;
}
/**
* Set the group title
*
* @param int $group_id
*
*/
public function get_group_id() {
return $this->group_id;
}
/**
* Set the group title
*
* @param str $group_id
*
*/
public function set_group_title($group_title) {
$this->group_title = $group_title;
}
/**
* get the group title
*
* @return int $group_id
*
*/
public function get_group_title() {
return $this->group_title;
}
/**
* Set the group about
*
* @param str $group_id
*
*/
public function set_group_about($group_about) {
$this->group_about = $group_about;
}
/**
* Get the group abo
Solution
Yes, you are most certainly on the right path, and as a first step, it's very good. Some pointers for the future.
None of the above issues are critical (except for
- Don't use
mysql_*- I know you said you're already planning to. I'm mainly saying this for future users.
- Objects work best with other objects - If you have groups, it makes sense to have a
Userclass, etc.
- Code style - Make sure your spacing and indentation are uniform throughout the file, and throughout the application in general.
- Naming - By the name
GroupsI understand that this class is a collection of singleGroupobjects, that doesn't seem to be the case, so this class should be calledGroup.
- Separation of concerns - Your
Groupshouldn't know where it came from. It shouldn't be aware of the database, or know how to fetch itself. Another object,GroupMappershould be responsible for that, and have methods likefetchGroupDetails($group).
None of the above issues are critical (except for
mysql_* maybe), you're doing a good job!Context
StackExchange Code Review Q#53885, answer score: 4
Revisions (0)
No revisions yet.