<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="/xsl/main.xsl"?>

<response>
	<page>
		<menu>
			<item link="/">home</item>
			<item link="/lib360/">lib360</item>
			<item link="/code/">code</item>
		</menu>
		<content>
			<section>
				<title>lib360</title>
				<paragraph>
					lib360 is a spoof library of classes and components 
					that aim for extensibility and ease of use.
				</paragraph>
			</section>
			<section>
				<title>lib360 database</title>
				<paragraph>
				</paragraph>
			</section>
			<tabs>
				<menu>
					<item link="overview">overview</item>
					<item link="code-setup">setup</item>
					<item link="code-basic">basic use</item>
					<item link="code-advanced">advanced use</item>
					<item link="diagram">diagram</item>
					<item link="reference">reference</item>
				</menu>
				<tab name="overview">
					<section>
						<title>overview</title>
						<paragraph>
							<list>
								<item>abstracted components: connection,
								driver, storage (table, view), language,
								execution</item>
								<item>every component is fully extensible</item>
								<item>programatically define reusable
								storage components (e.g. tables and views)</item>
								<item>create new languages, drivers</item>
							</list>
						</paragraph>
					</section>
				</tab>
				<tab name="code-setup">
					<section>
						<title>include lib360</title>
						<paragraph>
							Place lib360 anywhere within your includes.
							This will be the only require statement
							you'll use with lib360.
						</paragraph>
						<code>&lt;?php

require_once('lib360/initialize.php');

?&gt;</code>
						<title>connection</title>
						<paragraph>
							Create a PDO connection and add to
							connection pool with alias 'test'.
						</paragraph>
						<code>&lt;?php

use \lib360\db\connection as conn;

$conn = new conn\PDO(
		new conn\Config('mysql:host=localhost;dbname=test', 'root', NULL)
);
conn\Pool::add($conn, 'test');

?&gt;</code>
					</section>
				</tab>
				<tab name="code-basic">
					<section>
						<title>select using table factory</title>
						<paragraph>
							This method allows very quick, one-off access
							to your data.
						</paragraph>
						<code>&lt;?php

use \lib360\db\data as data;

$userTable = data\TableFactory::get('test', 'users');
$result = $userTable-&gt;select();

?&gt;</code>
						<title>select using a table class</title>
						<paragraph>
							Defining a table class allows you to define
							a reusable component instead of using
							defaults from factory. Below $db is the
							database alias name, and $name is the table
							or storage name.
						</paragraph>
						<code>&lt;?php

class UserTable extends data\Table
{
	protected $db = 'test';
	protected $name = 'users';
}

$userTable = new UserTable();
$result = $userTable-&gt;select();

?&gt;</code>
						<title>create conditions</title>
						<paragraph>
							Condition objects allow you to define a
							query restriction that can be reused. The
							condition object below would read:
							column user_id equals to integer 5.
						</paragraph>
						<code>&lt;?php

use \lib360\db\condition as cond;
use \lib360\db\value as val;

$cond = new cond\Condition(
		new val\Value('user_id', val\Value::TYPE_COLUMN),
		cond\Condition::OPERATOR_EQUALS,
		new val\Value(5, val\Value::TYPE_INTEGER)
);

?&gt;</code>
						<title>use condition groups</title>
						<paragraph>
							Condition groups allow you to combine
							conditions and other condition groups
							together.
						</paragraph>
						<code>&lt;?php

$condgroup1 = new cond\ConditionGroup($cond1);
$condgroup1->addCondition(
		cond\ConditionGroup::OPERATOR_AND,
		$cond2
);

$condgroup1->addCondition(
		cond\ConditionGroup::OPERATOR_OR,
		$condgroup2
);

?&gt;</code>
						<title>use conditions in select</title>
						<paragraph>
							Condition (or condition group) objects can
							be easily plugged in select/update/delete
							statements.
						</paragraph>
						<code>&lt;?php

$result = $userTable->delete($condgroup1);

?&gt;</code>
						<title>limit returned fields per query</title>
						<paragraph>
							This will select id and name fields only.
						</paragraph>
						<code>&lt;?php

$result = $userTable->select($condgroup1, NULL, array('id', 'name'));

?&gt;</code>
						<title>limit fields in class definition</title>
						<paragraph>
							This is equivalent of above but defined
							inside the class as default. You can always
							override per query.
						</paragraph>
						<code>&lt;?php

class UserTable extends data\Table
{
	protected $db = 'test';
	protected $name = 'user';
	protected $fields = array('id', 'name');
}

$userTable = new UserTable();
$result = $userTable->select($condgroup1);

?&gt;</code>
					</section>
				</tab>
				<tab name="code-advanced">
					<section>
						<title>create joins</title>
						<paragraph>
							Let's say you want to display comments
							made by users; but comments table has the
							users' ID value, so you want to join against
							the users table to grab name instead. And
							you also want to join users table against
							user_groups to grab their group name.
						</paragraph>
						<code>&lt;?php

use \lib360\db\value as val;
use \lib360\db\conditioin as cond;
use \lib360\db\join as join;

// create condition object linking comments.user_id = users.user_id
$cond12 = new cond\Condition(
				new val\Value('comments.user_id', val\Value::TYPE_COLUMN),
				cond\Condition::OPERATOR_EQUALS,
				new val\Value('users.user_id', val\Value::TYPE_COLUMN)
);

// create a condition object linking users.group_id = user_group.group_id
$cond23 = new cond\Condition(
				new val\Value('users.group_id', val\Value::TYPE_COLUMN),
				cond\Condition::OPERATOR_EQUALS,
				new val\Value('user_group.group_id', val\Value::TYPE_COLUMN)
);

// create a join object with initial inner join of users and comments tables
$j = new join\Join('comments', join\Join::JOIN_TYPE_INNER, 'users', $cond12);

// add user_group table as a left outer join
$j->addTable(join\Join::JOIN_TYPE_LEFT_OUTER, 'user_group', $cond23);

?&gt;</code>
						<title>create views</title>
						<paragraph>
							Now use the above join inside a view class.
							Notice you can add as many join objects as
							desired.
						</paragraph>
						<code>&lt;?php

use \lib360\db\data as data;

class UserCommentsView extends data\View
{

	public function __construct()
	{
		// same join creation code as above resulting in $j object
		// ...

		// add join to array
		$this->joins[] = $j;
	}

}

?&gt;</code>
						<title>use views</title>
						<paragraph>
							Views can be used very similar to tables. In
							fact, they share most of the implementation.
						</paragraph>
						<code>&lt;?php

$userComments = new UserCommentsView();

$result = $userComments->select();

?&gt;</code>
						<title>export XML</title>
						<paragraph>
							Results of a select query can be easily
							exported to XML.
						</paragraph>
						<code>&lt;?php

// DOM document
$dom = $result->toXML();

// XML string
$xml = $result->toXML()->saveXML();

?&gt;</code>
					</section>
				</tab>
				<tab name="diagram">
					<section>
						<paragraph>
							<image>/image/usage anatomy.png</image>
						</paragraph>
					</section>
				</tab>
				<tab name="reference">
					<section>
						<title>reference</title>
						<paragraph>
							<link uri="http://docs.codefly.org/doxygen/html/">doxygen reference documentation</link>
							<list>
								<item><link uri="http://docs.codefly.org/doxygen/html/inherits.html">class hierarchy</link></item>
								<item><link uri="http://docs.codefly.org/doxygen/html/namespaces.html">namespaces</link></item>
							</list>
						</paragraph>
					</section>
				</tab>
			</tabs>
		</content>
	</page>
</response>