本文整理汇总了PHP中Sample::validate方法的典型用法代码示例。如果您正苦于以下问题:PHP Sample::validate方法的具体用法?PHP Sample::validate怎么用?PHP Sample::validate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sample
的用法示例。
在下文中一共展示了Sample::validate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: analyzeCsv
protected static function analyzeCsv($bytes, $biobank_id, $fileImportedId, $add)
{
$import = fopen(CommonTools::data_uri($bytes, 'text/csv'), 'r');
$row = 1;
$keysArray = array();
$listBadSamples = array();
$newSamples = array();
// $tempSaveList = new MongoInsertBatch(Sample::model()->getCollection());
$tempSaveList = array();
/**
* Version 1 : Les champs non repertorés sont ajoutés en notes
*/
while (($data = fgetcsv($import, 1000, ",")) !== FALSE) {
/*
* Traitement de la ligne d'entete
*/
if ($row == 1) {
foreach ($data as $key => $value) {
if ($value != null && $value != "") {
$keysArray[$key] = $value;
}
}
} else {
$model = new Sample();
$model->disableBehavior('LoggableBehavior');
$model->_id = new MongoId();
while (!$model->validate(array('_id'))) {
$model->_id = new MongoId();
}
$model->biobank_id = $biobank_id;
$model->file_imported_id = $fileImportedId;
foreach ($keysArray as $key2 => $value2) {
if ($value2 != "biobank_id" && $value2 != "file_imported_id") {
if (in_array($value2, Sample::model()->attributeNames())) {
$model->{$value2} = $data[$key2];
if (!$model->validate(array($value2))) {
// Yii::log("Problem with item" . $model->getAttributeLabel($value2) . ",set to null.\n " . implode(", ", $model->errors[$value2]), CLogger::LEVEL_ERROR);
$model->{$value2} = null;
}
} else {
$note = new Note();
$note->key = $value2;
$note->value = $data[$key2];
$model->notes[] = $note->attributes;
}
}
}
if (!$model->validate()) {
Yii::log("Problem with sample validation " . print_R($model->errors, true), CLogger::LEVEL_ERROR);
$listBadSamples[] = $row;
} else {
$tempSaveList[] = $model->attributes;
// $tempSaveList->add($model->attributes);
$newSamples[] = $model->_id;
}
}
$row++;
if ($row != 2 && $row % 400 == 2) {
Yii::log("Nb treated : " . $row, 'error');
Sample::model()->getCollection()->batchInsert($tempSaveList, array());
$tempSaveList = array();
//$tempSaveList->execute(array());
//$tempSaveList = new MongoInsertBatch(Sample::model()->getCollection());
}
}
Sample::model()->getCollection()->batchInsert($tempSaveList, array("w" => 1));
/*
* Version 2 : seuls nes champs dont la colonne est annotée avec le préfixe 'notes' sont pris en note
*/
// while (($data = fgetcsv($import, 1000, ",")) !== FALSE) {
//
// /*
// * Traitement de la ligne d'entete
// */
//
//
//
// if ($row == 1) {
// foreach ($data as $key => $value) {
// if (in_array($value, Sample::model()->attributeNames())) {
// $keysArray[$key] = $value;
// } elseif (substr($value, 0, 5) == 'notes') {
// $keysArray[$key] = $value;
// }
// }
// /*
// * Traitement des lignes de données
// */
// } else {
// $model = new Sample();
// $model->disableBehavior('LoggableBehavior');
// $model->biobank_id = $biobank_id;
// $model->file_imported_id = $fileImportedId;
// foreach ($keysArray as $key2 => $value2) {
// if (substr($value2, 0, 5) != 'notes') {
//
// $model->$value2 = $data[$key2];
// if (!$model->validate($value2)) {
//
// Yii::log("Problem with item" . $model->getAttributeLabel($value2) . ",set to null.", CLogger::LEVEL_ERROR);
//.........这里部分代码省略.........