public function testIsAppAddedException() { $actual = Api_Dao_Pages::hasApp(-1, 1); $this->assertFalse($actual); }
/** * This method gets the full page info and then uses the fields and appId to create a new data structure to pass back to the caller. * Meant to be used by the API layer as someone else probably just wants the Doctrine Data Structure and can get that by calling * getPages from this BO. * * @param unknown_type $fields * @param unknown_type $loggedInUser * @param unknown_type $uid * @param unknown_type $pageIds * @return unknown */ public static function getPagesInfo($fields, $loggedInUser, $uid, $pageIds, $appId) { // Get the pages based on the parameters $pages = self::getPages($fields, $loggedInUser, $uid, $pageIds); // Figure out what common fields we need and what fields the user is asking for $commonFieldNames = array('name', 'has_added_app', 'page_id', 'pic_big', 'pic_small', 'pic_square', 'pic_large', 'type', 'pic'); $commonFields = array_intersect($fields, $commonFieldNames); $pageFields = array_diff($fields, $commonFieldNames); $response = array(); if (count($pages) > 0) { $response['page'] = array(); // Loop throught the pages collecting the data the user asked for foreach ($pages as $page) { $pageResult = array(); // First, get the obvious ones, the common fields $pageResult['page_id'] = $page->page_id; if (in_array('name', $commonFields)) { $pageResult['name'] = $page->name; } if (in_array('type', $commonFields)) { $pageResult['type'] = $page->type; } if (in_array('pic_big', $commonFields)) { $pageResult['pic_big'] = $page->pic_url; } if (in_array('pic_small', $commonFields)) { $pageResult['pic_small'] = $page->pic_url; } if (in_array('pic_square', $commonFields)) { $pageResult['pic_square'] = $page->pic_url; } if (in_array('pic_large', $commonFields)) { $pageResult['pic_large'] = $page->pic_url; } if (in_array('pic', $commonFields)) { $pageResult['pic'] = $page->pic_url; } // Now find out if this app was added to this particular page if (in_array('has_added_app', $commonFields)) { $hasApp = Api_Dao_Pages::hasApp($page->page_id, $appId); if ($hasApp) { $pageResult['has_added_app'] = '1'; } else { $pageResult['has_added_app'] = '0'; } } // Now get all the dynamic fields the user asked for $found = array(); foreach ($page->RingsidePagesInfo as $pi) { if (in_array($pi->name, $pageFields)) { if ($pi->json_encoded == 0) { $pageResult[$pi->name] = $pi->value; } else { $pageResult[$pi->name] = json_decode($pi->value, true); } $found[] = $pi->name; } } $left = array_diff($pageFields, $found); foreach ($left as $a) { $pageResult[$a] = ''; } // Add this page to our response $response['page'][] = $pageResult; } } return $response; }