Skip to content

Instantly share code, notes, and snippets.

@onlyjazz
Last active July 6, 2017 12:14
Show Gist options
  • Save onlyjazz/c92816bdc024cef6e7f5b4c5b5d34f46 to your computer and use it in GitHub Desktop.
Save onlyjazz/c92816bdc024cef6e7f5b4c5b5d34f46 to your computer and use it in GitHub Desktop.
Studies Table
class StudiesTable extends Table
{
public function getStudies($data = array()) {
$customer_id = $data['customer_id'];
$connection = ConnectionManager::get('default');
$sql = "select * from getStudies($customer_id)";
$s = $this->schema();
pr($s);
$stmt = $connection->execute($sql);
$results = $stmt->fetch();
return $results;
}
/**
* Initialize method
*
* @param array $config The configuration for the Table.
* @return void
*/
public function initialize(array $config)
{
parent::initialize($config);
$this->table('studies');
$this->displayField('id');
$this->primaryKey('id');
$this->addBehavior('Timestamp');
$this->belongsTo('Customers', [
'foreignKey' => 'customer_id'
]);
$this->belongsTo('StudyTypes', [
'foreignKey' => 'study_type_id'
]);
$this->belongsTo('StudyPurposes', [
'foreignKey' => 'study_purpose_id'
]);
$this->belongsTo('StudyPhases', [
'foreignKey' => 'study_phase_id'
]);
$this->belongsTo('StudyModels', [
'foreignKey' => 'study_model_id'
]);
$this->belongsTo('StudyMaskings', [
'foreignKey' => 'study_masking_id'
]);
$this->belongsTo('StudyAllocations', [
'foreignKey' => 'study_allocation_id'
]);
$this->belongsTo('StudyTimeperspectives', [
'foreignKey' => 'study_timeperspective_id'
]);
$this->belongsTo('Statuses', [
'foreignKey' => 'status_id'
]);
$this->belongsTo('OwnerUsers', [
'foreignKey' => 'owner_user_id'
]);
$this->belongsTo('UpdateUsers', [
'foreignKey' => 'update_user_id'
]);
$this->hasMany('Alertrules', [
'foreignKey' => 'study_id'
]);
$this->hasMany('Alerts', [
'foreignKey' => 'study_id'
]);
$this->hasMany('Analyticrules', [
'foreignKey' => 'study_id'
]);
$this->hasMany('Entities', [
'foreignKey' => 'study_id'
]);
$this->hasMany('EntityComments', [
'foreignKey' => 'study_id'
]);
$this->hasMany('Measures', [
'foreignKey' => 'study_id'
]);
$this->hasMany('SiteStudies', [
'foreignKey' => 'study_id'
]);
$this->hasMany('UserStudies', [
'foreignKey' => 'study_id'
]);
$this->hasMany('Vuserstudies', [
'foreignKey' => 'study_id'
]);
}
/**
* Default validation rules.
*
* @param \Cake\Validation\Validator $validator Validator instance.
* @return \Cake\Validation\Validator
*/
public function validationDefault(Validator $validator)
{
$validator
->integer('id')
->allowEmpty('id', 'create');
$validator
->allowEmpty('brief_title');
$validator
->allowEmpty('official_title');
$validator
->allowEmpty('brief_summary');
$validator
->allowEmpty('detailed_description');
$validator
->allowEmpty('unique_protocolid');
$validator
->allowEmpty('nct_number');
$validator
->allowEmpty('dbname');
$validator
->allowEmpty('sponsor');
$validator
->allowEmpty('collaborator');
$validator
->allowEmpty('url');
$validator
->integer('enrollment_target')
->allowEmpty('enrollment_target');
$validator
->integer('no_of_arms')
->allowEmpty('no_of_arms');
$validator
->date('study_start_date')
->allowEmpty('study_start_date');
$validator
->date('study_completion_date')
->allowEmpty('study_completion_date');
return $validator;
}
/**
* Returns a rules checker object that will be used for validating
* application integrity.
*
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
* @return \Cake\ORM\RulesChecker
*/
public function buildRules(RulesChecker $rules)
{
$rules->add($rules->existsIn(['customer_id'], 'Customers'));
$rules->add($rules->existsIn(['study_type_id'], 'StudyTypes'));
$rules->add($rules->existsIn(['study_purpose_id'], 'StudyPurposes'));
$rules->add($rules->existsIn(['study_phase_id'], 'StudyPhases'));
$rules->add($rules->existsIn(['study_model_id'], 'StudyModels'));
$rules->add($rules->existsIn(['study_masking_id'], 'StudyMaskings'));
$rules->add($rules->existsIn(['study_allocation_id'], 'StudyAllocations'));
$rules->add($rules->existsIn(['study_timeperspective_id'], 'StudyTimeperspectives'));
return $rules;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment