Skip to content

Instantly share code, notes, and snippets.

@jpalala
Created April 28, 2014 01:09
Show Gist options
  • Save jpalala/11359444 to your computer and use it in GitHub Desktop.
Save jpalala/11359444 to your computer and use it in GitHub Desktop.
Some entity based table design idea i have
/*Profile node helps to segragate the actual query sql from the model code*/
class Profile_node {
public $CInst;
private $dB;
public $profile_id;
public $social_keys;
public function __construct($profile_id) {
$this->CInst =& get_instance();
$this->dB = $this->CInst->db->database;
$this->profile_id = $profile_id;
var_dump($profile_id);
$this->social_keys = array('linkedin','twitter','facebook','github');
}
public function getTestimonials(){
$query = "SELECT * FROM testimonial WHERE tesstimonial_userpid";
}
public function getMeta() {
$social = $this->getSocial();
$interests = $this->getProfileInterests();
return array('getProfileSocial' => $social,
'getProfileInterests' => $interests);
}
public function getSocial() {
$where = '';
$meta = 'profilemeta_';
foreach($this->social_keys as $val) {
$where .= "`". $meta."key` = '". $val . "' OR ";
}
$where = substr($where,0,-3);
$query = $this->CInst->db->query("SELECT `profilemeta_value` FROM profilemeta WHERE ".$where);
return $query;
}
public function getProfileInterests() {
//pykoboxc_sensei
$select = 'SELECT `profilemeta_value`';
$tbl = '`'. $this->dB. '`.profilemeta';
$where = "`key` = 'interest'";
$query = $this->CInst->db->query($select . ' FROM '.$tbl . ' LIMIT 10');
return $query;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment