« Request forwarding to JSP from Jython | Main | LOM OAI-PMH Harvester in Python »
February 28, 2012
Example OOP PHP Code
<?php abstract class pid_entity{ function details(){ global $r; $r['dbname'] = 'uebs'; $r['schema'] = 'pid'; if(!$this->id){ return false; } if(!$this->table){ return false; } $reply = just::sql(sprintf('select * from %s.%s where %s_id = %d',$r['schema'] , $this->table, $this->table, $this->id)); $this->details = $reply['first_row']; $this->row = $this->details; } function create(){ if(!$this->table){ return false; } global $r; $r['dbname'] = 'uebs'; $r['schema'] = 'pid'; $this->id = just::add($this->table); } function set(){ if(!$this->table){ return false; } global $r; $r['dbname'] = 'uebs'; $r['schema'] = 'pid'; if(!$this->id){ $this->create(); } $reply = just::update($this->table, $r, $this->id); $_SESSION['pid_set'] = $reply; $this->details(); $this->row = $this->details; return $reply['status']; } function annotate(){ global $r; $r['dbname'] = 'uebs'; $r['schema'] = 'pid'; $id = just::add('note'); $r[$this->table.'_id'] = $this->id; $reply = just::update('note', $r, $id); return $reply['status']; } function get_notes(){ global $r; $r['dbname'] = 'uebs'; $r['schema'] = 'pid'; $reply = just::sql(sprintf('select notes, to_timestamp(insert_date) as ts, insert_date from %s.note where expired_date is null and %s_id = %d order by insert_date desc', $r['schema'], $this->table, $this->id )); return $reply['rows']; } } interface pid_entity_if{ function details(); function create(); function set(); function add_child($object); function get_children(); function calculate_start(); function calculate_end(); function annotate(); function get_notes(); } class project extends pid_entity implements pid_entity_if{ public $id; public $title; public $percent_complete; public $start_date; public $end_date; public $children; public $table = 'project'; function __construct($key){ if($key > 0){ $this->id = $key; $this->details(); } } function add_child($object){} function get_children(){} function calculate_start(){} function calculate_end(){} } class phase extends project{ public $id; public $title; public $percent_complete; public $start_date; public $end_date; public $children; public $table = 'phase'; function __construct($phase_id){ parent::__construct($phase_id); } } class work_package extends project{ public $id; public $title; public $percent_complete; public $start_date; public $end_date; public $children; public $table = 'work_package'; function __construct($wp_id){ parent::__construct($wp_id); } } class deliverable extends project{ public $id; public $title; public $percent_complete; public $start_date; public $end_date; public $children; public $table = 'deliverable'; function __construct($del_id){ parent::__construct($del_id); } } /* End of /waf/classes/project_initiation.php */
DB Model:
drop table if exists pid.project; create table pid.project ( project_id serial unique not null, project_type_id integer null, name text null, purpose text null, background text null, assumptions text null, constraints text null, risks text null, insert_by integer null, insert_date bigint null, update_by integer null, update_date bigint null, expired_date bigint null, primary key (project_id) ); alter table pid.project drop project_type_id; drop table if exists pid.phase; create table pid.phase ( phase_id serial unique not null, phase_type_id integer null, project_id integer null, phase_sort decimal null, name text null, description text null, insert_by integer null, insert_date bigint null, update_by integer null, update_date bigint null, expired_date bigint null, primary key (phase_id) ); alter table pid.phase drop phase_type_id; drop table if exists pid.work_package; create table pid.work_package ( work_package_id serial unique not null, work_package_type_id integer null, phase_id integer null, dependent_on_package_id integer null, name text null, package_sort decimal null, description text null, start_date bigint null, length_days decimal null, completion_date bigint null, insert_by integer null, insert_date bigint null, update_by integer null, update_date bigint null, expired_date bigint null, primary key (work_package_id) ); alter table pid.work_package drop work_package_type_id; drop table if exists pid.staff; create table pid.staff ( staff_id serial unique not null, staff_type_id integer null, insert_by integer null, insert_date bigint null, update_by integer null, update_date bigint null, expired_date bigint null, primary key (staff_id) ); alter table pid.staff drop staff_type_id; drop table if exists pid.note; create table pid.note ( note_id serial unique not null, note_type_id integer null, project_id integer null, phase_id integer null, work_package_id integer null, notes text null, insert_by integer null, insert_date bigint null, update_by integer null, update_date bigint null, expired_date bigint null, primary key (note_id) ); alter table pid.note drop note_type_id; drop table if exists pid.deliverable; create table pid.deliverable ( deliverable_id serial unique not null, deliverable_type_id integer null, work_package_id integer null, name text null, delivery_date bigint null, insert_by integer null, insert_date bigint null, update_by integer null, update_date bigint null, expired_date bigint null, primary key (deliverable_id) ); alter table pid.deliverable drop deliverable_type_id; drop table if exists pid.work_package_status; create table pid.work_package_status ( work_package_status_id serial unique not null, work_package_status_type_id integer null, insert_by integer null, insert_date bigint null, update_by integer null, update_date bigint null, expired_date bigint null, primary key (work_package_status_id) ); drop table if exists pid.work_package_status_type; create table pid.work_package_status_type ( work_package_status_type_id serial unique not null, name text null, description text, insert_by integer null, insert_date bigint null, update_by integer null, update_date bigint null, non_deletable boolean not null default true, expired_date bigint null, primary key (work_package_status_type_id) ); drop table if exists pid.upload_file; create table pid.upload_file ( upload_file_id serial unique not null, upload_file_type_id integer null, project_id integer null, phase_id integer null, work_package_id integer null, file_name text null, file_mime_type text null, file_length bigint null, file_data bytea null, insert_by integer null, insert_date bigint null, update_by integer null, update_date bigint null, expired_date bigint null, primary key (upload_file_id) ); alter table pid.upload_file drop upload_file_type_id; drop table if exists pid.project_staff_link; create table pid.project_staff_link ( project_staff_link_id serial unique not null, project_id integer null, staff_id integer null, insert_by integer null, insert_date bigint null, update_by integer null, update_date bigint null, expired_date bigint null, primary key(project_staff_link_id) );
Windows .ini file:
[schema] default = pid [table_list] project = 0 phase = 0 work_package = 0 staff = 0 note = 0 deliverable = 0 work_package_status = 1 upload_file = 0 [upload_file] project_id = integer phase_id = integer work_package_id = integer file_name = text file_mime_type = text file_length = bigint file_data = bytea [work_package_status] work_package_id [note] project_id = integer phase_id = integer work_package_id = integer notes = text [deliverable] work_package_id = integer name = text delivery_date = bigint [work_package] phase_id = integer dependent_on_package_id = integer name = text package_sort = decimal name = text description = text start_date = bigint length_days = decimal completion_date = bigint [project] name = text purpose = text background = text assumptions = text constraints = text risks = text [phase] project_id = integer phase_sort = decimal name = text description = text [staff] [link_tables] project:staff = 0 ;programme:course = 0
Tags: PHP
Posted by pj at February 28, 2012 02:37 PM