public function readCsv($filePath) { unset($this->_ratingArr); unset($this->_infoArr); $this->_mappingArr = ImportMappingPeer::getAll(); $rowNum = 0; $fh = fopen($filePath, "r"); $firstRow = true; while (($data = fgetcsv($fh, 0, ",")) !== false) { if ($firstRow) { $firstRow = false; continue; } $this->interpretData($data, $rowNum); $rowNum++; } }
/** * If this collection has already been initialized with * an identical criteria, it returns the collection. * Otherwise if this EnumItem is new, it will return * an empty collection; or if this EnumItem has previously * been saved, it will retrieve related ImportMappingsRelatedByMapping from storage. * * This method is protected by default in order to keep the public * api reasonable. You can provide public methods for those you * actually need in EnumItem. */ public function getImportMappingsRelatedByMappingJoinRatingField($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN) { if ($criteria === null) { $criteria = new Criteria(EnumItemPeer::DATABASE_NAME); } elseif ($criteria instanceof Criteria) { $criteria = clone $criteria; } if ($this->collImportMappingsRelatedByMapping === null) { if ($this->isNew()) { $this->collImportMappingsRelatedByMapping = array(); } else { $criteria->add(ImportMappingPeer::MAPPING, $this->id); $this->collImportMappingsRelatedByMapping = ImportMappingPeer::doSelectJoinRatingField($criteria, $con, $join_behavior); } } else { // the following code is to determine if a new query is // called for. If the criteria is the same as the last // one, just return the collection. $criteria->add(ImportMappingPeer::MAPPING, $this->id); if (!isset($this->lastImportMappingRelatedByMappingCriteria) || !$this->lastImportMappingRelatedByMappingCriteria->equals($criteria)) { $this->collImportMappingsRelatedByMapping = ImportMappingPeer::doSelectJoinRatingField($criteria, $con, $join_behavior); } } $this->lastImportMappingRelatedByMappingCriteria = $criteria; return $this->collImportMappingsRelatedByMapping; }
/** * Retrieve object using using composite pkey values. * @param int $column @param int $import_file_type * @param PropelPDO $con * @return ImportMapping */ public static function retrieveByPK($column, $import_file_type, PropelPDO $con = null) { $key = serialize(array((string) $column, (string) $import_file_type)); if (null !== ($obj = ImportMappingPeer::getInstanceFromPool($key))) { return $obj; } if ($con === null) { $con = Propel::getConnection(ImportMappingPeer::DATABASE_NAME, Propel::CONNECTION_READ); } $criteria = new Criteria(ImportMappingPeer::DATABASE_NAME); $criteria->add(ImportMappingPeer::COLUMN, $column); $criteria->add(ImportMappingPeer::IMPORT_FILE_TYPE, $import_file_type); $v = ImportMappingPeer::doSelect($criteria, $con); return !empty($v) ? $v[0] : null; }
private function getMappingData() { $conn = Propel::getConnection(); $c = new Criteria(); $c->add(ImportMappingPeer::IMPORT_FILE_TYPE, EnumItemPeer::CSV_TYPE); $c->addAscendingOrderByColumn(ImportMappingPeer::COLUMN); return ImportMappingPeer::doselect($c, $conn); }
/** * This is a method for emulating ON DELETE CASCADE for DBs that don't support this * feature (like MySQL or SQLite). * * This method is not very speedy because it must perform a query first to get * the implicated records and then perform the deletes by calling those Peer classes. * * This method should be used within a transaction if possible. * * @param Criteria $criteria * @param PropelPDO $con * @return int The number of affected rows (if supported by underlying database driver). */ protected static function doOnDeleteCascade(Criteria $criteria, PropelPDO $con) { // initialize var to track total num of affected rows $affectedRows = 0; // first find the objects that are implicated by the $criteria $objects = RatingFieldPeer::doSelect($criteria, $con); foreach ($objects as $obj) { // delete related ImportMapping objects $c = new Criteria(ImportMappingPeer::DATABASE_NAME); $c->add(ImportMappingPeer::RATING_FIELD_ID, $obj->getId()); $affectedRows += ImportMappingPeer::doDelete($c, $con); } return $affectedRows; }
/** * Populates the object using an array. * * This is particularly useful when populating an object from one of the * request arrays (e.g. $_POST). This method goes through the column * names, checking to see whether a matching key exists in populated * array. If so the setByName() method is called for that column. * * You can specify the key type of the array by additionally passing one * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME, * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM. * The default key type is the column's phpname (e.g. 'AuthorId') * * @param array $arr An array to populate the object from. * @param string $keyType The type of keys the array uses. * @return void */ public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME) { $keys = ImportMappingPeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setColumn($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setImportFileType($arr[$keys[1]]); } if (array_key_exists($keys[2], $arr)) { $this->setMapping($arr[$keys[2]]); } if (array_key_exists($keys[3], $arr)) { $this->setRatingFieldId($arr[$keys[3]]); } if (array_key_exists($keys[4], $arr)) { $this->setQuestionRating($arr[$keys[4]]); } }
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; }