Skip to content

Commit

Permalink
adding a method for getting displayFields for rows via ajax
Browse files Browse the repository at this point in the history
  • Loading branch information
dogmatic69 committed May 22, 2012
1 parent e23275f commit 1cd7ef7
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Core/Libs/Controller/Component/InfinitasActionsComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,29 @@ public function actionAdminGetActions(){
)
);
}

/**
* @brief get a list of all the actions for the selected plugin + controller
*
* @access public
*
* @return void
*/
public function actionAdminGetRecords(){
if (!(isset($this->Controller->request->data[$this->Controller->modelClass]['plugin']) &&
isset($this->Controller->request->data[$this->Controller->modelClass]['model'] ))) {
$this->Controller->set('json', array('error'));
return;
}

$this->Controller->set(
'json',
$this->Controller->{$this->Controller->modelClass}->getRecords(
$this->Controller->request->data[$this->Controller->modelClass]['plugin'],
$this->Controller->request->data[$this->Controller->modelClass]['model']
)
);
}

/**
* @brief Simple Admin add method.
Expand Down
27 changes: 27 additions & 0 deletions Core/Libs/Model/Behavior/InfinitasBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,33 @@ public function getActions($Model, $plugin, $controller){

return $actions;
}

public function getRecords($Model, $plugin, $model) {
try {
$_Model = ClassRegistry::init($plugin . '.' . $model);

if(!isset($_Model->contentable) || !$_Model->contentable) {
return $_Model->find('list');
}

return $_Model->GlobalContent->find(
'list',
array(
'fields' => array(
$_Model->GlobalContent->alias . '.foreign_key',
'GlobalContent.title'
),
'conditions' => array(
$_Model->GlobalContent->alias . '.model' => $plugin . '.' . $model
)
)
);
}

catch(Exception $e) {
return array($e->getMessage());
}
}

/**
* actions to filter out
Expand Down

0 comments on commit 1cd7ef7

Please sign in to comment.