示例#1
0
 /**
  * Setup method
  *
  */
 public function setUp()
 {
     with($conn = DriverManager::getConnection('mock://mock/JOBS?autoconnect=1'));
     Job::getPeer()->setConnection($conn);
     Person::getPeer()->setConnection($conn);
     $this->qa = new SelectQuery();
     $this->qa->setPeer(Job::getPeer());
     $this->qa->setCriteria(create(new Criteria(Job::column('job_id')->equal(5)))->setProjection(Projections::ProjectionList()->add(Job::column('job_id'))->add(Job::column('title'))));
     $this->qb = new SelectQuery();
     $this->qb->setPeer(Person::getPeer());
     $this->qb->setCriteria(create(new Criteria())->setProjection(Projections::ProjectionList()->add(Person::column('job_id'))->add(Person::column('name'))));
 }
 /**
  * @param f_peristentdocument_PersistentDocument $conditionOn
  * @return integer[]
  */
 private function getExcludeIds($conditionOn)
 {
     $excludeIds = array();
     if ($conditionOn instanceof form_persistentdocument_field) {
         $excludeIds = array($conditionOn->getId());
     } else {
         if ($conditionOn instanceof form_persistentdocument_group) {
             $query = form_FieldService::getInstance()->createQuery();
             $query->add(Restrictions::descendentOf($conditionOn->getId()));
             $query->setProjection(Projections::property('id'));
             $excludeIds = $query->findColumn('id');
         }
     }
     return $excludeIds;
 }
 /**
  * Add a new row to the result set.
  * Param can also be a rdbms.Column, a property
  * projection will be assumed then.
  *
  * @param    rdbms.SQLRenderable projection
  * @param    string alias optional
  * @return   rdbms.criterion.ProjectionList
  */
 public function add(SQLRenderable $projection, $alias = '')
 {
     $this->projections[] = array('alias' => empty($alias) && $projection instanceof CountProjection ? 'count' : $alias, 'projection' => $projection instanceof Projection ? $projection : ($projection = Projections::property($projection)));
     return $this;
 }
 public function testJoinWithProjection()
 {
     $jp = new JoinProcessor(Job::getPeer());
     $jp->setFetchModes(array('PersonJob->Department' => 'join'));
     $jp->enterJoinContext();
     $this->assertEquals('select  PersonJob.job_id, PersonJob_Department.department_id from JOBS.job as start, JOBS.Person as PersonJob, JOBS.Department as PersonJob_Department where start.job_id *= PersonJob.job_id and PersonJob.department_id *= PersonJob_Department.department_id and  1 = 1', create(new Criteria())->setFetchmode(Fetchmode::join('PersonJob'))->setProjection(Projections::ProjectionList()->add(Job::column('PersonJob->job_id'))->add(Job::column('PersonJob->Department->department_id')))->getSelectQueryString($this->conn, $this->peer, $jp));
     $jp->leaveJoinContext();
 }
 /**
  * Set projection
  * param can also be a rdbms.Column, a property
  * If the first parameter is omitted or NULL given the projection will be cleared
  * projection is then assumed
  *
  * @param   rdbms.SQLRenderable projection optional
  * @param   string optional alias
  * @return  rdbms.Criteria this object
  */
 public function setProjection(SQLRenderable $projection = NULL, $alias = '')
 {
     $this->projection = is_null($projection) || $projection instanceof ProjectionList ? $projection : ($projection = Projections::ProjectionList()->add($projection, $alias));
     return $this;
 }
 function mathArithFunctionTest()
 {
     $this->assertProjection('abs(-6)', 'abs(-6)', 'abs(-6)', 'php(\'abs\', -6)', create(new Criteria())->setProjection(SQLFunctions::abs(-6)));
     $this->assertProjection('ceil(5.1)', 'ceiling(5.1)', 'ceil(5.1)', 'php(\'ceil\', 5.1)', create(new Criteria())->setProjection(SQLFunctions::ceil(5.1)));
     $this->assertProjection('floor(5.7)', 'floor(5.7)', 'floor(5.7)', 'php(\'floor\', 5.7)', create(new Criteria())->setProjection(SQLFunctions::floor(5.7)));
     $this->assertProjection('exp(log(1))', 'exp(log(1))', 'exp(log(1))', 'php(\'exp\', php(\'log\', 1))', create(new Criteria())->setProjection(SQLFunctions::exp(SQLFunctions::log(1))));
     $this->assertProjection('log10(power(10, 5))', 'log10(power(10, 5))', 'log10(power(10, 5))', 'php(\'log10\', php(\'pow\', 10, 5))', create(new Criteria())->setProjection(SQLFunctions::log10(SQLFunctions::power(10, 5))));
     $this->assertProjection('power(10, log10(5))', 'power(10, log10(5))', 'power(10, log10(5))', 'php(\'pow\', 10, php(\'log10\', 5))', create(new Criteria())->setProjection(SQLFunctions::power(10, SQLFunctions::log10(5))));
     $this->assertProjection('round(1.5, 0) as `roundtest1`, round(1.49, 0) as `roundtest2`, round(1.49, 1) as `roundtest3`', 'round(1.5, 0) as \'roundtest1\', round(1.49, 0) as \'roundtest2\', round(1.49, 1) as \'roundtest3\'', 'round(1.5, 0) as "roundtest1", round(1.49, 0) as "roundtest2", round(1.49, 1) as "roundtest3"', 'php(\'round\', 1.5, 0) as \'roundtest1\', php(\'round\', 1.49, 0) as \'roundtest2\', php(\'round\', 1.49, 1) as \'roundtest3\'', create(new Criteria())->setProjection(Projections::ProjectionList()->add(SQLFunctions::round(1.5), 'roundtest1')->add(SQLFunctions::round(1.49), 'roundtest2')->add(SQLFunctions::round(1.49, 1), 'roundtest3')));
     $this->assertProjection('sign(-7) as `signTest1`, sign(0) as `signTest2`, sign(4) as `signTest3`', 'convert(int, sign(-7)) as \'signTest1\', convert(int, sign(0)) as \'signTest2\', convert(int, sign(4)) as \'signTest3\'', 'sign(-7) as "signTest1", sign(0) as "signTest2", sign(4) as "signTest3"', 'sign(-7) as \'signTest1\', sign(0) as \'signTest2\', sign(4) as \'signTest3\'', create(new Criteria())->setProjection(Projections::ProjectionList()->add(SQLFunctions::sign(-7), 'signTest1')->add(SQLFunctions::sign(0), 'signTest2')->add(SQLFunctions::sign(4), 'signTest3')));
 }
示例#7
0
}
include 'header.php';
?>

<h4>Projection For <?php 
echo $month_name;
?>
</h4>
<form method="post">
    <input type="hidden" name="add_projection" value="yes">
    <p>Folder <input name="folder_name" type="text"> Amount <input name="amount" type="text"> </p>
    <input type="submit" value="Submit">
</form>
<?php 
echo $error_msg;
$projections = Projections::projections_for_month($budget_id, $month_id);
$entries = Entries::summary_for_month($budget_id, $month_id);
$projections_by_folder = array();
$summary_by_folder = array();
$known_folders = array();
foreach ($projections as $p) {
    $projections_by_folder[$p->folder_id] = $p;
    if (!in_array($p->folder_id, $known_folders)) {
        array_push($known_folders, $p->folder_id);
    }
}
foreach ($entries as $e) {
    $summary_by_folder[$e->folder_id] = $e;
    if (!in_array($e->folder_id, $known_folders)) {
        array_push($known_folders, $e->folder_id);
    }
 function withProjectionTest()
 {
     $crit = new Criteria();
     $this->assertClass($crit->withProjection(Projections::property(Job::column('job_id'))), 'rdbms.Criteria');
     $this->assertFalse($crit->isProjection());
     $this->assertTrue($crit->withProjection(Projections::property(Job::column('job_id')))->isProjection());
 }