/** * 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 = DistancePeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setTrackAId($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setTrackBId($arr[$keys[1]]); } if (array_key_exists($keys[2], $arr)) { $this->setFeaturevectortypeId($arr[$keys[2]]); } if (array_key_exists($keys[3], $arr)) { $this->setDistancetypeId($arr[$keys[3]]); } if (array_key_exists($keys[4], $arr)) { $this->setValue($arr[$keys[4]]); } if (array_key_exists($keys[5], $arr)) { $this->setInserted($arr[$keys[5]]); } if (array_key_exists($keys[6], $arr)) { $this->setUpdated($arr[$keys[6]]); } }
/** This is executed when searched for related tracks and metadata */ public function executeRelatedtrack(sfWebRequest $request) { $this->getContext()->getConfiguration()->loadHelpers('Url'); $empty_metadatafilteredquery = false; $distances = NULL; $files = NULL; // get request parameters $metadataquery = $request->getParameter('metadataquery'); $tracknr = $request->getParameter('tracknr'); $limit = $request->getParameter('limit', $this->getContext()->getConfiguration()->getSmintMaxQueryResults()); $offset = $request->getParameter('offset', 0); $id_prefix = $request->getParameter('id_prefix', '') . smintTools::generateHtmlId($tracknr) . "_"; $omit_empty_metadataquery = $request->getParameter('omit_empty_metadataquery', false); $distancetypeid = sfConfig::get('app_defaults_distancetypeid', 0); $featurevectortypeid = sfConfig::get('app_defaults_featurevectortypeid', 0); mysfLog::logRequest($this, $request); //get file via external key $file = FilePeer::getFileByExternalKey($tracknr); //only if the file was found in the smafestore db if ($file) { // run query $fileTrackId = $file->getTrackid(); $relatedCriteria = $this->buildRelatedQuery($fileTrackId, $featurevectortypeid, $distancetypeid, $limit, $offset, $metadataquery); $related = FilePeer::doSelect($relatedCriteria); // if omit empty metadataquery is true if ($omit_empty_metadataquery) { if (count($related) > 0) { // if the query returned results $distances = DistancePeer::doSelect($relatedCriteria); } else { // if the query returned no results -> retry without metadata $empty_metadatafilteredquery = true; $relatedCriteria = $this->buildRelatedQuery($fileTrackId, $featurevectortypeid, $distancetypeid, $limit, $offset); $related = FilePeer::doSelect($relatedCriteria); $distances = DistancePeer::doSelect($relatedCriteria); } } else { $distances = DistancePeer::doSelect($relatedCriteria); } } $files = FiledescPeer::doSelect($relatedCriteria); // add duration // $fileDownloadURL = url_for("getAudioFile/download") . "?tracknr=" . rawurlencode($tracknr); $queryFileMetadata = FiledescPeer::retrieveByPk($tracknr); $fileInfoName = $queryFileMetadata->getTitle() . " - " . $queryFileMetadata->getPerformers(); $uploadedFilePHPUrl_incomplete = url_for("getAudioFile/download", true) . "?tracknr=" . rawurlencode($tracknr); $uploadedFileURL = smintUploadFileHelper::getDirectFileUrl($file->getUri()); return $this->renderPartial('search/result', array('render' => 'related', 'uploadedFilePHPUrl_incomplete' => $uploadedFilePHPUrl_incomplete, 'uploadedFileURL' => $uploadedFileURL, 'seedLabel' => $fileInfoName, 'id_prefix' => $id_prefix, 'tracknr' => $tracknr, 'files' => $files, 'distances' => $distances, 'limit' => $limit, 'offset' => $offset, 'metadataquery' => $metadataquery, 'empty_metadatafilteredquery' => $empty_metadatafilteredquery, 'aSegmSearch' => $aSegmSearch)); }
public function saveDistanceList($con = null) { if (!$this->isValid()) { throw $this->getErrorSchema(); } if (!isset($this->widgetSchema['distance_list'])) { // somebody has unset this widget return; } if (null === $con) { $con = $this->getConnection(); } $c = new Criteria(); $c->add(DistancePeer::DISTANCETYPE_ID, $this->object->getPrimaryKey()); DistancePeer::doDelete($c, $con); $values = $this->getValue('distance_list'); if (is_array($values)) { foreach ($values as $value) { $obj = new Distance(); $obj->setDistancetypeId($this->object->getPrimaryKey()); $obj->setTrackAId($value); $obj->save(); } } }
/** * If this collection has already been initialized with * an identical criteria, it returns the collection. * Otherwise if this Distancetype is new, it will return * an empty collection; or if this Distancetype has previously * been saved, it will retrieve related Distances 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 Distancetype. */ public function getDistancesJoinFeaturevectorRelatedByTrackBId($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN) { if ($criteria === null) { $criteria = new Criteria(DistancetypePeer::DATABASE_NAME); } elseif ($criteria instanceof Criteria) { $criteria = clone $criteria; } if ($this->collDistances === null) { if ($this->isNew()) { $this->collDistances = array(); } else { $criteria->add(DistancePeer::DISTANCETYPE_ID, $this->id); $this->collDistances = DistancePeer::doSelectJoinFeaturevectorRelatedByTrackBId($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(DistancePeer::DISTANCETYPE_ID, $this->id); if (!isset($this->lastDistanceCriteria) || !$this->lastDistanceCriteria->equals($criteria)) { $this->collDistances = DistancePeer::doSelectJoinFeaturevectorRelatedByTrackBId($criteria, $con, $join_behavior); } } $this->lastDistanceCriteria = $criteria; return $this->collDistances; }
/** * Retrieve object using using composite pkey values. * @param int $track_a_id * @param int $track_b_id * @param int $featurevectortype_id * @param int $distancetype_id * @param PropelPDO $con * @return Distance */ public static function retrieveByPK($track_a_id, $track_b_id, $featurevectortype_id, $distancetype_id, PropelPDO $con = null) { $key = serialize(array((string) $track_a_id, (string) $track_b_id, (string) $featurevectortype_id, (string) $distancetype_id)); if (null !== ($obj = DistancePeer::getInstanceFromPool($key))) { return $obj; } if ($con === null) { $con = Propel::getConnection(DistancePeer::DATABASE_NAME, Propel::CONNECTION_READ); } $criteria = new Criteria(DistancePeer::DATABASE_NAME); $criteria->add(DistancePeer::TRACK_A_ID, $track_a_id); $criteria->add(DistancePeer::TRACK_B_ID, $track_b_id); $criteria->add(DistancePeer::FEATUREVECTORTYPE_ID, $featurevectortype_id); $criteria->add(DistancePeer::DISTANCETYPE_ID, $distancetype_id); $v = DistancePeer::doSelect($criteria, $con); return !empty($v) ? $v[0] : null; }