protected function getResponse()
 {
     $options = array('filter' => $this->filters, 'start' => $this->start, 'limit' => $this->limit, 'sort' => $this->sortColumn, 'dir' => $this->sortDir);
     $params = $this->params;
     $params[] = $options;
     return afCall::funcArray($this->callback, $params);
 }
Exemplo n.º 2
0
function callback($limit, $i = 1)
{
    //echo call_user_func_array(array("P$i", 'execute_me'), array());
    echo afCall::funcArray(array("P{$i}", 'execute_me'), array());
    if ($i < $limit) {
        callback($limit, $i + 1);
    }
}
 /**
  * Caches the callback result under a given unique key.
  */
 public static function cacheNamed($key, $callback, $params)
 {
     if (!function_exists('apc_fetch')) {
         return afCall::funcArray($callback, $params);
     }
     $result = apc_fetch($key);
     if ($result !== false) {
         return $result;
     }
     //error_log("cache miss: $key");
     $result = afCall::funcArray($callback, $params);
     apc_store($key, $result);
     return $result;
 }
 private static function createDataSource($view, $filters, $format = 'html')
 {
     $listView = new afListView($view);
     $selectedColumns = $listView->getSelectedColumns();
     //TODO: support also the file datasource
     $sourceType = $view->get('datasource@type');
     $className = $view->get('datasource@className');
     $modelName = $view->get('datasource@modelName');
     if ($sourceType === 'orm') {
         list($callback, $params) = self::getDataSourceCallback($view);
         $result = afCall::funcArray($callback, $params);
         if ($modelName == '') {
             $peer = $view->get('datasource/class');
             afFilterUtil::setFilters($peer, $result, $filters);
             if ($peer == "afGenerator") {
                 $peer = $params[0];
             }
             $class = self::getClassFromPeerClass($peer);
         } else {
             $peer = $modelName . 'Peer';
             afFilterUtil::setFilters($peer, $result, $filters);
             $class = $modelName;
         }
         $extractor = new afColumnExtractor($class, $selectedColumns, $format);
         if ($className === '') {
             $className = 'afPropelSource';
         }
         $source = new $className($extractor);
         $source->setCriteria($result);
     } else {
         if ($sourceType === 'static') {
             list($callback, $params) = self::getDataSourceCallback($view);
             if ($className === '') {
                 $className = 'afStaticSource';
             }
             $source = new $className($callback, $params);
             if (method_exists($source, 'setFilters')) {
                 $source->setFilters($filters);
             }
         } else {
             throw new XmlParserException('Unsupported datasource type: ' . $sourceType);
         }
     }
     return $source;
 }
 private static function isRowActionEnabled($condition, $row)
 {
     return afCall::evaluate($condition, $row);
 }
 protected function getResponse()
 {
     return afCall::funcArray($this->callback, $this->params);
 }
Exemplo n.º 7
0
<?php

include dirname(__FILE__) . '/../bootstrap/dbunit.php';
$t = new lime_test(13, new lime_output_color());
$t->is(afCall::evaluate('5 + 3', array()), 8);
$t->is(afCall::evaluate('"good"." day"', array()), 'good day');
$t->is(afCall::evaluate('strtolower("BIG")', array()), 'big');
$t->is(afCall::evaluate('$id + 3', array('id' => 100)), 103);
$t->is(afCall::evaluate('$values["name"]', array('values' => array('id' => 1, 'name' => 'my name'))), 'my name');
$t->is(afCall::evaluate('strtoupper($name)', array('name' => 'my name')), 'MY NAME');
$t->is(afCall::evaluate('StringUtil::startsWith("hello", "hell")', array()), true);
$t->is(afCall::evaluate('StringUtil::startsWith("hello", "heaven")', array()), false);
$t->is(afCall::rewriteIfOldCondition('MyPeer,isEnabled,extra1,extra2', array('id')), 'MyPeer::isEnabled(array($id,$extra1,$extra2))');
$t->is(afCall::rewriteIfOldCondition('MyPeer,isEnabled,123', array()), 'MyPeer::isEnabled(array(123))');
$t->is(afCall::rewriteIfOldCondition('MyPeer,isEnabled', array()), 'MyPeer::isEnabled(array())');
try {
    afCall::evaluate('5 + all', array());
    $t->fail();
} catch (Exception $e) {
    $t->pass();
}
function raiseException($msg)
{
    throw new Exception($msg);
}
try {
    afCall::evaluate('raiseException("hello")', array());
    $t->fail();
} catch (Exception $e) {
    $t->is($e->getMessage(), 'hello');
}
Exemplo n.º 8
0
 function executeListgridjson()
 {
     $start = $this->request->getParameterHolder()->has('start') ? $this->request->getParameterHolder()->get('start') : 0;
     $limit = $this->request->getParameterHolder()->has('limit') ? $this->request->getParameterHolder()->get('limit') : 20;
     $anode = $this->request->getParameterHolder()->has('anode') ? $this->request->getParameterHolder()->get('anode') : null;
     $uid = $this->request->getParameterHolder()->get('uid');
     $page = $start == 0 ? 1 : ceil($start / $limit) + 1;
     $parser = $this->getUser()->getAttributeHolder()->getAll('parser/grid');
     $host = "https://" . $this->getRequest()->getHost();
     foreach ($parser as $data) {
         if ($data["uid"] == $uid) {
             $parser = $data;
             break;
         }
     }
     $pager = new sfPropelPager($parser["class"], $parser["limit"]);
     if ($anode === null) {
         $c = $parser["criteria"];
     } else {
         $parser["datasource"]["method"]["params"]["criteria"] = $parser["criteria"];
         $parser["datasource"]["method"]["params"]["gid"] = $anode;
         $c = afCall::funcArray(array($parser["datasource"]["class"], $parser["datasource"]["method"]["name"]), $parser["datasource"]["method"]["params"]);
     }
     $pager->setPeerMethod($parser["select_method"]);
     $pager->setPage($page);
     $pager->setCriteria($c);
     $pager->init();
     $grid_data = new afExtjsGridData();
     $grid_data->totalCount = $pager->getNbResults();
     $items = array();
     $i = $j = 0;
     foreach ($pager->getResults() as $object) {
         foreach ($parser["columns"] as $column) {
             $j = 0;
             $id = $object->getId();
             if (method_exists($object, "get" . $column["phpname"])) {
                 $tmp = call_user_func(array($object, "get" . $column["phpname"]));
             } else {
                 $tmp = "";
             }
             if ($tmp && in_array($column["phpname"], $parser["foreign_keys"])) {
                 $items[$i][$column["column"]] = call_user_func(array($tmp, "__toString"));
             } else {
                 $items[$i][$column["column"]] = $tmp;
             }
             $items[$i]["_id"] = $anode == null ? $id : rand();
             $items[$i]["_parent"] = $anode;
             $items[$i]["_is_leaf"] = $anode == null ? false : true;
             foreach ($parser["rowactions"] as $k => $action) {
                 if (!strstr($host . $action["attributes"]["url"], "?")) {
                     $host . ($action["attributes"]["url"] .= "?");
                 }
                 if ($anode !== null) {
                     $items[$i]["action" . ($j + 1)] = $host . $action["attributes"]["url"] . "id=" . $id . "&";
                 }
                 $j++;
             }
         }
         $i++;
     }
     foreach ($items as $item) {
         $grid_data->addRowData($item);
     }
     return $this->renderText($grid_data->end());
 }
Exemplo n.º 9
0
 private function childToAttribute(&$data, $key)
 {
     if (isset($data["help"])) {
         if (!isset($data["attributes"]["help"])) {
             $data["attributes"]["help"] = $data["help"];
         }
     } else {
         $data["attributes"]["help"] = "";
     }
     if ($this->widgetHelpSettings->getHelpType()) {
         if ($this->widgetHelpSettings->getHelpType() == 1) {
             $data["attributes"]["helpType"] = "comment";
         } else {
             $data["attributes"]["helpType"] = "inline";
         }
     }
     if (isset($data["comment"])) {
         if (!isset($data["attributes"]["comment"])) {
             $data["attributes"]["comment"] = $data["comment"];
         }
     } else {
         $data["attributes"]["comment"] = "";
     }
     // Values..
     if (isset($data["attributes"]["content"])) {
         $data["attributes"]["value"] = $data["attributes"]["content"];
     } else {
         if (isset($data["value"])) {
             if (isset($data["value"]["default"]) || isset($data["value"]["static"])) {
                 if (!isset($data["value"]["static"])) {
                     $akey = "default";
                 } else {
                     $akey = "static";
                 }
                 if ($data["attributes"]["type"] == "doubletree") {
                 } else {
                     if ($data["attributes"]["type"] == "combo" || $data["attributes"]["type"] == "multicombo" || $data["attributes"]["type"] == "doublemulticombo" || $data["attributes"]["type"] == "itemSelectorAutoSuggest") {
                         $data["attributes"]["options"] = $data["value"][$akey]["value"];
                         if (isset($data["value"][$akey]["selected"])) {
                             if ($data["attributes"]["type"] == "doublemulticombo") {
                                 $data["attributes"]["selected"] = array_flip($data["value"][$akey]["selected"]);
                             } else {
                                 $data["attributes"]["selected"] = trim(implode(",", $data["value"][$akey]["selected"]), ",");
                             }
                         }
                     } else {
                         if ($data["attributes"]["type"] == "checkbox") {
                             $data["attributes"]["checked"] = true;
                         }
                         $data["attributes"]["value"] = $data["value"][$akey]["value"];
                     }
                 }
             } else {
                 try {
                     if (!class_exists($data["value"]["class"])) {
                         throw new XmlParserException("Class " . $data["value"]["class"] . " doesn't exists!");
                     }
                     if ($data["value"]["type"] == 1 && $data["value"]["class"] == $this->process["parses"][$key]["datasource"]["class"]) {
                         $params = isset($this->process["parses"][$key]["datasource"]["method"]["params"]) ? $this->process["parses"][$key]["datasource"]["method"]["params"] : array(null);
                         $class = afCall::funcArray(array($data["value"]["class"], $this->process["parses"][$key]["datasource"]["method"]["name"]), $params);
                         if (!$class || !is_object($class)) {
                             if ($this->view == "show") {
                                 throw new XmlParserException("Invalid id was specified, non-object value has been returned!");
                             } else {
                                 $class = "";
                             }
                         }
                         $params = array();
                     }
                     if (!isset($class)) {
                         $class = $data["value"]["class"];
                         $params = isset($data["value"]["method"]["params"]) ? $data["value"]["method"]["params"] : array();
                     }
                     $method = is_array($data["value"]["method"]) ? $data["value"]["method"]["name"] : $data["value"]["method"];
                     if (isset($data["attributes"]["selected"]) && $data["attributes"]["selected"] && !($class == 'ModelCriteriaFetcher' && $method == 'getDataForComboWidget')) {
                         $params[] = $data["attributes"]["selected"];
                     }
                     if ($class && !method_exists($class, $method)) {
                         throw new XmlParserException("The method " . $method . " doesn't exist in class " . (is_string($class) ? $class : get_class($class)) . "!");
                     }
                     if ($class) {
                         $value = afCall::funcArray(array($class, $method), $params);
                         if (isset($data["attributes"]["content"])) {
                             $value = $data["attributes"]["content"];
                         }
                     } else {
                         $value = "";
                     }
                     if (!is_numeric($value) && !is_array($value) && !is_string($value) && !is_bool($value) && get_class($value) != "Collection" && $value !== null && !$value instanceof sfExtjs2Var) {
                         throw new XmlParserException("Invalid value has been returned by " . $data["value"]["class"] . "->" . $data["value"]["method"] . ", number, array, object, booelan or string expected, but " . gettype($value) . " given!");
                     }
                     if (isset($data["attributes"]["type"]) && $data["attributes"]["type"] == "checkbox") {
                         if (!isset($data["attributes"]["checked"])) {
                             if ($value) {
                                 $data["attributes"]["checked"] = true;
                             } else {
                                 $data["attributes"]["checked"] = false;
                             }
                         }
                     }
                 } catch (Exception $e) {
                     throw $e;
                 }
                 if (@get_class($value) != "Collection") {
                     if (isset($data["attributes"]["type"])) {
                         if ($data["attributes"]["type"] == "itemSelectorAutoSuggest" || $data["attributes"]["type"] == "doublemulticombo" || $data["attributes"]["type"] == "doubletree") {
                             if (isset($value[1])) {
                                 $data["attributes"]["selected"] = $value[1];
                                 foreach ($value[1] as $k => $v) {
                                     if ($data["attributes"]["type"] == "doubletree") {
                                         foreach ($v["children"] as $kk => $c) {
                                             if (($idx = array_search($c, $value[0][$k]["children"])) !== false) {
                                                 unset($value[0][$k]["children"][$idx]);
                                                 $value[0][$k]["children"] = array_merge($value[0][$k]["children"], array());
                                             }
                                         }
                                         if (empty($value[0][$k]["children"])) {
                                             unset($value[0][$k]);
                                             $value[0] = array_merge($value[0], array());
                                         }
                                     } else {
                                         if (isset($value[0][$k])) {
                                             unset($value[0][$k]);
                                         }
                                     }
                                 }
                             }
                             $data["attributes"]["options"] = $value[0];
                         } else {
                             $data["attributes"][is_array($value) ? "options" : "value"] = $value;
                         }
                     }
                 } else {
                     $data["attributes"]["options"] = $value->getArray();
                     $data["attributes"]["selected"] = $value->getSelected();
                 }
             }
         }
     }
     if ($this->type === self::WIZARD) {
         $session = $this->context->getUser()->getAttributeHolder()->getAll("parser/wizard");
         if (isset($session[$this->current]["fields"])) {
             $step = $session[$this->current]["fields"];
         } else {
             if (isset($session[$this->current]) && isset($session[$this->current][sizeof($session[$this->current]) - 1]["fields"])) {
                 $step = $session[$this->current][sizeof($session[$this->current]) - 1]["fields"];
             } else {
                 $step = null;
                 // An exception for PDF reports.. tmp solution, must be properly addressed after 4.0
                 if (isset($session[2]["fields"]["report_type_value"]) && $this->current == 4 && isset($session[3]["fields"])) {
                     $step = $session[3]["fields"];
                 }
             }
         }
         if ($step && isset($data["attributes"]["name"])) {
             $name = substr($data["attributes"]["name"], strpos($data["attributes"]["name"], "2") + 3, -1);
             if ($data["attributes"]["type"] == "combo") {
                 $name .= "_value";
             }
             if (isset($step[$name])) {
                 if (isset($data["attributes"]["type"]) && $data["attributes"]["type"] != "password") {
                     if ($data["attributes"]["type"] == "checkbox" || $data["attributes"]["type"] == "radio") {
                         $data["attributes"]["checked"] = true;
                     } else {
                         if ($data["attributes"]["type"] == "combo") {
                             $data["attributes"]["selected"] = $step[$name];
                         } else {
                             if ($data["attributes"]["type"] == "itemSelectorAutoSuggest" || $data["attributes"]["type"] == "doublemulticombo" || $data["attributes"]["type"] == "multicombo") {
                                 $tmp = explode(",", $step[$name]);
                                 if (isset($value[0])) {
                                     $data["attributes"]["selected"] = $this->mapKeys($tmp, $value[0]);
                                 }
                             } else {
                                 $data["attributes"]["value"] = $step[$name];
                             }
                         }
                     }
                 }
             }
         }
         unset($session);
     }
     // Handlers
     if (isset($data["handlers"])) {
         ExtEvent::attachAll($data);
     }
 }
 public static function fetchDataInstance($view)
 {
     list($callback, $params) = afDataFacade::getDataSourceCallback($view);
     return afCall::funcArray($callback, $params);
 }