daily pastebin goal
69%
SHARE
TWEET

Untitled

a guest Mar 13th, 2018 146 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. <?php
  126. // +---------------------------------------------------------------------------+
  127. // | This file is part of a Agavi Propel Mootools (APM) Project.               |
  128. // | Copyright (C) Jean-Philippe Dery (jeanphilippe.dery@gmail.com)            |
  129. // |                                                                           |
  130. // | For the full copyright and license information, please view the LICENSE   |
  131. // | file that was distributed with this source code.                          |
  132. // +---------------------------------------------------------------------------+
  133.  
  134. class Panel_ProjectPaneAction extends ApmBaseAction
  135. {
  136.     public function executeRead(AgaviRequestDataHolder $rd)
  137.     {
  138.         $projectsModel = $this->context->getModel('ApmProjects');
  139.         switch ($rd->getParameter('filter', 'unfinished')) {
  140.             case 'all' :
  141.                 $projects = $projectsModel->getAllProjects();
  142.                 break;
  143.             case 'finished' :
  144.                 $projects = $projectsModel->getFinishedProjects();
  145.                 break;
  146.             case 'unfinished' :
  147.                 $projects = $projectsModel->getUnfinishedProjects();
  148.                 break;
  149.         }
  150.         $this->setAttribute('projects', $projects);
  151.         return 'Success';
  152.     }
  153.    
  154.     public function getDefaultViewName()
  155.     {
  156.         return 'Success';
  157.     }
  158. }
  159. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top