function checkUniqEmail(array $group)
 {
     $email = $group['email'];
     if (!Am_Validate::email($email)) {
         return ___('Please enter valid Email');
     }
     if ($this->record->getTable()->checkUniqEmail($email, $this->record ? $this->record->pk() : null) === 0) {
         return ___('An account with the same email already exists.');
     }
 }
    public function testInsert() {
        $count = count($this->dbh);


        $listener = new Transaction_TestLogger();

        $user = new User();
        $user->getTable()->getConnection()->setListener($listener);

        $this->connection->beginTransaction();

        $user->name = 'John';

        $user->save();

        $this->assertEqual($listener->pop(), 'onSave');
        $this->assertEqual($listener->pop(), 'onInsert');
        $this->assertEqual($listener->pop(), 'onPreInsert');
        $this->assertEqual($listener->pop(), 'onPreSave');
        $this->assertEqual($listener->pop(), 'onSetProperty');
        $this->assertEqual($listener->pop(), 'onTransactionBegin');
        $this->assertEqual($listener->pop(), 'onPreTransactionBegin');

        $this->assertEqual($user->id, 1);
        
        $this->assertTrue($count < count($this->dbh));

        $this->connection->commit();

        $this->assertEqual($listener->pop(), 'onTransactionCommit');
        $this->assertEqual($listener->pop(), 'onPreTransactionCommit');
    }
 public function testTest()
 {
     $user = new User();
     $record1 = $user->getTable()->find(4);
     $record2 = Doctrine_Core::getTable('User')->find(4);
     $this->assertIdentical($record1, $record2);
 }
Example #4
0
 /**
  * Remove a role
  */
 public function remove()
 {
     $role = Role::getById($this->roleId);
     if ($role && $role->isRemovable()) {
         User::getDbInstance()->update(User::getTable(), new DBExample(array('roleId' => $role->id)), array('roleId' => Option::get('roles.default-role')));
         $role->delete();
     }
 }
 public function testAddingQueriesWithNamespaces()
 {
     $registry = new Doctrine_Query_Registry();
     $registry->add('User/all', 'SELECT u.* FROM User u');
     $this->assertEqual($registry->get('all', 'User')->getDql(), 'SELECT u.* FROM User u');
     $this->manager->setQueryRegistry($registry);
     $user = new User();
     $user->getTable()->execute('all');
 }
Example #6
0
 public function testHydrateHooks()
 {
     $user = new User();
     $user->getTable()->addRecordListener(new HydrationListener());
     $user->name = 'zYne';
     $user->save();
     $this->conn->clear();
     $user = Doctrine_Query::create()->from('User u')->fetchOne();
     $this->assertEqual($user->name, 'ZYNE');
     $this->assertEqual($user->password, 'DEFAULT PASS');
 }
Example #7
0
 public function testFetchCollectionWithNameAsIndex()
 {
     $user = new User();
     $user->attribute(Doctrine::ATTR_COLL_KEY, 'name');
     $users = $user->getTable()->findAll();
     $this->assertFalse($users->contains(0));
     $this->assertEqual($users->count(), 8);
 }
                    <div class="panel-heading">
                        <h3 class="panel-title">Newest Users</h3>
                    </div>
                    <div class="panel-body">
                        <div class="table-responsive">
                            <table class="table table-bordered">
                                <thead>
                                <th>ID</th>
                                <th>Name</th>
                                <th>Username</th>
                                <th>Email</th>
                                <th>Joined</th>
                                </thead>

                                <?php 
    foreach ($user->getTable('users', array('id', 'name', 'username', 'email', 'joined'), 'joined DESC', 10) as $users) {
        //Output Last 10 Registered Users
        ?>

                                    <tbody>
                                    <tr>
                                        <td><?php 
        echo escape($users->id);
        ?>
</td>
                                        <td><?php 
        echo escape($users->name);
        ?>
</td>
                                        <td><a href="profile.php?user=<?php 
        echo escape($users->username);
Example #9
0
<?php

require_once 'Model.php';
class User extends Model
{
    protected static $table = 'contacts';
}
echo User::getTable() . PHP_EOL;
 public function testOneToManyForeignKeyRelation()
 {
     $user = new User();
     $this->assertTrue($user->getTable()->getRelation('Phonenumber') instanceof Doctrine_Relation_ForeignKey);
 }
                </div>
                <div class="panel-body">
                    <div class="table-responsive">
                        <table class="table table-bordered">
                            <thead>
                            <th>ID</th>
                            <th>Title</th>
                            <th>Author</th>
                            <th>Date Created</th>
                            <th>Action</th>
                            </thead>

                            <?php 
    $pages = new Pagination();
    //Pagination Initialization
    $data = $user->getTable('news', array('id', 'title', 'author', 'date'), 'date DESC', 100);
    $numbers = $pages->paginate($data, 6);
    $result = $pages->fetchResult();
    foreach ($result as $news) {
        //Output Last 10 Registered Users
        ?>

                                <tbody>
                                <tr>
                                    <td><?php 
        echo escape($news->id);
        ?>
</td>
                                    <td><?php 
        echo escape($news->title);
        ?>
<?php

// Initialize the Yellow Duck Framework
require_once dirname(__FILE__) . '/../../YDFramework2/YDF2_init.php';
YDConfig::set('YD_DATABASEOBJECT_PATH', YD_SELF_DIR . YD_DIRDELIM . 'includes');
YDInclude('User.php');
$user = new User();
// Let's truncate the table first
$user->executeSql('TRUNCATE ' . $user->getTable());
// Let's begin
echo "<h1>Let's add some Users</h1>";
$user->name = 'David Bittencourt';
$user->email = '*****@*****.**';
$user->is_admin = 1;
$user->birthday = '19801120';
$user->insert();
YDDebugUtil::dump($user->getValues());
echo '<p>The user "' . $user->name . '" have ID = ' . $user->id . '.</p>';
$user->reset();
$user->name = 'Pieter Claerhout';
$user->email = '*****@*****.**';
$user->is_admin = 1;
$user->birthday = null;
// we can have null values if we set the field correctly
$user->insert();
YDDebugUtil::dump($user->getValues());
echo '<p>The user "' . $user->name . '" have ID = ' . $user->id . '.</p>';
$user->reset();
$user->name = 'Francisco';
$user->email = '*****@*****.**';
$user->birthday = null;
Example #13
0
 function testTableName()
 {
     $this->assertEquals(User::getTable(), 'users');
     $this->assertEquals(Account::getTable(), 'accounts');
 }
                <div class="panel-body">
                    <div class="table-responsive">
                        <table class="table table-bordered">
                            <thead>
                            <th>ID</th>
                            <th>Name</th>
                            <th>Username</th>
                            <th>Email</th>
                            <th>Joined</th>
                            <th>Action</th>
                            </thead>

                            <?php 
    $pages = new Pagination();
    //Pagination Initialization
    $data = $user->getTable('users', array('id', 'name', 'username', 'email', 'joined'), 'joined DESC', 1000);
    $numbers = $pages->paginate($data, 10);
    $result = $pages->fetchResult();
    foreach ($result as $users) {
        //Output Last 10 Registered Users
        ?>

                            <tbody>
                            <tr>
                                <td><?php 
        echo escape($users->id);
        ?>
</td>
                                <td><?php 
        echo escape($users->name);
        ?>
    echo escape($user->data()->name);
    ?>
!</h1>
                    <p>This is a PHP OOP Member System with Bootstrap Material Design.</p>
                </div>
            </div>

            <div class="col-md-8 panel panel-default">
                <div class="panel-body">
                    <div class="panel-header">
                        <h1>News</h1>
                    </div>
                    <hr>

                    <?php 
    foreach ($user->getTable('news', array('title', 'author', 'body', 'date'), 'date DESC', 4) as $news) {
        //Output Last 4 News
        ?>

                        <div class="panel-body">
                            <h3 style="margin-top: 10px;"><?php 
        echo escape($news->title);
        ?>
 <small style="font-size: 12px;">by <?php 
        echo escape($news->author);
        ?>
</small></h3><hr>

                                <?php 
        echo html_entity_decode($news->body);
        ?>
Example #16
0
 public function testSaveAssociations()
 {
     $user = $this->objTable->find(5);
     $gf = $this->connection->getTable("Group");
     $this->assertTrue($user->Group instanceof Doctrine_Collection);
     $this->assertEqual($user->Group->count(), 1);
     $this->assertEqual($user->Group[0]->id, 3);
     // ADDING ASSOCIATED REFERENCES
     $group1 = $gf->find(1);
     $group2 = $gf->find(2);
     $user->Group[1] = $group1;
     $user->Group[2] = $group2;
     $this->assertEqual($user->Group->count(), 3);
     $user->save();
     $coll = $user->Group;
     // UNSETTING ASSOCIATED REFERENCES
     unset($user);
     $user = $this->objTable->find(5);
     $this->assertEqual($user->Group->count(), 3);
     $this->assertEqual($user->Group[1]->id, 1);
     $this->assertEqual($user->Group[2]->id, 2);
     $user->unlink('Group', array($group1->id, $group2->id), true);
     $this->assertEqual($user->Group->count(), 1);
     $user->save();
     unset($user);
     // CHECKING THE PERSISTENCE OF UNSET ASSOCIATED REFERENCES
     $this->connection->clear();
     $user = $this->objTable->find(5);
     $this->assertEqual($user->Group->count(), 1);
     $this->assertEqual($user->Group[0]->id, 3);
     $this->assertEqual($gf->findAll()->count(), 3);
     // REPLACING OLD ASSOCIATED REFERENCE
     $user->unlink('Group', 3, true);
     // you MUST first unlink old relationship
     $user->Group[1] = $group1;
     $user->Group[0] = $group2;
     $user->save();
     $user = $this->objTable->find(5);
     $this->assertEqual($user->Group->count(), 2);
     $this->assertEqual($user->Group[0]->identifier(), $group2->identifier());
     $this->assertEqual($user->Group[1]->identifier(), $group1->identifier());
     $user->unlink('Group', array(), true);
     $user->save();
     $user->free();
     $user = $this->objTable->find(5);
     $this->assertEqual($user->Group->count(), 0);
     // ACCESSING ASSOCIATION OBJECT PROPERTIES
     $user = new User();
     $this->assertTrue($user->getTable()->getRelation("Groupuser") instanceof Doctrine_Relation_ForeignKey);
     $this->assertTrue($user->Groupuser instanceof Doctrine_Collection);
     $this->assertTrue($user->Groupuser[0] instanceof Groupuser);
     $user->name = "Jack Daniels";
     $user->Group[0]->name = "Group #1";
     $user->Group[1]->name = "Group #2";
     $t1 = time();
     $t2 = time();
     $user->Groupuser[0]->added = $t1;
     $user->Groupuser[1]->added = $t2;
     $this->assertEqual($user->Groupuser[0]->added, $t1);
     $this->assertEqual($user->Groupuser[1]->added, $t2);
     $user->save();
     $user->refresh();
     $this->assertEqual($user->Groupuser[0]->added, $t1);
     $this->assertEqual($user->Groupuser[1]->added, $t2);
 }
 function checkUniqEmail(array $group)
 {
     $email = $group['email'];
     if (!Am_Validate::email($email)) {
         return ___('Please enter valid Email');
     }
     // Do the same for email if case there are plugins that use email as username.
     // We need to check email only when user is not exists, or when he change his email.
     $user_id = $this->record ? $this->record->pk() : null;
     if (!$user_id || strcasecmp($this->record->email, $email) !== 0) {
         if (!$this->record->getTable()->checkUniqEmail($email, $user_id)) {
             return ___('An account with the same email already exists.');
         }
     }
 }
Example #18
0
 /** 
  * getcontactbyUsername
  * Load the contact in the dataobject using the Username of that contact
  * @param string username
  */
 function getContactbyUsername($username)
 {
     $do_user = new User();
     $do_user->query("select idcontact from " . $do_user->getTable() . " where  username='******'");
     if (isset($do_user->idcontact) && !empty($do_user->idcontact)) {
         $this->getId($do_user->idcontact);
     } else {
         return false;
     }
 }
Example #19
0
function ajax_get_users()
{
    if (!Auth::userCan('list_users')) {
        exit;
    }
    $usersTable = User::getTable();
    $rolesTable = Role::getTable();
    $columns = array(array('db' => "{$usersTable}.id", 'dt' => 0, 'as' => 'id'), array('db' => 'username', 'dt' => 1), array('db' => 'email', 'dt' => 2), array('db' => 'display_name', 'dt' => 3), array('db' => 'joined', 'dt' => 4, 'formatter' => function ($data, $row) {
        $date = new DateTime($data);
        return '<span title="' . $date->format('Y-m-d H:i:s') . '">' . $date->format('M j, Y') . '</span>';
    }), array('db' => 'status', 'dt' => 5), array('db' => "{$rolesTable}.name", 'dt' => 6, 'as' => 'role'));
    $query = User::join($rolesTable, "{$usersTable}.role_id", '=', "{$rolesTable}.id", 'left');
    $dt = new Hazzard\Support\DataTables($_GET, $columns, $query);
    echo json_encode($dt->get());
}