function testEntity()
 {
     global $_PA;
     // Dal::register_query_callback("explain_query");
     // see if our test entity already exists
     $entity = Entity::load("PHPUnit", "TestEntity", "#1");
     $this->assertNull($entity, "we shouldn't have any Entites in the service PHPUnit at this point.");
     $myEntity = new TestEntity('#1');
     echo "sync #1\n";
     Entity::sync($myEntity);
     // create a second
     $myEntity2 = new TestEntity('#2');
     echo "sync #2\n";
     Entity::sync($myEntity2);
     // modify #1
     $myEntity->attributes['ThreeAttribute'] = array('value' => "Baz");
     Entity::sync($myEntity);
     // remove an attribute from #2
     unset($myEntity2->attributes['OneAttribute']);
     Entity::sync($myEntity2);
     $myEntity3 = new TestEntity('#3');
     Entity::sync($myEntity3);
     $myEntity4 = new TestEntity('#4');
     $myEntity4->attributes['ThreeAttribute'] = array('value' => "Baz");
     $myEntity4->attributes['fourAttribute'] = array('value' => "4");
     Entity::sync($myEntity4);
     // test attribute search
     // Dal::register_query_callback("explain_query");
     $foundEntities = Entity::search(array('entity_service' => 'PHPUnit', 'entity_type' => 'TestEntity'), array('OneAttribute' => 'F', 'TwoAttribute' => 'b', 'ThreeAttribute' => 'b', 'FourAttribute' => '4'));
     // Dal::unregister_query_callback("explain_query");
     echo "\nfound " . count($foundEntities) . " entities by attribute search:\n";
     foreach ($foundEntities as $i => $e) {
         echo "entity: '{$e['entity_service']}:{$e['entity_type']}:{$e['entity_id']}\n";
     }
     // Dal::register_query_callback("explain_query");
     $foundEntities = Entity::search(array(), array('FourAttribute' => '4'));
     // Dal::unregister_query_callback("explain_query");
     echo "\nfound " . count($foundEntities) . " entities by attribute search:\n";
     foreach ($foundEntities as $i => $e) {
         echo "entity: '{$e['entity_service']}:{$e['entity_type']}:{$e['entity_id']}\n";
     }
     $testEntities = Entity::search(array('entity_service' => 'PHPUnit', 'entity_type' => 'TestEntity'));
     echo "\nfound " . count($testEntities) . " test entities:\n";
     // load test entities
     foreach ($testEntities as $i => $e) {
         echo "entity: '{$e['entity_service']}:{$e['entity_type']}:{$e['entity_id']}\n";
         // print_r(Entity::load($e['entity_service'], $e['entity_type'], $e['entity_id'])); echo "\n";
     }
     // clean up test entities
     foreach ($testEntities as $i => $e) {
         Entity::delete($e['entity_service'], $e['entity_type'], $e['entity_id']);
     }
     // test again
     $testEntities = Entity::search(array('entity_service' => 'PHPUnit'));
     $this->assertEquals(count($testEntities), 0, "There should no longer be any Entities in the PHPUnit service.");
 }
 public static function get_all_entities($sort_by = null, $page = 1, $show = null)
 {
     $result = Entity::search(array('entity_service' => 'typedGroup'), null, '=', $sort_by, $page, $show);
     $entities = array();
     foreach ($result as $i => $entity_result) {
         if ($entity = TypedGroupEntity::load_for_group($entity_result['entity_id'])) {
             $entities[$i] = $entity;
         }
     }
     return $entities;
 }
 public static function search($points_attributes, $count = false, $sort_by = null, $page = 1, $show = null, $search_type = 'LIKE')
 {
     $entity_params = array('entity_service' => 'internal', 'entity_type' => 'points');
     $points_ent = array();
     try {
         if ($count) {
             $points_ent = parent::search($entity_params, $points_attributes, $search_type);
         } else {
             $points_ent = parent::search($entity_params, $points_attributes, $search_type, $sort_by, $page, $show);
             foreach ($points_ent as &$ent) {
                 $ent['attributes'] = parent::load_attributes((int) $ent['id']);
             }
         }
     } catch (PAException $e) {
         throw $e;
     }
     //echo "PENT<pre>" . print_r($points_ent, 1) . "</pre>";
     return $count ? count($points_ent) : $points_ent;
 }