Пример #1
0
<?php

include '../rolisz.php';
rolisz::connect('MySQLi', 'localhost', 'root', '', 'rolisz');
include '../db.php';
table::set('posts');
table::addRelationM2MS('posts', 'post_category', 'id', 'pid', 'category', 'id', 'cid');
table::addRelationM2MS('posts', 'post_tags', 'id', 'pid', 'tags', 'id', 'tid');
table::addRelationS('posts', 'users', 'author', 'id');
table::addRelationS('posts', 'comments', 'pid');
//var_dump(table::findS('posts'));
$posts = new table('posts');
// $posts->addRelationM2M('post_category','id','pid','category','id','cid');
// $posts->addRelation('users','author','id');
// $posts->addRelation('comments','pid');
$posts->title = 'Test Post';
$posts->body = 'Lorem Ipsum Doloret coloret';
$posts->author = 1;
//$posts->save();
$posts1 = new table('posts', 1);
$test = $posts1->find('category');
$comment = new table('comments', 1);
$comment->posts(array('id' => 1));
$comment->save();
$author = new table('users', 1);
$posts2 = new table('posts', 2);
$posts2->tags(array('tag' => 'google'));
Пример #2
0
<?php

include '../rolisz.php';
rolisz::connect('MySQLi', 'localhost', 'root', '', 'wordpress');
include '../db.php';
$posts = new table('wpb_posts', '59');
$posts->addRelationM2M('wpb_term_relationships', 'id', 'object_id', 'wpb_terms', 'term_id', 'term_taxonomy_id');
$posts->addRelation('wpb_users', 'post_author', 'ID');
$posts->addRelation('wpb_comments', 'comment_post_ID');
$term_rel = new table('wpb_terms');
$term_rel->addRelation('wpb_term_taxonomy', 'term_id');
//$posts->save();
$test = $posts->find('wpb_posts', array('wpb_terms' => array('wpb_term_taxonomy' => array('taxonomy' => 'category'), 'name' => 'Customization')));
var_dump($test);
echo 'yooooo';
$test = $posts->find('wpb_terms');
var_dump($test);
Пример #3
0
 /**
  * Returns an array of table objects each set to there id
  *
  * @param string $where (sql where clause to limit which rows are fetched)
  * @param string $orderby (sql order by clause to order the result records)
  * @param string $other (any other sql you would like to tack on the end)
  * @return array or bool (array on success, bool on none found)
  * @access public
  */
 function findMany($where = '', $orderby = '', $other = '')
 {
     $all = array();
     $sql = "SELECT {$this->primary_key} FROM {$this->table} {$where} {$orderby} {$other}";
     if ($this->debug) {
         echo '<p><strong>Find Many SQL:</strong> ' . $sql . '</p>';
         if ($this->db->isError()) {
             echo $this->db->getErrorMsg();
             return false;
         }
     }
     $result = $this->db->query($sql);
     if ($result->numRows() > 0) {
         while ($row = $result->fetchRow()) {
             $t = new table($this->db, $this->table);
             $t->find($row[$this->primary_key]);
             $all[] = $t;
         }
         return $all;
     } else {
         if ($this->debug) {
             echo "<p>No results were found based on the criteria you provided. (where = {$where} // orderby = {$orderby})</p>";
         }
         return false;
     }
 }
Пример #4
0
 /** 
  * Static wrapper for find(). Arguments the same.
  * 		@param string $table Table in which to search
  * 		@param array $filters Filters to apply. Can be name=>value pair, SQL statement, or recursive array relating to conditions on other tables
  * 		@param array $ordergroup How to order, group and limit the search
  * 		@param array $columns What columns to return in search
  * 		@return array
  **/
 public static function findS($table, $filters = array(), $ordergroup = array(), $columns = array())
 {
     $Table = new table($table);
     return $Table->find($table, $filters, $ordergroup, $columns);
 }
Пример #5
0
 /**
  *  Edit the ACL. Parameters the same as for addNew(), except an extra parameter.
  * 		@param string $type It can be 'resource', 'action', 'requester' or 'permission'
  * 		@param mixed $what For 'resource', 'action' and 'requester' it should be a string containing the name of the new 
  * 	element. For 'permission' it should be an associative array containing key-value pairs for each of the types. If no action
  * 	has to be defined then it action should be NULL. 
  * 		@param string $towhat What to change this to
  * 		@param string $where Used only for 'requester', it should the name of the node after which to insert. If it is not found,
  * 	the new value is inserted as a new group.
  * 		@retval false It returns false if you are trying to use it without a database or XML file or if an element can't be found.
  * 		@retval true
  * 
  */
 public function editACL($type, $what, $towhat, $where = FALSE)
 {
     if (is_null($this->prefix)) {
         return false;
     }
     if (is_string($what)) {
         $req = table::findS($this->prefix . "_{$type}s", array($type => $what));
         if (!$req) {
             trigger_error("Can't find {$what} of {$type}");
             return false;
         }
         $what = $req->id;
     }
     if ($type == 'resource' || $type == 'action') {
         $req = new table($this->prefix . "_{$type}s", $what);
         $req->{$type} = $towhat;
         $req->save();
     }
     if ($type == 'requester') {
         $req = new table($this->prefix . '_requesters', $what);
         if (!$req) {
             trigger_error("Can't find {$what} {$type} to edit");
             return false;
         }
         //Treat cases where $where is another requester, another id, or it is not defined/found
         if ($where) {
             if (is_numeric($where)) {
                 $orig = new table($this->prefix . '_requesters', $where);
             } else {
                 $orig = $req->find($this->prefix . '_requesters', array('requester' => $where));
             }
             if ($orig) {
                 $right = $orig->right;
             } else {
                 trigger_error("Can't find {$where} to put there the {$what} {$type}");
                 return false;
             }
             rolisz::get('dbCon')->query("UPDATE `{$this->prefix}_requesters` SET \n\t\t\t\t\t\t\t\tleft = left-2 WHERE left>{$req->right} AND left<{$right}+3");
             rolisz::get('dbCon')->query("UPDATE `{$this->prefix}_requesters` SET \n\t\t\t\t\t\t\t\tright = right-2 WHERE right>{$req->right} AND right<{$right}+3");
             $req->left = $right + 1;
             $req->right = $right + 2;
         }
         $req->requester = $towhat;
         $req->save();
     }
     if ($type == 'permission') {
         //Loop through each type and if it's a string, get the associated id
         foreach ($towhat as $type => $value) {
             if (is_string($value)) {
                 $towhat[$type] = rolisz::table($this->prefix . "_{$type}s")->find($this->prefix . "_{$type}s", array($type => $value));
                 if (!$towhat[$type]) {
                     trigger_error("{$value} {$type} not found");
                     return false;
                 }
                 $towhat[$type] = $towhat[$type]->id;
             }
         }
         $perm = new table($this->prefix . '_permissions', $what);
         foreach ($towhat as $type => $value) {
             $perm->{$type} = $value;
         }
         $perm->save();
     }
     return true;
 }