public function delete(PropelPDO $con = null) { if ($con === null) { $con = Propel::getConnection(sfGuardGroupPeer::DATABASE_NAME, Propel::CONNECTION_WRITE); } if ($this->isDefaultGroup()) { throw new sfException('Cannot remove default group (ID ' . $this->id . ')!'); return false; } /* * get default group * */ $default_group = sfGuardGroupPeer::getDefaultGroup(); //get default group /* * check if servers has this group * If servers found remove reference to group to be deleted */ $con->beginTransaction(); try { //select from... $c1 = new Criteria(); $c1->add(EtvaServerPeer::SF_GUARD_GROUP_ID, $this->getId()); //update set $c2 = new Criteria(); $c2->add(EtvaServerPeer::SF_GUARD_GROUP_ID, $default_group->getId()); BasePeer::doUpdate($c1, $c2, $con); parent::delete($con); $con->commit(); } catch (PropelException $e) { $con->rollBack(); throw $e; } }
public static function doUpdateAllModerations($selectCriteria, $values, $con = null) { if ($con === null) { $con = Propel::getConnection(self::DATABASE_NAME); } return BasePeer::doUpdate($selectCriteria, $values, $con); }
protected function assertCriteriaTranslation($criteria, $expectedSql, $expectedParams, $message = '') { $params = array(); $result = BasePeer::createSelectSql($criteria, $params); $this->assertEquals($expectedSql, $result, $message); $this->assertEquals($expectedParams, $params, $message); }
protected function execute($arguments = array(), $options = array()) { $context = sfContext::createInstance(sfProjectConfiguration::getApplicationConfiguration('app', 'dev', true)); parent::execute($arguments, $options); // initialize the database connection $databaseManager = new sfDatabaseManager($this->configuration); $con = $databaseManager->getDatabase($options['connection'])->getConnection(); // add your code here $this->log('[INFO] Checking VirtAgents state...' . "\n"); $offset = sfConfig::get('app_node_keepalive_update') + sfConfig::get('app_node_keepalive_update_offset'); $total_nodes = EtvaNodePeer::doCount(new Criteria()); if ($total_nodes > 0) { $con->beginTransaction(); $affected = 0; try { $offset_date = date("c", time() - $offset); /* * get nodes that have last_keepalive field outdated */ $c1 = new Criteria(); $c1->add(EtvaNodePeer::LAST_KEEPALIVE, $offset_date, Criteria::LESS_THAN); $c1->add(EtvaNodePeer::STATE, EtvaNode::NODE_ACTIVE); // only active //update statement $c2 = new Criteria(); $c2->add(EtvaNodePeer::STATE, EtvaNode::NODE_INACTIVE); $affected += BasePeer::doUpdate($c1, $c2, $con); // update maintenance and running to maintenance $c1 = new Criteria(); $c1->add(EtvaNodePeer::LAST_KEEPALIVE, $offset_date, Criteria::LESS_THAN); $c1->add(EtvaNodePeer::STATE, EtvaNode::NODE_MAINTENANCE_UP); //update statement $c2 = new Criteria(); $c2->add(EtvaNodePeer::STATE, EtvaNode::NODE_MAINTENANCE); $affected += BasePeer::doUpdate($c1, $c2, $con); // update fail and running to fail $c1 = new Criteria(); $c1->add(EtvaNodePeer::LAST_KEEPALIVE, $offset_date, Criteria::LESS_THAN); $c1->add(EtvaNodePeer::STATE, EtvaNode::NODE_FAIL_UP); // only active //update statement $c2 = new Criteria(); $c2->add(EtvaNodePeer::STATE, EtvaNode::NODE_FAIL); $affected += BasePeer::doUpdate($c1, $c2, $con); $con->commit(); $message = sprintf('%d Node(s) NOT received update in time offset of %d seconds', $affected, $offset); if ($affected > 0) { $context->getEventDispatcher()->notify(new sfEvent(sfConfig::get('config_acronym'), 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::ERR))); } $this->log('[INFO]' . $message); } catch (PropelException $e) { $con->rollBack(); throw $e; } } $logger = new sfFileLogger($context->getEventDispatcher(), array('file' => sfConfig::get("sf_log_dir") . '/cron_status.log')); // log the message! $logger->log("[INFO] The check virtAgents task ran!", 6); }
public function getNotas($ciclolectivo_id) { $notaAlumno = array(); $notaActividad = array(); // notas del alumno $criteria = new Criteria(); $criteria->add(BoletinActividadesPeer::FK_ALUMNO_ID, $this->getId()); $criteria->add(PeriodoPeer::CALCULAR, false); $criteria->add(PeriodoPeer::FK_CICLOLECTIVO_ID, $ciclolectivo_id); $criteria->addJoin(BoletinActividadesPeer::FK_ESCALANOTA_ID, EscalanotaPeer::ID); $criteria->addJoin(BoletinActividadesPeer::FK_PERIODO_ID, PeriodoPeer::ID); $criteria->addAsColumn("boletinActividades_periodo_id", BoletinActividadesPeer::FK_PERIODO_ID); $criteria->addAsColumn("boletinActividades_actividad_id", BoletinActividadesPeer::FK_ACTIVIDAD_ID); $criteria->addAsColumn("escalanota_nombre", EscalanotaPeer::NOMBRE); $aBoletinActividades = BasePeer::doSelect($criteria); foreach ($aBoletinActividades as $boletinActividades) { $notaAlumno[$boletinActividades[0]][$boletinActividades[1]] = $boletinActividades[2]; $notaActividad[$boletinActividades[1]][$boletinActividades[0]] = $boletinActividades[2]; } $c = new Criteria(); $c->add(PeriodoPeer::FK_CICLOLECTIVO_ID, $ciclolectivo_id); $c->add(PeriodoPeer::CALCULAR, true); $periodos = PeriodoPeer::doSelect($c); foreach ($notaActividad as $act_indice => &$act) { foreach ($periodos as $periodo) { //validar que esten ok if (trim($periodo->getFormula()) != '') { list($class_formula, $parametros) = explode('|', $periodo->getFormula()); $parametros = explode(',', $parametros); //if (array_intersect($parametros,array_keys($act)) == $parametros) { sfContext::getInstance()->getLogger()->debug("estan todo slo ids"); $class_formula = "formula_{$class_formula}"; require_once sfConfig::get('sf_lib_dir') . DIRECTORY_SEPARATOR . 'formulas' . DIRECTORY_SEPARATOR . $class_formula . ".class.php"; $formula = new $class_formula(); $notas_parametros = array(); foreach ($parametros as $parametro) { if (isset($act[$parametro])) { array_push($notas_parametros, sprintf("%01.2f", str_replace(",", ".", $act[$parametro]))); } else { array_push($notas_parametros, ''); } } $nota = $formula->calcular($notas_parametros); $notaAlumno[$periodo->getId()][$act_indice] = $nota; $act[$periodo->getId()] = $nota; //} //else { // sfContext::getInstance()->getLogger()->debug('faltan parametros para la formula'); //} } else { sfContext::getInstance()->getLogger()->debug('el periodo es calculable pero no tiene una formula cargada'); } } } return $notaAlumno; }
public function testDoInsert() { try { $c = new Criteria(); $c->setPrimaryTableName(BookPeer::TABLE_NAME); $c->add(BookPeer::AUTHOR_ID, 'lkhlkhj'); BasePeer::doInsert($c, Propel::getConnection()); } catch (PropelException $e) { $this->assertContains('[INSERT INTO `book` (`AUTHOR_ID`) VALUES (:p1)]', $e->getMessage(), 'SQL query is written in the exception message'); } }
public function testApplyLimitDuplicateColumnName() { Propel::setDb('oracle', new DBOracle()); $c = new Criteria(); $c->setDbName('oracle'); BookPeer::addSelectColumns($c); AuthorPeer::addSelectColumns($c); $c->setLimit(1); $params = array(); $sql = BasePeer::createSelectSql($c, $params); $this->assertEquals('SELECT B.* FROM (SELECT A.*, rownum AS PROPEL_ROWNUM FROM (SELECT book.ID AS book_ID, book.TITLE AS book_TITLE, book.ISBN AS book_ISBN, book.PRICE AS book_PRICE, book.PUBLISHER_ID AS book_PUBLISHER_ID, book.AUTHOR_ID AS book_AUTHOR_ID, author.ID AS author_ID, author.FIRST_NAME AS author_FIRST_NAME, author.LAST_NAME AS author_LAST_NAME, author.EMAIL AS author_EMAIL, author.AGE AS author_AGESELECT book.ID, book.TITLE, book.ISBN, book.PRICE, book.PUBLISHER_ID, book.AUTHOR_ID, author.ID, author.FIRST_NAME, author.LAST_NAME, author.EMAIL, author.AGE FROM book, author) A ) B WHERE B.PROPEL_ROWNUM <= 1', $sql, 'applyLimit() creates a subselect with aliased column names when a duplicate column name is found'); }
public function checkForRepeatedNames($validator, $value) { $criteria = new Criteria(); $criteria->add(QubitTerm::ID, $this->resource->id, Criteria::NOT_EQUAL); $criteria->add(QubitTerm::TAXONOMY_ID, $this->resource->taxonomyId); $criteria->addJoin(QubitTerm::ID, QubitTermI18n::ID); $criteria->add(QubitTermI18n::CULTURE, $this->context->user->getCulture()); $criteria->add(QubitTermI18n::NAME, $value); if (0 < intval(BasePeer::doCount($criteria)->fetchColumn(0))) { throw new sfValidatorError($validator, $this->context->i18n->__('Name - A term with this name already exists.')); } }
public function execute($request) { if (!isset($request->limit)) { $request->limit = sfConfig::get('app_hits_per_page'); } $this->resource = $this->getRoute()->resource; $criteria = new Criteria(); $criteria->add(QubitRelation::SUBJECT_ID, $this->resource->id); $criteria->add(QubitRelation::TYPE_ID, QubitTerm::HAS_PHYSICAL_OBJECT_ID); $criteria->addJoin(QubitRelation::OBJECT_ID, QubitInformationObject::ID); $this->informationObjects = QubitInformationObject::get($criteria); $c2 = clone $criteria; $this->foundcount = BasePeer::doCount($c2)->fetchColumn(0); }
/** * @param int $entryId */ protected function entryDeleted($entryId) { $c = new Criteria(); $c->add(CuePointPeer::ENTRY_ID, $entryId); CuePointPeer::setUseCriteriaFilter(false); $cuePoints = CuePointPeer::doSelect($c); $update = new Criteria(); $update->add(CuePointPeer::STATUS, CuePointStatus::DELETED); $con = Propel::getConnection(myDbHelper::DB_HELPER_CONN_MASTER); BasePeer::doUpdate($c, $update, $con); foreach ($cuePoints as $cuePoint) { kEventsManager::raiseEvent(new kObjectDeletedEvent($cuePoint)); } }
public function testApplyLimitDuplicateColumnNameWithColumn() { Propel::setDb('oracle', new DBOracle()); $c = new Criteria(); $c->setDbName('oracle'); BookPeer::addSelectColumns($c); AuthorPeer::addSelectColumns($c); $c->addAsColumn('BOOK_PRICE', BookPeer::PRICE); $c->setLimit(1); $params = array(); $asColumns = $c->getAsColumns(); $sql = BasePeer::createSelectSql($c, $params); $this->assertEquals('SELECT B.* FROM (SELECT A.*, rownum AS PROPEL_ROWNUM FROM (SELECT book.id AS ORA_COL_ALIAS_0, book.title AS ORA_COL_ALIAS_1, book.isbn AS ORA_COL_ALIAS_2, book.price AS ORA_COL_ALIAS_3, book.publisher_id AS ORA_COL_ALIAS_4, book.author_id AS ORA_COL_ALIAS_5, author.id AS ORA_COL_ALIAS_6, author.first_name AS ORA_COL_ALIAS_7, author.last_name AS ORA_COL_ALIAS_8, author.email AS ORA_COL_ALIAS_9, author.age AS ORA_COL_ALIAS_10, book.price AS BOOK_PRICE FROM book, author) A ) B WHERE B.PROPEL_ROWNUM <= 1', $sql, 'applyLimit() creates a subselect with aliased column names when a duplicate column name is found'); $this->assertEquals($asColumns, $c->getAsColumns(), 'createSelectSql supplementary add alias column'); }
public function testApplyLimitDuplicateColumnNameWithColumn() { Propel::setDb('oracle', new DBOracle()); $c = new Criteria(); $c->setDbName('oracle'); BookPeer::addSelectColumns($c); AuthorPeer::addSelectColumns($c); $c->addAsColumn('BOOK_PRICE', BookPeer::PRICE); $c->setLimit(1); $params = array(); $asColumns = $c->getAsColumns(); $sql = BasePeer::createSelectSql($c, $params); $this->assertEquals('SELECT B.* FROM (SELECT A.*, rownum AS PROPEL_ROWNUM FROM (SELECT book.ID AS ORA_COL_ALIAS_0, book.TITLE AS ORA_COL_ALIAS_1, book.ISBN AS ORA_COL_ALIAS_2, book.PRICE AS ORA_COL_ALIAS_3, book.PUBLISHER_ID AS ORA_COL_ALIAS_4, book.AUTHOR_ID AS ORA_COL_ALIAS_5, author.ID AS ORA_COL_ALIAS_6, author.FIRST_NAME AS ORA_COL_ALIAS_7, author.LAST_NAME AS ORA_COL_ALIAS_8, author.EMAIL AS ORA_COL_ALIAS_9, author.AGE AS ORA_COL_ALIAS_10, book.PRICE AS BOOK_PRICE FROM book, author) A ) B WHERE B.PROPEL_ROWNUM <= 1', $sql, 'applyLimit() creates a subselect with aliased column names when a duplicate column name is found'); $this->assertEquals($asColumns, $c->getAsColumns(), 'createSelectSql supplementary add alias column'); }
/** * @param int $entryId */ protected function entryDeleted($entryId) { $c = new Criteria(); $c->add(AnnotationPeer::ENTRY_ID, $entryId); $c->add(AnnotationPeer::STATUS, AnnotationStatus::ANNOTATION_STATUS_DELETED, Criteria::NOT_EQUAL); AnnotationPeer::setUseCriteriaFilter(false); $annotations = AnnotationPeer::doSelect($c); foreach ($annotations as $annotation) { kEventsManager::raiseEvent(new kObjectDeletedEvent($annotation)); } $update = new Criteria(); $update->add(AnnotationPeer::STATUS, AnnotationStatus::ANNOTATION_STATUS_DELETED); $con = Propel::getConnection(AnnotationPeer::DATABASE_NAME, Propel::CONNECTION_READ); BasePeer::doUpdate($c, $update, $con); }
public static function getCriteriaCacheKey(Criteria $c) { $cloned_c = clone $c; $arr = array(); $str = BasePeer::createSelectSql($c, $arr); $param_map = array(); $keys = $c->keys(); foreach ($keys as $k) { $val = $c->getCriterion($k); if ($val) { $param_map[$k] = $val->hashCode(); } } $str .= print_r($param_map, true); $cache_key = md5($str); return $cache_key; }
/** * @param int $objectType * @param string $objectId */ protected function deleteMetadataObjects($objectType, $objectId) { $c = new Criteria(); $c->add(MetadataPeer::OBJECT_TYPE, $objectType); $c->add(MetadataPeer::OBJECT_ID, $objectId); $c->add(MetadataPeer::STATUS, Metadata::STATUS_DELETED, Criteria::NOT_EQUAL); $peer = null; MetadataPeer::setUseCriteriaFilter(false); $metadatas = MetadataPeer::doSelect($c); foreach ($metadatas as $metadata) { kEventsManager::raiseEvent(new kObjectDeletedEvent($metadata)); } $update = new Criteria(); $update->add(MetadataPeer::STATUS, Metadata::STATUS_DELETED); $con = Propel::getConnection(MetadataPeer::DATABASE_NAME, Propel::CONNECTION_READ); BasePeer::doUpdate($c, $update, $con); }
public static function setJobStateIds($jobs, $stateId) { $c1 = new Criteria(); $c2 = new Criteria(); $c1->add(JobPeer::ID, $jobs, Criteria::IN); $c2->add(JobPeer::STATUS_ID, $stateId); BasePeer::doUpdate($c1, $c2, Propel::getConnection()); $state = StatusPeer::retrieveByPK($stateId); foreach ($jobs as $id) { $logEntry = new Log(); $logEntry->setWhen(time()); $logEntry->setPropelClass("Job"); $logEntry->setSfGuardUserProfileId(sfContext::getInstance()->getUser()->getUserId()); $logEntry->setMessage("Changed job state to " . $state->getState()); $logEntry->setLogMessageTypeId(sfConfig::get("app_log_type_change_status")); $logEntry->setPropelId($id); $logEntry->save(); } }
public static function getMiSQL($criteria) { if (!isset($criteria)) { return null; } if (!$criteria->getSelectColumns()) { $criteria = clone $criteria; self::addSelectColumns($criteria); } $criteria->setDbName(self::DATABASE_NAME); $con = Propel::getConnection($criteria->getDbName()); $params = array(); $sql = BasePeer::createSelectSql($criteria, $params); $stmt = null; $stmt = $con->prepare($sql); $stmt->setLimit($criteria->getLimit()); $stmt->setOffset($criteria->getOffset()); return $stmt; }
private static function lockObjects(kExclusiveLockKey $lockKey, array $objects, $max_execution_time) { $exclusive_objects = array(); // make sure the objects where not taken - $con = Propel::getConnection(); $not_exclusive_count = 0; foreach ($objects as $object) { $lock_version = $object->getLockVersion(); $criteria_for_exclusive_update = new Criteria(); $criteria_for_exclusive_update->add(BatchJobPeer::ID, $object->getId()); $criteria_for_exclusive_update->add(BatchJobPeer::LOCK_VERSION, $lock_version); $update = new Criteria(); // increment the lock_version - this will make sure it's exclusive $update->add(BatchJobPeer::LOCK_VERSION, $lock_version + 1); // increment the execution_attempts $update->add(BatchJobPeer::EXECUTION_ATTEMPTS, $object->getExecutionAttempts() + 1); $update->add(BatchJobPeer::SCHEDULER_ID, $lockKey->getSchedulerId()); $update->add(BatchJobPeer::WORKER_ID, $lockKey->getWorkerId()); $update->add(BatchJobPeer::BATCH_INDEX, $lockKey->getBatchIndex()); $update->add(BatchJobPeer::LAST_SCHEDULER_ID, $lockKey->getSchedulerId()); $update->add(BatchJobPeer::LAST_WORKER_ID, $lockKey->getWorkerId()); $processor_expiration = time() + $max_execution_time; $update->add(BatchJobPeer::PROCESSOR_EXPIRATION, $processor_expiration); $affectedRows = BasePeer::doUpdate($criteria_for_exclusive_update, $update, $con); KalturaLog::log("Lock update affected rows [{$affectedRows}] on job id [" . $object->getId() . "] lock version [{$lock_version}]"); if ($affectedRows == 1) { // fix the object to reflect what is in the DB $object->setLockVersion($lock_version + 1); $object->setExecutionAttempts($object->getExecutionAttempts() + 1); $object->setSchedulerId($lockKey->getSchedulerId()); $object->setWorkerId($lockKey->getWorkerId()); $object->setBatchIndex($lockKey->getBatchIndex()); $object->setProcessorExpiration($processor_expiration); KalturaLog::log("Job id [" . $object->getId() . "] locked and returned"); $exclusive_objects[] = $object; } else { $not_exclusive_count++; KalturaLog::log("Object not exclusive: [" . get_class($object) . "] id [" . $object->getId() . "]"); } } return $exclusive_objects; }
public function executeImpl($partner_id, $subp_id, $puser_id, $partner_prefix, $puser_kuser) { $job_type = $this->getPM("job_type"); $processor_name = $this->getPM("processor_name"); $processor_timeout = $this->getPM("processor_timeout"); $over_quota_partners = $this->getPM("over_quota_partners"); $defered_partners = $this->getPM("defered_partners"); $con = Propel::getConnection(); // fetch one pending row of a given job_type // where the over_quota_partner requests are dropped // and defered_partners request are of less priority $query = "SELECT " . BatchJobPeer::ID . " FROM " . BatchJobPeer::TABLE_NAME . " WHERE " . BatchJobPeer::STATUS . "=" . BatchJob::BATCHJOB_STATUS_PENDING . " AND " . BatchJobPeer::JOB_TYPE . "=" . $job_type . " " . (count($over_quota_partners) ? " AND " . BatchJobPeer::PARTNER_ID . " NOT IN ({$over_quota_partners}) " : "") . " ORDER BY " . (count($defered_partners) ? BatchJobPeer::PARTNER_ID . " IN ({$defered_partners}), " : "") . BatchJobPeer::CREATED_AT . " LIMIT 1"; $statement = $con->prepareStatement($query); $resultset = $statement->executeQuery(); $batch_job = null; while ($resultset->next()) { $batch_job = BatchJobPeer::retrieveByPK($resultset->getInt('ID')); } $batch_job = BatchJobPeer::doSelectOne($c); if ($batch_job) { // force update to work on the currently selected row and ensure it is still in pending status $c->add(BatchJobPeer::ID, $batch_job->getId()); $c->add(BatchJobPeer::STATUS, BatchJob::BATCHJOB_STATUS_PENDING); $update = new Criteria(); $update->add(BatchJobPeer::STATUS, BatchJob::BATCHJOB_STATUS_QUEUED); $update->add(BatchJobPeer::PROCESSOR_NAME, $processor_name); $update->add(BatchJobPeer::PROCESSOR_EXPIRATION, time() + $processor_timeout); $affectedRows = BasePeer::doUpdate($c, $update, $con); if ($affectedRows != 1) { $batch_job = null; } } if (!$batch_job) { //xx$this->addError ( APIErrors::INVALID_ENTRY_ID, $this->getObjectPrefix() , $entry_id ); } else { $wrapper = objectWrapperBase::getWrapperClass($batch_job, objectWrapperBase::DETAIL_LEVEL_REGULAR); // TODO - remove this code when cache works properly when saving objects (in their save method) $wrapper->removeFromCache("batch_job", $batch_job->getId()); $this->addMsg("batchjob", $wrapper); } }
function lockJob($object) { global $jobStatus; $con = Propel::getConnection(); $lock_version = $object->getVersion(); $criteria_for_exclusive_update = new Criteria(); $criteria_for_exclusive_update->add(BatchJobLockPeer::ID, $object->getId()); $criteria_for_exclusive_update->add(BatchJobLockPeer::VERSION, $lock_version); $criteria_for_exclusive_update->add(BatchJobLockPeer::STATUS, $jobStatus); $update = new Criteria(); // increment the lock_version - this will make sure it's exclusive $update->add(BatchJobLockPeer::VERSION, $lock_version + 1); $update->add(BatchJobLockPeer::STATUS, TEMP_JOB_STATUS); $affectedRows = BasePeer::doUpdate($criteria_for_exclusive_update, $update, $con); if ($affectedRows != 1) { return false; } // update $object with what is in the database $object->setVersion($lock_version + 1); $object->setStatus(TEMP_JOB_STATUS); return true; }
public function setDefaultGroup() { $con = Propel::getConnection(sfGuardGroupPeer::DATABASE_NAME); $criteria = new Criteria(); $criteria->add(self::NAME, 'Admin'); $group = self::doSelectOne($criteria); $new = false; if (!$group) { $group = new sfGuardGroup(); $new = true; } $group->setName('Admin'); $group->setDescription('Admin Group'); if ($new) { $group->save(); } $selectCriteria = $group->buildPkeyCriteria(); // update values are also stored in Criteria object $group->setId(self::DEFAULT_GROUP_ID); $updateValues = $group->buildCriteria(); BasePeer::doUpdate($selectCriteria, $updateValues, $con); return $group; }
public function saveVNCkeymap(PropelPDO $con = null) { if ($con === null) { $con = Propel::getConnection(EtvaSettingPeer::DATABASE_NAME, Propel::CONNECTION_WRITE); } $con->beginTransaction(); $isInsert = $this->isNew(); try { parent::save($con); //select statement $c1 = new Criteria(); $c1->add(EtvaServerPeer::VNC_KEYMAP_DEFAULT, 1, Criteria::EQUAL); //update statement $c2 = new Criteria(); $c2->add(EtvaServerPeer::VNC_KEYMAP, $this->getValue()); BasePeer::doUpdate($c1, $c2, $con); $con->commit(); return true; } catch (PropelException $e) { $con->rollBack(); throw $e; } }
public function execute($request) { $this->resource = $this->getRoute()->resource; if (!isset($this->resource)) { $this->forward404(); } if (!$this->getUser()->isAuthenticated()) { QubitAcl::forwardUnauthorized(); } $criteria = new Criteria(); $criteria->setDistinct(); $criteria->add(QubitInformationObject::LFT, $this->resource->lft, Criteria::GREATER_EQUAL); $criteria->add(QubitInformationObject::RGT, $this->resource->rgt, Criteria::LESS_EQUAL); $criteria->add(QubitRelation::TYPE_ID, QubitTerm::HAS_PHYSICAL_OBJECT_ID); $criteria->addJoin(QubitRelation::OBJECT_ID, QubitInformationObject::ID); $criteria->addJoin(QubitRelation::SUBJECT_ID, QubitPhysicalObject::ID); $this->physicalObjects = QubitPhysicalObject::get($criteria); if (0 == count($this->physicalObjects)) { return sfView::ERROR; } $c2 = clone $criteria; $this->foundcount = BasePeer::doCount($c2)->fetchColumn(0); }
public static function doCount(Criteria $criteria, $distinct = false, PropelPDO $con = null) { // we may modify criteria, so copy it first $criteria = clone $criteria; // We need to set the primary table name, since in the case that there are no WHERE columns // it will be impossible for the BasePeer::createSelectSql() method to determine which // tables go into the FROM clause. $criteria->setPrimaryTableName(FormularioPeer::TABLE_NAME); if ($distinct && !in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) { $criteria->setDistinct(); } if (!$criteria->hasSelectClause()) { FormularioPeer::addSelectColumns($criteria); } $criteria->clearOrderByColumns(); // ORDER BY won't ever affect the count $criteria->setDbName(self::DATABASE_NAME); // Set the correct dbName if ($con === null) { $con = Propel::getConnection(FormularioPeer::DATABASE_NAME, Propel::CONNECTION_READ); } foreach (sfMixer::getCallables('BaseFormularioPeer:doCount:doCount') as $callable) { call_user_func($callable, 'BaseFormularioPeer', $criteria, $con); } $criteria = self::kriterio($criteria); // BasePeer returns a PDOStatement $stmt = BasePeer::doCount($criteria, $con); if ($row = $stmt->fetch(PDO::FETCH_NUM)) { $count = (int) $row[0]; } else { $count = 0; // no rows returned; we infer that means 0 matches. } $stmt->closeCursor(); return $count; }
public function execute($request) { $this->thumbnails = array(); // Set limit (null for no limit) if (!isset($request->showFullImageflow) || 'true' != $request->showFullImageflow) { $this->limit = sfConfig::get('app_hits_per_page', 10); } // Add thumbs $criteria = new Criteria(); $criteria->addJoin(QubitInformationObject::ID, QubitDigitalObject::INFORMATION_OBJECT_ID); $criteria->add(QubitInformationObject::LFT, $this->resource->lft, Criteria::GREATER_THAN); $criteria->add(QubitInformationObject::RGT, $this->resource->rgt, Criteria::LESS_THAN); if (isset($this->limit)) { $criteria->setLimit($this->limit); } foreach (QubitDigitalObject::get($criteria) as $item) { $thumbnail = $item->getRepresentationByUsage(QubitTerm::THUMBNAIL_ID); if (!$thumbnail) { $thumbnail = QubitDigitalObject::getGenericRepresentation($item->mimeType, QubitTerm::THUMBNAIL_ID); $thumbnail->setParent($item); } $this->thumbnails[] = $thumbnail; } // Get total number of descendant digital objects $this->total = 0; if (isset($this->resource)) { $criteria = new Criteria(); $criteria->addJoin(QubitInformationObject::ID, QubitDigitalObject::INFORMATION_OBJECT_ID); $criteria->add(QubitInformationObject::LFT, $this->resource->lft, Criteria::GREATER_THAN); $criteria->add(QubitInformationObject::RGT, $this->resource->rgt, Criteria::LESS_THAN); $this->total = BasePeer::doCount($criteria)->fetchColumn(0); } if (2 > count($this->thumbnails)) { return sfView::NONE; } }
public static function doValidate(Lorfields $obj, $cols = null) { $columns = array(); if ($cols) { $dbMap = Propel::getDatabaseMap(LorfieldsPeer::DATABASE_NAME); $tableMap = $dbMap->getTable(LorfieldsPeer::TABLE_NAME); if (!is_array($cols)) { $cols = array($cols); } foreach ($cols as $colName) { if ($tableMap->containsColumn($colName)) { $get = 'get' . $tableMap->getColumn($colName)->getPhpName(); $columns[$colName] = $obj->{$get}(); } } } else { } $res = BasePeer::doValidate(LorfieldsPeer::DATABASE_NAME, LorfieldsPeer::TABLE_NAME, $columns); if ($res !== true) { $request = sfContext::getInstance()->getRequest(); foreach ($res as $failed) { $col = LorfieldsPeer::translateFieldname($failed->getColumn(), BasePeer::TYPE_COLNAME, BasePeer::TYPE_PHPNAME); $request->setError($col, $failed->getMessage()); } } return $res; }
/** * Validates all modified columns of given BpmnProject object. * If parameter $columns is either a single column name or an array of column names * than only those columns are validated. * * NOTICE: This does not apply to primary or foreign keys for now. * * @param BpmnProject $obj The object to validate. * @param mixed $cols Column name or array of column names. * * @return mixed TRUE if all columns are valid or the error message of the first invalid column. */ public static function doValidate(BpmnProject $obj, $cols = null) { $columns = array(); if ($cols) { $dbMap = Propel::getDatabaseMap(BpmnProjectPeer::DATABASE_NAME); $tableMap = $dbMap->getTable(BpmnProjectPeer::TABLE_NAME); if (!is_array($cols)) { $cols = array($cols); } foreach ($cols as $colName) { if ($tableMap->containsColumn($colName)) { $get = 'get' . $tableMap->getColumn($colName)->getPhpName(); $columns[$colName] = $obj->{$get}(); } } } else { } return BasePeer::doValidate(BpmnProjectPeer::DATABASE_NAME, BpmnProjectPeer::TABLE_NAME, $columns); }
/** * Method to soft delete all rows from the a_traitements table. * * @param PropelPDO $con the connection to use * @return int The number of affected rows (if supported by underlying database driver). * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doSoftDeleteAll(PropelPDO $con = null) { if ($con === null) { $con = Propel::getConnection(AbsenceEleveTraitementPeer::DATABASE_NAME, Propel::CONNECTION_WRITE); } $selectCriteria = new Criteria(); $selectCriteria->add(AbsenceEleveTraitementPeer::DELETED_AT, null, Criteria::ISNULL); $selectCriteria->setDbName(AbsenceEleveTraitementPeer::DATABASE_NAME); $modifyCriteria = new Criteria(); $modifyCriteria->add(AbsenceEleveTraitementPeer::DELETED_AT, time()); return BasePeer::doUpdate($selectCriteria, $modifyCriteria, $con); }
/** * Update the row in the database. * * @param PropelPDO $con * * @see doSave() */ protected function doUpdate(PropelPDO $con) { $selectCriteria = $this->buildPkeyCriteria(); $valuesCriteria = $this->buildCriteria(); BasePeer::doUpdate($selectCriteria, $valuesCriteria, $con); }
/** * Performs the work of inserting or updating the row in the database. * * If the object is new, it inserts it; otherwise an update is performed. * All related objects are also updated in this method. * * @param PropelPDO $con * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. * @throws PropelException * @see save() */ protected function doSave(PropelPDO $con) { $affectedRows = 0; // initialize var to track total num of affected rows if (!$this->alreadyInSave) { $this->alreadyInSave = true; if ($this->isNew()) { $this->modifiedColumns[] = OpenidAssociationPeer::ID; } // If this object has been modified, then save it to the database. if ($this->isModified()) { if ($this->isNew()) { $criteria = $this->buildCriteria(); if ($criteria->keyContainsValue(OpenidAssociationPeer::ID)) { throw new PropelException('Cannot insert a value for auto-increment primary key (' . OpenidAssociationPeer::ID . ')'); } $pk = BasePeer::doInsert($criteria, $con); $affectedRows = 1; $this->setId($pk); //[IMV] update autoincrement primary key $this->setNew(false); } else { $affectedRows = OpenidAssociationPeer::doUpdate($this, $con); } $this->resetModified(); // [HL] After being saved an object is no longer 'modified' } $this->alreadyInSave = false; } return $affectedRows; }