示例#1
0
 public function executeAjaxSaveMappings(sfWebRequest $request)
 {
     if (!$request->isXmlHttpRequest()) {
         $this->forward404();
     }
     if (!$request->hasParameter("mapping_save_descr")) {
         throw new Exception("ajax_query does not exist");
     }
     if (!$request->hasParameter("mapping_save_col")) {
         throw new Exception("ajax_query does not exist");
     }
     if (!$request->hasParameter("mapping_save_type_descr")) {
         throw new Exception("ajax_query does not exist");
     }
     if (!$request->hasParameter("mapping_save_scale")) {
         throw new Exception("ajax_query does not exist");
     }
     $critDescr = trim($request->getParameter("mapping_save_descr"));
     $col = trim($request->getParameter("mapping_save_col"));
     $typeDescr = trim($request->getParameter("mapping_save_type_descr"));
     $rating = trim($request->getParameter("mapping_save_scale"));
     // find the corresponding mapping type object
     $c = new Criteria();
     $crit1 = $c->getNewCriterion(EnumItemPeer::PARENT_ID, EnumItemPeer::MAPPING_ITEMS_NODE_ID);
     $crit2 = $c->getNewCriterion(EnumItemPeer::DESCR, $typeDescr);
     $c->addAnd($crit1);
     $c->addAnd($crit2);
     $enum = EnumItemPeer::doSelectOne($c);
     if (!isset($enum)) {
         echo "Failed";
         return sfView::NONE;
     }
     // find the rating field object
     if ($critDescr != "") {
         $c = new Criteria();
         $crit = $c->getNewCriterion(RatingFieldPeer::DESCR, $critDescr);
         $c->addAnd($crit);
         $criterion = RatingFieldPeer::doSelectOne($c);
         if (!isset($criterion)) {
             echo "Failed";
             return sfView::NONE;
         }
     } elseif ($enum->getId() == EnumItemPeer::MAPPING_NUMBER_ENROLLED) {
         $criterion = RatingFieldPeer::retrieveByPK(RatingFieldPeer::NUMBER_ENROLLED);
     } elseif ($enum->getId() == EnumItemPeer::MAPPING_NUMBER_RESPONSE) {
         $criterion = RatingFieldPeer::retrieveByPK(RatingFieldPeer::NUMBER_RESPONDED);
     }
     // deal with rating
     if ($rating == "") {
         $rating = 0;
     } elseif ($rating == "Yes") {
         $rating = 1;
     } elseif ($rating == "No") {
         $rating = 0;
     }
     // save
     $mappingObj = ImportMappingPeer::retrieveByPK($col, EnumItemPeer::CSV_TYPE);
     if (!isset($mappingObj)) {
         $mappingObj = new ImportMapping();
         $mappingObj->setColumn($col);
         $mappingObj->setImportFileType(EnumItemPeer::CSV_TYPE);
     }
     $mappingObj->setMapping($enum->getid());
     if (isset($criterion)) {
         $mappingObj->setRatingFieldId($criterion->getId());
     } else {
         $mappingObj->setRatingFieldId(1);
     }
     $mappingObj->setQuestionRating($rating);
     $mappingObj->save();
     echo "<script type='text/javascript'>saveMappings(", $col + 1, ");</script>";
     return sfView::NONE;
 }