/**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database.  In some cases -- especially when you override doSelect*()
  * methods in your stub classes -- you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by doSelect*()
  * and retrieveByPK*() calls.
  *
  * @param      ImportMapping $value A ImportMapping object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool(ImportMapping $obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = serialize(array((string) $obj->getColumn(), (string) $obj->getImportFileType()));
         }
         // if key === null
         self::$instances[$key] = $obj;
     }
 }
Beispiel #2
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;
 }