public function detectCallableForField(FieldInterface $field) { $method = null; $type = null; if (!$field instanceof DbField) { return false; } if ($field->isType('reference')) { return $this->handleDbReference($field, 'reference'); } elseif ($field->isType('manytomany')) { return $this->handleDbReference($field, 'manytomany'); } if ($field->isType('boolean')) { $type = 'boolean'; } elseif ($field->isType('date', 'timestamp')) { $type = 'date'; } elseif ($field->isType('integer', 'float')) { $type = 'numeric'; } elseif ($field->isType('clob', 'text')) { $type = 'text'; } else { return false; } if (null !== $type) { return function () use($type) { return array('type' => $type, 'options' => ''); }; } return false; }
/** * Detect which view helper should be used to edit the supplied * \Dewdrop\Db\Field. THis is basic logic used to determine a suitable * helper: * * <ol> * <li> * If a custom helper was assigned by calling customizeField(), * use that. * </li> * <li> * If it is an EAV field, use whatever helper is assigned in the * EAV definition. * </li> * <li> * Otherwise, look at the field's type to determine which helper * would be appropriate. * </li> * <li> * If a suitable helper cannot be determined, throw an exception. * </li> * </ol> * * @throws \Dewdrop\Exception * @param Field $field * @return string */ public function detect(FieldInterface $field) { if (array_key_exists($field->getControlName(), $this->customHelpers)) { return $this->customHelpers[$field->getControlName()]; } elseif ($field instanceof EavField) { return $field->getEditHelperName(); } elseif ($field->isType('boolean', 'boolean')) { return 'inputCheckbox'; } elseif ($field->isType('manytomany')) { return 'checkboxList'; } elseif ($field->isType('reference')) { return 'select'; } elseif ($field->isType('clob')) { return 'textarea'; } elseif ($field->isType('text', 'integer', 'float')) { return 'inputText'; } elseif ($field->isType('date')) { return 'inputDate'; } elseif ($field->isType('timestamp')) { return 'inputTimestamp'; } throw new Exception('Fields\\EditHelperDetector: Could not find a suitable view helper for field ' . $field->getControlName() . '.'); }
/** * Try to detect a default callback for the provided field. THis helper * will only provide a default for database fields of common types. For * custom fields, you'll have to assign your own callback, if you want them * to be sortable. * * @param FieldInterface $field * @return false|callable */ public function detectCallableForField(FieldInterface $field) { $method = null; if (!$field instanceof DbField) { return false; } if ($field->isType('reference')) { $method = 'sortDbReference'; } elseif ($field->isType('date', 'timestamp')) { $method = 'sortDbDate'; } elseif ($field->isType('manytomany', 'clob', 'string', 'numeric', 'boolean')) { $method = 'sortDbDefault'; } if (!$method) { return false; } else { return function ($helper, Select $select, $direction) use($field, $method) { return $this->{$method}($field, $select, $direction); }; } }
public function detectCallableForField(FieldInterface $field) { $type = null; if (!$field instanceof DbField) { return false; } if ($field->isType('manytomany')) { /* @var $field \Dewdrop\Db\ManyToMany\Field */ $filter = new ManyToManyFilter($field->getManyToManyRelationship()); } else { if ($field->isType('reference')) { $type = 'Reference'; } elseif ($field->isType('boolean')) { $type = 'Boolean'; } elseif ($field->isType('date', 'timestamp')) { $type = 'Date'; } elseif ($field->isType('integer', 'float')) { $type = 'Numeric'; } elseif ($field->isType('clob', 'text')) { $type = 'Text'; } else { return false; } if ($field instanceof EavField) { $tableName = $field->getName(); $fieldName = 'value'; } else { $tableName = $field->getTable()->getTableName(); $fieldName = $field->getName(); } $className = '\\Dewdrop\\Db\\Select\\Filter\\' . $type; $filter = new $className($tableName, $fieldName); } return function ($helper, $select, $conditionSetName, $queryVars) use($filter) { return $filter->apply($select, $conditionSetName, $queryVars); }; }
/** * If no custom callback is defined for a field, it will fall back to this * method to find a suitable callback. In the case of the Content helper, * we only provide a fall back for DB-based fields. Custom fields will have * to define a callback in order to function properly. * * @param FieldInterface $field * @return mixed */ public function detectCallableForField(FieldInterface $field) { $method = null; if (!$field instanceof DbField) { return false; } if ($field->isType('boolean')) { $method = 'renderDbBoolean'; } elseif ($field->isType('reference')) { $method = 'renderDbReference'; } elseif ($field->isType('date')) { $method = 'renderDbDate'; } elseif ($field->isType('timestamp')) { $method = 'renderDbTimestamp'; } elseif ($field->isType('manytomany', 'clob', 'string', 'numeric')) { $method = 'renderDbText'; } if (!$method) { return false; } else { return function ($helper, array $rowData) use($field, $method) { return $this->{$method}($field, $rowData); }; } }