Example #1
0
 /**
  * @inheritDoc
  */
 public function prepareModel(ModelInterface $model)
 {
     $out = array();
     $name = $model->instanceLabel();
     if (empty($name) && $model instanceof ActiveRecord) {
         $name = $model->getPrimaryKey();
     }
     $out[] = "# " . \Yii::t('resource', "{resourceLabel}: {resourceName}", array('{resourceLabel}' => $model->classLabel(), '{resourceName}' => $name)) . "\n";
     $attributeNames = $model->getVisibleAttributeNames();
     foreach ($attributeNames as $name) {
         if (!empty($model->{$name})) {
             $out[] = "__" . $model->getAttributeLabel($name) . "__ `" . $model->{$name} . "`\n";
         }
     }
     return implode("\n", $out) . "\n---\n";
 }
Example #2
0
 /**
  * @inheritDoc
  */
 public function prepareModel(ModelInterface $model)
 {
     $names = $model->getVisibleAttributeNames();
     $row = array();
     foreach ($names as $name) {
         $row[] = $model->{$name};
     }
     if ($model->hasErrors()) {
         foreach ($model->getErrors() as $attribute => $errors) {
             $names[] = $attribute . '_ERRORS';
             $row[] = implode(' and ', $errors);
         }
     }
     return array($names, $row);
 }
Example #3
0
 /**
  * Prepare a resource model
  *
  * @param ModelInterface $model the resource to prepare
  *
  * @return array the prepared response
  */
 public function prepareModel(ModelInterface $model)
 {
     $prepared = array();
     $links = $model->links();
     foreach ($model->getVisibleAttributeNames() as $name) {
         $prepared[$name] = $this->prepare($model->{$name});
     }
     if ($model instanceof ActiveRecord) {
         $embedded = array();
         foreach ($model->getMetaData()->relations as $name => $config) {
             if (!$model->hasRelated($name)) {
                 continue;
             }
             $embedded[$name] = $this->prepare($model->getRelated($name));
         }
         if (count($embedded)) {
             $prepared['_embedded'] = $embedded;
         }
         if ($model->getIsDeleted()) {
             $prepared['_deleted'] = true;
         }
     }
     if ($model->hasErrors()) {
         $prepared['_errors'] = $model->getErrors();
     }
     $prepared['_links'] = $links;
     return $prepared;
 }
Example #4
0
 /**
  * Applies the user input to a given model. Child classes should
  * override this if they need to do anything special.
  *
  * @param array $input the user input
  * @param ModelInterface $model the model to apply the input to
  * @return bool true if the input was applied successfully, note this is not
  * the same as validation.
  */
 public function applyUserInput($input, ModelInterface $model)
 {
     $model->setAttributes($input);
     return true;
 }