/** * Creates node for agent tree */ protected function _createNode(Model_Row_User $user) { $node = System_Locator_TableLocator::getInstance()->get('AgentTree')->createRow(); $node->id = $user->id; $node->parentId = $this->getSponsor()->id; $node->save(); }
public function testGetData() { $data = $this->object->getData(System_Locator_TableLocator::getInstance()->get('User')->select()); self::assertArrayHasKey('data', $data); self::assertArrayHasKey('total', $data); self::assertTrue($data['success']); }
public function testFilter() { $obj = new System_Filter_Db_NameToId('User', 'username'); self::assertNull($obj->filter(null)); self::assertNull($obj->filter('notExistingValue')); $user = System_Locator_TableLocator::getInstance()->get('User')->find(1)->current(); self::assertEquals($user->id, $obj->filter($user->username)); }
/** * Constructor * @param $table string|Zend_Db_Table * @param $field string */ public function __construct($table, $field) { if (!$table instanceof Zend_Db_Table_Abstract) { $this->_table = System_Locator_TableLocator::getInstance()->get($table); } else { $this->_table = $table; } $this->_field = $field; }
/** * Get logined user * @return Model_Row_User */ public function getUser() { $auth = $this->getAuth(); if (!$auth->hasIdentity()) { throw new System_Exception('No set identity'); } $user = System_Locator_TableLocator::getInstance()->get($this->_tableName)->find($auth->getIdentity()->id)->current(); if ($user == null) { throw new System_Exception('No set user'); } return $user; }
private function createTableMocks($tableName, $returnData = null) { $tableMock = $this->getMock('Model_Table_' . $tableName, array('fetchAll')); $rows = array(); if (is_array($returnData)) { foreach ($returnData as $aRow) { $rows[] = (object) $aRow; } } $tableMock->expects($this->once())->method('fetchAll')->will($this->returnValue($rows)); $this->tables[$tableName] = System_Locator_TableLocator::getInstance()->get($tableName); System_Locator_TableLocator::getInstance()->set($tableName, $tableMock); return $tableMock; }
public function testGetUser() { $username = '******'; $pwd = 'test'; System_Locator_TableLocator::getInstance()->get('User')->createRow(array('username' => $username, 'password' => md5($pwd), 'sponsorId' => 1))->save(); $authAdapter = new Model_Auth_Adapter_User($username, $pwd); $result = $this->object->getAuth()->authenticate($authAdapter); self::assertTrue($result->isValid()); $user = $this->object->getUser(); self::assertType('Model_Row_User', $user); self::assertFalse($user->isReadOnly()); self::assertTrue(isset($user->password)); //var_dump($_SESSION); }
/** * Creates user. * Creates UserSettings entry, balance and commission user accounts, and user income center in current tree. */ public function create() { $db = System_Locator_TableLocator::getInstance()->get('User')->getAdapter(); try { $db->beginTransaction(); $user = $this->_createUser(); $user->save(); $db->commit(); } catch (Exceptino $e) { $db->rollBack(); throw $e; } return $user; }
/** * Performs an authentication attempt * * @throws Zend_Auth_Adapter_Exception If authentication cannot be performed * @return Zend_Auth_Result */ public function authenticate() { $code = null; $identity = null; $messages = array(); try { $users = System_Locator_TableLocator::getInstance()->get('User'); $select = $users->select()->where('username = :username')->where('password = MD5(:password)')->bind(array('username' => $this->_username, 'password' => $this->_password)); $identity = $users->fetchRow($select); if ($identity != null) { unset($identity->password); $identity->setReadOnly(true); $code = Zend_Auth_Result::SUCCESS; $messages[] = 'Authentication successful'; } else { $code = Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID; $messages[] = 'Authentication not successful'; } } catch (Zend_Db_Exception $e) { $code = Zend_Auth_Result::FAILURE_UNCATEGORIZED; $messages[] = $e->getMessage(); } return new Zend_Auth_Result($code, $identity, $messages); }
/** * Get table from Locator * @param string $name * @return System_Db_Table_Abstract */ public function getTable($name) { return System_Locator_TableLocator::getInstance()->get($name); }
protected function setUp() { parent::setUp(); $this->table = System_Locator_TableLocator::getInstance()->get('Tree'); }
/** * Get table * @param $name * @return System_Db_Table */ protected function _getTable($name) { return System_Locator_TableLocator::getInstance()->get($this->_options['tables'][$name]); }
/** * _getTableFromString * * @param string $tableName * @return Zend_Db_Table_Abstract */ protected function _getTableFromString($tableName) { return System_Locator_TableLocator::getInstance()->get($tableName); }
/** * Returns user's account by its type * * @param string $typeId * @return Model_Row_Account */ public function getAccountByTypeId($typeId) { $accountTable = System_Locator_TableLocator::getInstance()->get('Account'); $select = $accountTable->select()->where('ownerId=?', $this->id)->where('typeId=?', $typeId); return $accountTable->fetchRow($select); }
/** * Unset Table Locator instance * Should be used only inside unit tests. */ public static function unsetInstance() { self::$_instance = null; }
public function init() { $this->_table = System_Locator_TableLocator::getInstance()->get('User'); }
/** * @covers System_Locator_TableLocator::get */ public function testGet() { $locator = System_Locator_TableLocator::getInstance(); $locator->setClassPrefix('System_Db_'); self::assertNotNull($locator->get('Table')); }
/** * Get setting by name * @param $name * @return unknown_type */ protected function getSettings($name) { return System_Locator_TableLocator::getInstance()->get('UserSettings')->getSettings($name, $this->getUser()); }
/** * Creates a User entry * @return Model_Row_User */ protected function _createUser() { $user = System_Locator_TableLocator::getInstance()->get('User')->createRow(); $user->username = $this->getUsername(); $user->setPassword($this->getPassword()); $user->email = $this->getEmail(); $user->countryCode = $this->getCountryCode(); $user->createdAt = date(DATE_ISO8601); return $user; }
public function testGetTable() { $tableMock = $this->getMock('Model_Table_User'); System_Locator_TableLocator::getInstance()->set('User', $tableMock); self::assertEquals($tableMock, $this->_object->getTable('User')); }