コード例 #1
0
ファイル: field.php プロジェクト: eliudiaz/p4a
 /**
  * If we use fields like combo box we have to set a data source.
  * By default we'll take the data source primary key as value field
  * and the first fiels (not pk) as description.
  * @param P4A_Data_Source $data_source
  * @return P4A_Field
  */
 public function setSource($data_source)
 {
     unset($this->data);
     if ($data_source === null) {
         return $this;
     }
     $this->data =& $data_source;
     $pk = $this->data->getPk();
     if (is_string($pk)) {
         if ($this->getSourceValueField() === null) {
             $this->setSourceValueField($pk);
         }
         if ($this->getSourceDescriptionField() === null) {
             $num_fields = $this->data->fields->getNumItems();
             $fields = $this->data->fields->getNames();
             $pk = $this->getSourceValueField();
             if ($num_fields == 1) {
                 $description_field = $pk;
             } else {
                 foreach ($fields as $field) {
                     if ($field != $pk) {
                         $description_field = $field;
                         break;
                     }
                 }
             }
             $this->setSourceDescriptionField($description_field);
         }
     } elseif (is_array($pk)) {
         trigger_error("Only single primary key is allowed", E_USER_ERROR);
     } elseif (is_null($pk)) {
         trigger_error("Please define a primary key", E_USER_ERROR);
     }
     return $this;
 }
コード例 #2
0
ファイル: table.php プロジェクト: eliudiaz/p4a
 /**
  * If we use fields like combo box we have to set a data source.
  * By default we'll take the data source primary key as value field
  * and the first fiels (not pk) as description.
  * @param P4A_Data_Source $data_source
  * @return P4A_Table_Col
  */
 public function setSource(P4A_Data_Source $data_source)
 {
     $this->data = $data_source;
     $pk = $this->data->getPk();
     if ($pk !== null) {
         if ($this->getSourceValueField() === null) {
             if (is_array($pk)) {
                 trigger_error("P4A_Table::setSource(): Columns support only one primary key");
             } else {
                 $this->setSourceValueField($pk);
             }
         }
         if ($this->getSourceDescriptionField() === null) {
             $source_value = $this->getSourceValueField();
             $names = $this->data->fields->getNames();
             foreach ($names as $name) {
                 if ($name != $source_value) {
                     $this->setSourceDescriptionField($name);
                     break;
                 }
             }
         }
     }
     return $this;
 }