Example #1
0
 function HTML_QuickForm_related_select(&$relationship)
 {
     $sql = $relationship->getDomainSQL();
     // The sql query to return all candidate rows of relationship
     $fkeys = $relationship->getForeignKeyValues();
     // Values of foreign keys (fields involved in where and join clauses)
     $table = $relationship->getDomainTable();
     if (isset($fkeys[$table])) {
         $query = $fkeys[$table];
         foreach ($query as $key => $val) {
             if (strpos($val, '$') === 0 or $val == '__' . $table . '__auto_increment__') {
                 unset($query[$key]);
             }
         }
     } else {
         $query = array();
     }
     $qt = new Dataface_QueryTool($table, $relationship->_sourceTable->db, $query);
     $options = $qt->getTitles();
     //print_r($options);
     $this->HTML_QuickForm_select('test', 'test', $options);
     echo $this->toHtml();
 }
Example #2
0
 /**
  * Returns a valuelist of the records that can be added to this relationship.
  *
  * @param Dataface_Record &$record The parent record.
  * @param array $query A query to filter the possible records.
  * @returns array Associative array where the keys are of the form
  * 		key1=value1&key2=value2  and the values are the title of the record.
  */
 function getAddableValues(&$record, $filter = array())
 {
     $filter = array_merge($this->getAddExistingFilters(), $filter);
     $t =& Dataface_Table::loadTable($this->getDomainTable());
     $r =& $this->_schema;
     $tkey_names = array_keys($t->keys());
     if (!is_a($record, 'Dataface_Record')) {
         throw new Exception("Attempt to call getAddableValues() without providing a Dataface_Record as context.", E_USER_ERROR);
     }
     if (($res = $record->callDelegateFunction($this->_name . '__' . __FUNCTION__)) !== null) {
         return $res;
     }
     if (isset($this->_schema['vocabulary']['existing'])) {
         // A custom vocabulary has been specified in the relationships.ini
         // file for this relationship.
         $options_temp = $t->getValuelist($r['vocabulary']['existing']);
         $options = array();
         foreach (array_keys($options_temp) as $optkey) {
             if (strpos($optkey, '=') === false) {
                 $options[$tkey_names[0] . '=' . urlencode($optkey)] = $options_temp[$optkey];
             } else {
                 $options[$optkey] = $options_temp[$optkey];
             }
         }
     } else {
         // No custom vocabulary has been specified.  Let's do our best
         // to figure out what the vocabulary should be.
         //$fkeys = $this->getForeignKeyValues(null,null,$record);
         $table = $this->getDomainTable();
         if (isset($fkeys[$table])) {
             $query = $fkeys[$table];
             foreach ($query as $key => $val) {
                 if ($this->isNullForeignKey($val) or strpos($val, '$') === 0 or $val == '__' . $table . '__auto_increment__') {
                     unset($query[$key]);
                 }
             }
         } else {
             $query = array();
         }
         $query = array_merge($filter, $query);
         $qt = new Dataface_QueryTool($table, $this->_sourceTable->db, $query);
         $options = $qt->getTitles(true, false, true);
     }
     return $options;
 }
Example #3
0
 function test_get_titles()
 {
     $qt = new Dataface_QueryTool('Profiles', $this->table1->db);
     $titles = $qt->getTitles();
     $this->assertEquals(array('id=10' => 'John', 'id=11' => 'Johnson', 'id=12' => 'William'), $titles);
 }