Exemplo n.º 1
0
 /**
  * @param $conditions string[] the key is the name of the condition, the value is the name of the
  *   value that enables the condition
  * @param $filters string[] the key is the name of the filter, the value is the name of the form
  *   containing its value
  * @return string
  */
 public function buildObject($conditions = null, $filters = null)
 {
     if (!isset($conditions)) {
         $conditions_values = $this->property->getListAnnotation('conditions')->values();
         if ($conditions_values) {
             foreach ($conditions_values as $condition) {
                 if (strpos($condition, '=')) {
                     list($name, $condition) = explode('=', $condition);
                 } else {
                     $name = $condition;
                 }
                 $conditions[$name] = isset($conditions[$name]) ? $conditions[$name] . ',' . $condition : $condition;
             }
         }
     }
     if (!isset($filters)) {
         $filters_values = $this->property->getListAnnotation('filters')->values();
         if ($filters_values) {
             $properties = $this->property->getDeclaringClass()->getProperties([T_EXTENDS, T_USE]);
             foreach ($filters_values as $filter) {
                 if ($properties[$filter]->getType()->isClass()) {
                     $filter = 'id_' . $filter;
                 }
                 $filters[$filter] = $filter;
             }
         }
     }
     return parent::buildObject($conditions, $filters);
 }
Exemplo n.º 2
0
 /**
  * Gets mysql default value for a property
  *
  * Must be called only after $column's Null and Type has been set
  *
  * @param $property Reflection_Property
  * @param $column Column
  * @return mixed
  */
 private static function propertyDefaultToMysql(Reflection_Property $property, Column $column)
 {
     $default = $property->getDeclaringClass()->getDefaultProperties()[$property->name];
     if (isset($default)) {
         $property_type = $column->getType();
         if ($property_type->isNumeric()) {
             $default = $default + 0;
         } elseif (is_array($default)) {
             $default = '';
         }
     } else {
         if ($column->canBeNull()) {
             $default = null;
         } else {
             $property_type = $column->getType();
             if ($property_type->isNumeric()) {
                 $default = 0;
             } elseif ($property_type->isString() || $property_type->isMultipleString()) {
                 $default = '';
             } elseif ($property_type->isDateTime()) {
                 $default = '0000-00-00 00:00:00';
             }
         }
     }
     return $default;
 }