Example #1
0
 /**
  * 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();
 }
Example #2
0
 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']);
 }
Example #3
0
 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));
 }
Example #4
0
 /**
  * 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;
 }
Example #5
0
 /**
  * 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;
 }
Example #6
0
 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;
 }
Example #7
0
 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);
 }
Example #8
0
 /**
  * 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;
 }
Example #9
0
 /**
  * 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);
 }
Example #10
0
 /**
  * Get table from Locator
  * @param string $name
  * @return System_Db_Table_Abstract
  */
 public function getTable($name)
 {
     return System_Locator_TableLocator::getInstance()->get($name);
 }
Example #11
0
 protected function setUp()
 {
     parent::setUp();
     $this->table = System_Locator_TableLocator::getInstance()->get('Tree');
 }
Example #12
0
File: Db.php Project: kandy/system
 /**
  * Get table
  * @param $name
  * @return System_Db_Table
  */
 protected function _getTable($name)
 {
     return System_Locator_TableLocator::getInstance()->get($this->_options['tables'][$name]);
 }
Example #13
0
 /**
  * _getTableFromString
  *
  * @param string $tableName
  * @return Zend_Db_Table_Abstract
  */
 protected function _getTableFromString($tableName)
 {
     return System_Locator_TableLocator::getInstance()->get($tableName);
 }
Example #14
0
 /**
  * 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);
 }
Example #15
0
 /**
  * Unset Table Locator instance
  * Should be used only inside unit tests.
  */
 public static function unsetInstance()
 {
     self::$_instance = null;
 }
Example #16
0
 public function init()
 {
     $this->_table = System_Locator_TableLocator::getInstance()->get('User');
 }
Example #17
0
 /**
  * @covers System_Locator_TableLocator::get
  */
 public function testGet()
 {
     $locator = System_Locator_TableLocator::getInstance();
     $locator->setClassPrefix('System_Db_');
     self::assertNotNull($locator->get('Table'));
 }
Example #18
0
 /**
  * Get setting by name
  * @param $name
  * @return unknown_type
  */
 protected function getSettings($name)
 {
     return System_Locator_TableLocator::getInstance()->get('UserSettings')->getSettings($name, $this->getUser());
 }
Example #19
0
 /**
  * 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;
 }
Example #20
0
 public function testGetTable()
 {
     $tableMock = $this->getMock('Model_Table_User');
     System_Locator_TableLocator::getInstance()->set('User', $tableMock);
     self::assertEquals($tableMock, $this->_object->getTable('User'));
 }