Exemple #1
0
 /**
  * Pushes a new model on to the stack
  *
  * @param   \Hubzero\Database\Relational|static  $model  The model to add
  * @return  void
  * @since   2.0.0
  **/
 public function push(Relational $model)
 {
     // Index by primary key if possible, otherwise plain incremental array
     // Also check to see if that key already exists.  If so, we'll just start
     // appending items to the array.  This will result in a mixed array and
     // subsequent items will not be seekable.
     if ($model->getPkValue() && (!is_array($this->rows) || !array_key_exists($model->getPkValue(), $this->rows))) {
         $this->rows[$model->getPkValue()] = $model;
     } else {
         $this->rows[] = $model;
     }
 }
Exemple #2
0
 /**
  * Associates the model provided back to the model by way of their proper keys
  *
  * Because this is a singular relationship, we never expect to have more than one
  * model at at time.
  *
  * @param   object   $model     The model to associate
  * @param   closure  $callback  A callback to potentially append additional data
  * @return  object
  * @since   2.0.0
  **/
 public function associate($model, $callback = null)
 {
     $model->set($this->relatedKey, $this->model->getPkValue());
     if (isset($callback) && is_callable($callback)) {
         call_user_func_array($callback, [$model]);
     }
     return $model;
 }
Exemple #3
0
 /**
  * Computes the (distinct) name of the asset
  *
  * @return  string
  * @since   2.0.0
  */
 private function getAssetName()
 {
     // @FIXME: this scheme won't always work...
     //          * namespace isn't always defined, at which point the model name is the namespace
     //          * namespace might be something like time_hub, which should become time.hub
     //          * non-integer ids will fail
     return strtolower("com_{$this->model->getNamespace()}.{$this->model->getModelName()}.") . (int) $this->model->getPkValue();
 }