Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * ApmModel is the base class of each models which use propel for data access
- * layer. This method will implement a __call method which will call the right
- * method of the model object.
- * @package core
- * @subpackage model
- * @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 ApmModel extends AgaviModel
- {
- /**
- * @var object The propel object.
- */
- protected $propelobj = null;
- /**
- * Set the propel object.
- * @param object The propel object.
- * @return void
- * @author Jean-Philippe Dery (jeanphilippe.dery@gmail.com)
- * @since 1.0.0
- */
- public function setPropelObject($obj)
- {
- $this->propelobj = $obj;
- }
- /**
- * Return the propel object.
- * @return object The propel object.
- * @author Jean-Philippe Dery (jeanphilippe.dery@gmail.com)
- * @since 1.0.0
- */
- public function getPropelObject()
- {
- return $this->propelobj;
- }
- /**
- * Convenience overload for accessing the user attributes with a simple
- * method call.
- * @param string The method name.
- * @param array The method arguments.
- * @author Jean-Philippe Dery (jeanphilippe.dery@gmail.com)
- * @since 1.0.0
- */
- public function __call($name, array $args)
- {
- if (preg_match('/^(get|set)(.+)$/', $name, $matches)) {
- if (method_exists($this->propelobj, $name) {
- return call_user_func_array(array($this->propelobj, $name), $args);
- }
- return null;
- }
- }
- /**
- * If the object is new, it inserts it; otherwise an update is performed.
- * @return int The number of rows affected by this insert/update.
- * @author Jean-Philippe Dery (jeanphilippe.dery@gmail.com)
- * @since 1.0.0
- */
- public function save()
- {
- return $this->propelobj->save();
- }
- /**
- * Removes this object from datastore and sets delete attribute.
- * @return void
- * @author Jean-Philippe Dery (jeanphilippe.dery@gmail.com)
- * @since 1.0.0
- */
- public function delete()
- {
- return $this->propelobj->delete();
- }
- }
- // ---------------------------------------------------------------------
- /**
- * ApmCustomerModel model is the business logic around a customer.
- * @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 ApmCustomerModel extends ApmModel
- {
- /*
- * Constructor. Initialize this model.
- * @return void
- * @author Jean-Philippe Dery (jeanphilippe.dery@gmail.com)
- * @since 1.0.0
- */
- public function __construct()
- {
- $this->setPropelObject(new DeskCustomerPeer());
- }
- /*
- * Create a new customer based on the given attributes. A new instance of
- * the customer model will be return upon creation.
- * @param array The user attributes.
- * @return object The customer model.
- * @author Jean-Philippe Dery (jeanphilippe.dery@gmail.com)
- * @since 1.0.0
- */
- public function create(array $attrs)
- {
- $customer = $this->context->getModel('ApmCustomerModel');
- $customer->setCompany($attrs['company']);
- $customer->setFirstName($attrs['firstname']);
- $customer->setLastName($attrs['lastname']);
- $customer->setEmail($attrs['email']);
- $customer->setDateCreated(new DateTime());
- $customer->save();
- return $customer;
- }
- /**
- * If the object is new, it inserts it; otherwise an update is performed and
- * the date of the update is saved.
- * @return int The number of rows affected by this insert/update.
- * @author Jean-Philippe Dery (jeanphilippe.dery@gmail.com)
- * @since 1.0.0
- */
- public function save()
- {
- $this->setDateUpdated(new DateTime());
- return parent::save();
- }
- }
- // --------------------------------------------------------------------------
- /**
- * ApmCustomerFinderModel model is the business logic around finding customers.
- * @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 ApmCustomerFinderModel extends AgaviModel implements AgaviISingletonModel
- {
- /**
- * Find a given customer based on his id.
- * @param object The propel object.
- * @return void
- * @author Jean-Philippe Dery (jeanphilippe.dery@gmail.com)
- * @since 1.0.0
- */
- public function findById($id)
- {
- $customer = DeskCustomerPeer::retrieveByPk($id)
- if ($customer) {
- $model = $this->context->getModel('ApmCustomerModel');
- $model->setPropelObject($customer);
- return $model;
- }
- return null;
- }
- }
- ?>
Add Comment
Please, Sign In to add comment