<?php
/**
 * This class has been auto-generated by the Doctrine ORM Framework
 */
class PropertiesTable extends DarwinTable
{
  /**
  * Find a property (joined with values)
  * for a given table and record id
  * @param string $table_name db table name
  * @param int $record_id id of the record
  * @return a Doctrine_collection of results
  */
  public function findForTable($table_name, $record_id)
  {
    $q = Doctrine_Query::create()
      ->from('Properties p')
      ->orderBy('p.property_type ASC');
    $q = $this->addCatalogueReferences($q, $table_name, $record_id, 'p', true);
    return $q->execute();
  }

  /**
  * Get Distincts type of properties
  * @return array an Array of types in keys
  */
  public function getDistinctType($ref_relation=null)
  {
    if(is_null($ref_relation))
      $q = $this->createFlatDistinct('properties', 'property_type', 'type');
    else
      $q = $this->createFlatDistinctDepend('properties', 'property_type', $ref_relation, 'type');

    $a = DarwinTable::CollectionToArray($q->execute(), 'type');
    return array_merge(array(''=>''),$a);
  }

  /**
  * Get Distincts Sub Type of properties
  * filter by type if one given
  * @param string $type a type
  * @return array an Array of sub-types in keys/values
  */
  public function getDistinctApplies($type=null)
  {
    if(is_null($type))
      $q = $this->createFlatDistinct('properties', 'applies_to', 'applies_to');
    else
      $q = $this->createFlatDistinctDepend('properties', 'applies_to', $type, 'applies_to');
    $a =  DarwinTable::CollectionToArray($q->execute(), 'applies_to');
    return array_merge(array(''=>''),$a);

  }

  /**
  * Get Distincts units (accuracy + normal) of properties
  * filter by type if one given
  * @param string $type a type
  * @return array an Array of Qualifier in keys/values
  */
  public function getDistinctUnit($type=null)
  {
    if(is_null($type))
      $q = $this->createFlatDistinct('properties', 'property_unit', 'unit');
    else
      $q = $this->createFlatDistinctDepend('properties', 'property_unit', $type, 'unit');
    $res_unit = DarwinTable::CollectionToArray($q->execute(), 'unit');

    return array_merge(array(''=>''),$res_unit);
  }
}
