/**
  * Test the getAllProjects() function in PageAssessmentsBody class
  */
 public function testGetAllProjects()
 {
     $pageBody = new PageAssessmentsBody();
     // Insert a record
     $this->testInsert();
     $values = array('pa_page_id' => '10', 'pa_project_id' => '4', 'pa_class' => 'B', 'pa_importance' => 'Low', 'pa_page_revision' => '21');
     // Insert another record
     $pageBody->insertRecord($values);
     $res = $pageBody->getAllProjects('10');
     $expected = array(3, 4);
     // Since the projects may be returned in any order, we can't do a simple
     // assertEquals() on the arrays. Instead we compare the arrays using array_diff()
     // in both directions and make sure that the results are empty.
     $this->assertEmpty(array_merge(array_diff($expected, $res), array_diff($res, $expected)));
 }
 /**
  * Driver function
  */
 public static function execute(&$parser, $project = '', $class = '', $importance = '')
 {
     $newRecord = false;
     // Title class object for the Main page of this Talk page
     $pageObj = $parser->getTitle()->getSubjectPage();
     $pageTitle = $pageObj->getText();
     $exists = PageAssessmentsBody::checkIfExists($pageTitle, $project, $class, $importance);
     switch ($exists) {
         case 'nochange':
             return;
         case 'change':
             break;
         default:
             $newRecord = true;
             break;
     }
     $pageNamespace = $pageObj->getNamespace();
     $pageId = $pageObj->getArticleID();
     $revisionId = $pageObj->getLatestRevID();
     // Compile the array to be inserted to the DB
     $values = array('pa_page_id' => $pageId, 'pa_page_name' => $pageTitle, 'pa_page_namespace' => $pageNamespace, 'pa_project' => $project, 'pa_class' => $class, 'pa_importance' => $importance, 'pa_page_revision' => $revisionId);
     if ($newRecord) {
         PageAssessmentsBody::insertRecord($values);
     } else {
         PageAssessmentsBody::updateRecord($values);
     }
     $values['pa_user_id'] = $parser->getRevisionUser();
     PageAssessmentsBody::insertLogRecord($values);
     return;
 }
 private function buildDbQuery(array $params, $resultPageSet)
 {
     $this->addTables(array('page', 'page_assessments'));
     $this->addFields(array('page_id' => 'pa_page_id', 'project_id' => 'pa_project_id'));
     $this->addJoinConds(array('page' => array('JOIN', array('page_id = pa_page_id'))));
     if ($resultPageSet === null) {
         $this->addTables('page_assessments_projects');
         $this->addFields(array('title' => 'page_title', 'namespace' => 'page_namespace', 'project_name' => 'pap_project_title'));
         $this->addJoinConds(array('page_assessments_projects' => array('JOIN', array('pa_project_id = pap_project_id'))));
         if ($params['assessments']) {
             $this->addFields(array('class' => 'pa_class', 'importance' => 'pa_importance'));
         }
     } else {
         $this->addFields($resultPageSet->getPageTableFields());
     }
     if (isset($params['projects'])) {
         // Convert the project names into corresponding IDs
         foreach ($params['projects'] as $project) {
             $id = PageAssessmentsBody::getProjectId($project);
             if ($id) {
                 $this->projectIds[] = $id;
             } else {
                 $this->setWarning('Project name not recognized: ' . $project);
             }
         }
     }
     // DB stores project IDs, so that's what goes into the where field
     $this->addWhereFld('pa_project_id', $this->projectIds);
     $this->addOption('LIMIT', $params['limit'] + 1);
     if ($params['continue'] !== null) {
         $this->handleQueryContinuation($params['continue']);
     }
     // If more than 1 project is requested (or all projects), order by project first.
     if (count($this->projectIds) !== 1) {
         $this->addOption('ORDER BY', 'pa_project_id, pa_page_id');
     } else {
         $this->addOption('ORDER BY', 'pa_page_id');
     }
 }
 /**
  * Delete assessment records when page is deleted
  */
 public static function onArticleDeleteComplete(&$article, &$user, $reason, $id, $content = null, $logEntry)
 {
     PageAssessmentsBody::deleteRecordsForPage($id);
 }