Ejemplo n.º 1
0
 public function buildModelCriteria()
 {
     $search = AttributeAvQuery::create();
     /* manage translations */
     $this->configureI18nProcessing($search);
     $id = $this->getId();
     if (null !== $id) {
         $search->filterById($id, Criteria::IN);
     }
     $exclude = $this->getExclude();
     if (null !== $exclude) {
         $search->filterById($exclude, Criteria::NOT_IN);
     }
     $attribute = $this->getAttribute();
     if (null !== $attribute) {
         $search->filterByAttributeId($attribute, Criteria::IN);
     }
     $product = $this->getProduct();
     if (null !== $product) {
         // Return only Attributes Av that are part on a product's combination
         /* The request is:
            select * from attribute_av aav
            left join attribute_combination ac on ac.attribute_av_id = aav.id
            left join product_sale_elements pse on pse.id = ac.product_sale_elements_id
            where aav.attribute_id=3 and pse.product_id = 279
            group by aav.id
             */
         $pseJoin = new Join();
         $pseJoin->addCondition(AttributeCombinationTableMap::PRODUCT_SALE_ELEMENTS_ID, ProductSaleElementsTableMap::ID, Criteria::EQUAL);
         $pseJoin->setJoinType(Criteria::LEFT_JOIN);
         $search->leftJoinAttributeCombination('attribute_combination')->groupById()->addJoinObject($pseJoin)->where(ProductSaleElementsTableMap::PRODUCT_ID . "=?", $product, \PDO::PARAM_INT);
     }
     $orders = $this->getOrder();
     foreach ($orders as $order) {
         switch ($order) {
             case 'id':
                 $search->orderById(Criteria::ASC);
                 break;
             case 'id_reverse':
                 $search->orderById(Criteria::DESC);
                 break;
             case "alpha":
                 $search->addAscendingOrderByColumn('i18n_TITLE');
                 break;
             case "alpha_reverse":
                 $search->addDescendingOrderByColumn('i18n_TITLE');
                 break;
             case "manual":
                 $search->orderByPosition(Criteria::ASC);
                 break;
             case "manual_reverse":
                 $search->orderByPosition(Criteria::DESC);
                 break;
         }
     }
     return $search;
 }
Ejemplo n.º 2
0
 public function testEquality()
 {
     $j1 = new Join('foo', 'bar', 'INNER JOIN');
     $this->assertFalse($j1->equals(null), 'Join and null is not equal');
     $j2 = new Join('foo', 'bar', 'LEFT JOIN');
     $this->assertFalse($j1->equals($j2), 'INNER JOIN and LEFT JOIN are not equal');
     $j3 = new Join('foo', 'bar', 'INNER JOIN');
     $j3->addCondition('baz.foo', 'baz.bar');
     $this->assertFalse($j1->equals($j3), 'Joins with differend conditionsare not equal');
     $j4 = new Join('foo', 'bar', 'INNER JOIN');
     $j4->addExplicitCondition('book', 'AUTHOR_ID', null, 'author', 'ID', 'a', Join::EQUAL);
     $this->assertFalse($j1->equals($j4), 'Joins with differend clauses not equal');
     $j5 = new Join('foo', 'bar');
     $j6 = new Join('foo', 'bar');
     $this->assertTrue($j5->equals($j6), 'Joins without specified join type should be equal as they fallback to default join type');
 }
Ejemplo n.º 3
0
 /**
  * @api
  *
  * @param int $idGroup
  *
  * @return \Orm\Zed\User\Persistence\SpyUserQuery
  */
 public function queryGroupUsers($idGroup)
 {
     $query = $this->getFactory()->createUserQuery();
     $join = new Join();
     $join->addCondition(SpyUserTableMap::COL_ID_USER, SpyAclUserHasGroupTableMap::COL_FK_USER);
     $query->addJoinObject($join, self::GROUP_JOIN);
     $condition = sprintf('%s = %s', SpyAclUserHasGroupTableMap::COL_FK_ACL_GROUP, $idGroup);
     $query->addJoinCondition(self::GROUP_JOIN, $condition);
     return $query;
 }
Ejemplo n.º 4
0
 public function testCountConditions()
 {
     $j = new Join();
     $this->assertEquals(0, $j->countConditions());
     $j->addCondition('foo', 'bar');
     $this->assertEquals(1, $j->countConditions());
     $j->addCondition('foo1', 'bar1');
     $this->assertEquals(2, $j->countConditions());
 }