/** * Copied from Jelly_Field_Relationship but allows for null/zero values with an * additional label if the field specifies it. * * @param string $prefix The prefix to put before the filename to be rendered * @return View **/ public function input($prefix = 'jelly/field', $data = array()) { if (!isset($data['options'])) { $options = array(); $loaded_options = Jelly::select($this->foreign['model'])->execute(); foreach ($loaded_options as $option) { $options[$option->id()] = $option->name(); } $data['options'] = $options; if (isset($this->allow_nil)) { $data['options'] = array($this->allow_nil) + $data['options']; } } return parent::input($prefix, $data); }
/** * 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'; } // Split them apart $foreign = explode('.', $this->foreign); // Create an array from them $this->foreign = array('model' => $foreign[0], 'column' => $foreign[1]); // Default to the foreign model's primary key if (empty($this->column)) { $this->column = $this->foreign['model'] . '_id'; } // Column is set and won't be overridden parent::initialize($model, $column); }
/** * Adds the "ids" variable to the view data * * @param string $prefix * @param array $data * @return View */ public function input($prefix = 'jelly/field', $data = array()) { $data['ids'] = array(); foreach ($data['value'] as $model) { $data['ids'][] = $model->id(); } return parent::input($prefix, $data); }
/** * Provides the input with the ids variable. An array of * all the ID's in the foreign model that this record owns. * * @param string $prefix * @param string $data * @return void */ public function input($prefix = 'jelly/field', $data = array()) { // Kind of a wart here, but since HasOne extends this, we don't always want to iterate if ($data['value'] instanceof Iterator) { $data['ids'] = array(); // Grab the IDS foreach ($data['value'] as $model) { $data['ids'][] = $model->id(); } } return parent::input($prefix, $data); }