/**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new FileType();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['FileType'])) {
         $model->attributes = $_POST['FileType'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
Exemplo n.º 2
0
 public function updateFile($f, $data)
 {
     $f->name = $data[0];
     $f->code = $data[1];
     $type = $f->type;
     $format = $f->format;
     if ($data[2] != $type->name) {
         $nt = FileType::model()->find(array('condition' => 'lower(name) = :name', 'params' => array(':name' => strtolower($data[2]))));
         if ($nt) {
             $f->type_id = $nt->id;
         } else {
             $nt = FileType::model()->findByAttributes(array('name' => 'Other'));
             if (!$nt) {
                 $nt = new FileType();
                 $nt->name = 'Other';
                 $nt->save();
             }
             $f->type_id = $nt->id;
         }
     }
     if ($data[3] != $format->name) {
         $nf = FileFormat::model()->find(array('condition' => 'lower(name) =:name', 'params' => array(':name' => strtolower($data[3]))));
         if ($nf) {
             $f->format_id = $nf->id;
         } else {
             $nf = FileFormat::model()->findByAttributes(array('name' => 'UNKNOWN'));
             if (!$nf) {
                 $nf->name = 'UNKNOWN';
                 $nf->save();
             }
             $f->format_id = $nf->id;
         }
     }
     $f->description = $data[4];
     if (!$f->save()) {
         Yii::log(print_r($f->getErrors(), true), 'debug');
     }
     return;
 }
Exemplo n.º 3
0
 private function getFileType($type)
 {
     $file_type = FileType::model()->find("name=?", array($type));
     if ($file_type == null) {
         $file_type = new FileType();
         $file_type->name = $type;
         $file_type->description = " ";
         $file_type->save(false);
     }
     return $file_type->id;
 }