Example #1
0
 public function preDelete(PropelPDO $con = null)
 {
     /*
      * delete lvs that are not shared....numVgs=1 only
      *
      */
     $criteria = new Criteria();
     $criteria->add(EtvaLogicalvolumePeer::CLUSTER_ID, $this->getClusterId());
     $criteria->addGroupByColumn(EtvaNodeLogicalvolumePeer::LOGICALVOLUME_ID);
     $criteria->addAsColumn('numLvs', 'COUNT(' . EtvaNodeLogicalvolumePeer::LOGICALVOLUME_ID . ')');
     $criteria->addHaving($criteria->getNewCriterion(EtvaNodeLogicalvolumePeer::LOGICALVOLUME_ID, 'numLvs=1', Criteria::CUSTOM));
     $records = EtvaNodeLogicalvolumePeer::doSelectJoinEtvaLogicalvolume($criteria);
     foreach ($records as $record) {
         $etva_lv = $record->getEtvaLogicalvolume();
         if ($record->getNodeId() == $this->getId()) {
             $etva_lv->delete();
         }
     }
     /*
      * delete vgs that are not shared....numVgs=1 only
      *
      */
     $criteria = new Criteria();
     $criteria->add(EtvaVolumegroupPeer::CLUSTER_ID, $this->getClusterId());
     $criteria->addGroupByColumn(EtvaNodeVolumegroupPeer::VOLUMEGROUP_ID);
     $criteria->addAsColumn('numVgs', 'COUNT(' . EtvaNodeVolumegroupPeer::VOLUMEGROUP_ID . ')');
     $criteria->addHaving($criteria->getNewCriterion(EtvaNodeVolumegroupPeer::VOLUMEGROUP_ID, 'numVgs=1', Criteria::CUSTOM));
     $records = EtvaNodeVolumegroupPeer::doSelectJoinEtvaVolumegroup($criteria);
     foreach ($records as $record) {
         $etva_vg = $record->getEtvaVolumegroup();
         if ($record->getNodeId() == $this->getId()) {
             $etva_vg->delete();
         }
     }
     /*
      * delete pvs that are not shared....numVgs=1 only
      *
      */
     $criteria = new Criteria();
     $criteria->add(EtvaPhysicalvolumePeer::CLUSTER_ID, $this->getClusterId());
     $criteria->addGroupByColumn(EtvaNodePhysicalvolumePeer::PHYSICALVOLUME_ID);
     $criteria->addAsColumn('numPvs', 'COUNT(' . EtvaNodePhysicalvolumePeer::PHYSICALVOLUME_ID . ')');
     $criteria->addHaving($criteria->getNewCriterion(EtvaNodePhysicalvolumePeer::PHYSICALVOLUME_ID, 'numPvs=1', Criteria::CUSTOM));
     $records = EtvaNodePhysicalvolumePeer::doSelectJoinEtvaPhysicalvolume($criteria);
     foreach ($records as $record) {
         $etva_pv = $record->getEtvaPhysicalvolume();
         if ($record->getNodeId() == $this->getId()) {
             $etva_pv->delete();
         }
     }
     // delete rra node dir and cpu load rrd
     $this->deleteRRAFiles();
     return true;
 }
Example #2
0
 public function testMergeWithHavingConditions()
 {
     $c1 = new Criteria();
     $cton = $c1->getNewCriterion(BookPeer::TITLE, 'foo', Criteria::EQUAL);
     $c1->addHaving($cton);
     $c2 = new Criteria();
     $c1->mergeWith($c2);
     $sql = 'SELECT  FROM  HAVING book.TITLE=:p1';
     $this->assertCriteriaTranslation($c1, $sql, 'mergeWith() does not remove an existing having condition');
     $c1 = new Criteria();
     $c2 = new Criteria();
     $cton = $c2->getNewCriterion(BookPeer::TITLE, 'foo', Criteria::EQUAL);
     $c2->addHaving($cton);
     $c1->mergeWith($c2);
     $sql = 'SELECT  FROM  HAVING book.TITLE=:p1';
     $this->assertCriteriaTranslation($c1, $sql, 'mergeWith() merges having condition to an empty having');
     $c1 = new Criteria();
     $cton = $c1->getNewCriterion(BookPeer::TITLE, 'foo', Criteria::EQUAL);
     $c1->addHaving($cton);
     $c2 = new Criteria();
     $cton = $c2->getNewCriterion(BookPeer::TITLE, 'bar', Criteria::EQUAL);
     $c2->addHaving($cton);
     $c1->mergeWith($c2);
     $sql = 'SELECT  FROM  HAVING (book.TITLE=:p1 AND book.TITLE=:p2)';
     $this->assertCriteriaTranslation($c1, $sql, 'mergeWith() combines having with AND');
 }
Example #3
0
 /**
  * Tests including aliases in criterion objects.
  * @link       http://propel.phpdb.org/trac/ticket/636
  */
 public function testAliasInCriterion()
 {
     $c = new Criteria();
     $c->addAsColumn("column_alias", "tbl.COL1");
     $crit = $c->getNewCriterion("column_alias", "FOO");
     $this->assertNull($crit->getTable());
     $this->assertEquals("column_alias", $crit->getColumn());
     $c->addHaving($crit);
     // produces invalid SQL referring to '.olumn_alias'
 }
Example #4
0
 public function testHavingRaw()
 {
     $c = new Criteria();
     $c->addSelectColumn(BookPeer::TITLE);
     $c->addAsColumn("isb_n", BookPeer::ISBN);
     $c->addHaving('isb_n = ?', '1234567890123', PDO::PARAM_STR);
     $expected = 'SELECT book.TITLE, book.ISBN AS isb_n FROM book HAVING isb_n = :p1';
     $params = array();
     $result = BasePeer::createSelectSql($c, $params);
     $this->assertEquals($expected, $result);
     BasePEer::doSelect($c, $this->con);
     $expected = 'SELECT book.TITLE, book.ISBN AS isb_n FROM book HAVING isb_n = \'1234567890123\'';
     $this->assertEquals($expected, $this->con->getLastExecutedQuery());
 }
Example #5
0
 private static function unsuspendRootJob($jobIds)
 {
     if (empty($jobIds)) {
         return array();
     }
     // Get possible root job ids
     // select root_job_id from batch_job_lock where id in (unsuspended jobs)
     $c = new Criteria();
     $c->addSelectColumn(BatchJobLockPeer::ROOT_JOB_ID);
     $c->setDistinct();
     $c->add(BatchJobLockPeer::ID, $jobIds, Criteria::IN);
     $stmt = BatchJobLockPeer::doSelectStmt($c);
     $rootIds = $stmt->fetchAll(PDO::FETCH_COLUMN);
     // Select only root ids that has no other suspended descendats
     $c = new Criteria();
     $c->addSelectColumn(BatchJobLockSuspendPeer::ROOT_JOB_ID);
     $c->add(BatchJobLockSuspendPeer::ROOT_JOB_ID, $rootIds, Criteria::IN);
     $c->add(BatchJobLockSuspendPeer::ID, '(batch_job_lock_suspend.ID != batch_job_lock_suspend.ROOT_JOB_ID)', Criteria::CUSTOM);
     $c->addGroupByColumn(BatchJobLockSuspendPeer::ROOT_JOB_ID);
     $c->addHaving($c->getNewCriterion(BatchJobLockSuspendPeer::ROOT_JOB_ID, 'COUNT(batch_job_lock_suspend.ID)>0', Criteria::CUSTOM));
     $stmt = BatchJobLockSuspendPeer::doSelectStmt($c);
     $usedRootIds = $stmt->fetchAll(PDO::FETCH_COLUMN);
     $unsuspendedRootJobs = array_diff($rootIds, $usedRootIds);
     self::moveFromSuspendedJobsTable($unsuspendedRootJobs);
     return $unsuspendedRootJobs;
 }
Example #6
0
 /**
  * Returns the taggings associated to one tag or a set of tags.
  *
  * The second optionnal parameter permits to restrict the results with
  * different criterias
  *
  * @param      mixed       $tags      Array of tag strings or string
  * @param      array       $options   Array of options parameters
  * @return     array
  */
 public static function getTaggings($tags = array(), $options = array())
 {
     $tags = sfPropelActAsTaggableToolkit::explodeTagString($tags);
     if (is_string($tags)) {
         $tags = array($tags);
     }
     $c = new Criteria();
     $c->addJoin(TagPeer::ID, TaggingPeer::TAG_ID);
     if (count($tags) > 0) {
         $c->add(TagPeer::NAME, $tags, Criteria::IN);
         $having = $c->getNewCriterion('COUNT(' . TaggingPeer::TAGGABLE_MODEL . ') ', count($tags), Criteria::GREATER_EQUAL);
         $c->addHaving($having);
     }
     $c->addGroupByColumn(TaggingPeer::TAGGABLE_ID);
     $c->clearSelectColumns();
     $c->addSelectColumn(TaggingPeer::TAGGABLE_MODEL);
     $c->addSelectColumn(TaggingPeer::TAGGABLE_ID);
     // Taggable model class option
     if (isset($options['model'])) {
         if (!class_exists($options['model']) || !is_callable(array(new $options['model'](), 'getPeer'))) {
             throw new PropelException(sprintf('The class "%s" does not exist, or it is not a model class.', $options['model']));
         }
         $c->add(TaggingPeer::TAGGABLE_MODEL, $options['model']);
     } else {
         $c->addGroupByColumn(TaggingPeer::TAGGABLE_MODEL);
     }
     if (isset($options['triple'])) {
         $c->add(TagPeer::IS_TRIPLE, $options['triple']);
     }
     if (isset($options['namespace'])) {
         $c->add(TagPeer::TRIPLE_NAMESPACE, $options['namespace']);
     }
     if (isset($options['key'])) {
         $c->add(TagPeer::TRIPLE_KEY, $options['key']);
     }
     if (isset($options['value'])) {
         $c->add(TagPeer::TRIPLE_VALUE, $options['value']);
     }
     $param = array();
     $sql = BasePeer::createSelectSql($c, $param);
     $con = Propel::getConnection();
     if (Propel::VERSION < '1.3') {
         $stmt = $con->prepareStatement($sql);
         $position = 1;
         foreach ($tags as $tag) {
             $stmt->setString($position, $tag);
             $position++;
         }
         if (isset($options['model'])) {
             $stmt->setString($position, $options['model']);
             $position++;
         }
         if (isset($options['triple'])) {
             $stmt->setBoolean($position, $options['triple']);
             $position++;
         }
         if (isset($options['namespace'])) {
             $stmt->setString($position, $options['namespace']);
             $position++;
         }
         if (isset($options['key'])) {
             $stmt->setString($position, $options['key']);
             $position++;
         }
         if (isset($options['value'])) {
             $stmt->setString($position, $options['value']);
             $position++;
         }
     } else {
         $stmt = $con->prepare($sql);
         $position = 1;
         foreach ($tags as $tag) {
             $stmt->bindValue(':p' . $position, $tag, PDO::PARAM_STR);
             $position++;
         }
         if (isset($options['model'])) {
             $stmt->bindValue(':p' . $position, $options['model'], PDO::PARAM_STR);
             $position++;
         }
         if (isset($options['triple'])) {
             $stmt->bindValue(':p' . $position, $options['triple']);
             $position++;
         }
         if (isset($options['namespace'])) {
             $stmt->bindValue(':p' . $position, $options['namespace'], PDO::PARAM_STR);
             $position++;
         }
         if (isset($options['key'])) {
             $stmt->bindValue(':p' . $position, $options['key'], PDO::PARAM_STR);
             $position++;
         }
         if (isset($options['value'])) {
             $stmt->bindValue(':p' . $position, $options['value'], PDO::PARAM_STR);
             $position++;
         }
     }
     if (!isset($options['nb_common_tags']) || $options['nb_common_tags'] > count($tags)) {
         $options['nb_common_tags'] = count($tags);
     }
     if ($options['nb_common_tags'] > 0) {
         if (Propel::VERSION >= '1.3') {
             $stmt->bindValue(':p' . $position, $options['nb_common_tags'], PDO::PARAM_STR);
         } else {
             $stmt->setString($position, $options['nb_common_tags']);
         }
     }
     $taggings = array();
     if (Propel::VERSION >= '1.3') {
         $rs = $stmt->execute();
         while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
             $model = $row[0];
             if (!isset($taggings[$model])) {
                 $taggings[$model] = array();
             }
             $taggings[$model][] = $row[1];
         }
     } else {
         $rs = $stmt->executeQuery(ResultSet::FETCHMODE_NUM);
         while ($rs->next()) {
             $model = $rs->getString(1);
             if (!isset($taggings[$model])) {
                 $taggings[$model] = array();
             }
             $taggings[$model][] = $rs->getInt(2);
         }
     }
     return $taggings;
 }
 public function testHavingRaw()
 {
     $db = Propel::getDB();
     $c = new Criteria();
     $c->addSelectColumn(BookPeer::TITLE);
     $c->addAsColumn("isb_n", BookPeer::ISBN);
     $c->addHaving('isb_n = ?', '1234567890123', PDO::PARAM_STR);
     $expected = 'SELECT book.title, book.isbn AS ' . $db->quoteIdentifier('isb_n') . ' FROM book HAVING isb_n = :p1';
     $params = array();
     $result = BasePeer::createSelectSql($c, $params);
     $this->assertEquals($expected, $result);
 }
 public function addDisciplinarySanctionCountColumnCriteria(Criteria $criteria, $field, $values)
 {
     if ($values) {
         $criteria->addJoin(StudentPeer::ID, StudentDisciplinarySanctionPeer::STUDENT_ID, Criteria::INNER_JOIN);
         $criteria->add(StudentDisciplinarySanctionPeer::SCHOOL_YEAR_ID, SchoolYearPeer::retrieveCurrent()->getId());
         $criteria->addGroupByColumn(StudentDisciplinarySanctionPeer::STUDENT_ID);
         $criterion = $criteria->getNewCriterion(StudentDisciplinarySanctionPeer::STUDENT_ID, 'count(' . StudentDisciplinarySanctionPeer::STUDENT_ID . ') >=' . $values, Criteria::CUSTOM);
         $criteria->addHaving($criterion);
     }
 }
Example #9
0
 public static function getByFilterCamp($max = 10, $page = 1, $sort_by, $availability, $first_date, $last_date, $not_available, $no_weekday, $no_weekend, $as_ma, $orgin, $dest, $airport_id, $date_range1, $date_range2, $filled, $open, $pilot, $mission_assistant, $ifr_backup, $wing, $ident, $city, $state, $zip, $day_1 = '', $day_2 = '', $day_3 = '', $day_4 = '', $day_5 = '', $day_6 = '', $day_7 = '', $all_type, $max_pass, $max_wei, $max_dist, $max_eff)
 {
     $c = new Criteria();
     $c->addAscendingOrderByColumn(self::MISSION_ID);
     $c->addJoin(self::MISSION_ID, MissionPeer::ID, Criteria::LEFT_JOIN);
     $c->add(MissionPeer::CAMP_ID, null, Criteria::ISNOTNULL);
     $c->add(self::TRANSPORTATION, 'air_mission', Criteria::LIKE);
     $c->addGroupByColumn(MissionPeer::CAMP_ID);
     $c->addJoin(MissionPeer::MISSION_TYPE_ID, MissionTypePeer::ID, Criteria::LEFT_JOIN);
     $c->addJoin(self::ID, PilotRequestPeer::LEG_ID, Criteria::LEFT_JOIN);
     //wing
     $c->addJoin(MissionPeer::PASSENGER_ID, PassengerPeer::ID, Criteria::LEFT_JOIN);
     $c->addJoin(PassengerPeer::PERSON_ID, PersonPeer::ID, Criteria::LEFT_JOIN);
     $c->addJoin(PersonPeer::ID, MemberPeer::PERSON_ID, Criteria::LEFT_JOIN);
     $c->addJoin(MemberPeer::WING_ID, WingPeer::ID, Criteria::LEFT_JOIN);
     $c->addJoin(MemberPeer::ID, AvailabilityPeer::MEMBER_ID, Criteria::LEFT_JOIN);
     if ($airport_id != null) {
         $criterion = $c->getNewCriterion(self::FROM_AIRPORT_ID, $airport_id, Criteria::LIKE);
         $criterion->addOR($c->getNewCriterion(self::TO_AIRPORT_ID, $airport_id, Criteria::LIKE));
         $c->add($criterion);
     }
     if ($sort_by == '0') {
         $c->addDescendingOrderByColumn(MissionPeer::MISSION_DATE);
     } else {
         $c->addAscendingOrderByColumn(MissionPeer::MISSION_DATE);
     }
     if ($not_available == 1) {
         return 'You have checked "Not Available" in Availablity form!';
     } else {
         if ($availability == '') {
             if ($first_date != null && $last_date != null) {
                 $criterion = $c->getNewCriterion(MissionPeer::MISSION_DATE, date('Y-m-d', strtotime($first_date)), Criteria::GREATER_EQUAL);
                 $criterion->addAnd($c->getNewCriterion(MissionPeer::MISSION_DATE, date('Y-m-d', strtotime($last_date)), Criteria::LESS_EQUAL));
                 $c->add($criterion);
             }
         } elseif ($availability == 'on') {
             if ($date_range1 != null && $date_range2 != null) {
                 $criterion = $c->getNewCriterion(MissionPeer::MISSION_DATE, date('Y-m-d', strtotime($date_range1)), Criteria::GREATER_EQUAL);
                 $criterion->addAnd($c->getNewCriterion(MissionPeer::MISSION_DATE, date('Y-m-d', strtotime($date_range2)), Criteria::LESS_EQUAL));
                 $c->add($criterion);
             }
             #max filters
             if ($max_dist) {
                 $c->add(self::FROM_AIRPORT_ID, 'Round(ACos(Sin(Radians(c1.latitude)) * Sin(Radians(c2.latitude)) + Cos(Radians(c1.latitude)) * Cos(Radians(c2.latitude)) * Cos(Radians(c1.longitude)-Radians(c2.longitude))) * ((180*60)/3.1415),0) < ' . (int) $max_dist, Criteria::CUSTOM);
             }
             $c->addGroupByColumn(CompanionPeer::PASSENGER_ID);
             if ($max_pass) {
                 $c->addHaving($c->getNewCriterion(CompanionPeer::PASSENGER_ID, 'COUNT(' . CompanionPeer::PASSENGER_ID . ') > ' . $max_pass, Criteria::CUSTOM));
             }
             $c->addGroupByColumn(CompanionPeer::WEIGHT);
             if ($max_wei) {
                 $c->addHaving($c->getNewCriterion(CompanionPeer::WEIGHT, 'SUM(' . CompanionPeer::WEIGHT . ') > ' . $max_wei, Criteria::CUSTOM));
             }
             $c->addJoin(MissionPeer::PASSENGER_ID, CompanionPeer::PASSENGER_ID, Criteria::LEFT_JOIN);
             #max efficiency
             if ($orgin == 'on' && $airport_id != null) {
                 $c->add(self::FROM_AIRPORT_ID, $airport_id, Criteria::LIKE);
             }
             if ($dest == 'on' && $airport_id != null) {
                 $c->add(self::TO_AIRPORT_ID, $airport_id, Criteria::LIKE);
             }
             if ($all_type == '') {
                 if ($filled == 'on') {
                     $c->add(MissionTypePeer::NAME, 'filled', Criteria::LIKE);
                 }
                 if ($open == 'on') {
                     $c->add(MissionTypePeer::NAME, 'open', Criteria::LIKE);
                 }
             }
             if ($pilot == 'on') {
                 $c->add(self::COPILOT_WANTED, '1', Criteria::LIKE);
             }
             if ($mission_assistant == 'on') {
                 $c->add(PilotRequestPeer::MISSION_ASSISTANT_WANTED, '1', Criteria::LIKE);
             }
             if ($ifr_backup == 'on') {
                 $c->add(PilotRequestPeer::IFR_BACKUP_WANTED, '1', Criteria::LIKE);
             }
             if ($as_ma) {
                 $c->add(PilotRequestPeer::MISSION_ASSISTANT_WANTED, '1', Criteria::LIKE);
             }
             if (!$no_weekday) {
                 //DAYS
                 if ($day_1) {
                     $c->addOr(MissionPeer::MISSION_DATE, 'date_format(' . MissionPeer::MISSION_DATE . ', "%W")="' . date('l', strtotime($day_1)) . '"', Criteria::CUSTOM);
                 }
                 if ($day_2) {
                     $c->addOr(MissionPeer::MISSION_DATE, 'date_format(' . MissionPeer::MISSION_DATE . ', "%W")="' . date('l', strtotime($day_2)) . '"', Criteria::CUSTOM);
                 }
                 if ($day_3) {
                     $c->addOr(MissionPeer::MISSION_DATE, 'date_format(' . MissionPeer::MISSION_DATE . ', "%W")="' . date('l', strtotime($day_3)) . '"', Criteria::CUSTOM);
                 }
                 if ($day_4) {
                     $c->addOr(MissionPeer::MISSION_DATE, 'date_format(' . MissionPeer::MISSION_DATE . ', "%W")="' . date('l', strtotime($day_4)) . '"', Criteria::CUSTOM);
                 }
                 if ($day_5) {
                     $c->addOr(MissionPeer::MISSION_DATE, 'date_format(' . MissionPeer::MISSION_DATE . ', "%W")="' . date('l', strtotime($day_5)) . '"', Criteria::CUSTOM);
                 }
             }
             if (!$no_weekend) {
                 if ($day_6) {
                     $c->addOr(MissionPeer::MISSION_DATE, 'date_format(' . MissionPeer::MISSION_DATE . ', "%W")="' . date('l', strtotime($day_6)) . '"', Criteria::CUSTOM);
                 }
                 if ($day_7) {
                     $c->addOr(MissionPeer::MISSION_DATE, 'date_format(' . MissionPeer::MISSION_DATE . ', "%W")="' . date('l', strtotime($day_7)) . '"', Criteria::CUSTOM);
                 }
             }
             //if($wing)$c->add(WingPeer::Name,'%'.$wing.'%',Criteria::LIKE);
             if ($ident != null) {
                 $criterion = $c->getNewCriterion(AirportPeer::alias("c1", AirportPeer::IDENT), $ident);
                 $criterion->addOr($c->getNewCriterion(AirportPeer::alias("c2", AirportPeer::IDENT), $ident));
                 $c->add($criterion);
             }
             if ($city != null) {
                 $criterion = $c->getNewCriterion(AirportPeer::alias("c1", AirportPeer::CITY), $city);
                 $criterion->addOr($c->getNewCriterion(AirportPeer::alias("c2", AirportPeer::CITY), $city));
                 $c->add($criterion);
             }
             if ($state != null) {
                 $criterion = $c->getNewCriterion(AirportPeer::alias("c1", AirportPeer::STATE), $state);
                 $criterion->addOr($c->getNewCriterion(AirportPeer::alias("c2", AirportPeer::STATE), $state));
                 $c->add($criterion);
             }
             if ($zip != null) {
                 $criterion = $c->getNewCriterion(AirportPeer::alias("c1", AirportPeer::ZIPCODE), $zip);
                 $criterion->addOr($c->getNewCriterion(AirportPeer::alias("c2", AirportPeer::ZIPCODE), $zip));
                 $c->add($criterion);
             }
         }
     }
     #max distance
     //$c->addAsColumn('aaaa', 'Round(ACos(Sin(Radians(c1.latitude)) * Sin(Radians(c2.latitude)) + Cos(Radians(c1.latitude)) * Cos(Radians(c2.latitude)) * Cos(Radians(c1.longitude)-Radians(c2.longitude))) * ((180*60)/3.1415),0)');
     //$c->addAsColumn('aaaa', 1);
     //$c->addAsColumn('aaaa', 'Round(ACos(Sin(Radians(c1.latitude)) * Sin(Radians(c2.latitude)) + Cos(Radians(c1.latitude)) * Cos(Radians(c2.latitude)) * Cos(Radians(c1.longitude)-Radians(c2.longitude))) * ((180*60)/3.1415),0)');
     //return self::doSelectStmt($c);
     return self::doSelect($c);
 }