ExpandAsArray() public static method

public static ExpandAsArray ( $objNode )
コード例 #1
0
 /**
  * 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);
 }
コード例 #2
0
 public function testMultiLevel()
 {
     $arrPeople = Person::LoadAll(QQ::Clause(QQ::ExpandAsArray(QQN::Person()->Address), QQ::ExpandAsArray(QQN::Person()->ProjectAsManager), QQ::ExpandAsArray(QQN::Person()->ProjectAsManager->Milestone)));
     $targetPerson = null;
     foreach ($arrPeople as $objPerson) {
         if ($objPerson->LastName == "Wolfe") {
             $targetPerson = $objPerson;
         }
     }
     $this->assertEqual(sizeof($arrPeople), 12);
     $this->assertNotEqual($targetPerson, null, "Karen Wolfe found");
     $targetProject = null;
     foreach ($targetPerson->_ProjectAsManagerArray as $objProject) {
         if ($objProject->Name == "ACME Payment System") {
             $targetProject = $objProject;
         }
     }
     $this->assertEqual(sizeof($targetPerson->_ProjectAsManagerArray), 2, "2 projects found");
     $this->assertNotEqual($targetProject, null, "ACME Payment System project found");
     $targetMilestone = null;
     foreach ($targetProject->_MilestoneArray as $objMilestone) {
         if ($objMilestone->Name == "Milestone H") {
             $targetMilestone = $objMilestone;
         }
     }
     $this->assertEqual(sizeof($targetProject->_MilestoneArray), 4, "4 milestones found");
     $this->assertNotEqual($targetMilestone, null, "Milestone H found");
 }
コード例 #3
0
 public function testSelectSubsetInExpandAsArray()
 {
     $objPersonArray = Person::LoadAll(QQ::Clause(QQ::Select(QQN::Person()->FirstName), QQ::ExpandAsArray(QQN::Person()->Address, QQ::Select(QQN::Person()->Address->Street, QQN::Person()->Address->City)), QQ::ExpandAsArray(QQN::Person()->ProjectAsManager, QQ::Select(QQN::Person()->ProjectAsManager->StartDate)), QQ::ExpandAsArray(QQN::Person()->ProjectAsManager->Milestone, QQ::Select(QQN::Person()->ProjectAsManager->Milestone->Name))));
     foreach ($objPersonArray as $objPerson) {
         $this->assertNull($objPerson->LastName, "LastName should be null, since it was not selected");
         $this->assertNotNull($objPerson->Id, "Id should not be null since it's always added to the select list");
         if (sizeof($objPerson->_AddressArray) > 0) {
             foreach ($objPerson->_AddressArray as $objAddress) {
                 $this->assertNotNull($objAddress->Id, "Address->Id should not be null since it's always added to the select list");
                 $this->assertNull($objAddress->PersonId, "Address->PersonId should be null, since it was not selected");
             }
         }
         if (sizeof($objPerson->_ProjectAsManagerArray) > 0) {
             foreach ($objPerson->_ProjectAsManagerArray as $objProject) {
                 $this->assertNotNull($objProject->Id, "Project->Id should not be null since it's always added to the select list");
                 $this->assertNull($objProject->Name, "Project->Name should be null, since it was not selected");
                 if (sizeof($objProject->_MilestoneArray) > 0) {
                     foreach ($objProject->_MilestoneArray as $objMilestone) {
                         $this->assertNotNull($objMilestone->Id, "Milestone->Id should not be null since it's always added to the select list");
                         $this->assertNull($objMilestone->ProjectId, "Milestone->ProjectId should be null, since it was not selected");
                     }
                 }
             }
         }
     }
 }
コード例 #4
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);
     }
 }
コード例 #5
0
 protected function dtrText_Conditions($blnReset = false)
 {
     $this->arrConditions = array(QQ::AndCondition(QQ::Equal(QQN::NarroContextInfo()->LanguageId, QApplication::GetLanguageId()), QQ::Equal(QQN::NarroContextInfo()->Context->Active, true), QQ::Equal(QQN::NarroContextInfo()->Context->File->Active, true)));
     if ($blnReset) {
         $this->intMaxRowCount = 0;
     }
     $this->arrClauses = array(QQ::Expand(QQN::NarroContextInfo()->Context), QQ::Expand(QQN::NarroContextInfo()->Context->Text), QQ::Expand(QQN::NarroContextInfo()->Context->File), QQ::Expand(QQN::NarroContextInfo()->Context->Project), QQ::Expand(QQN::NarroContextInfo()->ValidSuggestion));
     if ($this->lstProject->SelectedValue > 0) {
         $this->arrConditions[] = QQ::Equal(QQN::NarroContextInfo()->Context->ProjectId, $this->lstProject->SelectedValue);
     }
     switch ($this->lstFilter->SelectedValue) {
         case self::SHOW_NOT_TRANSLATED:
             $this->arrConditions[] = QQ::Equal(QQN::NarroContextInfo()->HasSuggestions, false);
             break;
         case self::SHOW_NOT_APPROVED:
             $this->arrConditions[] = QQ::AndCondition(QQ::IsNull(QQN::NarroContextInfo()->ValidSuggestionId), QQ::Equal(QQN::NarroContextInfo()->HasSuggestions, true));
             break;
         case self::SHOW_APPROVED:
             $this->arrConditions[] = QQ::IsNotNull(QQN::NarroContextInfo()->ValidSuggestionId);
             break;
         case self::SHOW_APPROVED_AND_NOT_APPROVED:
             $this->arrConditions[] = QQ::Equal(QQN::NarroContextInfo()->HasSuggestions, true);
             break;
         case self::SHOW_NOT_APPROVED_AND_NOT_TRANSLATED:
             $this->arrConditions[] = QQ::IsNull(QQN::NarroContextInfo()->ValidSuggestionId);
             break;
         case self::SHOW_NOT_APPROVED_AND_WITHOUT_VOTES:
             $this->arrConditions[] = QQ::Equal(QQ::SubSql('SELECT COUNT(*) FROM narro_suggestion_vote, narro_suggestion WHERE narro_suggestion_vote.suggestion_id=narro_suggestion.suggestion_id AND narro_suggestion.text_id={1}', QQN::NarroContextInfo()->Context->TextId), 0);
             break;
         case self::SHOW_NOT_APPROVED_AND_WITH_VOTES:
             $this->arrConditions[] = QQ::NotEqual(QQ::SubSql('SELECT COUNT(*) FROM narro_suggestion_vote, narro_suggestion WHERE narro_suggestion_vote.suggestion_id=narro_suggestion.suggestion_id AND narro_suggestion.text_id={1}', QQN::NarroContextInfo()->Context->TextId), 0);
             break;
         case self::SHOW_IDENTICAL_APPROVED:
             $this->arrClauses[] = QQ::ExpandAsArray(QQN::NarroContextInfo()->Context->Text->NarroSuggestionAsText);
             $this->arrClauses[] = QQ::Distinct();
             $this->arrConditions[] = QQ::AndCondition(QQ::Equal(QQN::NarroContextInfo()->Context->Text->TextValueMd5, QQN::NarroContextInfo()->Context->Text->NarroSuggestionAsText->SuggestionValueMd5), QQ::Equal(QQN::NarroContextInfo()->ValidSuggestionId, QQN::NarroContextInfo()->Context->Text->NarroSuggestionAsText->SuggestionId), QQ::Equal(QQN::NarroContextInfo()->Context->Text->NarroSuggestionAsText->LanguageId, QQN::NarroContextInfo()->LanguageId));
             break;
         case self::SHOW_IDENTICAL:
             $this->arrClauses[] = QQ::ExpandAsArray(QQN::NarroContextInfo()->Context->Text->NarroSuggestionAsText);
             $this->arrClauses[] = QQ::Distinct();
             $this->arrConditions[] = QQ::AndCondition(QQ::Equal(QQN::NarroContextInfo()->Context->Text->TextValueMd5, QQN::NarroContextInfo()->Context->Text->NarroSuggestionAsText->SuggestionValueMd5), QQ::Equal(QQN::NarroContextInfo()->Context->Text->NarroSuggestionAsText->LanguageId, QQN::NarroContextInfo()->LanguageId));
             break;
         case self::SHOW_ALL:
         default:
     }
     if ($this->txtFile->Text != t('all files') && $this->txtFile->Text != '') {
         if (preg_match("/^'.+'\$/", $this->txtFile->Text)) {
             $this->arrConditions[] = QQ::Equal(QQN::NarroContextInfo()->Context->File->FilePath, substr($this->txtFile->Text, 1, -1));
         } elseif (preg_match('/^".+"$/', $this->txtFile->Text)) {
             $this->arrConditions[] = QQ::Equal(QQN::NarroContextInfo()->Context->File->FilePath, substr($this->txtFile->Text, 1, -1));
         } else {
             $this->arrConditions[] = QQ::Like(QQN::NarroContextInfo()->Context->File->FilePath, '%' . $this->txtFile->Text . '%');
         }
     }
     if ($this->txtSearch->Text) {
         if (preg_match("/^'.+'\$/", $this->txtSearch->Text)) {
             $strLikeSearch = substr($this->txtSearch->Text, 1, -1);
         } elseif (preg_match('/^".+"$/', $this->txtSearch->Text)) {
             $strLikeSearch = substr($this->txtSearch->Text, 1, -1);
         } else {
             $strLikeSearch = '%' . $this->txtSearch->Text . '%';
         }
         switch ($this->lstSearchIn->SelectedValue) {
             case self::SEARCH_IN_TEXTS:
                 $this->arrConditions[] = QQ::Like(QQN::NarroContextInfo()->Context->Text->TextValue, $strLikeSearch);
                 break;
             case self::SEARCH_IN_TRANSLATIONS:
                 $this->arrClauses[] = QQ::ExpandAsArray(QQN::NarroContextInfo()->Context->Text->NarroSuggestionAsText);
                 $this->arrConditions[] = QQ::AndCondition(QQ::Like(QQN::NarroContextInfo()->Context->Text->NarroSuggestionAsText->SuggestionValue, $strLikeSearch), QQ::Equal(QQN::NarroContextInfo()->Context->Text->NarroSuggestionAsText->LanguageId, QApplication::GetLanguageId()));
                 break;
             case self::SEARCH_IN_AUTHORS:
                 $this->arrClauses[] = QQ::ExpandAsArray(QQN::NarroContextInfo()->Context->Text->NarroSuggestionAsText);
                 $this->arrConditions[] = QQ::AndCondition(QQ::Like(QQN::NarroContextInfo()->Context->Text->NarroSuggestionAsText->User->RealName, $strLikeSearch), QQ::Equal(QQN::NarroContextInfo()->Context->Text->NarroSuggestionAsText->LanguageId, QApplication::GetLanguageId()));
                 break;
             case self::SEARCH_IN_CONTEXTS:
                 $this->arrConditions[] = QQ::OrCondition(QQ::Like(QQN::NarroContextInfo()->Context->Context, $strLikeSearch), QQ::Like(QQN::NarroContextInfo()->Context->Comment, $strLikeSearch));
                 break;
             case self::SEARCH_IN_ALL:
             default:
                 $this->arrClauses[] = QQ::Distinct();
                 $this->arrConditions[] = QQ::OrCondition(QQ::Like(QQN::NarroContextInfo()->Context->Text->TextValue, $strLikeSearch), QQ::AndCondition(QQ::Like(QQN::NarroContextInfo()->Context->Text->NarroSuggestionAsText->SuggestionValue, $strLikeSearch), QQ::Equal(QQN::NarroContextInfo()->Context->Text->NarroSuggestionAsText->LanguageId, QApplication::GetLanguageId())), QQ::AndCondition(QQ::Like(QQN::NarroContextInfo()->Context->Text->NarroSuggestionAsText->User->RealName, $strLikeSearch), QQ::Equal(QQN::NarroContextInfo()->Context->Text->NarroSuggestionAsText->LanguageId, QApplication::GetLanguageId())), QQ::Like(QQN::NarroContextInfo()->Context->Context, $strLikeSearch), QQ::Like(QQN::NarroContextInfo()->Context->Comment, $strLikeSearch));
         }
     }
     switch ($this->lstSort->SelectedValue) {
         case self::SORT_TEXT:
             $this->arrClauses[] = QQ::OrderBy(QQN::NarroContextInfo()->Context->Text->TextValue, $this->lstSortDir->SelectedValue);
             break;
         case self::SORT_TEXT_LENGTH:
             $this->arrClauses[] = QQ::OrderBy(QQN::NarroContextInfo()->Context->Text->TextWordCount, $this->lstSortDir->SelectedValue);
             break;
         case self::SORT_TRANSLATION:
             $this->arrClauses[] = QQ::OrderBy(QQN::NarroContextInfo()->ValidSuggestion->SuggestionValue, $this->lstSortDir->SelectedValue);
             break;
         case self::SORT_TRANSLATION_DATE:
             $this->arrClauses[] = QQ::OrderBy(QQN::NarroContextInfo()->Modified, $this->lstSortDir->SelectedValue);
             break;
     }
 }
コード例 #6
0
 public function testExpand()
 {
     // Test intermediate nodes on expansion
     $clauses = QQ::Clause(QQ::Expand(QQN::Milestone()->Project->ManagerPerson));
     $objMilestone = Milestone::QuerySingle(QQ::Equal(QQN::Milestone()->Id, 1), $clauses);
     $this->assertTrue(!is_null($objMilestone->Name), "Milestone 1 has a name");
     $this->assertEqual($objMilestone->Name, "Milestone A", "Milestone 1 has name of Milestone A");
     $this->assertTrue(!is_null($objMilestone->Project->Name), "Project 1 has a name");
     $this->assertEqual($objMilestone->Project->Name, "ACME Website Redesign", "Project 1 has name of ACME Website Redesign");
     $this->assertTrue(!is_null($objMilestone->Project->ManagerPerson->FirstName), "Person 7 has a name");
     $this->assertEqual($objMilestone->Project->ManagerPerson->FirstName, "Karen", "Person 7 has first name of Karen");
     $clauses = QQ::Clause(QQ::ExpandAsArray(QQN::Project()->PersonAsTeamMember), QQ::OrderBy(QQN::Project()->PersonAsTeamMember->Person->LastName, QQN::Project()->PersonAsTeamMember->Person->FirstName));
     // short reach
     $objProject = Project::QuerySingle(QQ::Equal(QQN::Project()->Id, 1), $clauses);
     $objPersonArray = $objProject->_PersonAsTeamMemberArray;
     $arrNamesOnly = array();
     foreach ($objPersonArray as $item) {
         $arrNamesOnly[] = $item->FirstName . " " . $item->LastName;
     }
     $this->assertEqual($arrNamesOnly, array("Samantha Jones", "Kendall Public", "Alex Smith", "Wendy Smith", "Karen Wolfe"), "Project Team Member expansion is correct");
     // long reach
     $clauses = QQ::Clause(QQ::ExpandAsArray(QQN::Milestone()->Project->PersonAsTeamMember), QQ::OrderBy(QQN::Milestone()->Project->PersonAsTeamMember->Person->LastName, QQN::Milestone()->Project->PersonAsTeamMember->Person->FirstName));
     $objMilestone = Milestone::QuerySingle(QQ::Equal(QQN::Milestone()->Id, 1), $clauses);
     $objPersonArray = $objMilestone->Project->_PersonAsTeamMemberArray;
     $arrNamesOnly = array();
     foreach ($objPersonArray as $item) {
         $arrNamesOnly[] = $item->FirstName . " " . $item->LastName;
     }
     $this->assertEqual($arrNamesOnly, array("Samantha Jones", "Kendall Public", "Alex Smith", "Wendy Smith", "Karen Wolfe"), "Long reach Milestone to Project Team Member expansion is correct");
 }
コード例 #7
0
ファイル: association.php プロジェクト: kmcelhinney/qcodo
	<h3>Get All People Who Are on a Project Managed by Karen Wolfe (Person ID #7)<br/>showing the Project which is involved in the JOIN via Expand()</h3>
	<i>Notice how some people may be listed twice, once for each project which he or she is part of that is managed by Karen Wolfe.</i><br/><br/>
<?php 
$objPersonArray = Person::QueryArray(QQ::Equal(QQN::Person()->ProjectAsTeamMember->Project->ManagerPersonId, 7), QQ::Clause(QQ::Expand(QQN::Person()->ProjectAsTeamMember->Project), QQ::OrderBy(QQN::Person()->LastName, QQN::Person()->FirstName)));
foreach ($objPersonArray as $objPerson) {
    printf('%s %s (via the "%s" project)<br/>', QApplication::HtmlEntities($objPerson->FirstName), QApplication::HtmlEntities($objPerson->LastName), QApplication::HtmlEntities($objPerson->_ProjectAsTeamMember->Name));
}
?>



	<br/>
	<h3>Same as above, but this time, use ExpandAsArray()</h3>
	<i>Notice how each person is only listed once... but each person has an internal/virtual <b>_ProjectAsTeamMemberArray</b> which may list more than one project.</i><br/><br/>
<?php 
$objPersonArray = Person::QueryArray(QQ::Equal(QQN::Person()->ProjectAsTeamMember->Project->ManagerPersonId, 7), QQ::Clause(QQ::ExpandAsArray(QQN::Person()->ProjectAsTeamMember), QQ::OrderBy(QQN::Person()->LastName, QQN::Person()->FirstName, QQN::Person()->ProjectAsTeamMember->Project->Name)));
foreach ($objPersonArray as $objPerson) {
    _p($objPerson->FirstName . ' ' . $objPerson->LastName);
    _p('<br/>', false);
    // Now, instead of using the _ProjectAsTeamMember virtual attribute, we will use
    // the _ProjectAsTeamMemberArray virtual attribute, which gives us an array of Project objects
    $strProjectNameArray = array();
    foreach ($objPerson->_ProjectAsTeamMemberArray as $objProject) {
        array_push($strProjectNameArray, QApplication::HtmlEntities($objProject->Name));
    }
    printf('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;via: %s<br/>', implode(', ', $strProjectNameArray));
}
?>

<?php 
require '../includes/footer.inc.php';
コード例 #8
0
ファイル: expandasarray.php プロジェクト: eliud254/q-auction
		number of rows returned from SQL in that one query is equal to:<br />
		<center><b>(Num of Persons) * (Num of Projects) * (Num of Milestones) *
		(Num of Addresses)</b></center><br />
		You can see how it can get out of hand quickly - and the performance gains
		you get out of issuing a single query can become a detriment instead, because
		of the amount of data that gets transfered from your database server to PHP.
		Thus, this approach only makes sense if you don't expect to have hundreds of
		items in each of the tables you're extracting the data from. Be sure to look
		at the SQL statement generated by QQuery, and try running it yourself, keeping
		the number of results in mind. 
	</div>
	<h3>Projects and Addresses for each Person</h3>    

<?php 
QApplication::$Database[1]->EnableProfiling();
$people = Person::LoadAll(QQ::Clause(QQ::ExpandAsArray(QQN::Person()->Address), QQ::ExpandAsArray(QQN::Person()->ProjectAsManager), QQ::ExpandAsArray(QQN::Person()->ProjectAsManager->Milestone)));
foreach ($people as $person) {
    echo "<b>" . $person->FirstName . " " . $person->LastName . "</b><br />";
    echo "Addresses: ";
    if (sizeof($person->_AddressArray) == 0) {
        echo "none";
    } else {
        foreach ($person->_AddressArray as $address) {
            echo $address->Street . "; ";
        }
    }
    echo "<br />";
    echo "Projects where this person is a project manager: ";
    if (sizeof($person->_ProjectAsManagerArray) == 0) {
        echo "none<br />";
    } else {
コード例 #9
0
ファイル: reverse.php プロジェクト: tomVertuoz/framework
<div id="demoZone">
	<h2>Get All People, Specifying the Project They Manage (if any), for Projects that have 'ACME' or 'HR' in it</h2>
	<p><em>Notice how some people may be listed twice, if they manage more than one project.</em></p>
	<ul>
<?php 
$objPersonArray = Person::QueryArray(QQ::OrCondition(QQ::Like(QQN::Person()->ProjectAsManager->Name, '%ACME%'), QQ::Like(QQN::Person()->ProjectAsManager->Name, '%HR%')), QQ::Clause(QQ::Expand(QQN::Person()->ProjectAsManager), QQ::OrderBy(QQN::Person()->LastName, QQN::Person()->FirstName)));
foreach ($objPersonArray as $objPerson) {
    printf('<li>%s %s (managing the "%s" project)</li>', QApplication::HtmlEntities($objPerson->FirstName), QApplication::HtmlEntities($objPerson->LastName), QApplication::HtmlEntities($objPerson->_ProjectAsManager->Name), false);
}
?>
	</ul>
	<h3>Same as above, but this time, use ExpandAsArray()</h3>
	<em>Notice how each person is only listed once... but each person has an internal/virtual <strong>_ProjectAsManagerArray</strong> which may list more than one project.</em></p>
<?php 
$objPersonArray = Person::QueryArray(QQ::OrCondition(QQ::Like(QQN::Person()->ProjectAsManager->Name, '%ACME%'), QQ::Like(QQN::Person()->ProjectAsManager->Name, '%HR%')), QQ::Clause(QQ::ExpandAsArray(QQN::Person()->ProjectAsManager), QQ::OrderBy(QQN::Person()->LastName, QQN::Person()->FirstName)));
foreach ($objPersonArray as $objPerson) {
    _p('<li>' . $objPerson->FirstName . ' ' . $objPerson->LastName, false);
    // Now, instead of using the _ProjectAsManager virtual attribute, we will use
    // the _ProjectAsManagerArray virtual attribute, which gives us an array of Project objects
    $strProjectNameArray = array();
    foreach ($objPerson->_ProjectAsManagerArray as $objProject) {
        array_push($strProjectNameArray, QApplication::HtmlEntities($objProject->Name));
    }
    printf(' via: %s</li>', implode(', ', $strProjectNameArray));
}
?>
</div>

<?php 
require '../includes/footer.inc.php';
コード例 #10
0
 /**
  * Make sure that expansions looking backwards are pointing to the same object looking forwards
  */
 public function testExpandReverseReferences()
 {
     // Test virtual binding of reverse relationships
     $clauses = [QQ::Expand(QQN::Person()->ProjectAsManager)];
     $objPerson = Person::QuerySingle(QQ::All(), $clauses);
     $objPerson->FirstName = 'test';
     $objProject = $objPerson->ProjectAsManager;
     $objPerson2 = $objProject->ManagerPerson;
     $this->assertEquals('test', $objPerson2->FirstName);
     // Test forward reference looking back
     $clauses = [QQ::Expand(QQN::Project()->ManagerPerson)];
     $objProject = Project::QuerySingle(QQ::All(), $clauses);
     $objProject->Name = 'test';
     $objPerson = $objProject->ManagerPerson;
     $objProject2 = $objPerson->ProjectAsManager;
     $this->assertEquals('test', $objProject2->Name);
     // test unique reverse reference
     $clauses = [QQ::Expand(QQN::Person()->Login)];
     $objPerson = Person::QuerySingle(QQ::All(), $clauses);
     $objPerson->FirstName = 'test';
     $objLogin = $objPerson->Login;
     $objPerson2 = $objLogin->Person;
     $this->assertEquals('test', $objPerson2->FirstName);
     // test many-to-many expansion
     $clauses = [QQ::ExpandAsArray(QQN::Project()->PersonAsTeamMember)];
     $objProject = Project::QuerySingle(QQ::All(), $clauses);
     $objProject->Name = 'test';
     $objPersonArray = $objProject->_PersonAsTeamMemberArray;
     $objProject2 = $objPersonArray[0]->_ProjectAsTeamMember;
     $this->assertEquals('test', $objProject2->Name);
 }
コード例 #11
0
 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);
 }
コード例 #12
0
ファイル: NarroUser.class.php プロジェクト: Jobava/narro
 public static function LoadByUserId($intUserId, $objOptionalClauses = null)
 {
     $objUser = NarroUser::QuerySingle(QQ::AndCondition(QQ::Equal(QQN::NarroUser()->UserId, $intUserId)), QQ::ExpandAsArray(QQN::NarroUser()->NarroUserRoleAsUser));
     if (!$objUser instanceof NarroUser) {
         return false;
     }
     foreach ($objUser->_NarroUserRoleAsUserArray as $objRole) {
         /* @var $objRole NarroUserRole */
         $arrRolePermission = NarroRolePermission::LoadArrayByRoleId($objRole->RoleId, QQ::Expand(QQN::NarroRolePermission()->Permission));
         foreach ($arrRolePermission as $objRolePermission) {
             $objUser->arrPermissions[$objRolePermission->Permission->PermissionName . '-' . $objRole->LanguageId . '-' . $objRole->ProjectId] = $objRolePermission;
         }
     }
     if (isset($objUser->Preferences['Language'])) {
         $objLanguage = NarroLanguage::LoadByLanguageCode($objUser->Preferences['Language']);
         if ($objLanguage instanceof NarroLanguage) {
             $objUser->Language = $objLanguage;
         } elseif (QApplication::$TargetLanguage instanceof NarroLanguage) {
             $objUser->Language = QApplication::$TargetLanguage;
         }
     } elseif (QApplication::$TargetLanguage instanceof NarroLanguage) {
         $objUser->Language = QApplication::$TargetLanguage;
     }
     return $objUser;
 }
コード例 #13
0
 public function testConditionalExpansion()
 {
     $clauses = QQ::Clause(QQ::ExpandAsArray(QQN::Person()->Address), QQ::Expand(QQN::Person()->ProjectAsManager, QQ::Equal(QQN::Person()->ProjectAsManager->ProjectStatusTypeId, ProjectStatusType::Open)), QQ::ExpandAsArray(QQN::Person()->ProjectAsManager->Milestone), QQ::OrderBy(QQN::Person()->Id));
     $targetPersonArray = Person::LoadAll($clauses);
     $targetPerson = reset($targetPersonArray);
     $this->assertEqual($targetPerson->Id, 1, "Person 1 found.");
     $this->assertNotNull($targetPerson->_ProjectAsManager, "Person 1 has a project.");
     $targetPerson = end($targetPersonArray);
     $this->assertEqual($targetPerson->Id, 12, "Person 12 found.");
     $this->assertNull($targetPerson->_ProjectAsManager, "Person 12 does not have a project.");
     //TODO: Conditional Array Expansion, requires API change
 }
コード例 #14
0
ファイル: qqselect.php プロジェクト: hiptc/dle2wordpress
	<h2>Get the last names of all the people, and the amount spent on the project they manage (if any), for Projects that
	have 'ACME' or 'HR' in it. Sort the result by Last Name, then First Name</h2>
	<p><i>Notice how some people may be listed twice, if they manage more than one project.</i></p>
	<ul>
<?php 
$objPersonArray = Person::QueryArray(QQ::OrCondition(QQ::Like(QQN::Person()->ProjectAsManager->Name, '%ACME%'), QQ::Like(QQN::Person()->ProjectAsManager->Name, '%HR%')), QQ::Clause(QQ::Select(QQN::Person()->LastName), QQ::Expand(QQN::Person()->ProjectAsManager, null, QQ::Select(QQN::Person()->ProjectAsManager->Spent)), QQ::OrderBy(QQN::Person()->LastName, QQN::Person()->FirstName)));
foreach ($objPersonArray as $objPerson) {
    printf("<li>%s's project spent \$%0.2f</li>", QApplication::HtmlEntities($objPerson->LastName), QApplication::HtmlEntities($objPerson->_ProjectAsManager->Spent));
}
?>
	</ul>
	<h3>Projects and Addresses for each Person</h3>
	<ul>
<?php 
$people = Person::LoadAll(QQ::Clause(QQ::Select(QQN::Person()->FirstName), QQ::ExpandAsArray(QQN::Person()->Address, QQ::Select(QQN::Person()->Address->Street, QQN::Person()->Address->City)), QQ::ExpandAsArray(QQN::Person()->ProjectAsManager, QQ::Select(QQN::Person()->ProjectAsManager->StartDate)), QQ::ExpandAsArray(QQN::Person()->ProjectAsManager->Milestone, QQ::Select(QQN::Person()->ProjectAsManager->Milestone->Name))));
foreach ($people as $person) {
    echo "<li><b>" . $person->FirstName . "</b><br />";
    assert(is_null($person->LastName));
    echo "Addresses: ";
    if (sizeof($person->_AddressArray) == 0) {
        echo "none";
    } else {
        foreach ($person->_AddressArray as $address) {
            echo $address->Street . ', ' . $address->City . "; ";
            assert(is_null($address->PersonId));
        }
    }
    echo "<br />";
    echo "Projects where this person is a project manager: ";
    if (sizeof($person->_ProjectAsManagerArray) == 0) {
コード例 #15
0
ファイル: NarroLanguage.class.php プロジェクト: Jobava/narro
 /**
  * Returns a tmx file
  * @param QQCondition $objLangCondition e.g. QQ::In(QQN::NarroText()->NarroSuggestionAsText->LanguageId, QApplication::GetLanguageId());
  * @return a tmx file, formatted as a string
  */
 public static function GetTmx($objLangCondition)
 {
     $tmx = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE tmx SYSTEM "tmx13.dtd"><tmx />');
     $tmx->addAttribute('version', '1.3');
     $header = $tmx->addChild('header');
     // mandatory
     $header->addAttribute('creationtool', "Narro");
     $header->addAttribute('creationtoolversion', NARRO_VERSION);
     $header->addAttribute('segtype', "sentence");
     $header->addAttribute('o-tmf', "ABCTransMem");
     $header->addAttribute('adminlang', NarroLanguage::SOURCE_LANGUAGE_CODE);
     $header->addAttribute('srclang', NarroLanguage::SOURCE_LANGUAGE_CODE);
     $header->addAttribute('datatype', "PlainText");
     // optional
     $header->addAttribute('creationdate', QDateTime::NowToString('YYYYMMDDThhmmssZ'));
     if (QApplication::$User) {
         $header->addAttribute('creationid', QApplication::$User->Username);
     }
     $header->addAttribute('changedate', "19970314T023401Z");
     $header->addAttribute('o-encoding', "utf-8");
     $body = $tmx->addChild('body');
     $strQuery = NarroText::GetQueryStatement($objQueryBuilder, QQ::AndCondition(QQ::IsNotNull(QQN::NarroText()->NarroSuggestionAsText->SuggestionId), $objLangCondition), array(QQ::ExpandAsArray(QQN::NarroText()->NarroSuggestionAsText)), array(), false);
     $objDbResult = NarroText::GetDatabase()->Query($strQuery);
     $intRowCount = $objDbResult->CountRows();
     $intLastTextId = 0;
     while ($objDbRow = $objDbResult->GetNextRow()) {
         $objText = NarroText::InstantiateDbRow($objDbRow, null, $objQueryBuilder->ExpandAsArrayNodes, null, $objQueryBuilder->ColumnAliasArray);
         if ($intLastTextId != $objText->TextId) {
             $intLastTextId = $objText->TextId;
             $tu = $body->addChild('tu');
             $tu->addAttribute('tuid', $objText->TextId);
             $tu->addAttribute('datatype', 'Text');
             // $tu->addAttribute('usagecount', $objText->CountNarroContextsAsText());
             // $objLastContext = NarroContext::QuerySingle(QQ::Equal(QQN::NarroContext()->TextId, $objText->TextId), array(QQ::OrderBy(QQN::NarroContext()->Created, 0)));
             // if ($objLastContext && $objLastContext->Created instanceof QDateTime)
             // $tu->addAttribute('lastusagedate', $objLastContext->Created->qFormat('YYYYMMDDThhmmssZ'));
             $tuv = $tu->addChild('tuv');
             $tuv->addAttribute('xml:lang', NarroLanguage::SOURCE_LANGUAGE_CODE);
             $seg = $tuv->addChild('seg');
             $tuv->seg = $objText->TextValue;
             if ($objText->Created instanceof QDateTime) {
                 $tuv->addAttribute('creationdate', $objText->Created->qFormat('YYYYMMDDThhmmssZ'));
             }
             if ($objText->Modified instanceof QDateTime) {
                 $tuv->addAttribute('changedate', $objText->Modified->qFormat('YYYYMMDDThhmmssZ'));
             }
         }
         foreach ($objText->_NarroSuggestionAsTextArray as $objSuggestion) {
             /* @var $objSuggestion NarroSuggestion */
             $tuv = $tu->addChild('tuv');
             $tuv->addAttribute('xml:lang', $objSuggestion->Language->LanguageCode);
             $seg = $tuv->addChild('seg');
             $tuv->seg = $objSuggestion->SuggestionValue;
             if ($objSuggestion->Created instanceof QDateTime) {
                 $tuv->addAttribute('creationdate', $objSuggestion->Created->qFormat('YYYYMMDDThhmmssZ'));
             }
             if ($objSuggestion->Modified instanceof QDateTime) {
                 $tuv->addAttribute('changedate', $objSuggestion->Modified->qFormat('YYYYMMDDThhmmssZ'));
             }
             if ($objSuggestion->User instanceof NarroUser) {
                 $tuv->addAttribute('creationid', $objSuggestion->User->RealName);
             }
             // $tuv->addAttribute('usagecount', $objSuggestion->CountNarroContextInfosAsValidSuggestion());
             // $objLastContextInfo = NarroContextInfo::QuerySingle(QQ::Equal(QQN::NarroContextInfo()->ValidSuggestionId, $objSuggestion->SuggestionId), array(QQ::OrderBy(QQN::NarroContextInfo()->Created, 0)));
             // if ($objLastContextInfo && $objLastContextInfo->Created instanceof QDateTime)
             // $tuv->addAttribute('lastusagedate', $objLastContextInfo->Created->qFormat('YYYYMMDDThhmmssZ'));
         }
     }
     return $tmx->asXML();
 }
コード例 #16
0
 public function testManyToMany()
 {
     $clauses = array(QQ::ExpandAsArray(QQN::Person()->ProjectAsTeamMember));
     $objPerson = Person::Load(2, $clauses);
     $mctPerson = new PersonConnector(self::$frmTest, $objPerson);
     $lstControl = $mctPerson->ProjectAsTeamMemberControl;
     $this->assertTrue($lstControl instanceof QListControl);
     $values = $lstControl->SelectedValues;
     sort($values);
     $this->assertEquals($values[0], 1);
     $this->assertEquals($values[1], 2);
     $this->assertEquals($values[2], 4);
     // test refresh
     $mctPerson->Load(3, $clauses);
     $values = $lstControl->SelectedValues;
     sort($values);
     $this->assertEquals($values[0], 4);
     $this->assertEquals(count($values), 1);
     // Test save
     $lstControl->SelectedValues = [2, 4];
     $mctPerson->SavePerson();
     $a = Project::LoadArrayByPersonAsTeamMember(3);
     $this->assertEquals(2, $a[0]->Id);
     $this->assertEquals(4, $a[1]->Id);
     $lstControl->SelectedValues = [4];
     $mctPerson->SavePerson();
     $a = Project::LoadArrayByPersonAsTeamMember(3);
     $this->assertEquals(4, $a[0]->Id);
 }
コード例 #17
0
ファイル: type_tables.php プロジェクト: tomVertuoz/framework
	Project ID: <?php 
_p($objProject->Id);
?>
<br/>
	Project Name: <?php 
_p($objProject->Name);
?>
<br/>
	Project Status: <?php 
_p(ProjectStatusType::ToString($objProject->ProjectStatusTypeId));
?>

	<h2>List the employees and their options.</h2>
<?php 
// Load all the people and expand the type array associated with the person table
$objClauses[] = QQ::ExpandAsArray(QQN::Person()->PersonType);
$objPeople = Person::LoadAll($objClauses);
foreach ($objPeople as $objPerson) {
    _p($objPerson->FirstName . ' ' . $objPerson->LastName . ': ');
    $intTypeArray = $objPerson->_PersonTypeArray;
    $strTypeArray = array();
    foreach ($intTypeArray as $intType) {
        $strTypeArray[] = PersonType::ToString($intType);
    }
    _p(implode(', ', $strTypeArray));
    _p('<br/>', false);
}
?>
</div>

コード例 #18
0
	Remember that a <strong>QQ::Expand</strong> is always a
	<a href="http://en.wikipedia.org/wiki/Join_(SQL)#Left_outer_join">left
	join</a> - so if a row of a table with which you are joining does not
	have a matching record, the left side of your join will still be there,
	and the right side will contain nulls.</p>

	<p>Remember that conditional joins only impact how tables are joined together, and so the conditions
	   must apply only to the joined table.</p>
</div>

<div id="demoZone">
	<h2>Names of every person, their username, and open projects they are managing.</h2>
	<ul>
<?php 
QApplication::$Database[1]->EnableProfiling();
$objPersonArray = Person::QueryArray(QQ::All(), array(QQ::Expand(QQN::Person()->Login, QQ::Equal(QQN::Person()->Login->IsEnabled, 1)), QQ::ExpandAsArray(QQN::Person()->ProjectAsManager, QQ::Equal(QQN::Person()->ProjectAsManager->ProjectStatusTypeId, ProjectStatusType::Open))));
foreach ($objPersonArray as $objPerson) {
    _p('<li>', false);
    _p($objPerson->FirstName . ' ' . $objPerson->LastName . ': ');
    if ($objPerson->Login) {
        _p(" Login: "******"<strong>" . $objPerson->Login->Username . "</strong>", false);
    } else {
        _p("- no login -");
    }
    if ($objPerson->_ProjectAsManagerArray) {
        _p("; Managed Open Projects: ");
        $strProjects = [];
        foreach ($objPerson->_ProjectAsManagerArray as $objProject) {
            $strProjects[] = $objProject->Name;
        }