/**
  * Verifica se os menus do banco estão atualizados com os do arquivo
  * @param $aDados- array de menus do banco
  * @return boolean
  */
 public function isUpToDate($aDados)
 {
     $aDados = Set::combine($aDados, "/Menu/id", "/Menu");
     App::import("Xml");
     App::import("Folder");
     App::import("File");
     $sCaminhosArquivos = Configure::read("Cms.CheckPoint.menus");
     $oFolder = new Folder($sCaminhosArquivos);
     $aConteudo = $oFolder->read();
     $aArquivos = Set::sort($aConteudo[1], "{n}", "desc");
     if (empty($aArquivos)) {
         return false;
     }
     $oFile = new File($sCaminhosArquivos . $aArquivos[0]);
     $oXml = new Xml($oFile->read());
     $aAntigo = $oXml->toArray();
     foreach ($aDados as &$aMenu) {
         $aMenu['Menu']['content'] = str_replace("\r\n", " ", $aMenu['Menu']['content']);
     }
     if (isset($aAntigo["menus"])) {
         $aAntigo["Menus"] = $aAntigo["menus"];
         unset($aAntigo["menus"]);
     }
     if (isset($aAntigo["Menus"])) {
         $aAntigo = Set::combine($aAntigo["Menus"], "/Menu/id", "/Menu");
         $aRetorno = Set::diff($aDados, $aAntigo);
     }
     return empty($aRetorno);
 }
 function index()
 {
     $this->ProductionManager->recursive = 2;
     $production_managers = $this->ProductionManager->find('all');
     $busiest_dev = array();
     $counter = 0;
     $total_working_projects = 0;
     if (!$this->Session->read('TempProd.total_working_projects_set')) {
         $this->Session->write('TempProd.total_working_projects_set', 1);
         foreach ($production_managers as $prod) {
             foreach ($prod['Project'] as $project) {
                 if ($project['complete'] == 0 || $project['complete'] == '0') {
                     $total_working_projects += 1;
                 }
             }
             //Update the SQL table with final value
             //$this->Developer->read(null, $dev['Developer']['id']);
             $data = array('ProductionManager' => array('id' => $prod['ProductionManager']['id'], 'total_working_projects' => $total_working_projects));
             $this->ProductionManager->save($data);
             $total_working_projects = 0;
             $counter++;
         }
     }
     $production_managers = Set::sort($production_managers, '{n}.ProductionManager.total_working_projects', 'desc');
     if ($production_managers[0]['ProductionManager']['total_working_projects'] == $production_managers[1]['ProductionManager']['total_working_projects']) {
         $busiest_prod[0] = $production_managers[0];
         $busiest_prod[1] = $production_managers[1];
     } else {
         $busiest_prod = $production_managers[0];
     }
     $this->paginate = array('order' => array('ProductionManager.total_working_projects' => 'desc'));
     $this->set('production_managers', $this->paginate());
 }
Ejemplo n.º 3
0
 public function testLookup_by_user_id()
 {
     $results = $this->User->find('lookup', array('user_id' => array('8620662', '15982041')));
     $results = Set::sort($results, '/id_str', 'asc');
     $screenNames = Set::extract('/screen_name', $results);
     $ids = Set::extract('/id_str', $results);
     $this->assertEquals(array('cakephp', 'nojimage'), $screenNames);
     $this->assertEquals(array('8620662', '15982041'), $ids);
 }
 function testIndex()
 {
     $result = $this->testAction('/surveys/index', array('return' => 'vars'));
     $surveys = Set::sort($result['paramsForList']['data']['entries'], '{n}.Survey.id', 'asc');
     $this->assertEqual($surveys[0]['Survey']['name'], 'Team Creation Survey');
     $this->assertEqual($surveys[0]['Survey']['question_count'], 2);
     $this->assertEqual($surveys[1]['Survey']['name'], 'Survey, all Q types');
     $this->assertEqual($surveys[1]['Survey']['question_count'], 4);
 }
Ejemplo n.º 5
0
 function findTop10()
 {
     $top_10 = array(43, 33, 26, 18, 296, 23, 69, 313, 292, 203);
     $records = $this->find('all', array('contain' => false, 'conditions' => array('id' => $top_10)));
     foreach ($records as $key => $val) {
         if (isset($val['Brand']['id']) && in_array($val['Brand']['id'], $top_10)) {
             $val['Brand']['top_10'] = array_search($val['Brand']['id'], $top_10) + 1;
         }
         $records[$key] = $val;
     }
     return Set::sort($records, '{n}.Brand.top_10', 'asc');
 }
Ejemplo n.º 6
0
 function findCommon()
 {
     $top_10 = array(3, 10, 9, 13, 12, 5, 4, 11, 36, 24);
     $records = $this->find('all', array('contain' => array('Container'), 'conditions' => array('Package.id' => $top_10)));
     foreach ($records as $key => $val) {
         if (isset($val['Package']['id']) && in_array($val['Package']['id'], $top_10)) {
             $val['Package']['top_10'] = array_search($val['Package']['id'], $top_10) + 1;
         }
         $records[$key] = $val;
     }
     return Set::sort($records, '{n}.Package.top_10', 'asc');
 }
 /**
  * Returns an array of CakeRequest objects. Performs various transformations on the request passed to the constructor,
  * so that the requests match the format expected by CakePHP.
  *
  * @return array Array with CakeRequest objects.
  */
 public function getRequests()
 {
     $requests = array();
     // If the request comes from $HTTP_RAW_POST_DATA it could be a batch request.
     if (strlen($this->rawPostData)) {
         $data = json_decode($this->rawPostData, true);
         // TODO: improve detection (not perfect, but should it should be correct in most cases.)
         if (isset($data['action']) || isset($data['method']) || isset($data['data'])) {
             $data = array($data);
         }
         $data = Set::sort($data, '{n}.tid', 'asc');
     } else {
         if (!empty($this->postData)) {
             // Form requests only contain one request.
             $data = array($this->postData);
         } else {
             // no data passed
             throw new BanchaException('Missing POST Data: The Bancha Dispatcher expected to get all requests in the Ext.Direct format as POST ' . 'parameter, but there is no data in this request. You can not access this site directly!');
         }
     }
     if (count($data) > 0) {
         for ($i = 0; $i < count($data); $i++) {
             $transformer = new BanchaRequestTransformer($data[$i]);
             // CakePHP should think that every Bancha request is a POST request.
             $_SERVER['REQUEST_METHOD'] = 'POST';
             // Create CakeRequest and fill it with values from the transformer.
             $requests[$i] = new CakeRequest($transformer->getUrl());
             // the CakeRequest uses the envirement variable $_POST in his
             // during the startup called _processPost() (currently line 153).
             // This is unclean and adds false data in our case. So delete this data.
             $requests[$i]->data = array();
             // now set params for the request
             $requests[$i]['controller'] = $transformer->getController();
             $requests[$i]['action'] = $transformer->getAction();
             $requests[$i]['named'] = $transformer->getPaging();
             $requests[$i]['plugin'] = null;
             // bancha-specific
             $requests[$i]['tid'] = $transformer->getTid();
             $requests[$i]['extUpload'] = $transformer->getExtUpload();
             $requests[$i]['client_id'] = $transformer->getClientId();
             $requests[$i]['isFormRequest'] = $transformer->isFormRequest();
             $requests[$i]['pass'] = $transformer->getPassParams();
             // additional property for cleaner controller syntax
             $requests[$i]['isBancha'] = true;
             // Handle all other parameters as POST parameters.
             foreach ($transformer->getCleanedDataArray() as $key => $value) {
                 $requests[$i]->data($key, $value);
             }
         }
     }
     return $requests;
 }
Ejemplo n.º 8
0
 function testGetCourseEvalEvent()
 {
     $empty = null;
     $this->Event =& ClassRegistry::init('Event');
     //Test a valid course number
     $course = Set::sort($this->Event->GetCourseEvalEvent(1), '{n}.Event.id', 'asc');
     $events = $this->toEventNameArray($course);
     $this->assertEqual($events['0'], 'Term 1 Evaluation');
     $this->assertEqual($events['1'], 'Term Report Evaluation');
     $this->assertEqual($events['2'], 'Project Evaluation');
     //Test an invalid course number
     $course = $this->Event->GetCourseEvalEvent(999);
     $this->assertEqual($course, $empty);
 }
Ejemplo n.º 9
0
 function cleanSearchString(&$Model, $searchString = null)
 {
     $clean = $this->settings[$Model->alias]['clean'];
     $clean['rules'] = Set::sort($clean['rules'], '{[\\w ]+}.order', 'asc');
     if (!empty($clean['rules'])) {
         foreach ($clean['rules'] as $ruleKey => $rule) {
             $searchString = preg_replace('/' . $rule['pattern'] . '/', $rule['replacement'], $searchString);
         }
         unset($ruleKey);
         unset($rule);
     }
     if (!empty($clean['trim'])) {
         $searchString = trim($searchString);
     }
     return $searchString;
 }
Ejemplo n.º 10
0
 function paginate($conditions, $fields, $order, $limit, $page = 1, $recursive = null, $extra = array())
 {
     App::import('Core', 'Folder');
     $Folder = new Folder($this->__path());
     $pages = $Folder->read();
     $pages = $pages[1];
     unset($Folder);
     $returnPages = array();
     foreach ($pages as $page) {
         if (strpos($page, '.ctp') !== false) {
             $returnPage = array('name' => Inflector::humanize(substr($page, 0, strlen($page) - 4)), 'file_name' => $page);
             $returnPages[]['Page'] = $returnPage;
         }
     }
     return Set::sort($returnPages, '{n}.Page.file_name', 'asc');
 }
Ejemplo n.º 11
0
 public function view($id = null)
 {
     if (!$id) {
         throw new NotFoundException(__('Invalid query'));
     }
     $query = $this->Query->find('all', array('conditions' => array('id' => $id), 'recursive' => 2));
     $userQuery = $this->Query->query("Select * from users where id = '" . $query[0]["Query"]["user_id"] . "'");
     if (!$query) {
         throw new NotFoundException(__('Invalid query'));
     }
     $this->set('targetQuery', $query[0]);
     $this->set('author', $userQuery[0]["users"]);
     $sql = "SELECT comments.id, sum(comments_users.vote) as votes FROM comments, comments_users WHERE comments.query_id = " . $query[0]["Query"]["id"] . "  AND comments.id = comments_users.comment_id GROUP BY comment_id";
     $commentsWithVotes = $this->Query->query($sql);
     $sql = "SELECT id FROM comments WHERE query_id = " . $query[0]["Query"]["id"];
     $allCommentsQuery = $this->Query->query($sql);
     foreach ($allCommentsQuery as $key => $row) {
         $exist = false;
         foreach ($commentsWithVotes as $key => $value) {
             if ($row['comments']['id'] == $value['comments']['id']) {
                 $exist = true;
                 break;
             }
         }
         if (!$exist) {
             $count = count($commentsWithVotes);
             $commentsWithVotes[$count]['comments']['id'] = $row['comments']['id'];
             $commentsWithVotes[$count][0]['votes'] = 0;
         }
     }
     $sortedComments = Set::sort($commentsWithVotes, '{n}.0.votes', 'desc');
     $this->set('sortedComments', $sortedComments);
     /*$commentsWithVotes[3]['comments']['id']=1;
     		$commentsWithVotes[3][0]['sum(comments_users.vote)']= 0;
     		print_r($commentsWithVotes);die();*/
     /*foreach ($query[0]['Comment'] as $key => $value) {
     			$sql = "SELECT sum(vote) as votes FROM comments_users where comment_id = ".$value['id'];
     			if(empty($this->Query->query($sql)[0][0]['votes']))
     				$aOrdenar[$value['id']]= 0;
     			else
     				$aOrdenar[$value['id']]= $this->Query->query($sql)[0][0]['votes'];
     		}
     		print_r(Set::sort($aOrdenar, '{n}', 'desc'));*/
     $sql = "SELECT sum(vote) from queries_users where query_id = {$id}";
     $numVotos = $this->Query->query($sql);
     $this->set('numVotos', $numVotos[0][0]["sum(vote)"]);
 }
Ejemplo n.º 12
0
 public function paginate($conditions, $fields, $order, $limit, $page = 1, $recursive = null, $extra = array())
 {
     App::import('Core', 'Folder');
     $Folder = new Folder($this->__path());
     $pages = $Folder->read();
     $pages = $pages[1];
     unset($Folder);
     $returnPages = array();
     foreach ($pages as $page) {
         if (strpos($page, '.ctp') !== false) {
             $returnPages[][$this->alias] = $this->__getPageData(basename($page));
         }
     }
     if (empty($returnPages)) {
         return array();
     }
     return Set::sort($returnPages, '{n}.' . $this->alias . '.file_name', 'asc');
 }
 protected function _order(array $controllers)
 {
     foreach ($controllers as $key => $controller) {
         $controllers[$key]['Controller']['order'] = 0;
         if (empty($controller['Controller'])) {
             continue;
         }
         $importName = $controller['Controller']['importName'];
         extract($controller['Controller']['properties']);
         App::uses($controller, $importName);
         if (class_exists($controller)) {
             $controllers[$key]['Controller']['order'] = isset($controller::$order) ? intval($controller::$order) : 0;
         }
     }
     extract($this->settings);
     $order_by = $order_by == 'name' ? 'key' : $order_by;
     return $this->controllersList = Set::sort($controllers, "{n}.Controller.{$order_by}", $order_sort);
 }
Ejemplo n.º 14
0
 /**
  * Restaura as configurações dos menus
  *
  * @param Array $aSnap -- Configurações a serem restauradas
  * @return Boolean
  */
 public function restauraBackup($aSnap)
 {
     $this->begin();
     $aSnap = Set::sort($aSnap, '{n}.id', 'asc');
     $this->Behaviors->detach('Tree');
     if ($this->deleteAll("1 = 1") && (empty($aSnap) || $this->saveAll($aSnap))) {
         $this->Behaviors->attach('Tree');
         $aRetorno = $this->query("select max(id) as last from cms.menus;");
         $last = $aRetorno[0][0]['last'] + 1;
         $sSql = "alter sequence cms.menus_id_seq restart with {$last};";
         $this->query($sSql);
         $this->commit();
         return true;
     }
     $this->Behaviors->attach('Tree');
     $this->rollback();
     return false;
 }
	/**
	 * The administration panel to view all of the flagged items. In this area, you can delete, deactivate, reactivate and remove flags from items.
	 * @param 
	 * @return 
	 * 
	*/
	function admin_index(){
		$flags = $this->paginate('Flag');
		
		//Get the flag count for each item and add that to the item array [Flag]['count']
		$counter = 0;
		foreach($flags as $flag){
			$flags[$counter]['Flag']['count'] = $this->Flag->getItemCount($flag['Flag']['model'],$flag['Flag']['model_id']);
			$counter++; 
		}
		$total_count = $this->Flag->getCount();
		
		//debug($flags);
		//Group like flagged items ex. The same item that has been flagged 
		$flags = Set::sort($flags,'{n}.Flag.model_id','desc');
		$flags = Set::sort($flags,'{n}.Flag.model','desc');
		
		$this->set(compact('total_count','flags'));
		$this->set('string', $this->String);
	}
Ejemplo n.º 16
0
 public function index()
 {
     if (!$this->request->is('get') || empty($this->request->query['terms'])) {
         //$this->redirect('/');
         //exit();
     }
     $terms = $this->request->query['terms'];
     $ControllersInfo = Admin::getControllersInfo();
     $results = array();
     foreach ($ControllersInfo as $ControllerInfo) {
         if (empty($ControllerInfo['adminSearch'])) {
             continue;
         }
         $adminSearch = $ControllerInfo['adminSearch'];
         $controllerClass = $ControllerInfo['controllerClass'];
         $C = new $controllerClass();
         $r = $C->{$adminSearch}($terms);
         $results = array_merge((array) $results, (array) $r);
     }
     $results = Set::sort($results, '{n}.score', 'desc');
     $this->set('results', $results);
 }
Ejemplo n.º 17
0
 function admin_export($dir = null, $filename = null, $importedTranslationFileId = null)
 {
     if (!$filename) {
         $this->Session->setFlash(__('Invalid file', true));
         $this->redirect($this->referer());
         return 0;
     }
     if (!$this->RawFile->open($dir, $filename, $writable = true)) {
         $this->Session->setFlash(__('Can\'t open file for writing', true));
         $this->redirect($this->referer());
         return 0;
     }
     $importedTranslationFileModel = $this->RawFile->ImportedTranslationFile;
     $importedTranslationFileModel->contain(array('TranslationFile', 'FileIdentifier' => array('Identifier' => array('Translation', 'IdentifierColumn' => 'Translation'))));
     $importedTranslationFile = $importedTranslationFileModel->find('first', array('conditions' => array('ImportedTranslationFile.filename' => $dir . DS . $filename)));
     if (!$importedTranslationFile) {
         $this->Session->setFlash(__('No imported translation file found for chosen file', true));
         $this->redirect($this->referer());
         return 0;
     }
     $translationFileModel = $importedTranslationFileModel->TranslationFile;
     $identifierModel = $translationFileModel->Identifier;
     // check if all identifiers have "best" translation
     $identifier_ids = $identifierModel->withoutBestTranslation(array('ImportedTranslationFile.id' => $importedTranslationFile['ImportedTranslationFile']['id']));
     if ($identifier_ids === false) {
         $this->Session->setFlash(__('Error: no conditions specified', true));
         $this->redirect($this->referer());
         return 0;
     } else {
         if (count($identifier_ids) > 0) {
             $this->Session->setFlash(__('Best translation is not set for some of the identifiers in this file. Set best translation before export.', true));
             $this->redirect(array('controller' => 'identifiers', 'action' => 'withoutBestTranslation', 'imported_translation_file_id' => $importedTranslationFile['ImportedTranslationFile']['id']));
             return 0;
         }
     }
     $translationFile_id = $importedTranslationFile['ImportedTranslationFile']['translation_file_id'];
     $i = 0;
     $sortResult = Set::sort($importedTranslationFile['FileIdentifier'], '{n}.translation_index', 'asc');
     if (!$sortResult) {
         $this->Session->setFlash(__('Sorting error', true));
         $this->redirect($this->referer());
         return 0;
     }
     foreach ($sortResult as $fileIdentifier) {
         if ($fileIdentifier['Identifier']['IdentifierColumn'] && !isset($entities[0])) {
             foreach ($fileIdentifier['Identifier']['IdentifierColumn'] as $column_no => $identifierColumn) {
                 $_columns[$column_no] = $identifierColumn['column_name'];
             }
             $ent['columns'] = $_columns;
             $ent['type'] = 'sheet_description';
             $ent['sheet_id_column'] = $fileIdentifier['arguments'];
             $ent['diff'] = isset($fileIdentifier['command']) && !empty($fileIdentifier['command']) ? true : null;
             $entities[] = $ent;
             $ent = array();
         }
         $ent = array('diff' => isset($fileIdentifier['command']) && !empty($fileIdentifier['command']) ? $fileIdentifier['command'] : null, 'command' => isset($fileIdentifier['command']) && !empty($fileIdentifier['command']) ? $fileIdentifier['command'] : null, 'index' => isset($fileIdentifier['translation_index']) && !empty($fileIdentifier['translation_index']) ? $fileIdentifier['translation_index'] : null, 'internal_index' => $i++, 'type' => count($fileIdentifier['Identifier']['IdentifierColumn']) > 0 ? 'sheet' : 'string', 'identifier' => $fileIdentifier['Identifier']['identifier'], 'arguments' => isset($fileIdentifier['arguments']) && !empty($fileIdentifier['arguments']) ? $fileIdentifier['arguments'] : null);
         if (isset($fileIdentifier['Identifier']['Translation'][0])) {
             $ent['string'] = $fileIdentifier['Identifier']['Translation'][0]['translation_text'];
         } else {
             if (isset($fileIdentifier['Identifier']['Translation']['translation_text'])) {
                 $ent['string'] = $fileIdentifier['Identifier']['Translation']['translation_text'];
             }
         }
         if (isset($fileIdentifier['Identifier']['BestTranslation']['translation_text'])) {
             $ent['string'] = $fileIdentifier['Identifier']['BestTranslation']['translation_text'];
         }
         if (($export_reference_if_empty_translation = true) && !isset($ent['string'])) {
             $ent['string'] = $fileIdentifier['Identifier']['reference_string'];
         } else {
             if (!isset($ent['string'])) {
                 $ent['string'] = '';
             }
         }
         foreach ($fileIdentifier['Identifier']['IdentifierColumn'] as $column_no => $identifierColumn) {
             if (isset($identifierColumn['Translation'][0])) {
                 $ent['columns'][$column_no] = $identifierColumn['Translation'][0]['translation_text'];
             } else {
                 if (isset($identifierColumn['Translation']['translation_text'])) {
                     $ent['columns'][$column_no] = $identifierColumn['Translation']['translation_text'];
                 }
             }
             if (isset($identifierColumn['BestTranslation']['translation_text'])) {
                 $ent['columns'][$column_no] = $identifierColumn['BestTranslation']['translation_text'];
             }
             if ($export_reference_if_empty_translation && !isset($ent['columns'][$column_no])) {
                 $ent['columns'][$column_no] = $identifierColumn['reference_string'];
             } else {
                 if (!isset($ent['columns'][$column_no])) {
                     $ent['columns'][$column_no] = '';
                 }
             }
         }
         if ($fileIdentifier['command']) {
             $ent['command'] = $ent['diff'] = $fileIdentifier['command'];
         }
         $entities[] = $ent;
     }
     ini_set('max_execution_time', 0);
     $result = $this->RawFile->buildFile($entities);
     if (!$result) {
         $this->Session->setFlash(__('Error exporting file', true));
         $this->redirect(array('action' => 'index'));
         return 0;
     }
 }
 /**
  * testMixedCreateUpdateWithArrayLocale method
  *
  * @return void
  */
 public function testMixedCreateUpdateWithArrayLocale()
 {
     $this->loadFixtures('Translate', 'TranslatedItem');
     $TestModel = new TranslatedItem();
     $TestModel->locale = array('cze', 'deu');
     $data = array('TranslatedItem' => array('id' => 1, 'title' => array('eng' => 'Updated Title #1', 'spa' => 'Nuevo leyenda #1'), 'content' => 'Upraveny obsah #1'));
     $TestModel->create();
     $TestModel->save($data);
     $TestModel->unbindTranslation();
     $translations = array('title' => 'Title', 'content' => 'Content');
     $TestModel->bindTranslation($translations, false);
     $result = $TestModel->read(null, 1);
     $result['Title'] = Set::sort($result['Title'], '{n}.id', 'asc');
     $result['Content'] = Set::sort($result['Content'], '{n}.id', 'asc');
     $expected = array('TranslatedItem' => array('id' => 1, 'slug' => 'first_translated', 'locale' => 'cze', 'title' => 'Titulek #1', 'content' => 'Upraveny obsah #1'), 'Title' => array(array('id' => 1, 'locale' => 'eng', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'Updated Title #1'), array('id' => 3, 'locale' => 'deu', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'Titel #1'), array('id' => 5, 'locale' => 'cze', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'Titulek #1'), array('id' => 19, 'locale' => 'spa', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'Nuevo leyenda #1')), 'Content' => array(array('id' => 2, 'locale' => 'eng', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'content', 'content' => 'Content #1'), array('id' => 4, 'locale' => 'deu', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'content', 'content' => 'Inhalt #1'), array('id' => 6, 'locale' => 'cze', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'content', 'content' => 'Upraveny obsah #1')));
     $this->assertEquals($expected, $result);
 }
 /**
  * testSaveAllHasMany method
  *
  * @return void
  */
 public function testSaveAllHasMany()
 {
     $this->loadFixtures('Article', 'Comment');
     $TestModel = new Article();
     $TestModel->hasMany['Comment']['order'] = array('Comment.created' => 'ASC');
     $TestModel->belongsTo = $TestModel->hasAndBelongsToMany = array();
     $result = $TestModel->saveAll(array('Article' => array('id' => 2), 'Comment' => array(array('comment' => 'First new comment', 'published' => 'Y', 'user_id' => 1), array('comment' => 'Second new comment', 'published' => 'Y', 'user_id' => 2))));
     $this->assertFalse(empty($result));
     $result = $TestModel->findById(2);
     $expected = array('First Comment for Second Article', 'Second Comment for Second Article', 'First new comment', 'Second new comment');
     $result = Set::extract(Set::sort($result['Comment'], '{n}.id', 'ASC'), '{n}.comment');
     $this->assertEquals($expected, $result);
     $result = $TestModel->saveAll(array('Article' => array('id' => 2), 'Comment' => array(array('comment' => 'Third new comment', 'published' => 'Y', 'user_id' => 1))), array('atomic' => false));
     $this->assertFalse(empty($result));
     $result = $TestModel->findById(2);
     $expected = array('First Comment for Second Article', 'Second Comment for Second Article', 'First new comment', 'Second new comment', 'Third new comment');
     $result = Set::extract(Set::sort($result['Comment'], '{n}.id', 'ASC'), '{n}.comment');
     $this->assertEquals($expected, $result);
     $TestModel->beforeSaveReturn = false;
     $result = $TestModel->saveAll(array('Article' => array('id' => 2), 'Comment' => array(array('comment' => 'Fourth new comment', 'published' => 'Y', 'user_id' => 1))), array('atomic' => false));
     $this->assertEquals(array('Article' => false), $result);
     $result = $TestModel->findById(2);
     $expected = array('First Comment for Second Article', 'Second Comment for Second Article', 'First new comment', 'Second new comment', 'Third new comment');
     $result = Set::extract(Set::sort($result['Comment'], '{n}.id', 'ASC'), '{n}.comment');
     $this->assertEquals($expected, $result);
 }
Ejemplo n.º 20
0
 /**
  * Used to read records from the Datasource. The "R" in CRUD
  *
  * @param Model $model The model being read.
  * @param array $queryData An array of query data used to find the data you want
  * @return mixed
  */
 public function read(&$model, $queryData = array())
 {
     if (!isset($model->records) || !is_array($model->records) || empty($model->records)) {
         $this->_requestsLog[] = array('query' => 'Model ' . $model->alias, 'error' => __('No records found in model.', true), 'affected' => 0, 'numRows' => 0, 'took' => 0);
         return array($model->alias => array());
     }
     $startTime = getMicrotime();
     $data = array();
     $i = 0;
     $limit = false;
     if (!isset($queryData['recursive'])) {
         $queryData['recursive'] = $model->recursive;
     }
     if (is_integer($queryData['limit']) && $queryData['limit'] > 0) {
         $limit = $queryData['page'] * $queryData['limit'];
     }
     foreach ($model->records as $pos => $record) {
         // Tests whether the record will be chosen
         if (!empty($queryData['conditions'])) {
             $queryData['conditions'] = (array) $queryData['conditions'];
             if (!$this->conditionsFilter($model, $record, $queryData['conditions'])) {
                 continue;
             }
         }
         $data[$i][$model->alias] = $record;
         $i++;
         // Test limit
         if ($limit !== false && $i == $limit && empty($queryData['order'])) {
             break;
         }
     }
     if ($queryData['fields'] === 'COUNT') {
         $this->_registerLog($model, $queryData, getMicrotime() - $startTime, 1);
         if ($limit !== false) {
             $data = array_slice($data, ($queryData['page'] - 1) * $queryData['limit'], $queryData['limit'], false);
         }
         return array(array(array('count' => count($data))));
     }
     // Order
     if (!empty($queryData['order'])) {
         if (is_string($queryData['order'][0])) {
             $field = $queryData['order'][0];
             $alias = $model->alias;
             if (strpos($field, '.') !== false) {
                 list($alias, $field) = explode('.', $field, 2);
             }
             if ($alias === $model->alias) {
                 $sort = 'ASC';
                 if (strpos($field, ' ') !== false) {
                     list($field, $sort) = explode(' ', $field, 2);
                 }
                 $data = Set::sort($data, '{n}.' . $model->alias . '.' . $field, $sort);
             }
         }
     }
     // Limit
     if ($limit !== false) {
         $data = array_slice($data, ($queryData['page'] - 1) * $queryData['limit'], $queryData['limit'], false);
     }
     // Filter fields
     if (!empty($queryData['fields'])) {
         $listOfFields = array();
         foreach ($queryData['fields'] as $field) {
             if (strpos($field, '.') !== false) {
                 list($alias, $field) = explode('.', $field, 2);
                 if ($alias !== $model->alias) {
                     continue;
                 }
             }
             $listOfFields[] = $field;
         }
         foreach ($data as $id => $record) {
             foreach ($record[$model->alias] as $field => $value) {
                 if (!in_array($field, $listOfFields)) {
                     unset($data[$id][$model->alias][$field]);
                 }
             }
         }
     }
     $this->_registerLog($model, $queryData, getMicrotime() - $startTime, count($data));
     $_associations = $model->__associations;
     if ($queryData['recursive'] > -1) {
         foreach ($_associations as $type) {
             foreach ($model->{$type} as $assoc => $assocData) {
                 $linkModel =& $model->{$assoc};
                 if ($model->useDbConfig == $linkModel->useDbConfig) {
                     $db =& $this;
                 } else {
                     $db =& ConnectionManager::getDataSource($linkModel->useDbConfig);
                 }
                 if (isset($db)) {
                     if (method_exists($db, 'queryAssociation')) {
                         $stack = array($assoc);
                         $db->queryAssociation($model, $linkModel, $type, $assoc, $assocData, $queryData, true, $data, $queryData['recursive'] - 1, $stack);
                     }
                     unset($db);
                 }
             }
         }
     }
     if ($model->findQueryType === 'first') {
         if (!isset($data[0])) {
             $data = array();
         } else {
             $data = array($data[0]);
         }
     }
     return $data;
 }
Ejemplo n.º 21
0
 /**
  * testSort method
  *
  * @access public
  * @return void
  */
 function testSort()
 {
     $a = array(0 => array('Person' => array('name' => 'Jeff'), 'Friend' => array(array('name' => 'Nate'))), 1 => array('Person' => array('name' => 'Tracy'), 'Friend' => array(array('name' => 'Lindsay'))));
     $b = array(0 => array('Person' => array('name' => 'Tracy'), 'Friend' => array(array('name' => 'Lindsay'))), 1 => array('Person' => array('name' => 'Jeff'), 'Friend' => array(array('name' => 'Nate'))));
     $a = Set::sort($a, '{n}.Friend.{n}.name', 'asc');
     $this->assertIdentical($a, $b);
     $b = array(0 => array('Person' => array('name' => 'Jeff'), 'Friend' => array(array('name' => 'Nate'))), 1 => array('Person' => array('name' => 'Tracy'), 'Friend' => array(array('name' => 'Lindsay'))));
     $a = array(0 => array('Person' => array('name' => 'Tracy'), 'Friend' => array(array('name' => 'Lindsay'))), 1 => array('Person' => array('name' => 'Jeff'), 'Friend' => array(array('name' => 'Nate'))));
     $a = Set::sort($a, '{n}.Friend.{n}.name', 'desc');
     $this->assertIdentical($a, $b);
     $a = array(0 => array('Person' => array('name' => 'Jeff'), 'Friend' => array(array('name' => 'Nate'))), 1 => array('Person' => array('name' => 'Tracy'), 'Friend' => array(array('name' => 'Lindsay'))), 2 => array('Person' => array('name' => 'Adam'), 'Friend' => array(array('name' => 'Bob'))));
     $b = array(0 => array('Person' => array('name' => 'Adam'), 'Friend' => array(array('name' => 'Bob'))), 1 => array('Person' => array('name' => 'Jeff'), 'Friend' => array(array('name' => 'Nate'))), 2 => array('Person' => array('name' => 'Tracy'), 'Friend' => array(array('name' => 'Lindsay'))));
     $a = Set::sort($a, '{n}.Person.name', 'asc');
     $this->assertIdentical($a, $b);
     $a = array(array(7, 6, 4), array(3, 4, 5), array(3, 2, 1));
     $b = array(array(3, 2, 1), array(3, 4, 5), array(7, 6, 4));
     $a = Set::sort($a, '{n}.{n}', 'asc');
     $this->assertIdentical($a, $b);
     $a = array(array(7, 6, 4), array(3, 4, 5), array(3, 2, array(1, 1, 1)));
     $b = array(array(3, 2, array(1, 1, 1)), array(3, 4, 5), array(7, 6, 4));
     $a = Set::sort($a, '{n}', 'asc');
     $this->assertIdentical($a, $b);
     $a = array(0 => array('Person' => array('name' => 'Jeff')), 1 => array('Shirt' => array('color' => 'black')));
     $b = array(0 => array('Shirt' => array('color' => 'black')), 1 => array('Person' => array('name' => 'Jeff')));
     $a = Set::sort($a, '{n}.Person.name', 'asc');
     $this->assertIdentical($a, $b);
 }
Ejemplo n.º 22
0
 /**
  * getCoursesByUserIdFilterPermission
  *
  * @param int    $userId     user id
  * @param mixed  $permission filter permission
  * @param string $type       find type
  * @param array  $options    find options
  *
  * @access protected
  * @return void
  */
 protected function getCoursesByUserIdFilterPermission($userId, $permission, $type = 'all', $options = array())
 {
     switch ($permission) {
         case Course::FILTER_PERMISSION_SUPERADMIN:
             // sort courses alphabetically
             $options['order'] = 'Course.course';
             $courses = $this->find($type, $options);
             break;
         case Course::FILTER_PERMISSION_FACULTY:
             $departmentIds = $this->Department->getIdsByUserId($userId);
             $adminCourses = $this->getByDepartmentIds($departmentIds, $type, $options);
             $options = array_merge(array('contain' => array(), 'conditions' => array()), $options);
             $instCourses = $this->getCourseByInstructor($userId, $type, $options['contain'], $options['conditions']);
             if ('first' == $type) {
                 $courses = !empty($adminCourses) ? $adminCourses : $instCourses;
                 break;
             }
             // for "all" type
             $courses = $adminCourses;
             $instCourseIds = Set::extract('/Course/id', $instCourses);
             if (empty($instCourseIds)) {
                 // no instructing course
                 break;
             }
             // merge two sets of courses
             $adminCourseIds = Set::extract('/Course/id', $adminCourses);
             foreach ($instCourses as $course) {
                 if (!in_array($course['Course']['id'], $adminCourseIds)) {
                     $courses[] = $course;
                 }
             }
             // sort the result
             $courses = Set::sort($courses, '{n}.Course.course', 'asc');
             break;
         case Course::FILTER_PERMISSION_OWNER:
             $options = array_merge(array('contain' => array(), 'conditions' => array()), $options);
             $courses = $this->getCourseByInstructor($userId, $type, $options['contain'], $options['conditions']);
             break;
         case Course::FILTER_PERMISSION_ENROLLED:
             $options = array_merge(array('contain' => array(), 'conditions' => array()), $options);
             $courses = $this->getCourseByStudent($userId, $type, $options['contain'], $options['conditions']);
             break;
         default:
             return array();
     }
     return $courses;
 }
Ejemplo n.º 23
0
 function testEditOthersEvent()
 {
     // test with instructor account
     $this->login = array('User' => array('username' => 'instructor2', 'password' => md5('ipeeripeer')));
     $data = array('Event' => array('id' => 8, 'title' => 'simple evaluation 4a', 'description' => 'result released with submissiona', 'event_template_type_id' => 1, 'SimpleEvaluation' => 1, 'self_eval' => 0, 'com_req' => 0, 'enable_details' => 1, 'due_date' => '2012-11-28 00:00:01', 'release_date_begin' => '2012-11-20 00:00:01', 'release_date_end' => '2012-11-29 00:00:01', 'result_release_date_begin' => '2012-11-30 00:00:01', 'result_release_date_end' => '2022-12-12 00:00:01'), 'Group' => array('Group' => array(1, 2)));
     $this->controller->expectOnce('redirect', array('index'));
     $this->testAction('/events/edit/8', array('fixturize' => true, 'data' => $data, 'method' => 'post'));
     $model = ClassRegistry::init('Event');
     $event = $model->find('first', array('conditions' => array('id' => $data['Event']['id']), 'contain' => array('Group', 'GroupEvent', 'EvaluationSubmission')));
     // data should not be changed
     $this->assertEqual($event['Event']['title'], 'simple evaluation 4');
     $this->assertEqual(count($event['Group']), 1);
     // make sure the GroupEvent id is not shifted
     $this->assertEqual(count($event['GroupEvent']), 1);
     $groupEvents = Set::sort($event['GroupEvent'], '{n}.id', 'asc');
     $this->assertEqual($groupEvents[0]['id'], 10);
     // make sure the submission id is not shifted
     $submissions = Set::sort($event['EvaluationSubmission'], '{n}.id', 'asc');
     $this->assertEqual($submissions[0]['id'], 11);
     $message = $this->controller->Session->read('Message.flash');
     $this->assertEqual($message['message'], 'Error: That event does not exist or you dont have access to it');
 }
Ejemplo n.º 24
0
 function __processReplacements($rules, $string)
 {
     if (!empty($rules)) {
         $rules = Set::sort($rules, '{[\\w ]+}.order', 'asc');
         foreach ($rules as $ruleKey => $rule) {
             $string = preg_replace('/' . $rule['pattern'] . '/', $rule['replacement'], $string);
         }
         unset($ruleKey);
         unset($rule);
     }
     return $string;
 }
 /**
  * testSaveHabtmNoPrimaryData method
  *
  * @return void
  */
 public function testSaveHabtmNoPrimaryData()
 {
     $this->loadFixtures('Article', 'User', 'Comment', 'Tag', 'ArticlesTag');
     $TestModel = new Article();
     $TestModel->unbindModel(array('belongsTo' => array('User'), 'hasMany' => array('Comment')), false);
     $result = $TestModel->findById(2);
     $expected = array('Article' => array('id' => '2', 'user_id' => '3', 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'), 'Tag' => array(array('id' => '1', 'tag' => 'tag1', 'created' => '2007-03-18 12:22:23', 'updated' => '2007-03-18 12:24:31'), array('id' => '3', 'tag' => 'tag3', 'created' => '2007-03-18 12:26:23', 'updated' => '2007-03-18 12:28:31')));
     $this->assertEquals($expected, $result);
     $ts = date('Y-m-d H:i:s');
     $TestModel->id = 2;
     $data = array('Tag' => array('Tag' => array(2)));
     $TestModel->save($data);
     $result = $TestModel->findById(2);
     $expected = array('Article' => array('id' => '2', 'user_id' => '3', 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => $ts), 'Tag' => array(array('id' => '2', 'tag' => 'tag2', 'created' => '2007-03-18 12:24:23', 'updated' => '2007-03-18 12:26:31')));
     $this->assertEquals($expected, $result);
     $this->loadFixtures('Portfolio', 'Item', 'ItemsPortfolio');
     $TestModel = new Portfolio();
     $result = $TestModel->findById(2);
     $expected = array('Portfolio' => array('id' => 2, 'seller_id' => 1, 'name' => 'Portfolio 2'), 'Item' => array(array('id' => 2, 'syfile_id' => 2, 'published' => '', 'name' => 'Item 2', 'ItemsPortfolio' => array('id' => 2, 'item_id' => 2, 'portfolio_id' => 2)), array('id' => 6, 'syfile_id' => 6, 'published' => '', 'name' => 'Item 6', 'ItemsPortfolio' => array('id' => 6, 'item_id' => 6, 'portfolio_id' => 2))));
     $this->assertEquals($expected, $result);
     $data = array('Item' => array('Item' => array(1, 2)));
     $TestModel->id = 2;
     $TestModel->save($data);
     $result = $TestModel->findById(2);
     $result['Item'] = Set::sort($result['Item'], '{n}.id', 'asc');
     $expected = array('Portfolio' => array('id' => 2, 'seller_id' => 1, 'name' => 'Portfolio 2'), 'Item' => array(array('id' => 1, 'syfile_id' => 1, 'published' => '', 'name' => 'Item 1', 'ItemsPortfolio' => array('id' => 7, 'item_id' => 1, 'portfolio_id' => 2)), array('id' => 2, 'syfile_id' => 2, 'published' => '', 'name' => 'Item 2', 'ItemsPortfolio' => array('id' => 8, 'item_id' => 2, 'portfolio_id' => 2))));
     $this->assertEquals($expected, $result);
 }
Ejemplo n.º 26
0
 /**
  * testSort method
  *
  * @access public
  * @return void
  */
 function testSort()
 {
     $a = array(0 => array('Person' => array('name' => 'Jeff'), 'Friend' => array(array('name' => 'z1'))), 1 => array('Person' => array('name' => 'Jeff'), 'Friend' => array(array('name' => 'z10'))), 2 => array('Person' => array('name' => 'Jeff'), 'Friend' => array(array('name' => 'z100'))), 3 => array('Person' => array('name' => 'Jeff'), 'Friend' => array(array('name' => 'z101'))), 4 => array('Person' => array('name' => 'Jeff'), 'Friend' => array(array('name' => 'z102'))), 5 => array('Person' => array('name' => 'Tracy'), 'Friend' => array(array('name' => 'z11'))), 6 => array('Person' => array('name' => 'Tracy'), 'Friend' => array(array('name' => 'Z12'))), 7 => array('Person' => array('name' => 'Tracy'), 'Friend' => array(array('name' => 'z13'))), 8 => array('Person' => array('name' => 'Tracy'), 'Friend' => array(array('name' => 'z14'))), 9 => array('Person' => array('name' => 'Tracy'), 'Friend' => array(array('name' => 'z15'))));
     $b = array(0 => array('Person' => array('name' => 'Jeff'), 'Friend' => array(array('name' => 'z1'))), 1 => array('Person' => array('name' => 'Jeff'), 'Friend' => array(array('name' => 'z10'))), 2 => array('Person' => array('name' => 'Tracy'), 'Friend' => array(array('name' => 'z11'))), 3 => array('Person' => array('name' => 'Tracy'), 'Friend' => array(array('name' => 'Z12'))), 4 => array('Person' => array('name' => 'Tracy'), 'Friend' => array(array('name' => 'z13'))), 5 => array('Person' => array('name' => 'Tracy'), 'Friend' => array(array('name' => 'z14'))), 6 => array('Person' => array('name' => 'Tracy'), 'Friend' => array(array('name' => 'z15'))), 7 => array('Person' => array('name' => 'Jeff'), 'Friend' => array(array('name' => 'z100'))), 8 => array('Person' => array('name' => 'Jeff'), 'Friend' => array(array('name' => 'z101'))), 9 => array('Person' => array('name' => 'Jeff'), 'Friend' => array(array('name' => 'z102'))));
     $a = Set::sort($a, '{n}.Friend.{n}.name', 'nat');
     $this->assertIdentical($a, $b);
     $a = array(0 => array('Person' => array('name' => 'Jeff'), 'Friend' => array(array('name' => 'Nate'))), 1 => array('Person' => array('name' => 'Tracy'), 'Friend' => array(array('name' => 'Lindsay'))));
     $b = array(0 => array('Person' => array('name' => 'Tracy'), 'Friend' => array(array('name' => 'Lindsay'))), 1 => array('Person' => array('name' => 'Jeff'), 'Friend' => array(array('name' => 'Nate'))));
     $a = Set::sort($a, '{n}.Friend.{n}.name', 'asc');
     $this->assertIdentical($a, $b);
     $b = array(0 => array('Person' => array('name' => 'Jeff'), 'Friend' => array(array('name' => 'Nate'))), 1 => array('Person' => array('name' => 'Tracy'), 'Friend' => array(array('name' => 'Lindsay'))));
     $a = array(0 => array('Person' => array('name' => 'Tracy'), 'Friend' => array(array('name' => 'Lindsay'))), 1 => array('Person' => array('name' => 'Jeff'), 'Friend' => array(array('name' => 'Nate'))));
     $a = Set::sort($a, '{n}.Friend.{n}.name', 'desc');
     $this->assertIdentical($a, $b);
     $a = array(0 => array('Person' => array('name' => 'Jeff'), 'Friend' => array(array('name' => 'Nate'))), 1 => array('Person' => array('name' => 'Tracy'), 'Friend' => array(array('name' => 'Lindsay'))), 2 => array('Person' => array('name' => 'Adam'), 'Friend' => array(array('name' => 'Bob'))));
     $b = array(0 => array('Person' => array('name' => 'Adam'), 'Friend' => array(array('name' => 'Bob'))), 1 => array('Person' => array('name' => 'Jeff'), 'Friend' => array(array('name' => 'Nate'))), 2 => array('Person' => array('name' => 'Tracy'), 'Friend' => array(array('name' => 'Lindsay'))));
     $a = Set::sort($a, '{n}.Person.name', 'asc');
     $this->assertIdentical($a, $b);
     $a = array(array(7, 6, 4), array(3, 4, 5), array(3, 2, 1));
     $b = array(array(3, 2, 1), array(3, 4, 5), array(7, 6, 4));
     $a = Set::sort($a, '{n}.{n}', 'asc');
     $this->assertIdentical($a, $b);
     $a = array(array(7, 6, 4), array(3, 4, 5), array(3, 2, array(1, 1, 1)));
     $b = array(array(3, 2, array(1, 1, 1)), array(3, 4, 5), array(7, 6, 4));
     $a = Set::sort($a, '{n}', 'asc');
     $this->assertIdentical($a, $b);
     $a = array(0 => array('Person' => array('name' => 'Jeff')), 1 => array('Shirt' => array('color' => 'black')));
     $b = array(0 => array('Shirt' => array('color' => 'black')), 1 => array('Person' => array('name' => 'Jeff')));
     $a = Set::sort($a, '{n}.Person.name', 'ASC');
     $this->assertIdentical($a, $b);
     $names = array(array('employees' => array(array('name' => array('first' => 'John', 'last' => 'Doe')))), array('employees' => array(array('name' => array('first' => 'Jane', 'last' => 'Doe')))), array('employees' => array(array('name' => array()))), array('employees' => array(array('name' => array()))));
     $result = Set::sort($names, '{n}.employees.0.name', 'asc', 1);
     $expected = array(array('employees' => array(array('name' => array('first' => 'John', 'last' => 'Doe')))), array('employees' => array(array('name' => array('first' => 'Jane', 'last' => 'Doe')))), array('employees' => array(array('name' => array()))), array('employees' => array(array('name' => array()))));
     $this->assertEqual($result, $expected);
 }
Ejemplo n.º 27
0
 /**
  * view function
  *
  * If view all, find the requested node and all nodes under.
  * If not, find only children which are set to not show in the TOC, and for any results
  * 	find all of their children
  * A time limit is set such that 10 nodes per second can be processed without timing out
  * this means 300 nodes typically before the custom time limit extension kicks in.
  *
  * @param bool $viewAll
  * @access protected
  * @return void
  */
 function _view($viewAll = false)
 {
     if (!isset($this->params['admin'])) {
         $this->cacheAction = array('duration' => CACHE_DURATION, 'callbacks' => false);
     }
     $recursive = 1;
     $this->Node->id = $this->currentNode;
     $fields = array('Node.id', 'Node.parent_id', 'Node.depth', 'Node.sequence', 'Node.lft', 'Node.rght', 'Node.edit_level', 'Node.comment_level', 'Revision.id', 'Revision.slug', 'Revision.title', 'Revision.content', 'Revision.flags', 'Revision.modified');
     $this->data = $this->Node->findById($this->currentNode, $fields, null, $recursive);
     $conditions = array('Node.lft >' => $this->data['Node']['lft'], 'Node.rght <' => $this->data['Node']['rght']);
     $count = ($this->data['Node']['rght'] - $this->data['Node']['lft']) / 2;
     set_time_limit(max(30, $count / 10));
     $order = 'Node.lft';
     $directChildren = $children = array();
     if ($viewAll) {
         $children = $this->Node->find('all', compact('conditions', 'fields', 'order', 'recursive'));
     } else {
         $conditions = array('Node.show_in_toc' => false, 'Node.parent_id' => $this->data['Node']['id']);
         $children = $this->Node->find('all', compact('conditions', 'fields', 'order', 'recursive'));
         if ($this->action === 'view') {
             $conditions['Node.show_in_toc'] = true;
             // Disabled
             // $directChildren = $this->Node->find('all',compact('conditions', 'fields', 'order', 'recursive'));
         }
         $conditions = array();
         if ($children) {
             foreach ($children as $child) {
                 $conditions['OR'][] = array('Node.lft >' => $child['Node']['lft'], 'Node.rght <' => $child['Node']['rght']);
             }
             $grandChildren = $this->Node->find('all', compact('conditions', 'fields', 'order', 'recursive'));
             $children = am($children, $grandChildren);
             $children = Set::sort($children, '/Node/lft', 'asc');
         }
     }
     if ($children) {
         $data = am(array('Node' => $this->data), $children);
     } else {
         $data = array('Node' => $this->data);
     }
     $neighbours = $this->Node->findNeighbors(null, $viewAll ? false : true);
     $conditions = array('Revision.status' => 'pending', 'Revision.lang' => $this->params['lang']);
     $recursive = -1;
     $fields = array('DISTINCT node_id');
     $pendingUpdates = $this->Node->Revision->find('all', compact('conditions', 'recursive', 'fields'));
     $pendingUpdates = Set::extract($pendingUpdates, '{n}.Revision.node_id');
     $slugs = $this->Node->Revision->find('all', array('fields' => array('lang', 'slug', 'title'), 'conditions' => array('Revision.status' => 'current', 'Revision.node_id' => $this->currentNode)));
     if ($slugs) {
         $slugs = Set::combine($slugs, '/Revision/lang', '/Revision');
     }
     $this->set(compact('data', 'neighbours', 'children', 'pendingUpdates', 'slugs', 'directChildren'));
     $this->set('loginFields', $this->Auth->fields);
     $this->helpers[] = 'Highlight';
     $this->helpers[] = 'Text';
     $this->_setTocData();
     $this->render('view_all');
 }
Ejemplo n.º 28
0
 function testGetMembersByGroupId()
 {
     $users = $this->User->getMembersByGroupId(1);
     $users = Set::sort($users, '{n}.User.id', 'asc');
     $this->assertEqual(Set::extract($users, '/User/id'), array(5, 6, 7, 35));
     // test invalid group id
     $users = $this->User->getMembersByGroupId(999);
     $this->assertFalse($users);
     // test excluding member
     $users = $this->User->getMembersByGroupId(1, 6);
     $users = Set::sort($users, '{n}.User.id', 'asc');
     $this->assertEqual(Set::extract($users, '/User/id'), array(5, 7, 35));
     // test excluding invalid member
     $users = $this->User->getMembersByGroupId(1, 8);
     $users = Set::sort($users, '{n}.User.id', 'asc');
     $this->assertEqual(Set::extract($users, '/User/id'), array(5, 6, 7, 35));
 }
Ejemplo n.º 29
0
 /**
  * test sorting with out of order keys.
  *
  * @return void
  */
 public function testSortWithOutOfOrderKeys()
 {
     $data = array(9 => array('class' => 510, 'test2' => 2), 1 => array('class' => 500, 'test2' => 1), 2 => array('class' => 600, 'test2' => 2), 5 => array('class' => 625, 'test2' => 4), 0 => array('class' => 605, 'test2' => 3));
     $expected = array(array('class' => 500, 'test2' => 1), array('class' => 510, 'test2' => 2), array('class' => 600, 'test2' => 2), array('class' => 605, 'test2' => 3), array('class' => 625, 'test2' => 4));
     $result = Set::sort($data, '{n}.class', 'asc');
     $this->assertEquals($expected, $result);
     $result = Set::sort($data, '{n}.test2', 'asc');
     $this->assertEquals($expected, $result);
 }
 public function getsearchlist()
 {
     $this->autoRender = false;
     $this->layout = '';
     $this->loadModel('OpenOrder');
     $express1 = array();
     $express2 = array();
     $standerd1 = array();
     $standerd2 = array();
     $tracked1 = array();
     $tracked2 = array();
     $barcode = $this->request->data['barcode'];
     if ($barcode) {
         $results = $this->OpenOrder->find('all', array('conditions' => array('OpenOrder.items REGEXP' => '.*;s:[0-9]+:"' . $barcode . '".*', 'OpenOrder.status' => '0')));
     }
     $i = 0;
     foreach ($results as $result) {
         $itemdetails[$i]['Id'] = $result['OpenOrder']['id'];
         $itemdetails[$i]['OrderId'] = $result['OpenOrder']['order_id'];
         $itemdetails[$i]['NumOrderId'] = $result['OpenOrder']['num_order_id'];
         $itemdetails[$i]['GeneralInfo'] = unserialize($result['OpenOrder']['general_info']);
         $itemdetails[$i]['ShippingInfo'] = unserialize($result['OpenOrder']['shipping_info']);
         $itemdetails[$i]['CustomerInfo'] = unserialize($result['OpenOrder']['customer_info']);
         $itemdetails[$i]['TotalsInfo'] = unserialize($result['OpenOrder']['totals_info']);
         $itemdetails[$i]['FolderName'] = unserialize($result['OpenOrder']['folder_name']);
         $itemdetails[$i]['Items'] = unserialize($result['OpenOrder']['items']);
         $i++;
     }
     if (isset($itemdetails)) {
         $itemdetails = json_decode(json_encode($itemdetails), TRUE);
         $myArray = Set::sort($itemdetails, '{n}.GeneralInfo.ReceivedDate', 'ASC');
         foreach ($myArray as $itemdetail) {
             if ($itemdetail['ShippingInfo']['PostalServiceName'] == 'EXPRESS' && count($itemdetail['Items']) == 1) {
                 $express1[] = $itemdetail;
             }
             if ($itemdetail['ShippingInfo']['PostalServiceName'] == 'Standard' && count($itemdetail['Items']) == 1) {
                 $standerd1[] = $itemdetail;
             }
             if ($itemdetail['ShippingInfo']['PostalServiceName'] == 'TRACKED' && count($itemdetail['Items']) == 1) {
                 $tracked1[] = $itemdetail;
             }
             if ($itemdetail['ShippingInfo']['PostalServiceName'] == 'EXPRESS' && count($itemdetail['Items']) > 1) {
                 $express2[] = $itemdetail;
             }
             if ($itemdetail['ShippingInfo']['PostalServiceName'] == 'Standard' && count($itemdetail['Items']) > 1) {
                 $standerd2[] = $itemdetail;
             }
             if ($itemdetail['ShippingInfo']['PostalServiceName'] == 'TRACKED' && count($itemdetail['Items']) > 1) {
                 $tracked2[] = $itemdetail;
             }
         }
     }
     $this->set(compact('express1', 'standerd1', 'tracked1', 'express2', 'standerd2', 'tracked2'));
     echo $this->render('scansearch');
     exit;
 }