Example #1
0
 protected function Form_Create()
 {
     // Define the DataGrid -- note that the Meta DataGrid is a DataGrid, itself --
     // so let's just use it as a datagrid
     $this->dtgProjects = new ProjectDataGrid($this);
     // DataBinding is already configured -- so we do not need to worry about it
     // But remember that dtgProjects is just a regular datagrid, as well
     // So we can configure as we see fit, e.g. adding pagination or styling
     $this->dtgProjects->Paginator = new QPaginator($this->dtgProjects);
     $this->dtgProjects->ItemsPerPage = 6;
     $this->dtgProjects->AlternateRowStyle->CssClass = 'alternate';
     // All we need to do is to utilize the ProjectDataGrid built-in functionality
     // to create, define and setup the various columns that WE choose, in the order
     // that WE want.  NOTE that we use simple string-based property names, OR QQuery
     // node descriptors to specify what we want for each column.
     $this->dtgProjects->MetaAddColumn('Name');
     $this->dtgProjects->MetaAddColumn('StartDate');
     $this->dtgProjects->MetaAddColumn(QQN::Project()->EndDate);
     // We can easily add columns from linked/related tables.  However, to do this
     // you MUST use a QQuery node descriptor.  No string-based properties allowed.
     // Bonus: the Meta DataGrid will even automatically add sorting for columns in related tables.
     $colUsername = $this->dtgProjects->MetaAddColumn(QQN::Project()->ManagerPerson->Login->Username);
     // And remember, since it's a regular datagrid with regular columns,
     // we can stylize as we see fit
     $colUsername->BackColor = '#cef';
     $colUsername->Name = 'Manager\'s Username';
     // Also, note that MetaAddColumn and MetaAddTypeColumn can use attribute overriding as well
     $this->dtgProjects->MetaAddTypeColumn('ProjectStatusTypeId', 'ProjectStatusType', 'FontBold=true');
     $this->pxyExample = new QControlProxy($this);
     $this->pxyExample->AddAction(new QClickEvent(), new QAjaxAction('pxyExample_Click'));
     // FInally, there are even Meta methods to add an Edit Button column
     $this->dtgProjects->MetaAddEditProxyColumn($this->pxyExample, 'Click Me', 'Faux Edit Column');
 }
 /**
  * Bind the Projects table to the html table.
  *
  * @throws QCallerException
  */
 protected function tblProjects_Bind()
 {
     // Expand the PersonAsTeamMember node as an array so that it will be included in each item sent to the columns.
     $clauses = QQ::ExpandAsArray(QQN::Project()->PersonAsTeamMember);
     // We load the data source, and set it to the datagrid's DataSource parameter
     $this->tblProjects->DataSource = Project::LoadAll($clauses);
 }
 protected function Form_Create()
 {
     // Instantiate the DataGrid
     $this->dtgProjects = new QDataGrid($this);
     // Style the DataGrid
     //$this->dtgProjects->CssClass = 'datagrid';
     $this->dtgProjects->AlternateRowCssClass = 'alternate';
     // Add Pagination
     $this->dtgProjects->Paginator = new QPaginator($this->dtgProjects);
     $this->dtgProjects->ItemsPerPage = 3;
     // Add columns
     // Create a column that will hold a toggle button. We will need to manually draw the content of the cell.
     $col = $this->dtgProjects->CreateCallableColumn('', [$this, 'render_btnToggleRecordsSummary']);
     $col->HtmlEntities = false;
     $col->CellStyler->Width = "1%";
     $this->dtgProjects->CreateNodeColumn('Id', QQN::Project()->Id);
     $this->dtgProjects->CreateNodeColumn('Name', QQN::Project()->Name);
     $this->dtgProjects->CreateNodeColumn('Status', QQN::Project()->ProjectStatusType);
     $this->dtgProjects->CreateNodeColumn('Description', QQN::Project()->Description);
     $this->dtgProjects->CreateNodeColumn('Start Date', QQN::Project()->StartDate);
     $this->dtgProjects->CreateNodeColumn('End Date', QQN::Project()->EndDate);
     $this->dtgProjects->CreateNodeColumn('Budget', QQN::Project()->Budget);
     $this->dtgProjects->CreateNodeColumn('Spent', QQN::Project()->Spent);
     // Create a column that will hold a child datagrid
     $col = $this->dtgProjects->CreateCallableColumn('', [$this, 'render_ucRecordsSummary']);
     $col->HtmlEntities = false;
     $col->CellStyler->Width = 0;
     // Specify the Datagrid's Data Binder method
     $this->dtgProjects->SetDataBinder('dtgProjects_Bind');
     // For purposes of this example, add a css file that styles the table.
     // Normally you would include your global style sheets in your tpl file or header.inc.php file.
     $this->dtgProjects->AddCssFile(__QCUBED_ASSETS__ . '/php/examples/master_detail/styles.css');
 }
Example #4
0
 /**
  * This constructor will only be executed once - afterwards,
  * the state of the control will be stored into the $_SESSION
  * and, on future loads, populated from the session state.
  */
 public function __construct($objParentObject)
 {
     parent::__construct($objParentObject);
     $projects = Project::QueryArray(QQ::All(), QQ::OrderBy(QQN::Project()->Name));
     foreach ($projects as $project) {
         $this->AddItem($project->Name, $project->Id);
     }
 }
 protected function dtgProjects_Create()
 {
     // Define the DataGrid
     $this->dtgProjects = new QDataGrid($this);
     $this->dtgProjects->ShowFilter = true;
     // To create pagination, we will create a new paginator, and specify the datagrid
     // as the paginator's parent.  (We do this because the datagrid is the control
     // who is responsible for rendering the paginator, as opposed to the form.)
     $objPaginator = new QPaginator($this->dtgProjects);
     $this->dtgProjects->Paginator = $objPaginator;
     // Now, with a paginator defined, we can set up some additional properties on
     // the datagrid.  For purposes of this example, let's make the datagrid show
     // only 5 items per page.
     $this->dtgProjects->ItemsPerPage = 20;
     // Define Columns
     //Project Name
     $colName = new QDataGridColumn('Project', '<?= $_ITEM->Name?>');
     $colName->OrderByClause = QQ::OrderBy(QQN::Project()->Name);
     $colName->ReverseOrderByClause = QQ::OrderBy(QQN::Project()->Name, false);
     $this->dtgProjects->AddColumn($colName);
     //Project type - filtered
     $colType = new QDataGridColumn('Type', '<?= ProjectStatusType::ToString($_ITEM->ProjectStatusTypeId) ?>');
     $colType->OrderByClause = QQ::OrderBy(QQN::Project()->ProjectStatusTypeId);
     $colType->ReverseOrderByClause = QQ::OrderBy(QQN::Project()->ProjectStatusTypeId, false);
     $colType->FilterType = QFilterType::ListFilter;
     foreach (ProjectStatusType::$NameArray as $value => $name) {
         $colType->FilterAddListItem($name, QQ::Equal(QQN::Project()->ProjectStatusTypeId, $value));
     }
     $this->dtgProjects->AddColumn($colType);
     //Manager First Name
     $colFName = new QDataGridColumn('First Name', '<?= $_ITEM->ManagerPerson->FirstName ?>');
     $colFName->OrderByClause = QQ::OrderBy(QQN::Project()->ManagerPerson->FirstName);
     $colFName->ReverseOrderByClause = QQ::OrderBy(QQN::Project()->ManagerPerson->FirstName, false);
     $this->dtgProjects->AddColumn($colFName);
     //Manager Last Name - filtered, only show with enabled logins
     $colLName = new QDataGridColumn('Last Name', '<?= $_ITEM->ManagerPerson->LastName ?>');
     $colLName->OrderByClause = QQ::OrderBy(QQN::Project()->ManagerPerson->LastName);
     $colLName->ReverseOrderByClause = QQ::OrderBy(QQN::Project()->ManagerPerson->LastName, false);
     QQN::Project()->ManagerPerson->LastName->SetFilteredDataGridColumnFilter($colLName);
     $colLName->FilterConstant = QQ::Equal(QQN::Project()->ManagerPerson->Login->IsEnabled, true);
     $this->dtgProjects->AddColumn($colLName);
     // Specify the Datagrid's Data Binder method
     $this->dtgProjects->SetDataBinder('dtgProjects_Bind');
     /*		 * *********************** */
     // Make the DataGrid look nice
     $objStyle = $this->dtgProjects->RowStyle;
     $objStyle->FontSize = 12;
     $objStyle = $this->dtgProjects->AlternateRowStyle;
     $objStyle->BackColor = '#f6f6f6';
     $objStyle = $this->dtgProjects->HeaderRowStyle;
     $objStyle->ForeColor = 'white';
     $objStyle->BackColor = '#780000';
     // Because browsers will apply different styles/colors for LINKs
     // We must explicitly define the ForeColor for the HeaderLink.
     // The header row turns into links when the column can be sorted.
     $objStyle = $this->dtgProjects->HeaderLinkStyle;
     $objStyle->ForeColor = 'white';
 }
 protected function Go_Click()
 {
     QApplication::$blnLocalCache = false;
     $timeNoCache = -microtime(true);
     $a = Person::LoadAll();
     // noncached loads
     $timeNoCache += microtime(true);
     QApplication::$blnLocalCache = true;
     $timeLoad1Cached = -microtime(true);
     $a = Person::LoadAll();
     // noncached loads
     $timeLoad1Cached += microtime(true);
     $timeLoad2Cached = -microtime(true);
     $a = Person::LoadAll();
     // cached loads
     $timeLoad2Cached += microtime(true);
     QApplication::$blnLocalCache = new QCacheProviderLocalMemory(array());
     $timeLoad3Cached = -microtime(true);
     $a = Person::LoadAll();
     // noncached loads
     $timeLoad3Cached += microtime(true);
     $timeLoad4Cached = -microtime(true);
     $a = Person::LoadAll();
     // cached loads
     $timeLoad4Cached += microtime(true);
     $this->pnlTiny->Text = sprintf("Load No Cache: %2.1f%% \n", 100 * $timeNoCache / $timeNoCache) . sprintf("Populate Cache: %2.1f%% \n", 100 * $timeLoad1Cached / $timeNoCache) . sprintf("Load With Cache: %2.1f%% \n", 100 * $timeLoad2Cached / $timeNoCache) . sprintf("Populate LocalCacheProvider: %2.1f%% \n", 100 * $timeLoad3Cached / $timeNoCache) . sprintf("Load LocalCacheProvider: %2.1f%% \n", 100 * $timeLoad4Cached / $timeNoCache);
     $cond = QQ::Equal(QQN::Project()->ProjectStatusTypeId, ProjectStatusType::Open);
     $clauses[] = QQ::Expand(QQN::Project()->ManagerPerson);
     Project::ClearCache();
     Person::ClearCache();
     QApplication::$blnLocalCache = false;
     $timeNoCache = -microtime(true);
     $a = Project::QueryArray($cond, $clauses);
     // noncached loads
     $timeNoCache += microtime(true);
     QApplication::$blnLocalCache = true;
     $timeLoad1Cached = -microtime(true);
     $a = Project::QueryArray($cond, $clauses);
     // noncached loads
     $timeLoad1Cached += microtime(true);
     $timeLoad2Cached = -microtime(true);
     $a = Project::QueryArray($cond, $clauses);
     // cached loads
     $timeLoad2Cached += microtime(true);
     QApplication::$blnLocalCache = new QCacheProviderLocalMemory(array());
     $timeLoad3Cached = -microtime(true);
     $a = Project::QueryArray($cond, $clauses);
     // noncached loads
     $timeLoad3Cached += microtime(true);
     $timeLoad4Cached = -microtime(true);
     $a = Project::QueryArray($cond, $clauses);
     // cached loads
     $timeLoad4Cached += microtime(true);
     $this->pnlBig->Text = sprintf("Load No Cache: %2.1f%% \n", 100 * $timeNoCache / $timeNoCache) . sprintf("Populate Cache: %2.1f%% \n", 100 * $timeLoad1Cached / $timeNoCache) . sprintf("Load With Cache: %2.1f%% \n", 100 * $timeLoad2Cached / $timeNoCache) . sprintf("Populate LocalCacheProvider: %2.1f%% \n", 100 * $timeLoad3Cached / $timeNoCache) . sprintf("Load LocalCacheProvider: %2.1f%% \n", 100 * $timeLoad4Cached / $timeNoCache);
 }
Example #7
0
 public function testGroupBy()
 {
     $objItems = Project::QueryArray(QQ::All(), QQ::Clause(QQ::GroupBy(QQN::Project()->Id), QQ::Count(QQN::Project()->PersonAsTeamMember->PersonId, 'team_member_count')));
     $this->assertEqual(sizeof($objItems), 4, "4 projects found");
     $this->assertEqual($objItems[0]->Name, "ACME Website Redesign", "Project " . $objItems[0]->Name . " found");
     $this->assertEqual($objItems[0]->GetVirtualAttribute('team_member_count'), 5, "5 team members found for project " . $objItems[0]->Name);
     $this->assertEqual($objItems[1]->Name, "State College HR System", "Project " . $objItems[1]->Name . " found");
     $this->assertEqual($objItems[1]->GetVirtualAttribute('team_member_count'), 6, "6 team members found for project " . $objItems[1]->Name);
     $this->assertEqual($objItems[2]->Name, "Blueman Industrial Site Architecture", "Project " . $objItems[2]->Name . " found");
     $this->assertEqual($objItems[2]->GetVirtualAttribute('team_member_count'), 5, "5 team members found for project " . $objItems[2]->Name);
 }
Example #8
0
 /**
  * This constructor will only be executed once - afterwards,
  * the state of the control will be stored into the $_SESSION
  * and, on future loads, populated from the session state.
  */
 public function __construct($objParentObject, $strControlId)
 {
     parent::__construct($objParentObject, $strControlId);
     $projects = Project::QueryArray(QQ::All(), QQ::OrderBy(QQN::Project()->Name));
     foreach ($projects as $project) {
         $this->AddItem($project->Name, $project->Id);
     }
     // Reset the status of the parent form's label to indicate
     // that the query was actually run
     $objParentObject->lblStatus->Text = "The query was executed";
 }
 public function testDbTypeCasting()
 {
     $dt1 = new QDateTime('Jan 15 2006');
     $dt2 = new QDateTime('Mar 15 2006');
     $cond = QQ::Between(QQN::Project()->StartDate, $dt1, $dt2);
     $a = Project::QueryArray($cond);
     $this->assertEquals(2, count($a), "Between 2 QDateTime types works");
     $cond = QQ::Between(QQN::Project()->Budget, 2000, 3000);
     $a = Project::QueryArray($cond);
     $this->assertEquals(1, count($a), "Between 2 int types works");
     $cond = QQ::Between(QQN::Project()->Name, 'A', 'C');
     $a = Project::QueryArray($cond);
     $this->assertEquals(3, count($a), "Between 2 string types works");
 }
Example #10
0
 /**
  * Add the items to the project list.
  */
 public function lstProjects_Bind()
 {
     $clauses[] = QQ::ExpandAsArray(QQN::Project()->PersonAsTeamMember);
     $objProjects = Project::QueryArray(QQ::All(), $clauses);
     foreach ($objProjects as $objProject) {
         $item = new QHListItem($objProject->Name);
         $item->Tag = 'ol';
         $item->GetSubTagStyler()->OrderedListType = QOrderedListType::LowercaseRoman;
         foreach ($objProject->_PersonAsTeamMemberArray as $objPerson) {
             /****
              * Here we add a sub-item to each item before adding the item to the main list.
              */
             $item->AddItem($objPerson->FirstName . ' ' . $objPerson->LastName);
         }
         $this->lstProjects->AddItem($item);
     }
 }
Example #11
0
 protected function Form_Create()
 {
     // Setup the Dropdown of Project Names
     $this->lstProjects = new QListBox($this);
     $this->lstProjects->AddItem('- Select One -', null, true);
     foreach (Project::LoadAll(QQ::Clause(QQ::OrderBy(QQN::Project()->Name))) as $objProject) {
         $this->lstProjects->AddItem($objProject->Name, $objProject->Id);
     }
     $this->lstProjects->AddAction(new QChangeEvent(), new QAjaxAction('lstProjects_Change'));
     // Setup our Left and Right Panel Placeholders
     // Notice that both panels have "AutoRenderChildren" set to true so that
     // instantiated child panels will automatically get displayed
     $this->pnlLeft = new QPanel($this);
     $this->pnlLeft->Position = QPosition::Relative;
     $this->pnlLeft->CssClass = 'panelDefault';
     $this->pnlLeft->AutoRenderChildren = true;
     $this->pnlRight = new QPanel($this);
     $this->pnlRight->Position = QPosition::Relative;
     $this->pnlRight->CssClass = 'panelDefault panelRight';
     $this->pnlRight->AutoRenderChildren = true;
     $this->objDefaultWaitIcon = new QWaitIcon($this);
 }
 protected function Form_Create()
 {
     // Define the DataGrid -- note that the DataGrid Connector is a DataGrid, itself --
     // so let's just use it as a datagrid
     $this->dtgProjects = new ProjectList($this);
     $this->dtgProjects->SetDataBinder('DefaultDataBinder', $this);
     // Only show projects whose status is "open"
     $this->objAdditionalConditions = QQ::Equal(QQN::Project()->ProjectStatusTypeId, ProjectStatusType::Open);
     //expand on the ManagerPerson's login, since we're displaying it
     $this->objAdditionalClauses = array(QQ::Expand(QQN::Project()->ManagerPerson), QQ::Expand(QQN::Project()->ManagerPerson->Login));
     // DataBinding is already configured -- so we do not need to worry about it
     // But remember that dtgProjects is just a regular datagrid, as well
     // So we can configure as we see fit, e.g. adding pagination or styling
     $this->dtgProjects->Paginator = new QPaginator($this->dtgProjects);
     $this->dtgProjects->ItemsPerPage = 6;
     $this->dtgProjects->AlternateRowCssClass = 'alternate';
     // All we need to do is to utilize the ProjectDataGrid built-in functionality
     // to create, define and setup the various columns that WE choose, in the order
     // that WE want.
     $this->dtgProjects->CreateNodeColumn('Name', QQN::Project()->Name);
     $this->dtgProjects->CreateNodeColumn('StartDate', QQN::Project()->StartDate);
     $this->dtgProjects->CreateNodeColumn("EndDate", QQN::Project()->EndDate);
     // We can easily add columns from linked/related tables.  However, to do this
     // you MUST use a QQuery node descriptor.  No string-based properties allowed.
     // Bonus: the DataGrid Connector will even automatically add sorting for columns in related tables.
     $colUsername = $this->dtgProjects->CreateNodeColumn('Username', QQN::Project()->ManagerPerson->Login->Username);
     // And remember, since it's a regular datagrid with regular columns,
     // we can stylize as we see fit
     $colUsername->CellParamsCallback = [$this, 'GetUserNameCellParams'];
     $colUsername->Name = 'Manager\'s Username';
     $colStatus = $this->dtgProjects->CreateNodeColumn('ProjectStatusType', QQN::Project()->ProjectStatusType);
     $colStatus->HtmlEntities = false;
     $colStatus->Format = '<strong>%s</strong>';
     $this->pxyExample = new QControlProxy($this);
     $this->pxyExample->AddAction(new QClickEvent(), new QAjaxAction('pxyExample_Click'));
 }
    public function dtgProjects_Bind()
    {
        // Get Total Count b/c of Pagination
        $this->dtgProjects->TotalItemCount = Project::CountAll();
        $objClauses = array();
        if ($objClause = $this->dtgProjects->OrderByClause) {
            $objClauses[] = $objClause;
        }
        if ($objClause = $this->dtgProjects->LimitClause) {
            $objClauses[] = $objClause;
        }
        // Create a virtual attribute that lets us know if this Project is related to ACME
        $objClauses[] = QQ::Expand(QQ::Virtual('assn_item', QQ::SubSql('select 
							project_id
					 	from 
					 		related_project_assn
					 	where 
							child_project_id = {1} 
							 and project_id = 1', QQN::Project()->Id)));
        $this->dtgProjects->DataSource = Project::LoadAll($objClauses);
    }
Example #14
0
	<h3>Custom Load Query: Select all Projects with Budgets over $5000, ordered by Descending Budget</h3>
<?php 
// Custom Load Queries must have a resultset that returns all the fields of the
// table which corresponds to the ORM class you want to instantiate
// Note that because the InstantiateDb* methods in your ORM classes are code generated
// it is actually safe to use "SELECT *" for your Custom Load Queries.
$strQuery = 'SELECT project.* FROM project WHERE budget > 5000 ORDER BY budget DESC';
// perform the query
$objDbResult = $objDatabase->Query($strQuery);
// Use the Project::InstantiateDbResult on the $objDbResult to get an array of Project objects
$objProjectArray = Project::InstantiateDbResult($objDbResult);
// Iterate through the Project Array as you would any other ORM object
foreach ($objProjectArray as $objProject) {
    _p($objProject->Name . ' has a budget of $' . $objProject->Budget);
    _p('<br/>', false);
}
?>



	<h3>Qcodo Query: Select all Projects which have a Budget over $5000 and under $10000, ordered by Descending Budget</h3>
<?php 
// Perform the Query using Project::QueryArray, which will return an array of Project objects
// given a QQ Condition, and any optional QQ Clauses.
$objProjectArray = Project::QueryArray(QQ::AndCondition(QQ::GreaterThan(QQN::Project()->Budget, 5000), QQ::LessThan(QQN::Project()->Budget, 10000)), QQ::Clause(QQ::OrderBy(QQN::Project()->Budget, false)));
// Iterate through the Project Array like last time
foreach ($objProjectArray as $objProject) {
    _p($objProject->Name . ' has a budget of $' . $objProject->Budget);
    _p('<br/>', false);
}
require '../includes/footer.inc.php';
Example #15
0
<?php

require_once '../qcubed.inc.php';
// Setup the Feed, itself
$objRss = new QRssFeed('Examples Site Projects', 'http://examples.qcu.be/', 'An Example RSS feed of the Qcubed Examples Site Projects');
$objRss->Image = new QRssImage('http://www.qcu.be/sites/all/themes/qcubednew/images/QCubed.png');
$objRss->PubDate = new QDateTime(QDateTime::Now);
// Iterate through all the projects, and setup a QRssItem per project
// Limit it to the "10 most recently started projects"
foreach ($objProjects = Project::LoadAll(QQ::Clause(QQ::OrderBy(QQN::Project()->StartDate, false), QQ::LimitInfo(10))) as $objProject) {
    $objItem = new QRssItem($objProject->Name, 'http://examples.qcu.be/examples/communication/rss.php/' . $objProject->Id, $objProject->Description);
    $objItem->Author = $objProject->ManagerPerson->FirstName . ' ' . $objProject->ManagerPerson->LastName;
    $objItem->PubDate = $objProject->StartDate;
    $objItem->Guid = $objItem->Link;
    $objItem->GuidPermaLink = true;
    $objItem->AddCategory(new QRssCategory('Some Project Category 1'));
    $objItem->AddCategory(new QRssCategory('Some Project Category 2'));
    $objRss->AddItem($objItem);
}
// Output/Run the feed
// Note that the Run method will reset the output buffer and setup the Headers to output XML,
// so any HTML or Text outputted until now will be lost.  If for whatever reason you just
// want the XML, you can call $objRss->GetXml(), which will return the XML string.
// Also, if you need to change the encoding of the XML, you can do so in QApplication::$EncodingType.
$objRss->Run();
Example #16
0
 public static function LoadArrayByBudgetMinimum($fltBudgetMinimum, $objOptionalClauses = null)
 {
     return Project::QueryArray(QQ::GreaterOrEqual(QQN::Project()->Budget, $fltBudgetMinimum), $objOptionalClauses);
 }
Example #17
0
 public function testHaving()
 {
     $objItems = Project::QueryArray(QQ::All(), QQ::Clause(QQ::GroupBy(QQN::Project()->Id), QQ::Count(QQN::Project()->PersonAsTeamMember->PersonId, 'team_member_count'), QQ::Having(QQ::SubSql('COUNT({1}) > 5', QQN::Project()->PersonAsTeamMember->PersonId))));
     $this->assertEqual(sizeof($objItems), 2, "2 projects found");
     $this->assertEqual($objItems[0]->Name, "State College HR System", "Project " . $objItems[0]->Name . " found");
     $this->assertEqual($objItems[0]->GetVirtualAttribute('team_member_count'), 6, "6 team members found for project " . $objItems[0]->Name);
 }
Example #18
0
	<h2>Select all People where: the first name is alphabetically "greater than" the last name</h2>
	<ul>
<?php 
$objPersonArray = Person::QueryArray(QQ::GreaterThan(QQN::Person()->FirstName, QQN::Person()->LastName));
foreach ($objPersonArray as $objPerson) {
    _p('<li>' . $objPerson->FirstName . ' ' . $objPerson->LastName . '</li>', false);
}
?>
	</ul>
	<h2>Select all Projects where: the manager's first name is alphabetically "greater than" the last name, or who's name contains "Website"</h2>
	<ul>
<?php 
$objProjectArray = Project::QueryArray(QQ::OrCondition(QQ::GreaterThan(QQN::Project()->ManagerPerson->FirstName, QQN::Project()->ManagerPerson->LastName), QQ::Like(QQN::Project()->Name, '%Website%')));
foreach ($objProjectArray as $objProject) {
    _p(sprintf('<li>%s (managed by %s %s)</li>', $objProject->Name, $objProject->ManagerPerson->FirstName, $objProject->ManagerPerson->LastName), false);
}
?>
	</ul>
	<h2>Select all Projects where: the Project ID <= 2 AND (the manager's first name is alphabetically "greater than" the last name, or who's name contains "Website")</h2>
	<ul>
<?php 
$objProjectArray = Project::QueryArray(QQ::AndCondition(QQ::OrCondition(QQ::GreaterThan(QQN::Project()->ManagerPerson->FirstName, QQN::Project()->ManagerPerson->LastName), QQ::Like(QQN::Project()->Name, '%Website%')), QQ::LessOrEqual(QQN::Project()->Id, 2)));
foreach ($objProjectArray as $objProject) {
    _p(sprintf('<li>%s (managed by %s %s)</li>', $objProject->Name, $objProject->ManagerPerson->FirstName, $objProject->ManagerPerson->LastName), false);
}
?>
	</ul>
</div>

<?php 
require '../includes/footer.inc.php';
 public function testMultiLevel()
 {
     $arrPeople = Person::LoadAll(self::getTestClauses());
     $this->assertEquals(12, sizeof($arrPeople), "12 Person objects found");
     $targetPerson = $this->verifyObjectPropertyHelper($arrPeople, 'LastName', 'Wolfe');
     $this->helperVerifyKarenWolfe($targetPerson);
     $objProjectArray = $targetPerson->_ProjectAsManagerArray;
     $this->assertEquals(2, sizeof($objProjectArray), "2 projects found");
     foreach ($objProjectArray as $objProject) {
         $objMilestoneArray = $objProject->_MilestoneArray;
         switch ($objProject->Id) {
             case 1:
                 $this->assertEquals(3, sizeof($objMilestoneArray), "3 milestones found");
                 break;
             case 4:
                 $this->assertEquals(4, sizeof($objMilestoneArray), "4 milestones found");
                 break;
             default:
                 $this->assertTrue(false, 'Unexpected project found, id: ' . $objProject->Id);
                 break;
         }
     }
     // Now test a multilevel expansion where first level does not expand by array. Should get duplicate entries at that level.
     $clauses = QQ::Clause(QQ::ExpandAsArray(QQN::Person()->Address), QQ::Expand(QQN::Person()->ProjectAsManager), QQ::ExpandAsArray(QQN::Person()->ProjectAsManager->Milestone));
     $arrPeople = Person::LoadAll($clauses);
     // Karen Wolfe should duplicate, since she is managing two projects
     $this->assertEquals(13, sizeof($arrPeople), "13 Person objects found");
     $targetPerson = $this->verifyObjectPropertyHelper($arrPeople, 'LastName', 'Wolfe');
     $objProjectArray = $targetPerson->_ProjectAsManagerArray;
     $this->assertNull($objProjectArray, "No project array found");
     $objProject = $targetPerson->_ProjectAsManager;
     $this->assertNotNull($objProject, "Project found");
     $objMilestoneArray = $objProject->_MilestoneArray;
     // since we didn't specify the order, not sure which one we will get, so check for either
     switch ($objProject->Id) {
         case 1:
             $this->assertEquals(3, sizeof($objMilestoneArray), "3 milestones found");
             break;
         case 4:
             $this->assertEquals(4, sizeof($objMilestoneArray), "4 milestones found");
             break;
         default:
             $this->assertTrue(false, 'Unexpected project found, id: ' . $objProject->Id);
             break;
     }
     // test that querying for expanded objects will return the cached version
     $objProject2 = Project::Load($objProject->Id, array(QQ::Select(QQN::Project()->Name)));
     // even though we only selected a name, we still get the other items in the cached object
     $this->assertNotNull($objProject2->ManagerPersonId, "ManagerPersonId found");
 }
 public function testConditionalExpansionAssociation()
 {
     // Conditional expansion on association nodes really can only work with the PK of the join.
     // Get all projects, and also expand on related projects if the id is 1
     $a = Project::QueryArray(QQ::All(), [QQ::ExpandAsArray(QQN::Project()->ParentProjectAsRelated, QQ::Equal(QQN::Project()->ParentProjectAsRelated->ProjectId, 1)), QQ::ExpandAsArray(QQN::Project()->ProjectAsRelated, QQ::Equal(QQN::Project()->ProjectAsRelated->Project->Id, 1)), QQ::OrderBy(QQN::Project()->Id)]);
     $this->assertEquals(1, $a[2]->_ParentProjectAsRelatedArray[0]->Id);
 }
Example #21
0
 public function btnGo_Click($strFormId, $strControlId, $strParameter)
 {
     //get a list of project ids that have had their status changed
     $changedIds = $this->colProjectSelected->GetChangedIds();
     //load all the changed project objects at once so we can avoid multiple DB hits
     $temp = Project::QueryArray(QQ::In(QQN::Project()->Id, array_keys($changedIds)));
     //Put them in an associated list so we can find the needed ones easily later
     $changedItems = array();
     foreach ($temp as $item) {
         $changedItems[$item->Id] = $item;
     }
     foreach ($changedIds as $id => $blnSelected) {
         //look up the appropriate item using the handily indexed array we built earlier
         $item = $changedItems[$id];
         if ($blnSelected) {
             //Associate this Project
             QApplication::DisplayAlert('Associating ' . $item->Name);
         } else {
             //Unassociate this Project
             QApplication::DisplayAlert('Unassociating ' . $item->Name);
         }
     }
 }
Example #22
0
}
?>

	<h2>Example 3: Managers having one least a project with a conson milestone, and for each manager, the first voyel milestone and the first conson one</h2>
<?php 
$emptySelect = QQ::Select();
$emptySelect->SetSkipPrimaryKey(true);
$nVoyel = QQ::Alias(QQN::Person()->ProjectAsManager->Milestone, 'voyel');
$nConson = QQ::Alias(QQN::Person()->ProjectAsManager->Milestone, 'conson');
$objPersonArray = Person::QueryArray(QQ::IsNotNull($nConson->Id), QQ::Clause(QQ::Expand(QQN::Person()->ProjectAsManager, null, $emptySelect), QQ::Expand($nVoyel, QQ::In($nVoyel->Name, array('Milestone A', 'Milestone E', 'Milestone I')), $emptySelect), QQ::Expand($nConson, QQ::NotIn($nConson->Name, array('Milestone A', 'Milestone E', 'Milestone I')), $emptySelect), QQ::GroupBy(QQN::Person()->Id), QQ::Minimum($nVoyel->Name, 'min_voyel'), QQ::Minimum($nConson->Name, 'min_conson'), QQ::Expand(QQN::Person()->ProjectAsManager, null, $emptySelect), QQ::Minimum(QQN::Person()->ProjectAsManager->Id, 'dummy'), QQ::Select(QQN::Person()->FirstName, QQN::Person()->LastName)));
foreach ($objPersonArray as $objManager) {
    _p($objManager->FirstName . ' ' . $objManager->LastName . " (" . $objManager->GetVirtualAttribute('min_voyel') . ', ' . $objManager->GetVirtualAttribute('min_conson') . ")");
    _p('<br/>', false);
}
?>

	<h2>Example 4: Projects with, for each one, the "min" city from the addresses containing 'r' and the "min" city from the addresses NOT containing 'r' </h2>
<?php 
$nWithR = QQ::Alias(QQN::Project()->PersonAsTeamMember->Person->Address, 'with_r');
$nWithoutR = QQ::Alias(QQN::Project()->PersonAsTeamMember->Person->Address, 'without_r');
$objProjectArray = Project::QueryArray(QQ::All(), QQ::Clause(QQ::Expand($nWithR, QQ::Like($nWithR->Street, '%r%')), QQ::Expand($nWithoutR, QQ::NotLike($nWithoutR->Street, '%r%')), QQ::GroupBy(QQN::Project()->Id), QQ::Minimum($nWithR->City, 'min_city_r'), QQ::Minimum($nWithoutR->City, 'min_city_wor')));
foreach ($objProjectArray as $objProject) {
    _p($objProject->Name . " (" . $objProject->GetVirtualAttribute('min_city_r') . ', ' . $objProject->GetVirtualAttribute('min_city_wor') . ")");
    _p('<br/>', false);
}
QApplication::$Database[1]->OutputProfiling();
?>
</div>

<?php 
require '../includes/footer.inc.php';
 public function testSubSql()
 {
     $objProject = Project::QuerySingle(QQ::All(), QQ::Clause(QQ::Count(QQ::SubSql('DISTINCT {1}', QQN::Project()->ManagerPersonId), "manager_count")));
     $this->assertEquals(3, $objProject->GetVirtualAttribute("manager_count"), "Project manager count is 3");
 }
Example #24
0
    _p('<li>' . $objPerson->FirstName . ' ' . $objPerson->LastName . '</li>', false);
}
?>
	</ul>
	<h2>Select all Projects and the Count of Team Members (if applicable)</h2>
	<p><em>GROUP BY in action</em></p>
	<ul>
<?php 
$objProjectArray = Project::QueryArray(QQ::All(), QQ::Clause(QQ::GroupBy(QQN::Project()->Id), QQ::Count(QQN::Project()->PersonAsTeamMember->PersonId, 'team_member_count')));
foreach ($objProjectArray as $objProject) {
    _p('<li>' . $objProject->Name . ' (' . $objProject->GetVirtualAttribute('team_member_count') . ' team members)' . '</li>', false);
}
?>
	</ul>

	<h2>Select all Projects with more than 5 team members. </h2>
	<p><em>Using a Having clause to further limit group functions</em></p>
	<ul>
<?php 
$objProjectArray = Project::QueryArray(QQ::All(), QQ::Clause(QQ::GroupBy(QQN::Project()->Id), QQ::Count(QQN::Project()->PersonAsTeamMember->PersonId, 'team_member_count'), QQ::Having(QQ::SubSql('COUNT({1}) > 5', QQN::Project()->PersonAsTeamMember->PersonId))));
foreach ($objProjectArray as $objProject) {
    _p($objProject->Name . ' (' . $objProject->GetVirtualAttribute('team_member_count') . ' team members)');
    _p('<br/>', false);
}
?>
	</ul>
</div>


<?php 
require '../includes/footer.inc.php';
Example #25
0
	<p>In a slightly more complex example 2 below, we are looking for all projects that
	are associated with two other projects (each is specified by name). We use the
	same technique with <b>QQ::Alias()</b> as in example 1, except that we now
	mix it in with relationships expanded to other tables.</p>
</div>

<div id="demoZone">
	<h2>Example 1: Project members whose are in both project 1 and 2</h2>
<?php 
QApplication::$Database[1]->EnableProfiling();
$objPersonArray = Person::QueryArray(QQ::AndCondition(QQ::Equal(QQ::Alias(QQN::Person()->ProjectAsTeamMember, 'pm1')->ProjectId, 1), QQ::Equal(QQ::Alias(QQN::Person()->ProjectAsTeamMember, 'pm2')->ProjectId, 2)));
foreach ($objPersonArray as $objPerson) {
    _p($objPerson->FirstName . ' ' . $objPerson->LastName);
    _p('<br/>', false);
}
?>

	<h2>Example 2: Projects that are related to both 'Blueman Industrial Site Architecture' and 'ACME Payment System' projects</h2>
<?php 
$objProjectArray = Project::QueryArray(QQ::AndCondition(QQ::Equal(QQ::Alias(QQN::Project()->ProjectAsRelated, 'related1')->Project->Name, 'Blueman Industrial Site Architecture'), QQ::Equal(QQ::Alias(QQN::Project()->ProjectAsRelated, 'related2')->Project->Name, 'ACME Payment System')));
foreach ($objProjectArray as $objProject) {
    _p($objProject->Name . " (" . $objProject->Description . ")");
    _p('<br/>', false);
}
QApplication::$Database[1]->OutputProfiling();
?>
</div>

<?php 
require '../includes/footer.inc.php';
Example #26
0
 public function testEmptyColumns()
 {
     $objItem = Login::QuerySingle(QQ::Equal(QQN::Login()->Id, 1));
     $this->assertTrue($objItem->IsEnabled === 0, "Zero column does not return null.");
     $objItem = Project::QuerySingle(QQ::Equal(QQN::Project()->Id, 2));
     $this->assertTrue($objItem->EndDate === null, "Null date column returns a null.");
 }
Example #27
0
$objPersonArray = Person::QueryArray(QQ::All(), QQ::Clause(QQ::OrderBy(QQN::Person()->LastName, QQN::Person()->FirstName)));
foreach ($objPersonArray as $objPerson) {
    _p($objPerson->FirstName . ' ' . $objPerson->LastName);
    _p('<br/>', false);
}
?>



	<h3>Select all People, Ordered by Last Name then First Name, Limited to the first 4 results</h3>
<?php 
$objPersonArray = Person::QueryArray(QQ::All(), QQ::Clause(QQ::OrderBy(QQN::Person()->LastName, QQN::Person()->FirstName), QQ::LimitInfo(4)));
foreach ($objPersonArray as $objPerson) {
    _p($objPerson->FirstName . ' ' . $objPerson->LastName);
    _p('<br/>', false);
}
?>



	<h3>Select all Projects and the Count of Team Members (if applicable)</h3>
<?php 
$objProjectArray = Project::QueryArray(QQ::All(), QQ::Clause(QQ::GroupBy(QQN::Project()->Id), QQ::Count(QQN::Project()->PersonAsTeamMember->PersonId, 'team_member_count')));
foreach ($objProjectArray as $objProject) {
    _p($objProject->Name . ' (' . $objProject->GetVirtualAttribute('team_member_count') . ' team members)');
    _p('<br/>', false);
}
?>

<?php 
require __INCLUDES__ . '/examples/footer.inc.php';
Example #28
0
	and in doing so they can unnecessarily overengineer some pieces of functionality.
	If the focus is on getting the application functional, first, then after the application is in
	a usable state, you can profile the functionality that tends to get used more often and simply
	focus on optimizing this smaller subset of heavily-used functionality.</p>

	<p>For information about Expanding through Association Tables, please refer to the
	<a href="../qcubed_query/association.php">Handling Association Tables example</a>.</p>
</div>

<div id="demoZone">
	<h2>List All Projects and its Manager</h2>
<?php 
// Enable Profiling (we're assuming the Examples Site Database is at index 1)
// NOTE: Profiling should only be enabled when you are actively wanting to profile a specific PHP script.
// Because of SIGNIFICANT performance degradation, it should otherwise always be off.
QApplication::$Database[1]->EnableProfiling();
// Load the Project array
// The following line of code is the ONLY line of code we will modify
$objProjectArray = Project::LoadAll(QQ::Clause(QQ::Expand(QQN::Project()->ManagerPerson)));
foreach ($objProjectArray as $objProject) {
    _p(QApplication::HtmlEntities($objProject->Name) . ' is managed by ' . $objProject->ManagerPerson->FirstName . ' ' . $objProject->ManagerPerson->LastName);
    _p('<br/>', false);
}
_p('<br/>', false);
// Output Profiling Data
QApplication::$Database[1]->OutputProfiling();
?>
</div>

<?php 
require '../includes/footer.inc.php';
 public function testAlias2()
 {
     $objProjectArray = Project::QueryArray(QQ::AndCondition(QQ::Equal(QQ::Alias(QQN::Project()->ProjectAsRelated, 'related1')->Project->Name, 'Blueman Industrial Site Architecture'), QQ::Equal(QQ::Alias(QQN::Project()->ProjectAsRelated, 'related2')->Project->Name, 'ACME Payment System')));
     $this->assertEquals(1, sizeof($objProjectArray));
     $this->verifyObjectPropertyHelper($objProjectArray, 'Name', 'ACME Website Redesign');
 }