コード例 #1
0
 /**
  * Fetch a single or first record by id or filter.
  *
  * If the model shall be retrieved by id, use $objConfig->setId() to populate the config with an Id.
  *
  * If the model shall be retrieved by filter, use $objConfig->setFilter() to populate the config with a filter.
  *
  * @param InterfaceGeneralDataConfig $objConfig
  *
  * @return InterfaceGeneralModel
  */
 public function fetch(InterfaceGeneralDataConfig $objConfig)
 {
     // TODO: implement find first item by filter here.
     $strBackupLanguage = '';
     if ($this->strCurrentLanguage != '') {
         $strBackupLanguage = $GLOBALS['TL_LANGUAGE'];
         $GLOBALS['TL_LANGUAGE'] = $this->strCurrentLanguage;
     }
     $objItem = $this->objMetaModel->findById($objConfig->getId());
     if ($strBackupLanguage != '') {
         $GLOBALS['TL_LANGUAGE'] = $strBackupLanguage;
     }
     if (!$objItem) {
         return null;
     }
     return new GeneralModelMetaModel($objItem);
 }
コード例 #2
0
 /**
  * Fetch a single or first record by id or filter.
  *
  * If the model shall be retrieved by id, use $objConfig->setId() to populate the config with an Id.
  *
  * If the model shall be retrieved by filter, use $objConfig->setFilter() to populate the config with a filter.
  *
  * @param InterfaceGeneralDataConfig $objConfig
  *
  * @return InterfaceGeneralModel
  */
 public function fetch(InterfaceGeneralDataConfig $objConfig)
 {
     if ($objConfig->getId() != null) {
         $strQuery = "SELECT " . $this->buildFieldQuery($objConfig) . " FROM {$this->strSource} WHERE id = ?";
         $arrResult = $this->objDatabase->prepare($strQuery)->execute($objConfig->getId())->fetchAllAssoc();
     } else {
         $arrParams = array();
         // Build SQL.
         $query = "SELECT " . $this->buildFieldQuery($objConfig) . " FROM " . $this->strSource;
         $query .= $this->buildWhereQuery($objConfig, $arrParams);
         $query .= $this->buildSortingQuery($objConfig);
         // Execute db query.
         $arrResult = $this->objDatabase->prepare($query)->limit(1, 0)->execute($arrParams)->fetchAllAssoc();
     }
     if (count($arrResult) == 0) {
         return null;
     }
     $objModel = $this->getEmptyModel();
     foreach ($arrResult[0] as $key => $value) {
         if ($key == "id") {
             $objModel->setID($value);
         }
         $objModel->setProperty($key, $value);
     }
     return $objModel;
 }
コード例 #3
0
 /**
  * Fetch a single record by id.
  *
  * This data provider only supports retrieving by id so use $objConfig->setId() to populate the config with an Id.
  *
  * @param InterfaceGeneralDataConfig $objConfig
  *
  * @return InterfaceGeneralModel
  *
  * @throws Exception if config object does not contain an Id.
  */
 public function fetch(InterfaceGeneralDataConfig $objConfig)
 {
     if (!$objConfig->getId()) {
         throw new Exception("Error, no id passed, GeneralDataTableRowsAsRecords is only intended for edit mode.", 1);
     }
     $strQuery = sprintf('SELECT %s FROM %s WHERE %s=?', $this->buildFieldQuery($objConfig), $this->strSource, $this->strGroupCol);
     if ($this->strSortCol) {
         $strQuery .= ' ORDER BY ' . $this->strSortCol;
     }
     $objResult = $this->objDatabase->prepare($strQuery)->execute($objConfig->getId());
     $objModel = $this->getEmptyModel();
     if ($objResult->numRows) {
         $objModel->setProperty('rows', $objResult->fetchAllAssoc());
     }
     $objModel->setID($objConfig->getId());
     return $objModel;
 }