Exemplo n.º 1
0
 /**
  * Sets up foreign and through properly.
  *
  * @param   string  $model
  * @param   string  $column
  * @return  void
  */
 public function initialize($model, $column)
 {
     // Default to the name of the column
     if (empty($this->foreign)) {
         $foreign_model = inflector::singular($column);
         $this->foreign = $foreign_model . '.' . $foreign_model . ':primary_key';
     } elseif (is_string($this->foreign) and FALSE === strpos($this->foreign, '.')) {
         $this->foreign = $this->foreign . '.' . $this->foreign . ':primary_key';
     }
     // Create an array from them for easier access
     if (!is_array($this->foreign)) {
         $this->foreign = array_combine(array('model', 'field'), explode('.', $this->foreign));
     }
     // Create the default through connection
     if (empty($this->through) or is_string($this->through)) {
         if (empty($this->through)) {
             // Find the join table based on the two model names pluralized,
             // sorted alphabetically and with an underscore separating them
             $through = array(inflector::plural($this->foreign['model']), inflector::plural($model));
             sort($through);
             $this->through = implode('_', $through);
         }
         $this->through = array('model' => $this->through, 'fields' => array(inflector::singular($model) . ':foreign_key', inflector::singular($this->foreign['model']) . ':foreign_key'));
     }
     parent::initialize($model, $column);
 }
Exemplo n.º 2
0
 /**
  * Determines the actual foreign model and field that the
  * relationship is tied to.
  *
  * @param   string  $model
  * @param   string  $column
  * @return  void
  */
 public function initialize($model, $column)
 {
     parent::initialize($model, $column);
     // Empty? The model defaults to the the singularized name
     // of this field, and the field defaults to this field's model's foreign key
     if (empty($this->foreign)) {
         $this->foreign = inflector::singular($this->name) . '.' . $model . ':foreign_key';
     } elseif (FALSE === strpos($this->foreign, '.')) {
         $this->foreign = $this->foreign . '.' . $model . ':foreign_key';
     }
     // Create an array fo easier access to the separate parts
     $this->foreign = array_combine(array('model', 'field'), explode('.', $this->foreign));
 }
Exemplo n.º 3
0
 /**
  * Automatically sets foreign to sensible defaults.
  *
  * @param   string  $model
  * @param   string  $column
  * @return  void
  */
 public function initialize($model, $column)
 {
     // Default to the name of the column
     if (empty($this->foreign)) {
         $this->foreign = $column . '.:primary_key';
     } elseif (FALSE === strpos($this->foreign, '.')) {
         $this->foreign = $this->foreign . '.:primary_key';
     }
     // Create an array from them
     $this->foreign = array_combine(array('model', 'field'), explode('.', $this->foreign));
     // Default to the foreign model's primary key
     if (empty($this->column)) {
         $this->column = $column . '_id';
     }
     // Column is set and won't be overridden
     parent::initialize($model, $column);
 }
Exemplo n.º 4
0
 /**
  * Adds a rule that uploads the file.
  *
  * @param   Jelly_Model  $model
  * @param   string       $column
  * @return void
  */
 public function initialize($model, $column)
 {
     parent::initialize($model, $column);
     if (count($this->rules) > 0) {
         // If rules can be found check if the rule for not_empty is set
         foreach ($this->rules as $rule) {
             if (is_string($rule[0]) and $rule[0] === 'not_empty') {
                 $this->rules[] = array(array(':field', 'file_not_empty'), array(':validation', ':model', ':field'));
             }
         }
     }
     if ((bool) $this->types) {
         $this->rules[] = array(array(':field', 'file_invalid_type'), array(':validation', ':model', ':field', $this->types));
     }
     // Add a rule to save the file when validating
     $this->rules[] = array(array(':field', '_upload'), array(':validation', ':model', ':field'));
 }