コード例 #1
0
ファイル: RequestValidator.php プロジェクト: mikemirten/zgrid
 /**
  * Validate search
  * 
  * @param RequestInterface $request
  * @param array            $errors
  */
 protected function validateSearch(RequestInterface $request, array &$errors)
 {
     foreach ($request->getSearch() as $field => $value) {
         if (!$this->schema->hasField($field)) {
             $errors[] = sprintf('Search cannot be applied to non-existent field "%s"', $field);
             continue;
         }
         if (!$this->schema->getField($field)->isSearchable()) {
             $errors[] = sprintf('Field "%s" is not searchable', $field);
         }
         if (empty($value)) {
             $errors[] = sprintf('Search string of field "%s" is empty', $value, $field);
         }
     }
 }
コード例 #2
0
ファイル: ResolvedRequest.php プロジェクト: mikemirten/zgrid
 /**
  * {@inheritdoc}
  */
 public function getSearch()
 {
     if ($this->search === null) {
         $this->search = [];
         foreach ($this->request->getSearch() as $name => $string) {
             $searchBy = $this->schema->getField($name)->getSearchBy();
             if (empty($searchBy)) {
                 $this->search[$name] = $string;
                 continue;
             }
             $this->search[] = array_fill_keys($searchBy, $string);
         }
     }
     return $this->search;
 }
コード例 #3
0
 /**
  * Add fields by properties without "Exclude" annotation
  */
 protected function addFieldsByExcludeStrategy()
 {
     $properties = $this->getClassReflection()->getProperties();
     $excludedAnnotations = $this->readPropertyAnnotations(ExcludeAnnotation::class);
     $columnsAnnotations = $this->readPropertyAnnotations(ColumnAnnotation::class);
     foreach ($properties as $property) {
         if ($property->isStatic()) {
             continue;
         }
         $name = $property->getName();
         if (isset($excludedAnnotations[$name])) {
             continue;
         }
         $field = new Field($name);
         if (isset($columnsAnnotations[$name])) {
             $this->applyAnnotation($field, $columnsAnnotations[$name]);
         }
         $this->resolveType($field);
         $this->schema->addField($field);
     }
 }
コード例 #4
0
 /**
  * {@inheritdoc}
  */
 public function getSchema()
 {
     $colsNumber = 0;
     foreach ($this->source as $row) {
         $count = count($row);
         if ($count > $colsNumber) {
             $colsNumber = $count;
         }
     }
     $schema = new Schema();
     if ($colsNumber === 0) {
         return $schema;
     }
     $colSize = (int) round(100 / $colsNumber);
     for ($i = 0; $i < $colsNumber; ++$i) {
         $field = new Field($i);
         $field->setWidth($colSize);
         $schema->addField($field);
     }
     return $schema;
 }