PageRenderTime 27ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/test/actions/actions.class.php

https://github.com/appflower/appflower_engine
PHP | 558 lines | 338 code | 208 blank | 12 comment | 22 complexity | 0f80dad2e6256ff0d21c2b33110a1944 MD5 | raw file
  1. <?php
  2. /**
  3. * test actions.
  4. *
  5. * @package manager
  6. * @subpackage test
  7. * @author Your name here
  8. * @version SVN: $Id: actions.class.php 2692 2006-11-15 21:03:55Z fabien $
  9. */
  10. class testActions extends CustomActions
  11. {
  12. /**
  13. * Executes index action
  14. *
  15. */
  16. public function executeIndex()
  17. {
  18. $this->forward('default', 'module');
  19. }
  20. public function executeEdit()
  21. {
  22. if($this->getRequest()->getMethod()==sfRequest::POST)
  23. {
  24. $result = array('success' => true);
  25. $result = json_encode($result);
  26. return $this->renderText($result);
  27. }
  28. $this->bar = "oo";
  29. $this->foobar = "lalala";
  30. }
  31. public function executeEditnew()
  32. {
  33. if($this->getRequest()->getMethod()==sfRequest::POST)
  34. {
  35. $result = array('success' => true);
  36. $result = json_encode($result);
  37. return $this->renderText($result);
  38. }
  39. $this->bar = "oo";
  40. $this->foobar = "lalala";
  41. }
  42. public function executePopup()
  43. {
  44. sfProjectConfiguration::getActive()->loadHelpers("Helper");
  45. $parser = new XmlParser();
  46. $this->layout = $parser->getLayout();
  47. $this->setLayout("layoutExtjs");
  48. $this->setTemplate("edit");
  49. return sfView::SUCCESS;
  50. }
  51. public function executeDummy()
  52. {
  53. $result = array('success' => true, 'message' => 'This is success message!');
  54. if($this->errors) {
  55. $result = array('success' => false, 'message' => 'A validation error occured!');
  56. foreach($this->errors as $error) {
  57. $result["errors"][$error[0]] = $error[1];
  58. }
  59. }
  60. $result = json_encode($result);
  61. return $this->renderText($result);
  62. }
  63. public function executeNew()
  64. {
  65. $result = array('success' => true, 'message' => 'This is new');
  66. $result = json_encode($result);
  67. return $this->renderText($result);
  68. }
  69. public function executeDelete()
  70. {
  71. $result = array('success' => true, 'message' => 'This is delete');
  72. $result = json_encode($result);
  73. return $this->renderText($result);
  74. }
  75. public function executeList()
  76. {
  77. $this->foobar = 2;
  78. $this->bar = "lalla";
  79. }
  80. public function executeButtons()
  81. {
  82. sfProjectConfiguration::getActive()->loadHelpers("Helper");
  83. $parser = new XmlParser();
  84. $this->layout = $parser->getLayout();
  85. $this->setLayout("layoutExtjs");
  86. $this->setTemplate("edit");
  87. return sfView::SUCCESS;
  88. }
  89. public function executeListtree()
  90. {
  91. sfProjectConfiguration::getActive()->loadHelpers("Helper");
  92. $parser = new XmlParser();
  93. $this->layout = $parser->getLayout();
  94. $this->setLayout("layoutExtjs");
  95. $this->setTemplate("edit");
  96. return sfView::SUCCESS;
  97. }
  98. public function executeInfo()
  99. {
  100. sfProjectConfiguration::getActive()->loadHelpers("Helper");
  101. $parser = new XmlParser();
  102. $this->layout = $parser->getLayout();
  103. $this->setLayout("layoutExtjs");
  104. $this->setTemplate("edit");
  105. return sfView::SUCCESS;
  106. }
  107. public function executeGroups()
  108. {
  109. $this->args = 0;
  110. sfProjectConfiguration::getActive()->loadHelpers("Helper");
  111. $parser = new XmlParser();
  112. $this->layout = $parser->getLayout();
  113. $this->setLayout("layoutExtjs");
  114. $this->setTemplate("edit");
  115. return sfView::SUCCESS;
  116. }
  117. public function executeListstatic()
  118. {
  119. $this->getVarHolder()->add(array("bar" => "foo11"));
  120. sfProjectConfiguration::getActive()->loadHelpers("Helper");
  121. $parser = new XmlParser();
  122. $this->layout = $parser->getLayout();
  123. $this->setLayout("layoutExtjs");
  124. $this->setTemplate("edit");
  125. return sfView::SUCCESS;
  126. }
  127. public function executeHtml()
  128. {
  129. $this->getVarHolder()->add(array("html" => "<b>this is bold<br />foo<br>bar<br /><br/>foobar</b>"));
  130. }
  131. public function executeWizard1()
  132. {
  133. sfProjectConfiguration::getActive()->loadHelpers("Helper");
  134. $parser = new XmlParser(XmlParser::WIZARD);
  135. $this->layout = $parser->getLayout();
  136. $this->setLayout("layoutExtjs");
  137. $parser->getNext();
  138. $parser->getPrevious();
  139. $this->setTemplate("edit");
  140. return sfView::SUCCESS;
  141. }
  142. public function executeWizard2()
  143. {
  144. sfProjectConfiguration::getActive()->loadHelpers("Helper");
  145. $parser = new XmlParser(XmlParser::WIZARD);
  146. $this->layout = $parser->getLayout();
  147. $this->setLayout("layoutExtjs");
  148. $parser->getNext();
  149. $parser->getPrevious();
  150. $this->setTemplate("edit");
  151. return sfView::SUCCESS;
  152. }
  153. public function executeWizard3()
  154. {
  155. sfProjectConfiguration::getActive()->loadHelpers("Helper");
  156. $parser = new XmlParser(XmlParser::WIZARD);
  157. $this->layout = $parser->getLayout();
  158. $this->setLayout("layoutExtjs");
  159. $parser->getNext();
  160. $parser->getPrevious();
  161. $this->setTemplate("edit");
  162. return sfView::SUCCESS;
  163. }
  164. public function executeLayout2()
  165. {
  166. $this->getVarHolder()->add(array("bar" => "foo11"));
  167. sfProjectConfiguration::getActive()->loadHelpers("Helper");
  168. $parser = new XmlParser(XmlParser::PAGE);
  169. $this->layout = $parser->getLayout();
  170. $this->setLayout("layoutExtjs");
  171. $this->setTemplate("edit");
  172. return sfView::SUCCESS;
  173. }
  174. public function executeLayout3()
  175. {
  176. $this->getVarHolder()->add(array("bar" => "foo11"));
  177. sfProjectConfiguration::getActive()->loadHelpers("Helper");
  178. $parser = new XmlParser(true);
  179. $this->layout = $parser->getLayout();
  180. $this->setLayout("layoutExtjs");
  181. $this->setTemplate("edit");
  182. return sfView::SUCCESS;
  183. }
  184. public function executeShow()
  185. {
  186. $this->getVarHolder()->add(array("id" => $this->getRequestParameter("id",1)));
  187. sfProjectConfiguration::getActive()->loadHelpers(array("Helper","sfExtjs2"));
  188. $parser = new XmlParser();
  189. $this->layout = $parser->getLayout();
  190. $this->setLayout("layoutExtjs");
  191. $this->setTemplate("edit");
  192. return sfView::SUCCESS;
  193. }
  194. public function executeZonepage()
  195. {
  196. }
  197. public function executeNewZone()
  198. {
  199. if($this->getRequest()->getMethod()==sfRequest::POST)
  200. {
  201. $x = new TimeZones();
  202. $formData = $this->getRequestParameter("edit");
  203. $formData = $formData[2];
  204. $x->setName($formData['name']);
  205. $x->setOffset($formData['offset']);
  206. $x->save();
  207. $result = array('success' => true);
  208. $result = json_encode($result);
  209. return $this->renderText($result);
  210. }
  211. sfProjectConfiguration::getActive()->loadHelpers("Helper");
  212. $parser = new XmlParser();
  213. $this->layout = $parser->getLayout();
  214. $this->setLayout("layoutExtjs");
  215. $this->setTemplate("edit");
  216. return sfView::SUCCESS;
  217. }
  218. public function executeShowZone()
  219. {
  220. $this->getVarHolder()->add(array("id" => $this->getRequestParameter("id")));
  221. sfProjectConfiguration::getActive()->loadHelpers("Helper");
  222. $parser = new XmlParser();
  223. $this->layout = $parser->getLayout();
  224. $this->setLayout("layoutExtjs");
  225. $this->setTemplate("edit");
  226. return sfView::SUCCESS;
  227. }
  228. public function executeListZones()
  229. {
  230. sfProjectConfiguration::getActive()->loadHelpers("Helper");
  231. $parser = new XmlParser();
  232. $this->layout = $parser->getLayout();
  233. $this->setLayout("layoutExtjs");
  234. $this->setTemplate("edit");
  235. return sfView::SUCCESS;
  236. }
  237. function executeListjson()
  238. {
  239. $start = $this->request->getParameterHolder()->has('start')?$this->request->getParameterHolder()->get('start'):0;
  240. $limit = $this->request->getParameterHolder()->has('limit')?$this->request->getParameterHolder()->get('limit'):20;
  241. $page=($start==0)?1:(ceil($start/$limit)+1);
  242. $parser = $this->getUser()->getAttributeHolder()->getAll('parser/grid');
  243. $host = "https://".$this->getRequest()->getHost();
  244. foreach($parser as $data) {
  245. if($data["proxy"] == $this->getModuleName()."/".$this->getActionName()) {
  246. $parser = $data;
  247. break;
  248. }
  249. }
  250. $pager = new sfPropelPager($parser["class"], $parser["limit"]);
  251. $pager->setPage($page);
  252. $pager->setPeerMethod($parser["select_method"]);
  253. $pager->setCriteria($parser["criteria"]);
  254. $pager->init();
  255. $grid_data = new afExtjsGridData();
  256. $grid_data->totalCount = $pager->getNbResults();
  257. $items = array();
  258. $i = $j = 0;
  259. foreach($pager->getResults() as $object) {
  260. foreach($parser["columns"] as $column) {
  261. $j = 0;
  262. $id = call_user_func(array($object,"getId"));
  263. $tmp = call_user_func(array($object,"get".$column["phpname"]));
  264. if(in_array($column["phpname"],$parser["foreign_keys"])) {
  265. $items[$i][$column["column"]] = call_user_func(array($tmp,"__toString"));
  266. } else {
  267. $items[$i][$column["column"]] = $tmp;
  268. }
  269. foreach($parser["rowactions"] as $k => $action) {
  270. if(!strstr($host.$action["attributes"]["url"],"?")) {
  271. $host.$action["attributes"]["url"] .= "?";
  272. }
  273. $items[$i]["action".($j+1)] = $host."/".$action["attributes"]["url"]."id=".$id."&";
  274. $j++;
  275. }
  276. }
  277. $i++;
  278. }
  279. foreach ($items as $item) {
  280. $grid_data->addRowData($item);
  281. }
  282. return $this->renderText($grid_data->end());
  283. }
  284. function executeListgridjson()
  285. {
  286. $start = $this->request->getParameterHolder()->has('start')?$this->request->getParameterHolder()->get('start'):0;
  287. $limit = $this->request->getParameterHolder()->has('limit')?$this->request->getParameterHolder()->get('limit'):20;
  288. $anode = $this->request->getParameterHolder()->has('anode')?$this->request->getParameterHolder()->get('anode'):null;
  289. $uid = $this->request->getParameterHolder()->get('uid');
  290. $page=($start==0)?1:(ceil($start/$limit)+1);
  291. $parser = $this->getUser()->getAttributeHolder()->getAll('parser/grid');
  292. $host = "https://".$this->getRequest()->getHost();
  293. foreach($parser as $data) {
  294. if($data["uid"] == $uid) {
  295. $parser = $data;
  296. break;
  297. }
  298. }
  299. $pager = new sfPropelPager($parser["class"], $parser["limit"]);
  300. if($anode === null) {
  301. $c = $parser["criteria"];
  302. } else {
  303. $parser["datasource"]["method"]["params"]["criteria"] = $parser["criteria"];
  304. $parser["datasource"]["method"]["params"]["gid"] = $anode;
  305. $c = afCall::funcArray(array($parser["datasource"]["class"],$parser["datasource"]["method"]["name"]),
  306. $parser["datasource"]["method"]["params"]);
  307. }
  308. $pager->setPeerMethod($parser["select_method"]);
  309. $pager->setPage($page);
  310. $pager->setCriteria($c);
  311. $pager->init();
  312. $grid_data = new afExtjsGridData();
  313. $grid_data->totalCount = $pager->getNbResults();
  314. $items = array();
  315. $i = $j = 0;
  316. foreach($pager->getResults() as $object) {
  317. foreach($parser["columns"] as $column) {
  318. $j = 0;
  319. $id = $object->getId();
  320. if(method_exists($object,"get".$column["phpname"])) {
  321. $tmp = call_user_func(array($object,"get".$column["phpname"]));
  322. } else {
  323. $tmp = "";
  324. }
  325. if($tmp && in_array($column["phpname"],$parser["foreign_keys"])) {
  326. $items[$i][$column["column"]] = call_user_func(array($tmp,"__toString"));
  327. } else {
  328. $items[$i][$column["column"]] = $tmp;
  329. }
  330. $items[$i]["_id"] = ($anode == null) ? $id : rand();
  331. $items[$i]["_parent"] = $anode;
  332. $items[$i]["_is_leaf"] = ($anode == null) ? false : true;
  333. foreach($parser["rowactions"] as $k => $action) {
  334. if(!strstr($host.$action["attributes"]["url"],"?")) {
  335. $host.$action["attributes"]["url"] .= "?";
  336. }
  337. if($anode !== null) {
  338. $items[$i]["action".($j+1)] = $host.$action["attributes"]["url"]."id=".$id."&";
  339. }
  340. $j++;
  341. }
  342. }
  343. $i++;
  344. }
  345. foreach ($items as $item) {
  346. $grid_data->addRowData($item);
  347. }
  348. return $this->renderText($grid_data->end());
  349. }
  350. }