Guest User

Untitled

a guest
Mar 13th, 2018
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.38 KB | None | 0 0
  1. <?php
  2. // +---------------------------------------------------------------------------+
  3. // | This file is part of a Agavi Propel Mootools (APM) Project. |
  4. // | Copyright (C) Jean-Philippe Dery (jeanphilippe.dery@gmail.com) |
  5. // | |
  6. // | For the full copyright and license information, please view the LICENSE |
  7. // | file that was distributed with this source code. |
  8. // +---------------------------------------------------------------------------+
  9.  
  10. /**
  11. * ApmProjectsModel model is the business logic around a project.
  12. * @package model
  13. * @subpackage models
  14. * @author Jean-Philippe Dery (jeanphilippe.dery@gmail.com)
  15. * @copyright Jean-Philippe Dery (jeanphilippe.dery@gmail.com)
  16. * @since 1.0.0
  17. * @version 1.0.0
  18. */
  19. class ApmProjectsModel extends ApmBaseStaticModel
  20. {
  21. /**
  22. * Transfer a general field name associated to this model to a propel
  23. * constant field name the database transparent from the outside.
  24. * @param string The field name.
  25. * @return string The translated field name.
  26. * @author Jean-Philippe Dery (jeanphilippe.dery@gmail.com)
  27. * @since 1.0.0
  28. */
  29. protected function translateFieldName($name)
  30. {
  31. try {
  32. $translation = DeskProjectPeer::translateFieldName($name, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_COLNAME);
  33. } catch (PropelException $e) {
  34. return null;
  35. }
  36. return $translation;
  37. }
  38.  
  39. /**
  40. * Return a list of projects based on criterias.
  41. * @param object The criteria.
  42. * @param mixed The order.
  43. * @param int The limit.
  44. * @param int The offset.
  45. * @return array The projects.
  46. * @author Jean-Philippe Dery (jeanphilippe.dery@gmail.com)
  47. * @since 1.0.0
  48. */
  49. protected function getProjects(Criteria $criteria = null, $order = null, $limit = null, $offset = null)
  50. {
  51. $projects = array();
  52. $criteria = $criteria ? $criteria : new Criteria();
  53. $criteria->addJoin(DeskProjectPeer::CUSTOMER_ID, DeskCustomerPeer::ID, Criteria::INNER_JOIN);
  54. $this->setCriteriaOrder($criteria, $order);
  55. $this->setCriteriaLimit($criteria, $limit);
  56. $this->setCriteriaOffset($criteria, $offset);
  57. foreach (DeskProjectPeer::doSelect($criteria) as $project) {
  58. $projects[] = $this->context->getModel('ApmProject', null, array('om' => $project));
  59. }
  60. return $projects;
  61. }
  62.  
  63. /**
  64. * Retrieve all the project that have ever been created.
  65. * @param mixed The order.
  66. * @param int The limit.
  67. * @param int The offset.
  68. * @return array The projects.
  69. * @author Jean-Philippe Dery (jeanphilippe.dery@gmail.com)
  70. * @since 1.0.0
  71. */
  72. public function getAllProjects($order = null, $limit = null, $offset = null)
  73. {
  74. return $this->getProjects(new Criteria(), $order, $limit, $offset);
  75. }
  76.  
  77. /**
  78. * Retrieve all the finished projects.
  79. * @param mixed The order.
  80. * @param int The limit.
  81. * @param int The offset.
  82. * @return array The projects.
  83. * @author Jean-Philippe Dery (jeanphilippe.dery@gmail.com)
  84. * @since 1.0.0
  85. */
  86. public function getFinishedProjects($order = null, $limit = null, $offset = null)
  87. {
  88. $criteria = new Criteria();
  89. $criteria->add(DeskProjectPeer::PERCENT_DONE, 100);
  90. return $this->getProjects($criteria, $order, $limit, $offset);
  91. }
  92.  
  93. /**
  94. * Retrieve all the unfinished projects.
  95. * @param mixed The order.
  96. * @param int The limit.
  97. * @param int The offset.
  98. * @return array The projects.
  99. * @author Jean-Philippe Dery (jeanphilippe.dery@gmail.com)
  100. * @since 1.0.0
  101. */
  102. public function getUnfinishedProjects($order = null, $limit = null, $offset = null)
  103. {
  104. $criteria = new Criteria();
  105. $criteria->add(DeskProjectPeer::PERCENT_DONE, 100, Criteria::LESS_THAN);
  106. return $this->getProjects($criteria, $order, $limit, $offset);
  107. }
  108.  
  109. /**
  110. * Retrieve a project based on his id.
  111. * @param int The project id.
  112. * @return object The project.
  113. * @author Jean-Philippe Dery (jeanphilippe.dery@gmail.com)
  114. * @since 1.0.0
  115. */
  116. public function getProjectById($projectId)
  117. {
  118. $criteria = new Criteria();
  119. $criteria->add(DeskProjectPeer::ID, $projectId);
  120. return array_pop($this->getProjects($criteria), null, 1);
  121. }
  122. }
  123. ?>
  124.  
  125.  
  126. <?php
  127. // +---------------------------------------------------------------------------+
  128. // | This file is part of a Agavi Propel Mootools (APM) Project. |
  129. // | Copyright (C) Jean-Philippe Dery (jeanphilippe.dery@gmail.com) |
  130. // | |
  131. // | For the full copyright and license information, please view the LICENSE |
  132. // | file that was distributed with this source code. |
  133. // +---------------------------------------------------------------------------+
  134.  
  135. class Panel_ProjectPaneAction extends ApmBaseAction
  136. {
  137. public function executeRead(AgaviRequestDataHolder $rd)
  138. {
  139. $projectsModel = $this->context->getModel('ApmProjects');
  140. switch ($rd->getParameter('filter', 'unfinished')) {
  141. case 'all' :
  142. $projects = $projectsModel->getAllProjects();
  143. break;
  144. case 'finished' :
  145. $projects = $projectsModel->getFinishedProjects();
  146. break;
  147. case 'unfinished' :
  148. $projects = $projectsModel->getUnfinishedProjects();
  149. break;
  150. }
  151. $this->setAttribute('projects', $projects);
  152. return 'Success';
  153. }
  154.  
  155. public function getDefaultViewName()
  156. {
  157. return 'Success';
  158. }
  159. }
  160. ?>
Add Comment
Please, Sign In to add comment