Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // +---------------------------------------------------------------------------+
- // | This file is part of a Agavi Propel Mootools (APM) Project. |
- // | Copyright (C) Jean-Philippe Dery (jeanphilippe.dery@gmail.com) |
- // | |
- // | For the full copyright and license information, please view the LICENSE |
- // | file that was distributed with this source code. |
- // +---------------------------------------------------------------------------+
- /**
- * ApmProjectsModel model is the business logic around a project.
- * @package model
- * @subpackage models
- * @author Jean-Philippe Dery (jeanphilippe.dery@gmail.com)
- * @copyright Jean-Philippe Dery (jeanphilippe.dery@gmail.com)
- * @since 1.0.0
- * @version 1.0.0
- */
- class ApmProjectsModel extends ApmBaseStaticModel
- {
- /**
- * Transfer a general field name associated to this model to a propel
- * constant field name the database transparent from the outside.
- * @param string The field name.
- * @return string The translated field name.
- * @author Jean-Philippe Dery (jeanphilippe.dery@gmail.com)
- * @since 1.0.0
- */
- protected function translateFieldName($name)
- {
- try {
- $translation = DeskProjectPeer::translateFieldName($name, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_COLNAME);
- } catch (PropelException $e) {
- return null;
- }
- return $translation;
- }
- /**
- * Return a list of projects based on criterias.
- * @param object The criteria.
- * @param mixed The order.
- * @param int The limit.
- * @param int The offset.
- * @return array The projects.
- * @author Jean-Philippe Dery (jeanphilippe.dery@gmail.com)
- * @since 1.0.0
- */
- protected function getProjects(Criteria $criteria = null, $order = null, $limit = null, $offset = null)
- {
- $projects = array();
- $criteria = $criteria ? $criteria : new Criteria();
- $criteria->addJoin(DeskProjectPeer::CUSTOMER_ID, DeskCustomerPeer::ID, Criteria::INNER_JOIN);
- $this->setCriteriaOrder($criteria, $order);
- $this->setCriteriaLimit($criteria, $limit);
- $this->setCriteriaOffset($criteria, $offset);
- foreach (DeskProjectPeer::doSelect($criteria) as $project) {
- $projects[] = $this->context->getModel('ApmProject', null, array('om' => $project));
- }
- return $projects;
- }
- /**
- * Retrieve all the project that have ever been created.
- * @param mixed The order.
- * @param int The limit.
- * @param int The offset.
- * @return array The projects.
- * @author Jean-Philippe Dery (jeanphilippe.dery@gmail.com)
- * @since 1.0.0
- */
- public function getAllProjects($order = null, $limit = null, $offset = null)
- {
- return $this->getProjects(new Criteria(), $order, $limit, $offset);
- }
- /**
- * Retrieve all the finished projects.
- * @param mixed The order.
- * @param int The limit.
- * @param int The offset.
- * @return array The projects.
- * @author Jean-Philippe Dery (jeanphilippe.dery@gmail.com)
- * @since 1.0.0
- */
- public function getFinishedProjects($order = null, $limit = null, $offset = null)
- {
- $criteria = new Criteria();
- $criteria->add(DeskProjectPeer::PERCENT_DONE, 100);
- return $this->getProjects($criteria, $order, $limit, $offset);
- }
- /**
- * Retrieve all the unfinished projects.
- * @param mixed The order.
- * @param int The limit.
- * @param int The offset.
- * @return array The projects.
- * @author Jean-Philippe Dery (jeanphilippe.dery@gmail.com)
- * @since 1.0.0
- */
- public function getUnfinishedProjects($order = null, $limit = null, $offset = null)
- {
- $criteria = new Criteria();
- $criteria->add(DeskProjectPeer::PERCENT_DONE, 100, Criteria::LESS_THAN);
- return $this->getProjects($criteria, $order, $limit, $offset);
- }
- /**
- * Retrieve a project based on his id.
- * @param int The project id.
- * @return object The project.
- * @author Jean-Philippe Dery (jeanphilippe.dery@gmail.com)
- * @since 1.0.0
- */
- public function getProjectById($projectId)
- {
- $criteria = new Criteria();
- $criteria->add(DeskProjectPeer::ID, $projectId);
- return array_pop($this->getProjects($criteria), null, 1);
- }
- }
- ?>
- <?php
- // +---------------------------------------------------------------------------+
- // | This file is part of a Agavi Propel Mootools (APM) Project. |
- // | Copyright (C) Jean-Philippe Dery (jeanphilippe.dery@gmail.com) |
- // | |
- // | For the full copyright and license information, please view the LICENSE |
- // | file that was distributed with this source code. |
- // +---------------------------------------------------------------------------+
- class Panel_ProjectPaneAction extends ApmBaseAction
- {
- public function executeRead(AgaviRequestDataHolder $rd)
- {
- $projectsModel = $this->context->getModel('ApmProjects');
- switch ($rd->getParameter('filter', 'unfinished')) {
- case 'all' :
- $projects = $projectsModel->getAllProjects();
- break;
- case 'finished' :
- $projects = $projectsModel->getFinishedProjects();
- break;
- case 'unfinished' :
- $projects = $projectsModel->getUnfinishedProjects();
- break;
- }
- $this->setAttribute('projects', $projects);
- return 'Success';
- }
- public function getDefaultViewName()
- {
- return 'Success';
- }
- }
- ?>
Add Comment
Please, Sign In to add comment