示例#1
0
文件: Driver.php 项目: designs2/core
 /**
  * Fetch a variant of a single record by id.
  *
  * @param ConfigInterface $objConfig The config holding the id of the base model.
  *
  * @return null|ModelInterface
  */
 public function createVariant(ConfigInterface $objConfig)
 {
     $objItem = $this->getMetaModel()->findById($objConfig->getId())->varCopy();
     if (!$objItem) {
         return null;
     }
     $model = new Model($objItem);
     $model->setMeta($model::IS_CHANGED, true);
     return $model;
 }
 /**
  * {@inheritDoc}
  */
 public function fetch(ConfigInterface $objConfig)
 {
     if ($objConfig->getId() != null) {
         $strQuery = sprintf('SELECT %s  FROM %s WHERE id = ?', $this->buildFieldQuery($objConfig), $this->strSource);
         $dbResult = $this->objDatabase->prepare($strQuery)->execute($objConfig->getId());
     } else {
         $arrParams = array();
         // Build SQL.
         $query = sprintf('SELECT %s FROM %s', $this->buildFieldQuery($objConfig), $this->strSource);
         $query .= $this->buildWhereQuery($objConfig, $arrParams);
         $query .= $this->buildSortingQuery($objConfig);
         // Execute db query.
         $dbResult = $this->objDatabase->prepare($query)->limit(1, 0)->execute($arrParams);
     }
     if ($dbResult->numRows == 0) {
         return null;
     }
     return $this->createModelFromDatabaseResult($dbResult);
 }
 /**
  * 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 ConfigInterface $objConfig The configuration to use.
  *
  * @return ModelInterface
  *
  * @throws DcGeneralException If config object does not contain an Id.
  */
 public function fetch(ConfigInterface $objConfig)
 {
     if (!$objConfig->getId()) {
         throw new DcGeneralException('Error, no id passed, TableRowsAsRecordsDriver 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->setPropertyRaw('rows', $objResult->fetchAllAssoc());
     }
     $objModel->setID($objConfig->getId());
     return $objModel;
 }
 /**
  * {@inheritdoc}
  */
 public function fetch(ConfigInterface $config)
 {
     if ($config->getId()) {
         $repository = $this->getEntityRepository();
         $entity = $repository->find($config->getId());
         return $entity ? $this->mapEntity($entity) : null;
     }
     if ($config->getFilter()) {
         $config = clone $config;
         $config->setAmount(1);
         $collection = $this->fetchAll($config);
         if (count($collection)) {
             return $collection[0];
         }
     }
     return null;
 }