salve a tutti , premetto che ho iniziato a programmare php solo da pochi giorni , il mio problema è : Ho un database che contiente due tabelle , devo creare degli script che riescano in modo automatico a popolare le tabelle con valori in modo casuale ; Dovrei creare una nuova funzione (es: public function Popola ) che contenga un ciclo (for o while) che permetta di popolare la tabella patients in modo casuale ( non so se esiste un oggetto Random ) il codice è questo:
PHP:
class Patients extends CActiveRecord
{
/**
* Returns the static model of the specified AR class.
* @param string $className active record class name.
* @return Patients the static model class
*/
public static function model($className=__CLASS__)
{
return parent::model($className);
}
/**
* @return string the associated database table name
*/
public function tableName()
{
return 'patients';
}
/**
* @return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('pin_xcare', 'required'),
array('birth_city_id, birth_nation_id, residence_city_id, residence_nation_id, visible, num_activations', 'numerical', 'integerOnly'=>true),
array('fiscal_code', 'length', 'max'=>16),
array('surname, name, nationality, european_card, asl, residence_address, phone_number, mobile_phone, email, emergency_contact', 'length', 'max'=>200),
array('gender, cultural_mediator', 'length', 'max'=>1),
array('race', 'length', 'max'=>100),
array('residence_cap', 'length', 'max'=>10),
array('pin_xcare', 'length', 'max'=>20),
array('birthday, first_access, policy_consensus, policy_cessation', 'safe'),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('patient_id, fiscal_code, surname, name, gender, race, nationality, european_card, asl, residence_address, residence_cap, cultural_mediator, phone_number, mobile_phone, email, emergency_contact, birth_city_id, birth_nation_id, residence_city_id, residence_nation_id, pin_xcare, birthday, first_access, policy_consensus, policy_cessation, visible, num_activations', 'safe', 'on'=>'search'),
);
}
/**
* @return array relational rules.
*/
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'detections' => array(self::HAS_MANY, 'Detections', 'patient_id'),
);
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'patient_id' => 'Patient',
'fiscal_code' => 'Fiscal Code',
'surname' => 'Surname',
'name' => 'Name',
'gender' => 'Gender',
'race' => 'Race',
'nationality' => 'Nationality',
'european_card' => 'European Card',
'asl' => 'Asl',
'residence_address' => 'Residence Address',
'residence_cap' => 'Residence Cap',
'cultural_mediator' => 'Cultural Mediator',
'phone_number' => 'Phone Number',
'mobile_phone' => 'Mobile Phone',
'email' => 'Email',
'emergency_contact' => 'Emergency Contact',
'birth_city_id' => 'Birth City',
'birth_nation_id' => 'Birth Nation',
'residence_city_id' => 'Residence City',
'residence_nation_id' => 'Residence Nation',
'pin_xcare' => 'Pin Xcare',
'birthday' => 'Birthday',
'first_access' => 'First Access',
'policy_consensus' => 'Policy Consensus',
'policy_cessation' => 'Policy Cessation',
'visible' => 'Visible',
'num_activations' => 'Num Activations',
);
}
/**
* Retrieves a list of models based on the current search/filter conditions.
* @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
*/
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('patient_id',$this->patient_id,true);
$criteria->compare('fiscal_code',$this->fiscal_code,true);
$criteria->compare('surname',$this->surname,true);
$criteria->compare('name',$this->name,true);
$criteria->compare('gender',$this->gender,true);
$criteria->compare('race',$this->race,true);
$criteria->compare('nationality',$this->nationality,true);
$criteria->compare('european_card',$this->european_card,true);
$criteria->compare('asl',$this->asl,true);
$criteria->compare('residence_address',$this->residence_address,true);
$criteria->compare('residence_cap',$this->residence_cap,true);
$criteria->compare('cultural_mediator',$this->cultural_mediator,true);
$criteria->compare('phone_number',$this->phone_number,true);
$criteria->compare('mobile_phone',$this->mobile_phone,true);
$criteria->compare('email',$this->email,true);
$criteria->compare('emergency_contact',$this->emergency_contact,true);
$criteria->compare('birth_city_id',$this->birth_city_id);
$criteria->compare('birth_nation_id',$this->birth_nation_id);
$criteria->compare('residence_city_id',$this->residence_city_id);
$criteria->compare('residence_nation_id',$this->residence_nation_id);
$criteria->compare('pin_xcare',$this->pin_xcare,true);
$criteria->compare('birthday',$this->birthday,true);
$criteria->compare('first_access',$this->first_access,true);
$criteria->compare('policy_consensus',$this->policy_consensus,true);
$criteria->compare('policy_cessation',$this->policy_cessation,true);
$criteria->compare('visible',$this->visible);
$criteria->compare('num_activations',$this->num_activations);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
}
Ultima modifica di un moderatore: