public function testFlip()
 {
     $testSet = new \Cx\Core_Modules\Listing\Model\Entity\DataSet($this->testArray);
     $flippedSet = $testSet->flip();
     $this->assertEquals($this->flippedArray, $flippedSet->toArray());
 }
 /**
  * Gets one or more entries from this DataSource
  *
  * If an argument is not provided, no restriction is made for this argument.
  * So if this is called without any arguments, all entries of this
  * DataSource are returned.
  * If no entry is found, an empty array is returned.
  * @param string $elementId (optional) ID of the element if only one is to be returned
  * @param array $filter (optional) field=>value-type condition array, only supports = for now
  * @param array $order (optional) field=>order-type array, order is either "ASC" or "DESC"
  * @param int $limit (optional) If set, no more than $limit results are returned
  * @param int $offset (optional) Entry to start with
  * @param array $fieldList (optional) Limits the result to the values for the fields in this list
  * @throws \Exception If doctrine repository for this DataSource could not be found
  * @return array Two dimensional array (/table) of results (array($row=>array($fieldName=>$value)))
  */
 public function get($elementId = null, $filter = array(), $order = array(), $limit = 0, $offset = 0, $fieldList = array())
 {
     $repo = $this->getRepository();
     $em = $this->cx->getDb()->getEntityManager();
     $criteria = array();
     // $filter
     if (count($fieldList)) {
         foreach ($filter as $field => $value) {
             if (!in_array($field, $fieldList)) {
                 continue;
             }
             $criteria[$field] = $value;
         }
     }
     // $elementId
     if (isset($elementId)) {
         $meta = $em->getClassMetadata($this->getIdentifier());
         $identifierField = $meta->getSingleIdentifierFieldName();
         $criteria[$identifierField] = $elementId;
     }
     // $order
     foreach ($order as $field => $ascdesc) {
         if (!in_array($field, $fieldList) || !in_array($ascdesc, array('ASC', 'DESC'))) {
             unset($order[$field]);
         }
     }
     // order, limit and offset are not supported by our doctrine version
     // yet! This would be the nice way to solve this:
     /*$result = $repo->findBy(
           $criteria,
           $order,
           (int) $limit,
           (int) $offset
       );//*/
     // but for now we'll have to:
     $qb = $em->createQueryBuilder();
     $qb->select('x')->from($this->getIdentifier(), 'x');
     // $filter
     $i = 1;
     foreach ($criteria as $field => $value) {
         $qb->andWhere($qb->expr()->eq('x.' . $field, '?' . $i));
         $qb->setParameter($i, $value);
         $i++;
     }
     // $order, $limit, $offset
     foreach ($order as $field => $ascdesc) {
         $qb->orderBy('x.' . $field, $ascdesc);
     }
     // $limit, $offset
     if ($limit) {
         $qb->setMaxResults($limit);
         if ($offset) {
             $qb->setFirstResult($offset);
         }
     }
     $result = $qb->getQuery()->getResult(\Doctrine\ORM\AbstractQuery::HYDRATE_ARRAY);
     // $fieldList
     $dataSet = new \Cx\Core_Modules\Listing\Model\Entity\DataSet($result);
     if (count($fieldList)) {
         $dataFlipped = $dataSet->flip()->toArray();
         foreach ($dataFlipped as $key => $value) {
             if (!in_array($key, $fieldList)) {
                 unset($dataFlipped[$key]);
             }
         }
         $dataSetFlipped = new \Cx\Core_Modules\Listing\Model\Entity\DataSet($dataFlipped);
         $dataSet = $dataSetFlipped->flip();
     }
     return $dataSet->toArray();
 }