/** * Selects a collection of CcBlockcontents objects pre-filled with all related objects except CcBlock. * * @param Criteria $criteria * @param PropelPDO $con * @param String $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN * @return array Array of CcBlockcontents objects. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doSelectJoinAllExceptCcBlock(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN) { $criteria = clone $criteria; // Set the correct dbName if it has not been overridden // $criteria->getDbName() will return the same object if not set to another value // so == check is okay and faster if ($criteria->getDbName() == Propel::getDefaultDB()) { $criteria->setDbName(self::DATABASE_NAME); } CcBlockcontentsPeer::addSelectColumns($criteria); $startcol2 = CcBlockcontentsPeer::NUM_COLUMNS - CcBlockcontentsPeer::NUM_LAZY_LOAD_COLUMNS; CcFilesPeer::addSelectColumns($criteria); $startcol3 = $startcol2 + (CcFilesPeer::NUM_COLUMNS - CcFilesPeer::NUM_LAZY_LOAD_COLUMNS); $criteria->addJoin(CcBlockcontentsPeer::FILE_ID, CcFilesPeer::ID, $join_behavior); $stmt = BasePeer::doSelect($criteria, $con); $results = array(); while ($row = $stmt->fetch(PDO::FETCH_NUM)) { $key1 = CcBlockcontentsPeer::getPrimaryKeyHashFromRow($row, 0); if (null !== ($obj1 = CcBlockcontentsPeer::getInstanceFromPool($key1))) { // We no longer rehydrate the object, since this can cause data loss. // See http://www.propelorm.org/ticket/509 // $obj1->hydrate($row, 0, true); // rehydrate } else { $cls = CcBlockcontentsPeer::getOMClass(false); $obj1 = new $cls(); $obj1->hydrate($row); CcBlockcontentsPeer::addInstanceToPool($obj1, $key1); } // if obj1 already loaded // Add objects for joined CcFiles rows $key2 = CcFilesPeer::getPrimaryKeyHashFromRow($row, $startcol2); if ($key2 !== null) { $obj2 = CcFilesPeer::getInstanceFromPool($key2); if (!$obj2) { $cls = CcFilesPeer::getOMClass(false); $obj2 = new $cls(); $obj2->hydrate($row, $startcol2); CcFilesPeer::addInstanceToPool($obj2, $key2); } // if $obj2 already loaded // Add the $obj1 (CcBlockcontents) to the collection in $obj2 (CcFiles) $obj2->addCcBlockcontents($obj1); } // if joined row is not null $results[] = $obj1; } $stmt->closeCursor(); return $results; }
/** * Retrieve multiple objects by pkey. * * @param array $pks List of primary keys * @param PropelPDO $con the connection to use * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function retrieveByPKs($pks, PropelPDO $con = null) { if ($con === null) { $con = Propel::getConnection(CcFilesPeer::DATABASE_NAME, Propel::CONNECTION_READ); } $objs = null; if (empty($pks)) { $objs = array(); } else { $criteria = new Criteria(CcFilesPeer::DATABASE_NAME); $criteria->add(CcFilesPeer::ID, $pks, Criteria::IN); $objs = CcFilesPeer::doSelect($criteria, $con); } return $objs; }
/** * 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 = CcFilesPeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setDbId($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setDbName($arr[$keys[1]]); } if (array_key_exists($keys[2], $arr)) { $this->setDbMime($arr[$keys[2]]); } if (array_key_exists($keys[3], $arr)) { $this->setDbFtype($arr[$keys[3]]); } if (array_key_exists($keys[4], $arr)) { $this->setDbDirectory($arr[$keys[4]]); } if (array_key_exists($keys[5], $arr)) { $this->setDbFilepath($arr[$keys[5]]); } if (array_key_exists($keys[6], $arr)) { $this->setDbState($arr[$keys[6]]); } if (array_key_exists($keys[7], $arr)) { $this->setDbCurrentlyaccessing($arr[$keys[7]]); } if (array_key_exists($keys[8], $arr)) { $this->setDbEditedby($arr[$keys[8]]); } if (array_key_exists($keys[9], $arr)) { $this->setDbMtime($arr[$keys[9]]); } if (array_key_exists($keys[10], $arr)) { $this->setDbUtime($arr[$keys[10]]); } if (array_key_exists($keys[11], $arr)) { $this->setDbLPtime($arr[$keys[11]]); } if (array_key_exists($keys[12], $arr)) { $this->setDbMd5($arr[$keys[12]]); } if (array_key_exists($keys[13], $arr)) { $this->setDbTrackTitle($arr[$keys[13]]); } if (array_key_exists($keys[14], $arr)) { $this->setDbArtistName($arr[$keys[14]]); } if (array_key_exists($keys[15], $arr)) { $this->setDbBitRate($arr[$keys[15]]); } if (array_key_exists($keys[16], $arr)) { $this->setDbSampleRate($arr[$keys[16]]); } if (array_key_exists($keys[17], $arr)) { $this->setDbFormat($arr[$keys[17]]); } if (array_key_exists($keys[18], $arr)) { $this->setDbLength($arr[$keys[18]]); } if (array_key_exists($keys[19], $arr)) { $this->setDbAlbumTitle($arr[$keys[19]]); } if (array_key_exists($keys[20], $arr)) { $this->setDbGenre($arr[$keys[20]]); } if (array_key_exists($keys[21], $arr)) { $this->setDbComments($arr[$keys[21]]); } if (array_key_exists($keys[22], $arr)) { $this->setDbYear($arr[$keys[22]]); } if (array_key_exists($keys[23], $arr)) { $this->setDbTrackNumber($arr[$keys[23]]); } if (array_key_exists($keys[24], $arr)) { $this->setDbChannels($arr[$keys[24]]); } if (array_key_exists($keys[25], $arr)) { $this->setDbUrl($arr[$keys[25]]); } if (array_key_exists($keys[26], $arr)) { $this->setDbBpm($arr[$keys[26]]); } if (array_key_exists($keys[27], $arr)) { $this->setDbRating($arr[$keys[27]]); } if (array_key_exists($keys[28], $arr)) { $this->setDbEncodedBy($arr[$keys[28]]); } if (array_key_exists($keys[29], $arr)) { $this->setDbDiscNumber($arr[$keys[29]]); } if (array_key_exists($keys[30], $arr)) { $this->setDbMood($arr[$keys[30]]); } if (array_key_exists($keys[31], $arr)) { $this->setDbLabel($arr[$keys[31]]); } if (array_key_exists($keys[32], $arr)) { $this->setDbComposer($arr[$keys[32]]); } if (array_key_exists($keys[33], $arr)) { $this->setDbEncoder($arr[$keys[33]]); } if (array_key_exists($keys[34], $arr)) { $this->setDbChecksum($arr[$keys[34]]); } if (array_key_exists($keys[35], $arr)) { $this->setDbLyrics($arr[$keys[35]]); } if (array_key_exists($keys[36], $arr)) { $this->setDbOrchestra($arr[$keys[36]]); } if (array_key_exists($keys[37], $arr)) { $this->setDbConductor($arr[$keys[37]]); } if (array_key_exists($keys[38], $arr)) { $this->setDbLyricist($arr[$keys[38]]); } if (array_key_exists($keys[39], $arr)) { $this->setDbOriginalLyricist($arr[$keys[39]]); } if (array_key_exists($keys[40], $arr)) { $this->setDbRadioStationName($arr[$keys[40]]); } if (array_key_exists($keys[41], $arr)) { $this->setDbInfoUrl($arr[$keys[41]]); } if (array_key_exists($keys[42], $arr)) { $this->setDbArtistUrl($arr[$keys[42]]); } if (array_key_exists($keys[43], $arr)) { $this->setDbAudioSourceUrl($arr[$keys[43]]); } if (array_key_exists($keys[44], $arr)) { $this->setDbRadioStationUrl($arr[$keys[44]]); } if (array_key_exists($keys[45], $arr)) { $this->setDbBuyThisUrl($arr[$keys[45]]); } if (array_key_exists($keys[46], $arr)) { $this->setDbIsrcNumber($arr[$keys[46]]); } if (array_key_exists($keys[47], $arr)) { $this->setDbCatalogNumber($arr[$keys[47]]); } if (array_key_exists($keys[48], $arr)) { $this->setDbOriginalArtist($arr[$keys[48]]); } if (array_key_exists($keys[49], $arr)) { $this->setDbCopyright($arr[$keys[49]]); } if (array_key_exists($keys[50], $arr)) { $this->setDbReportDatetime($arr[$keys[50]]); } if (array_key_exists($keys[51], $arr)) { $this->setDbReportLocation($arr[$keys[51]]); } if (array_key_exists($keys[52], $arr)) { $this->setDbReportOrganization($arr[$keys[52]]); } if (array_key_exists($keys[53], $arr)) { $this->setDbSubject($arr[$keys[53]]); } if (array_key_exists($keys[54], $arr)) { $this->setDbContributor($arr[$keys[54]]); } if (array_key_exists($keys[55], $arr)) { $this->setDbLanguage($arr[$keys[55]]); } if (array_key_exists($keys[56], $arr)) { $this->setDbFileExists($arr[$keys[56]]); } if (array_key_exists($keys[57], $arr)) { $this->setDbSoundcloudId($arr[$keys[57]]); } if (array_key_exists($keys[58], $arr)) { $this->setDbSoundcloudErrorCode($arr[$keys[58]]); } if (array_key_exists($keys[59], $arr)) { $this->setDbSoundcloudErrorMsg($arr[$keys[59]]); } if (array_key_exists($keys[60], $arr)) { $this->setDbSoundcloudLinkToFile($arr[$keys[60]]); } if (array_key_exists($keys[61], $arr)) { $this->setDbSoundCloundUploadTime($arr[$keys[61]]); } if (array_key_exists($keys[62], $arr)) { $this->setDbReplayGain($arr[$keys[62]]); } if (array_key_exists($keys[63], $arr)) { $this->setDbOwnerId($arr[$keys[63]]); } if (array_key_exists($keys[64], $arr)) { $this->setDbCuein($arr[$keys[64]]); } if (array_key_exists($keys[65], $arr)) { $this->setDbCueout($arr[$keys[65]]); } if (array_key_exists($keys[66], $arr)) { $this->setDbSilanCheck($arr[$keys[66]]); } if (array_key_exists($keys[67], $arr)) { $this->setDbHidden($arr[$keys[67]]); } if (array_key_exists($keys[68], $arr)) { $this->setDbIsScheduled($arr[$keys[68]]); } if (array_key_exists($keys[69], $arr)) { $this->setDbIsPlaylist($arr[$keys[69]]); } }
/** * Find object by primary key * Use instance pooling to avoid a database query if the object exists * <code> * $obj = $c->findPk(12, $con); * </code> * @param mixed $key Primary key to use for the query * @param PropelPDO $con an optional connection object * * @return CcFiles|array|mixed the result, formatted by the current formatter */ public function findPk($key, $con = null) { if (null !== ($obj = CcFilesPeer::getInstanceFromPool((string) $key)) && $this->getFormatter()->isObjectFormatter()) { // the object is alredy in the instance pool return $obj; } else { // the object has not been requested yet, or the formatter is not an object formatter $criteria = $this->isKeepQuery() ? clone $this : $this; $stmt = $criteria->filterByPrimaryKey($key)->getSelectStatement($con); return $criteria->getFormatter()->init($criteria)->formatOne($stmt); } }
public function getListofFilesMeetCriteria() { $storedCrit = $this->getCriteria(); $qry = CcFilesQuery::create(); $qry->useFkOwnerQuery("subj", "left join"); if (isset($storedCrit["crit"])) { foreach ($storedCrit["crit"] as $crit) { $i = 0; foreach ($crit as $criteria) { //$spCriteriaPhpName = self::$criteria2PeerMap[$criteria['criteria']]; $spCriteria = $criteria['criteria']; $spCriteriaModifier = $criteria['modifier']; $column = CcFilesPeer::getTableMap()->getColumnByPhpName(self::$criteria2PeerMap[$spCriteria]); // if the column is timestamp, convert it into UTC if ($column->getType() == PropelColumnTypes::TIMESTAMP) { $spCriteriaValue = Application_Common_DateHelper::ConvertToUtcDateTimeString($criteria['value']); /* Check if only a date was supplied and trim * the time after it is converted to UTC time */ if (strlen($criteria['value']) <= 10) { //extract date only from timestamp in db $spCriteria = 'date(' . $spCriteria . ')'; $spCriteriaValue = substr($spCriteriaValue, 0, 10); } if (isset($criteria['extra'])) { $spCriteriaExtra = Application_Common_DateHelper::ConvertToUtcDateTimeString($criteria['extra']); if (strlen($criteria['extra']) <= 10) { $spCriteriaExtra = substr($spCriteriaExtra, 0, 10); } } } elseif ($spCriteria == "bit_rate" || $spCriteria == 'sample_rate') { // multiply 1000 because we store only number value // e.g 192kps is stored as 192000 $spCriteriaValue = $criteria['value'] * 1000; if (isset($criteria['extra'])) { $spCriteriaExtra = $criteria['extra'] * 1000; } /* * If user is searching for an exact match of length we need to * search as if it starts with the specified length because the * user only sees the rounded version (i.e. 4:02.7 is 4:02.761625 * in the database) */ } elseif ($spCriteria == 'length' && $spCriteriaModifier == "is") { $spCriteriaModifier = "starts with"; $spCriteria = $spCriteria . '::text'; $spCriteriaValue = $criteria['value']; } else { /* Propel does not escape special characters properly when using LIKE/ILIKE * We have to add extra slashes in these cases */ $tempModifier = trim(self::$modifier2CriteriaMap[$spCriteriaModifier]); if ($tempModifier == 'ILIKE') { $spCriteriaValue = addslashes($criteria['value']); // addslashes() does not esapce '%' so we have to do it manually $spCriteriaValue = str_replace('%', '\\%', $spCriteriaValue); } else { $spCriteriaValue = $criteria['value']; } $spCriteriaExtra = $criteria['extra']; } if ($spCriteriaModifier == "starts with") { $spCriteriaValue = "{$spCriteriaValue}%"; } elseif ($spCriteriaModifier == "ends with") { $spCriteriaValue = "%{$spCriteriaValue}"; } elseif ($spCriteriaModifier == "contains" || $spCriteriaModifier == "does not contain") { $spCriteriaValue = "%{$spCriteriaValue}%"; } elseif ($spCriteriaModifier == "is in the range") { $spCriteriaValue = "{$spCriteria} >= '{$spCriteriaValue}' AND {$spCriteria} <= '{$spCriteriaExtra}'"; } $spCriteriaModifier = self::$modifier2CriteriaMap[$spCriteriaModifier]; try { if ($spCriteria == "owner_id") { $spCriteria = "subj.login"; } if ($i > 0) { $qry->addOr($spCriteria, $spCriteriaValue, $spCriteriaModifier); } else { $qry->add($spCriteria, $spCriteriaValue, $spCriteriaModifier); } if ($spCriteriaModifier == Criteria::NOT_ILIKE || $spCriteriaModifier == Criteria::NOT_EQUAL) { $qry->addOr($spCriteria, null, Criteria::ISNULL); } } catch (Exception $e) { Logging::info($e); } $i++; } } // check if file exists $qry->add("file_exists", "true", Criteria::EQUAL); $qry->addAscendingOrderByColumn('random()'); } // construct limit restriction $limits = array(); if (isset($storedCrit['limit'])) { if ($storedCrit['limit']['modifier'] == "items") { $limits['time'] = 1440 * 60; $limits['items'] = $storedCrit['limit']['value']; } else { $limits['time'] = $storedCrit['limit']['modifier'] == "hours" ? intval(floatval($storedCrit['limit']['value']) * 60 * 60) : intval($storedCrit['limit']['value'] * 60); $limits['items'] = null; } } try { $out = $qry->setFormatter(ModelCriteria::FORMAT_ON_DEMAND)->find(); return array("files" => $out, "limit" => $limits, "count" => $out->count()); } catch (Exception $e) { Logging::info($e); } }
public function isValid($params) { $isValid = true; $data = $this->preValidation($params); $criteria2PeerMap = array(0 => "Select criteria", "album_title" => "DbAlbumTitle", "artist_name" => "DbArtistName", "bit_rate" => "DbBitRate", "bpm" => "DbBpm", "composer" => "DbComposer", "conductor" => "DbConductor", "copyright" => "DbCopyright", "cuein" => "DbCuein", "cueout" => "DbCueout", "encoded_by" => "DbEncodedBy", "utime" => "DbUtime", "mtime" => "DbMtime", "lptime" => "DbLPtime", "genre" => "DbGenre", "info_url" => "DbInfoUrl", "isrc_number" => "DbIsrcNumber", "label" => "DbLabel", "language" => "DbLanguage", "length" => "DbLength", "mime" => "DbMime", "mood" => "DbMood", "owner_id" => "DbOwnerId", "replay_gain" => "DbReplayGain", "sample_rate" => "DbSampleRate", "track_title" => "DbTrackTitle", "track_number" => "DbTrackNumber", "year" => "DbYear"); // things we need to check // 1. limit value shouldn't be empty and has upperbound of 24 hrs // 2. sp_criteria or sp_criteria_modifier shouldn't be 0 // 3. validate formate according to DB column type $multiplier = 1; $result = 0; // validation start if ($data['etc']['sp_limit_options'] == 'hours') { $multiplier = 60; } if ($data['etc']['sp_limit_options'] == 'hours' || $data['etc']['sp_limit_options'] == 'mins') { $element = $this->getElement("sp_limit_value"); if ($data['etc']['sp_limit_value'] == "" || floatval($data['etc']['sp_limit_value']) <= 0) { $element->addError(_("Limit cannot be empty or smaller than 0")); $isValid = false; } else { $mins = floatval($data['etc']['sp_limit_value']) * $multiplier; if ($mins > 1440) { $element->addError(_("Limit cannot be more than 24 hrs")); $isValid = false; } } } else { $element = $this->getElement("sp_limit_value"); if ($data['etc']['sp_limit_value'] == "" || floatval($data['etc']['sp_limit_value']) <= 0) { $element->addError(_("Limit cannot be empty or smaller than 0")); $isValid = false; } elseif (!ctype_digit($data['etc']['sp_limit_value'])) { $element->addError(_("The value should be an integer")); $isValid = false; } elseif (intval($data['etc']['sp_limit_value']) > 500) { $element->addError(_("500 is the max item limit value you can set")); $isValid = false; } } if (isset($data['criteria'])) { foreach ($data['criteria'] as $rowKey => $row) { foreach ($row as $key => $d) { $element = $this->getElement("sp_criteria_field_" . $rowKey . "_" . $key); // check for not selected select box if ($d['sp_criteria_field'] == "0" || $d['sp_criteria_modifier'] == "0") { $element->addError(_("You must select Criteria and Modifier")); $isValid = false; } else { $column = CcFilesPeer::getTableMap()->getColumnByPhpName($criteria2PeerMap[$d['sp_criteria_field']]); // validation on type of column if (in_array($d['sp_criteria_field'], array('length', 'cuein', 'cueout'))) { if (!preg_match("/^(\\d{2}):(\\d{2}):(\\d{2})/", $d['sp_criteria_value'])) { $element->addError(_("'Length' should be in '00:00:00' format")); $isValid = false; } } elseif ($column->getType() == PropelColumnTypes::TIMESTAMP) { if (!preg_match("/(\\d{4})-(\\d{2})-(\\d{2})/", $d['sp_criteria_value'])) { $element->addError(_("The value should be in timestamp format (e.g. 0000-00-00 or 0000-00-00 00:00:00)")); $isValid = false; } else { $result = Application_Common_DateHelper::checkDateTimeRangeForSQL($d['sp_criteria_value']); if (!$result["success"]) { // check for if it is in valid range( 1753-01-01 ~ 12/31/9999 ) $element->addError($result["errMsg"]); $isValid = false; } } if (isset($d['sp_criteria_extra'])) { if (!preg_match("/(\\d{4})-(\\d{2})-(\\d{2})/", $d['sp_criteria_extra'])) { $element->addError(_("The value should be in timestamp format (e.g. 0000-00-00 or 0000-00-00 00:00:00)")); $isValid = false; } else { $result = Application_Common_DateHelper::checkDateTimeRangeForSQL($d['sp_criteria_extra']); if (!$result["success"]) { // check for if it is in valid range( 1753-01-01 ~ 12/31/9999 ) $element->addError($result["errMsg"]); $isValid = false; } } } } elseif ($column->getType() == PropelColumnTypes::INTEGER && $d['sp_criteria_field'] != 'owner_id') { if (!is_numeric($d['sp_criteria_value'])) { $element->addError(_("The value has to be numeric")); $isValid = false; } // length check if ($d['sp_criteria_value'] >= pow(2, 31)) { $element->addError(_("The value should be less then 2147483648")); $isValid = false; } } elseif ($column->getType() == PropelColumnTypes::VARCHAR) { if (strlen($d['sp_criteria_value']) > $column->getSize()) { $element->addError(sprintf(_("The value should be less than %s characters"), $column->getSize())); $isValid = false; } } } if ($d['sp_criteria_value'] == "") { $element->addError(_("Value cannot be empty")); $isValid = false; } } //end foreach } //for loop } //if return $isValid; }
/** * Method to invalidate the instance pool of all tables related to cc_music_dirs * by a foreign key with ON DELETE CASCADE */ public static function clearRelatedInstancePool() { // Invalidate objects in CcFilesPeer instance pool, // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule. CcFilesPeer::clearInstancePool(); }