private function fill_data(&$obj)
 {
     $ary = null;
     if ($obj->has_association($this->association_name)) {
         $ary = $obj->get_association($this->association_name);
     } else {
         $ary = new SilkAssociationCollection();
         if ($this->child_class != '' && $this->child_field != '') {
             $class = orm()->{$this->child_class};
             if ($obj->{$obj->id_field} > -1) {
                 $queryattrs = $this->extra_params;
                 $conditions = "{$this->child_field} = ?";
                 $params = array($obj->{$obj->id_field});
                 if (array_key_exists('conditions', $this->extra_params)) {
                     $conditions = "({$conditions}) AND ({$this->extra_params['conditions'][0]})";
                     if (count($this->extra_params['conditions']) > 1) {
                         $params = array_merge($params, array_slice($this->extra_params['conditions'], 1));
                     }
                 }
                 $queryattrs['conditions'] = array_merge(array($conditions), $params);
                 $ary->children = $class->find_all($queryattrs);
                 $obj->set_association($this->association_name, $ary);
             }
         }
     }
     return $ary;
 }
 /**
  * Returns the associated has_one association's objects.
  *
  * @return mixed The object, if it exists.  If not, null.
  * @author Ted Kulp
  **/
 public function get_data(&$obj)
 {
     $child = null;
     if ($obj->has_association($this->association_name)) {
         $child = $obj->get_association($this->association_name);
     } else {
         if ($this->child_class != '' && $this->child_field != '') {
             $class = orm()->{$this->child_class};
             if ($this->parent_class->{$this->parent_class->id_field} > -1) {
                 $queryattrs = $this->extra_params;
                 $conditions = "{$this->child_field} = ?";
                 $params = array($this->parent_class->{$this->parent_class->id_field});
                 if (array_key_exists('conditions', $this->extra_params)) {
                     $conditions = "({$conditions}) AND ({$this->extra_params['conditions'][0]})";
                     if (count($this->extra_params['conditions']) > 1) {
                         $params = array_merge($params, array_slice($this->extra_params['conditions'], 1));
                     }
                 }
                 $queryattrs['conditions'] = array_merge(array($conditions), $params);
                 $child = $class->find($queryattrs);
                 $obj->set_association($this->association_name, $child);
             }
         }
     }
     return $child;
 }
 public function init($arr)
 {
     $obj = new BasicModel();
     foreach ($arr as $key => $value) {
         $key = orm($key);
         $obj->{$key} = $value;
     }
     return $obj;
 }
 function login()
 {
     if ($_REQUEST['openid_mode']) {
         $consumer = $this->get_consumer();
         $response = $consumer->complete(SilkRequest::get_requested_uri(true));
         $msg = '';
         if ($response->status == Auth_OpenID_CANCEL) {
             // This means the authentication was cancelled.
             $this->validation_errors[] = 'Verification cancelled.';
         } else {
             if ($response->status == Auth_OpenID_FAILURE) {
                 // Authentication failed; display the error message.
                 $this->validation_errors[] = "OpenID authentication failed: " . $response->message;
             } else {
                 if ($response->status == Auth_OpenID_SUCCESS) {
                     $esc_identity = htmlentities($response->getDisplayIdentifier());
                     $user = orm('user')->find_by_openid($esc_identity);
                     if ($user != null) {
                         self::$current_user = $user;
                         $_SESSION['silk_user'] = $user;
                         return true;
                     } else {
                         $this->validation_errors[] = "No user associated to this login";
                     }
                 }
             }
         }
     } else {
         if ($this->params != null && is_array($this->params)) {
             if ($this->params['username'] != '' && $this->params['password'] != '') {
                 $user = orm('silk_user')->find_by_username($this->params['username']);
                 if ($user != null) {
                     //Add salt
                     if ($user->password == $this->encode_password($this->params['password'])) {
                         self::$current_user = $user;
                         $_SESSION['silk_user'] = $user;
                         return true;
                     }
                 }
                 $this->validation_errors[] = 'Username or password incorrect.';
             } else {
                 if ($this->params['openid'] != '') {
                     $consumer = $this->get_consumer();
                     $auth_request = $consumer->begin($this->params['openid']);
                     if ($auth_request) {
                         if ($auth_request->shouldSendRedirect()) {
                             $redirect_url = $auth_request->redirectURL(SilkRequest::get_calculated_url_base(true), SilkRequest::get_requested_uri(true));
                             redirect($redirect_url);
                         }
                     }
                 }
             }
         }
     }
     return false;
 }
 /**
  * Returns the associated belongs_to association's object.
  *
  * @return mixed The object, if it exists.  null if not.
  * @author Ted Kulp
  **/
 public function get_data(&$obj)
 {
     $belongs_to = null;
     if ($obj->has_association($this->association_name)) {
         $belongs_to = $obj->get_association($this->association_name);
     } else {
         if ($this->belongs_to_class_name != '' && $this->child_field != '') {
             $class = orm()->{$this->belongs_to_class_name};
             if ($obj->{$this->child_field} > -1) {
                 $belongs_to = call_user_func_array(array(&$class, 'find_by_id'), $obj->{$this->child_field});
                 $obj->set_association($this->association_name, $belongs_to);
             }
         }
     }
     return $belongs_to;
 }
Exemple #6
0
 function test_mysql_backend()
 {
     orm()->model_paths[] = realpath(join(DIRECTORY_SEPARATOR, array(dirname(__FILE__), 'res')));
     orm()->register('dummy');
     $manager = orm()->dummy;
     $this->assertEqual(count(orm()->_managers), 1);
     orm()->register_field_type('dummy', realpath(join(DIRECTORY_SEPARATOR, array(dirname(__FILE__), 'res', 'test_field_type.php'))), 'Dummy');
     $manager->dummy('dummy');
     orm()->set_backend('mysql', array('dbname' => 'test_minim', 'user' => 'root', 'password' => '', 'unix_socket' => '/tmp/mysql.sock'));
     $backend =& orm()->_backend;
     $backend->execute_query("CREATE TABLE dummy (dummy TEXT)", array());
     $do = orm()->dummy->create();
     $value = md5(microtime());
     $do->dummy = $value;
     $do->save();
     $sth = $backend->execute_query('SELECT * FROM dummy', array());
     $result = $sth->fetch(PDO::FETCH_ASSOC);
     $this->assertEqual($result['dummy'], $value);
 }
 private function fill_data(&$obj)
 {
     $ary = null;
     if ($obj->has_association($this->association_name)) {
         $ary = $obj->get_association($this->association_name);
     } else {
         $ary = new SilkAssociationCollection();
         if ($this->child_class != '' && $this->join_table != '') {
             $class = orm()->{$this->child_class};
             $table = $class->get_table();
             $other_id_field = $class->id_field;
             if ($obj->{$obj->id_field} > -1) {
                 $queryattrs = $this->extra_params;
                 $queryattrs['joins'] = "INNER JOIN {$this->join_table} ON {$this->join_table}.{$this->join_other_id_field} = {$table}.{$other_id_field}";
                 $queryattrs['conditions'] = array("{$this->join_table}.{$this->join_this_id_field} = ?", $obj->{$obj->id_field});
                 $ary->children = $class->find_all($queryattrs);
                 $obj->set_association($this->association_name, $ary);
             }
         }
     }
     return $ary;
 }
Exemple #8
0
<?php

orm()->register('dummy');
 function __construct()
 {
     parent::__construct();
     $this->groups = array(orm('group')->find_by_name('Anonymous'));
 }
 /**
  * Wrapper function for after_delete.  Only should be 
  * called by classes that entend the functionality of 
  * the ORM system.
  *
  * @return void
  * @author Ted Kulp
  */
 protected function after_delete_caller()
 {
     foreach (orm()->get_acts_as($this) as $one_acts_as) {
         $one_acts_as->after_delete($this);
     }
     $this->after_delete();
 }
Exemple #11
0
 function test_orm_numeric_filters()
 {
     orm()->register_field_type('num', realpath(join(DIRECTORY_SEPARATOR, array(dirname(__FILE__), 'res', 'test_field_type.php'))), 'Num');
     $backend =& orm()->_backend;
     if (!$backend) {
         throw new Exception("ORM backend not set");
     }
     $backend->execute_query("CREATE TABLE num (value INTEGER)", array());
     $manager =& orm()->register('num')->num('value');
     $manager->create(array('value' => 1))->save();
     $manager->create(array('value' => 2))->save();
     $manager->create(array('value' => 3))->save();
     $manager->create(array('value' => 4))->save();
     $count = count($manager->where('value')->gt(1));
     $this->assertEqual($count, 3, "Expecting 3 results, got {$count}");
     $count = count($manager->where('value')->lt(2));
     $this->assertEqual($count, 1, "Expecting 1 result, got {$count}");
     $count = count($manager->where('value')->gte(3));
     $this->assertEqual($count, 2, "Expecting 2 results, got {$count}");
     $count = count($manager->where('value')->lte(4));
     $this->assertEqual($count, 4, "Expecting 4 results, got {$count}");
     $count = count($manager->where('value')->in_range(2, 4));
     $this->assertEqual($count, 3, "Expecting 3 results, got {$count}");
 }