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. |
- // +---------------------------------------------------------------------------+
- /**
- * ApmMemberModel model is the business logic around a member.
- * @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 ApmMemberModel extends ApmBaseOmModel
- {
- /**
- * @constant int The developer type id.
- */
- const TYPE_DEVELOPER = 1;
- /**
- * @constant int The customer type id.
- */
- const TYPE_CUSTOMER = 2;
- /**
- * Initialize this model.
- * @param array [om] To specify the default record.
- * @return void
- * @author Jean-Philippe Dery (jeanphilippe.dery@gmail.com)
- * @since 1.0.0
- */
- public function initialize(AgaviContext $context, array $parameters = array())
- {
- parent::initialize($context, $parameters);
- $this->setObjectModel(isset($parameters['om']) ? $parameters['om'] : new DeskMember());
- }
- /**
- * Return the member's full name.
- * @return string The member's full name.
- * @author Jean-Philippe Dery (jeanphilippe.dery@gmail.com)
- * @since 1.0.0
- */
- public function getName()
- {
- return sprintf('%1$s %2$s',
- $this->getFirstname(),
- $this->getLastname()
- );
- }
- /**
- * Return the name associated with the member type.
- * @return string The type's name.
- * @author Jean-Philippe Dery (jeanphilippe.dery@gmail.com)
- * @since 1.0.0
- */
- public function getTypeName()
- {
- switch ($this->getType()) {
- case self::TYPE_DEVELOPER : return 'Developer';
- case self::TYPE_CUSTOMER : return 'Customer';
- }
- return '';
- }
- /**
- * 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();
- }
- }
- ?>
- <?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. |
- // +---------------------------------------------------------------------------+
- /**
- * ApmMembersModel model is the business logic around a member.
- * @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 ApmMembersModel extends ApmBaseModel
- {
- /**
- * Create a new member.
- * @param int The member type.
- * @param array The members attributes.
- * @return object The member.
- * @author Jean-Philippe Dery (jeanphilippe.dery@gmail.com)
- * @since 1.0.0
- */
- public function create($type, array $attrs)
- {
- $member = $this->context->getModel('ApmMember');
- $member->fromArray($attrs);
- $member->setType($type);
- $member->setDateCreated(new DateTime());
- $member->save();
- return $member;
- }
- /**
- * Create a new member with an administrator status.
- * @param array The members attributes.
- * @return object The member.
- * @author Jean-Philippe Dery (jeanphilippe.dery@gmail.com)
- * @since 1.0.0
- */
- public function createAdministratorMember(array $attrs)
- {
- return $this->create(ApmMemberModel::TYPE_ADMINISTRATOR, $attrs);
- }
- /**
- * Create a new member with a developer status.
- * @param array The members attributes.
- * @return object The member.
- * @author Jean-Philippe Dery (jeanphilippe.dery@gmail.com)
- * @since 1.0.0
- */
- public function createDeveloperMember(array $attrs)
- {
- return $this->create(ApmMemberModel::TYPE_DEVELOPER, $attrs);
- }
- /**
- * Create a new member with a customer status.
- * @param int The customer he is associated with.
- * @param array The members attributes.
- * @return object The member.
- * @author Jean-Philippe Dery (jeanphilippe.dery@gmail.com)
- * @since 1.0.0
- */
- public function createCustomerMember($customerId, array $attrs)
- {
- // TODO
- }
- /**
- * Retrieve a member based on his id.
- * @param int The member id.
- * @return object The member.
- * @author Jean-Philippe Dery (jeanphilippe.dery@gmail.com)
- * @since 1.0.0
- */
- public function getMemberById($memberId)
- {
- if ($member = DeskMemberPeer::retrieveByPk($memberId)) {
- return $this->context->getModel('ApmMember', array('om' => $member));
- }
- return null;
- }
- /**
- * Retrieves members based on their ids.
- * @param array The ids.
- * @return array The members.
- * @author Jean-Philippe Dery (jeanphilippe.dery@gmail.com)
- * @since 1.0.0
- */
- public function getMemberByIds(array $memberIds)
- {
- $members = array();
- $criteria = new Criteria();
- $criteria->add(DeskMemberPeer::ID, $memberIds, Criteria::IN);
- foreach (DeskMemberPeer::doSelect($criteria) as $member) {
- $members[] = $this->context->getModel('ApmMember', array('om' => $member));
- }
- return $members;
- }
- /**
- * Retrieve a member based on his username and password
- * @param string The username.
- * @param string The password.
- * @param bool True to encode the password.
- * @return mixed The member or false if it failed.
- * @author Jean-Philippe Dery (jeanphilippe.dery@gmail.com)
- * @since 1.0.0
- */
- public function getMemberByUsername($username, $password, $encode = true)
- {
- $password = $encode ? md5($password) : $password;
- $criteria = new Criteria();
- $criteria->add(DeskMemberPeer::USERNAME, $username);
- $criteria->add(DeskMemberPeer::PASSWORD, $password);
- if ($member = DeskMemberPeer::doSelectOne($criteria)) {
- return $this->context->getModel('ApmMember', array('om' => $member));
- }
- return null;
- }
- }
- ?>
Add Comment
Please, Sign In to add comment