21 import(
'Dataface/LanguageTool.php');
33 if ( $conf === null ){
37 $this->actions =& $conf;
46 import(
'Dataface/ConfigTool.php');
48 $actions =& $configTool->loadConfig(
'actions', null);
49 foreach ( array_keys(
$actions) as $key){
51 $action[
'name'] = $key;
52 if ( !isset($action[
'order']) ) $action[
'order'] = 0;
53 if ( !isset($action[
'id']) ) $action[
'id'] = $action[
'name'];
54 if ( !isset($action[
'label']) ) $action[
'label'] = str_replace(
'_',
' ',ucfirst($action[
'name']));
55 if ( !isset($action[
'accessKey'])) $action[
'accessKey'] = substr($action[
'name'],0,1);
59 if ( isset($action[
'description']) ){
60 $action[
'description'] = df_translate(
'actions.'.$action[
'name'].
'.description', $action[
'description']);
62 if ( isset($action[
'label']) ){
63 $action[
'label'] = df_translate(
'actions.'.$action[
'name'].
'.label',$action[
'label']);
66 $this->actions[$key] =& $action;
75 import(
'Dataface/Table.php');
79 if ( !
$table->_actionsLoaded ){
81 $table->getActions($params);
95 if ( !isset($action) ){
96 if ( @$params[
'table'] ){
99 if ( !isset($this->tableActions[$params[
'table']]) ){
100 $this->tableActions[$params[
'table']] = array();
102 $actions =& $this->tableActions[$params[
'table']];
106 if ( !isset($params[
'name']) or !$params[
'name'] ){
107 throw new Exception(
"ActionTool::getAction() requires 'name' parameter to be specified.", E_USER_ERROR);
109 if ( !isset(
$actions[$params[
'name']] ) ) {
113 "No action found named '".$params[
'name'].
"'",
114 array(
'name'=>$params[
'name'])
121 $action =
$actions[$params[
'name']];
125 if ( isset($action[
'selected_condition']) ) {
126 $action[
'selected'] =
$app->testCondition($action[
'selected_condition'], $params);
132 foreach (array_keys($action) as $attribute){
140 if ( preg_match(
'/condition/i',$attribute) )
continue;
141 if ( isset($action[$attribute.
'_condition']) and !
$app->testCondition($action[$attribute.
'_condition'], $params) ){
142 $action[$attribute] = null;
144 $action[$attribute] =
$app->parseString($action[$attribute], $params);
161 if ( !is_array($params) ){
162 trigger_error(
"In Dataface_ActionTool::getActions(), expected parameter to be an array but received a scalar: ".$params.
".".
Dataface_Error::printStackTrace(), E_USER_ERROR);
169 if ( isset($params[
'table']) )
$tablename = $params[
'table'];
170 if ( isset($params[
'record']) and is_a($params[
'record'],
'Dataface_Record') )
$tablename = $params[
'record']->_table->tablename;
171 else if ( isset($params[
'record']) and is_a($params[
'record'],
'Dataface_RelatedRecord'))
$tablename = $params[
'record']->_record->_table->tablename;
173 if ( isset( $params[
'record'] ) && is_a($params[
'record'],
'Dataface_Record') ){
175 $params[
'table'] = $params[
'record']->_table->tablename;
176 }
else if ( isset($params[
'record']) && is_a($params[
'record'],
'Dataface_RelatedRecord') ){
178 $temp =& $params[
'record']->getParent();
179 $params[
'table'] = $temp->_table->tablename;
182 $params[
'relationship'] = $params[
'record']->_relationshipName;
185 if ( @$params[
'relationship']){
186 if ( strpos($params[
'relationship'],
'.') !==
false ){
188 list($params[
'table'],$params[
'relationship']) = explode(
'.', $params[
'relationship']);
195 if ( !
$table->_actionsLoaded ){
197 $table->getActions($tparams,
true);
204 if ( @$params[
'table'] ){
205 if ( !isset($this->tableActions[$params[
'table']]) ){
206 $this->tableActions[$params[
'table']] = array();
208 $actions = $this->tableActions[$params[
'table']];
212 foreach ( array_keys(
$actions) as $key ){
213 if ( isset($action) ) unset($action);
215 $action[
'atts'] = array();
217 if ( @$params[
'name'] and @$params[
'name'] !== @$action[
'name'])
continue;
218 if ( @$params[
'id'] and @$params[
'id'] !== @$action[
'id'])
continue;
220 if ( isset($params[
'category']) and $params[
'category'] !== @$action[
'category'])
continue;
223 if ( @$params[
'table'] && !(@$action[
'table'] == @$params[
'table'] or @in_array(@$params[
'table'], @$action[
'table']) ))
continue;
226 if ( @$params[
'relationship'] && @$action[
'relationship'] && @$action[
'relationship'] != @$params[
'relationship'])
continue;
229 if ( @$action[
'condition'] and !
$app->testCondition($action[
'condition'], $params) ) {
232 if ( isset($params[
'record']) ){
233 if ( isset($action[
'permission']) and !$params[
'record']->checkPermission($action[
'permission']) ){
237 if ( isset( $action[
'permission'] ) and !
$app->checkPermission($action[
'permission'])){
242 if ( @$action[
'selected_condition'] ) $action[
'selected'] =
$app->testCondition($action[
'selected_condition'], $params);
244 $query =
$app->getQuery();
245 if ( @$action[
'name'] == @$query[
'-action'] ) $action[
'selected'] =
true;
248 if ( isset($action[
'visible']) and !$action[
'visible'])
continue;
250 foreach (array_keys($action) as $attribute){
259 if ( preg_match(
'/condition/i',$attribute) )
continue;
260 if ( is_array($action[$attribute]) )
continue;
261 if ( isset($action[$attribute.
'_condition']) and !
$app->testCondition($action[$attribute.
'_condition'], $params) ){
263 $action[$attribute] = null;
265 $action[$attribute] =
$app->parseString($action[$attribute], $params);
267 if ( strpos($attribute,
'atts:') === 0 ){
268 $attAtt = substr($attribute, 5);
269 if ( !preg_match(
'/_condition$/', $attAtt) ){
270 $action[
'atts'][$attAtt] = $action[$attribute];
274 $out[$key] =& $action;
279 uasort(
$out, array(&$this,
'_compareActions'));
287 if ( @$a[
'order'] < @$b[
'order'] )
return -1;
297 if ( @$action[
'table'] ){
298 $this->tableActions[$action[
'table']][$name] = $action;
300 if ( $query[
'-table'] == $action[
'table'] ){
302 $this->actions[$name] = $this->tableActions[$action[
'table']][$name];
306 $this->actions[$name] = $action;
315 if ( @$action[
'table'] ){
316 unset($this->tableActions[$action[
'table']][$name]);
318 unset( $this->actions[$name] );
326 static $instance = 0;