示例#1
0
 /**
  * @param       $table
  * @param array $data
  *
  * @return bool|null
  * @throws Exception
  */
 public function updateOrInsert($table, array $data = [])
 {
     $primaryKeys = $this->repository->getCache()->getTablePrimaryKeys($table);
     /**
      * @T00D00 - bug for translations, permissions ...!
      */
     if (!$primaryKeys) {
         return;
     }
     foreach ($primaryKeys as $primaryKey) {
         if (!isset($data[$primaryKey])) {
             return;
         }
     }
     $this->entity->setTable($table);
     foreach ($primaryKeys as $primaryKey) {
         $this->entity->where($primaryKey, $data[$primaryKey]);
     }
     $this->entity->getQuery()->select(['`' . $table . '`.*']);
     $record = $this->entity->one();
     if ($record) {
         return $this->update($table, $data);
     }
     return (new InsertRecord($this->record, $this->entity, $this->repository))->setTables($table)->execute();
 }
示例#2
0
 public function getMiddleCollection(Entity $middleEntity, $foreignKey, $primaryValue)
 {
     if (!$primaryValue) {
         return new Collection();
     }
     return (new GetRecords($middleEntity->where($foreignKey, $primaryValue)->where($this->morph, get_class($this->getLeftEntity()))))->executeAll();
 }
示例#3
0
 public function getRightRecord(Entity $rightEntity, $foreignKey, $primaryValue)
 {
     if (!$primaryValue) {
         return null;
     }
     $rightEntity->setRepository($this->getLeftEntity()->getRepository());
     $entity = $rightEntity->where($foreignKey, $primaryValue);
     /**
      * Add conditions applied on query.
      */
     foreach ($this->getQuery()->getWhere()->getChildren() as $condition) {
         $entity->where(function (Parenthesis $parenthesis) use($condition) {
             $parenthesis->push($condition);
         });
     }
     foreach ($this->getQuery()->getBinds('where') as $bind) {
         $entity->getQuery()->bind($bind, 'where');
     }
     return (new GetRecords($entity))->executeOne();
 }
示例#4
0
文件: Filter.php 项目: pckg/generic
 public function applyOnEntity(Entity $entity)
 {
     $filters = $this->getAppliedFilters();
     $signMapper = ['equals' => '=', 'greater' => '>', 'greaterOrEquals' => '>=', 'lower' => '<', 'lowerOrEquals' => '<=', 'not' => '!=', 'in' => 'IN', 'notIn' => 'NOT IN', 'like' => 'LIKE'];
     foreach ($filters as $filter) {
         if (!is_array($filter['value']) && in_array($filter['options']['method'], ['in', 'notIn'])) {
             $filter['value'] = explode(',', $filter['value']);
         }
         $entity->where($filter['field'], $filter['value'], $signMapper[$filter['options']['method']]);
     }
     $signMapper = ['equals' => '=', 'in' => 'IN', 'notIn' => 'NOT IN', 'not' => '!='];
     $relationFilters = $this->getAppliedRelationFilters();
     foreach ($relationFilters as $relationFilter) {
         $relation = (new Relations())->where('id', $relationFilter['id'])->one();
         if ($relation->dynamic_relation_type_id == 1) {
             $entity->where($relation->onField->field, $relationFilter['value'], $signMapper[$relationFilter['options']['method']]);
         } else {
             if ($relation->dynamic_relation_type_id == 2) {
                 $entity->join('INNER JOIN ' . $relation->showTable->table, $relation->onTable->table . '.id = ' . $relation->showTable->table . '.' . $relation->onField->field, $relation->showTable->table . '.' . $relationFilter['field'] . ' ' . $signMapper[$relationFilter['options']['method']] . ' ' . $entity->getRepository()->getConnection()->quote($relationFilter['value']));
             }
         }
     }
 }
示例#5
0
 public function getMiddleCollection(Entity $middleEntity, $foreignKey, $primaryValue)
 {
     return (new GetRecords($middleEntity->where($foreignKey, $primaryValue)))->executeAll();
 }