Esempio n. 1
0
 /**
  * Pushes the differences in $array2 onto the end of $array
  *
  * @param array $array Original array
  * @param array $array2 Differences to push
  * @return array Combined array
  * @link http://book.cakephp.org/2.0/en/core-utility-libraries/set.html#Set::pushDiff
  */
 public static function pushDiff($array, $array2)
 {
     if (empty($array) && !empty($array2)) {
         return $array2;
     }
     if (!empty($array) && !empty($array2)) {
         foreach ($array2 as $key => $value) {
             if (!array_key_exists($key, $array)) {
                 $array[$key] = $value;
             } else {
                 if (is_array($value)) {
                     $array[$key] = Set::pushDiff($array[$key], $array2[$key]);
                 }
             }
         }
     }
     return $array;
 }
Esempio n. 2
0
 /**
  * mergeHasMany - Merge the results of hasMany relations.
  *
  *
  * @param array $resultSet Data to merge into
  * @param array $merge Data to merge
  * @param string $association Name of Model being Merged
  * @param object $model Model being merged onto
  * @param object $linkModel Model being merged
  * @return void
  */
 function __mergeHasMany(&$resultSet, $merge, $association, &$model, &$linkModel)
 {
     foreach ($resultSet as $i => $value) {
         $count = 0;
         $merged[$association] = array();
         foreach ($merge as $j => $data) {
             if (isset($value[$model->alias]) && $value[$model->alias][$model->primaryKey] === $data[$association][$model->hasMany[$association]['foreignKey']]) {
                 if (count($data) > 1) {
                     $data = array_merge($data[$association], $data);
                     unset($data[$association]);
                     foreach ($data as $key => $name) {
                         if (is_numeric($key)) {
                             $data[$association][] = $name;
                             unset($data[$key]);
                         }
                     }
                     $merged[$association][] = $data;
                 } else {
                     $merged[$association][] = $data[$association];
                 }
             }
             $count++;
         }
         if (isset($value[$model->alias])) {
             $resultSet[$i] = Set::pushDiff($resultSet[$i], $merged);
             unset($merged);
         }
     }
 }
Esempio n. 3
0
 /**
  * Converts an object into an array
  *
  * @param object $object
  * @return array
  */
 function reverse($object)
 {
     if (is_object($object)) {
         $merge = array();
         if (is_a($object, 'xmlnode') || is_a($object, 'XMLNode')) {
             if ($object->name != Inflector::underscore($this->name)) {
                 if (is_object($object->child(Inflector::underscore($this->name)))) {
                     $object = $object->child(Inflector::underscore($this->name));
                     $object = $object->attributes;
                 } else {
                     return null;
                 }
             }
         } elseif (is_a($object, 'stdclass') || is_a($object, 'stdClass')) {
             $object = get_object_vars($object);
             $keys = array_keys($object);
             $count = count($keys);
             for ($i = 0; $i < $count; $i++) {
                 if ($keys[$i] == '__identity__') {
                     $key = $object[$keys[$i]];
                     unset($object[$keys[$i]]);
                     $object[$key] = $object;
                 } elseif (is_array($object[$keys[$i]])) {
                     $keys1 = array_keys($object[$keys[$i]]);
                     $count1 = count($keys1);
                     for ($ii = 0; $ii < $count1; $ii++) {
                         if (is_object($object[$keys[$i]][$keys1[$ii]])) {
                             $merge[$keys[$i]][$keys1[$ii]] = Set::reverse($object[$keys[$i]][$keys1[$ii]]);
                         } else {
                             $merge[$keys[$i]][$keys1[$ii]] = $object[$keys[$i]][$keys1[$ii]];
                         }
                     }
                     unset($object[$keys[$i]]);
                 } elseif (is_object($object[$keys[$i]])) {
                     $merge[$keys[$i]] = Set::reverse($object[$keys[$i]]);
                     unset($object[$keys[$i]]);
                 }
             }
         }
         $return = $object;
         if (!empty($merge)) {
             $mergeKeys = array_keys($merge);
             $objectKeys = array_keys($object);
             $count = count($mergeKeys);
             $change = $object;
             $count1 = count($objectKeys);
             for ($i = 0; $i < $count; $i++) {
                 $loop = $count1;
                 for ($ii = 0; $ii < $loop; $ii++) {
                     if (is_array($object[$objectKeys[$ii]])) {
                         if (array_key_exists($objectKeys[$ii], $object[$objectKeys[$ii]])) {
                             unset($change[$objectKeys[$ii]][$objectKeys[$ii]]);
                         }
                     } else {
                         unset($change[$objectKeys[$ii]]);
                     }
                 }
                 foreach ($objectKeys as $key => $value) {
                     if (is_array($object[$value])) {
                         if (array_key_exists($mergeKeys[$i], $object[$value])) {
                             unset($change[$value][$mergeKeys[$i]]);
                         }
                     } else {
                         unset($change[$value]);
                     }
                 }
             }
             $object = Set::pushDiff($change, $merge);
         }
         return $object;
     }
 }
Esempio n. 4
0
File: set.php Progetto: venka10/RUS
 /**
  * Pushes the differences in $array2 onto the end of $array
  *
  * @param mixed $array Original array
  * @param mixed $array2 Differences to push
  * @return array Combined array
  * @access public
  */
 function pushDiff($array = null, $array2 = null)
 {
     if ($array2 !== null && is_array($array2)) {
         foreach ($array2 as $key => $value) {
             if (!array_key_exists($key, $array)) {
                 $array[$key] = $value;
             } else {
                 if (is_array($value)) {
                     $array[$key] = Set::pushDiff($array[$key], $array2[$key]);
                 }
             }
         }
         return $array;
     }
     if (!isset($this->value)) {
         $this->value = array();
     }
     $this->value = Set::pushDiff($this->value, Set::__array($array));
     return $this->value;
 }
Esempio n. 5
0
 /**
  * Validate submitted form
  *
  * @param object $controller Instantiating controller
  * @return bool true if submitted form is valid
  * @access private
  */
 function __validatePost(&$controller)
 {
     if (!empty($controller->data)) {
         if (!isset($controller->data['__Token'])) {
             if (!$this->blackHole($controller, 'auth')) {
                 return null;
             }
         }
         $token = $controller->data['__Token']['key'];
         if ($this->Session->check('_Token')) {
             $tData = unserialize($this->Session->read('_Token'));
             if ($tData['expires'] < time() || $tData['key'] !== $token) {
                 if (!$this->blackHole($controller, 'auth')) {
                     return null;
                 }
             }
         }
         if (!isset($controller->data['__Token']['fields'])) {
             if (!$this->blackHole($controller, 'auth')) {
                 return null;
             }
         }
         $form = $controller->data['__Token']['fields'];
         $check = $controller->data;
         unset($check['__Token']['fields']);
         if (!empty($this->disabledFields)) {
             foreach ($check as $model => $fields) {
                 foreach ($fields as $field => $value) {
                     $key[] = $model . '.' . $field;
                 }
                 unset($field);
             }
             foreach ($this->disabledFields as $value) {
                 $parts = preg_split('/\\/|\\./', $value);
                 if (count($parts) == 1) {
                     $key1[] = $controller->modelClass . '.' . $parts['0'];
                 } elseif (count($parts) == 2) {
                     $key1[] = $parts['0'] . '.' . $parts['1'];
                 }
             }
             foreach ($key1 as $value) {
                 if (in_array($value, $key)) {
                     $remove = explode('.', $value);
                     unset($check[$remove['0']][$remove['1']]);
                     if (empty($check[$remove['0']])) {
                         unset($check[$remove['0']]);
                     }
                 } elseif (in_array('_' . $value, $key)) {
                     $remove = explode('.', $value);
                     $controller->data[$remove['0']][$remove['1']] = $controller->data['_' . $remove['0']][$remove['1']];
                     unset($check['_' . $remove['0']][$remove['1']]);
                     if (empty($check['_' . $remove['0']])) {
                         unset($check['_' . $remove['0']]);
                     }
                 }
             }
         }
         ksort($check);
         foreach ($check as $key => $value) {
             $merge = array();
             if ($key === '__Token') {
                 $field[$key] = $value;
                 continue;
             }
             $string = substr($key, 0, 1);
             if ($string === '_') {
                 $newKey = substr($key, 1);
                 if (!isset($controller->data[$newKey])) {
                     $controller->data[$newKey] = array();
                     if (array_keys($controller->data[$key]) === array($newKey)) {
                         $field[$newKey] = array($newKey);
                     }
                 }
                 if (is_array($value)) {
                     $values = array_values($value);
                     $k = array_keys($value);
                     $count = count($k);
                     if (is_numeric($k[0])) {
                         for ($i = 0; $count > $i; $i++) {
                             foreach ($values[$i] as $key2 => $value1) {
                                 if ($value1 === '0') {
                                     $field[$newKey][$i] = array_merge($field[$newKey][$i], array($key2));
                                 }
                             }
                         }
                         $controller->data[$newKey] = Set::pushDiff($controller->data[$key], $controller->data[$newKey]);
                     }
                     for ($i = 0; $count > $i; $i++) {
                         $field[$key][$k[$i]] = $values[$i];
                     }
                     foreach ($k as $lookup) {
                         if (isset($controller->data[$newKey][$lookup])) {
                             unset($controller->data[$key][$lookup]);
                         } elseif ($controller->data[$key][$lookup] === '0') {
                             $merge[] = $lookup;
                         }
                     }
                     if (!is_numeric($k[0])) {
                         if (isset($field[$newKey])) {
                             $field[$newKey] = array_merge($merge, $field[$newKey]);
                         } else {
                             $field[$newKey] = $merge;
                         }
                         $controller->data[$newKey] = Set::pushDiff($controller->data[$key], $controller->data[$newKey]);
                     }
                     unset($controller->data[$key]);
                 }
                 continue;
             }
             if (is_array($value)) {
                 $keys = array_keys($value);
             } else {
                 $keys = $value;
             }
             if (isset($field[$key])) {
                 $field[$key] = array_merge($field[$key], $keys);
             } elseif (is_array($keys) && !empty($keys) && is_numeric($keys[0])) {
                 foreach ($value as $fields) {
                     $merge[] = array_keys($fields);
                 }
                 $field[$key] = $merge;
             } else {
                 if (is_array($keys)) {
                     $field[$key] = $keys;
                 } else {
                     $field[] = $key;
                 }
             }
         }
         foreach ($field as $key => $value) {
             if ($key[0] != '_' && is_array($field[$key])) {
                 sort($field[$key]);
             }
         }
         ksort($field, SORT_STRING);
         $check = urlencode(Security::hash(serialize($field) . Configure::read('Security.salt')));
         if ($form !== $check) {
             if (!$this->blackHole($controller, 'auth')) {
                 return null;
             }
         }
     }
     return true;
 }
Esempio n. 6
0
 /**
  * Binds the given domain to a file in the specified directory.
  *
  * @param string $domain Domain to bind
  * @return string Domain binded
  */
 protected function _bindTextDomain($domain)
 {
     $this->_noLocale = true;
     $core = true;
     $merge = array();
     $searchPaths = App::path('locales');
     $plugins = CakePlugin::loaded();
     if (!empty($plugins)) {
         foreach ($plugins as $plugin) {
             $pluginDomain = Inflector::underscore($plugin);
             if ($pluginDomain === $domain) {
                 $searchPaths[] = CakePlugin::path($plugin) . 'Locale' . DS;
                 $searchPaths = array_reverse($searchPaths);
                 break;
             }
         }
     }
     foreach ($searchPaths as $directory) {
         foreach ($this->l10n->languagePath as $lang) {
             $localeDef = $directory . $lang . DS . $this->category;
             if (is_file($localeDef)) {
                 $definitions = self::loadLocaleDefinition($localeDef);
                 if ($definitions !== false) {
                     $this->_domains[$domain][$this->_lang][$this->category] = self::loadLocaleDefinition($localeDef);
                     $this->_noLocale = false;
                     return $domain;
                 }
             }
             if ($core) {
                 $app = $directory . $lang . DS . $this->category . DS . 'core';
                 $translations = false;
                 if (is_file($app . '.mo')) {
                     $translations = self::loadMo($app . '.mo');
                 }
                 if ($translations === false && is_file($app . '.po')) {
                     $translations = self::loadPo($app . '.po');
                 }
                 if ($translations !== false) {
                     $this->_domains[$domain][$this->_lang][$this->category] = $translations;
                     $merge[$domain][$this->_lang][$this->category] = $this->_domains[$domain][$this->_lang][$this->category];
                     $this->_noLocale = false;
                     $core = null;
                 }
             }
             $file = $directory . $lang . DS . $this->category . DS . $domain;
             $translations = false;
             if (is_file($file . '.mo')) {
                 $translations = self::loadMo($file . '.mo');
             }
             if ($translations === false && is_file($file . '.po')) {
                 $translations = self::loadPo($file . '.po');
             }
             if ($translations !== false) {
                 $this->_domains[$domain][$this->_lang][$this->category] = $translations;
                 $this->_noLocale = false;
                 break 2;
             }
         }
     }
     if (empty($this->_domains[$domain][$this->_lang][$this->category])) {
         $this->_domains[$domain][$this->_lang][$this->category] = array();
         return $domain;
     }
     if (isset($this->_domains[$domain][$this->_lang][$this->category][""])) {
         $head = $this->_domains[$domain][$this->_lang][$this->category][""];
         foreach (explode("\n", $head) as $line) {
             $header = strtok($line, ":");
             $line = trim(strtok("\n"));
             $this->_domains[$domain][$this->_lang][$this->category]["%po-header"][strtolower($header)] = $line;
         }
         if (isset($this->_domains[$domain][$this->_lang][$this->category]["%po-header"]["plural-forms"])) {
             $switch = preg_replace("/(?:[() {}\\[\\]^\\s*\\]]+)/", "", $this->_domains[$domain][$this->_lang][$this->category]["%po-header"]["plural-forms"]);
             $this->_domains[$domain][$this->_lang][$this->category]["%plural-c"] = $switch;
             unset($this->_domains[$domain][$this->_lang][$this->category]["%po-header"]);
         }
         $this->_domains = Set::pushDiff($this->_domains, $merge);
         if (isset($this->_domains[$domain][$this->_lang][$this->category][null])) {
             unset($this->_domains[$domain][$this->_lang][$this->category][null]);
         }
     }
     return $domain;
 }
Esempio n. 7
0
 /**
  * add
  *
  * @param mixed $course_id
  *
  * @access public
  * @return void
  */
 function add($course_id)
 {
     $course = $this->Course->getAccessibleCourseById($course_id, User::get('id'), User::getCourseFilterPermission());
     if (!$course) {
         $this->Session->setFlash(__('Error: Course does not exist or you do not have permission to view this course.', true));
         $this->redirect('/courses');
         return;
     }
     if (!empty($this->data)) {
         $this->data['Group']['group_name'] = trim($this->data['Group']['group_name']);
         if ($this->Group->save($this->data)) {
             $this->Session->setFlash(__('The group was added successfully.', true), 'good');
             $this->redirect('index/' . $course_id);
             return;
         }
     }
     $user_data1 = $this->User->getEnrolledStudentsForList($course_id);
     $user_data2 = $this->User->getCourseTutorsForList($course_id);
     $user_data = Set::pushDiff($user_data1, $user_data2);
     //Check if student is already assigned in a group
     $groups = $this->Group->getGroupsByCourseId($course_id);
     $assigned_users = $this->GroupsMembers->getUserListInGroups(array_keys($groups));
     foreach ($assigned_users as $assigned_user) {
         $user_data[$assigned_user] = $user_data[$assigned_user] . ' *';
     }
     $this->set('breadcrumb', $this->breadcrumb->push(array('course' => $course['Course']))->push(__('Add Group', true)));
     $this->data['Group']['course_id'] = $course_id;
     // gets all the students in db for the unfiltered students list
     $this->set('user_data', $user_data);
     $this->set('course_id', $course_id);
     $this->set('group_num', $this->Group->getFirstAvailGroupNum($course_id));
     $this->render('edit');
 }
Esempio n. 8
0
/**
 * mergeHasMany - Merge the results of hasMany relations.
 *
 *
 * @param array $resultSet Data to merge into
 * @param array $merge Data to merge
 * @param string $association Name of Model being Merged
 * @param Model $model Model being merged onto
 * @param Model $linkModel Model being merged
 * @return void
 */
	protected function _mergeHasMany(&$resultSet, $merge, $association, $model, $linkModel) {
		$modelAlias = $model->alias;
		$modelPK = $model->primaryKey;
		$modelFK = $model->hasMany[$association]['foreignKey'];
		foreach ($resultSet as &$result) {
			if (!isset($result[$modelAlias])) {
				continue;
			}
			$merged = array();
			foreach ($merge as $data) {
				if ($result[$modelAlias][$modelPK] === $data[$association][$modelFK]) {
					if (count($data) > 1) {
						$data = array_merge($data[$association], $data);
						unset($data[$association]);
						foreach ($data as $key => $name) {
							if (is_numeric($key)) {
								$data[$association][] = $name;
								unset($data[$key]);
							}
						}
						$merged[] = $data;
					} else {
						$merged[] = $data[$association];
					}
				}
			}
			$result = Set::pushDiff($result, array($association => $merged));
		}
	}
Esempio n. 9
0
 /**
  * Initializes singular inflection rules
  *
  * @return void
  * @access protected
  */
 function __initSingularRules()
 {
     $coreSingularRules = array('/(s)tatuses$/i' => '\\1\\2tatus', '/^(.*)(menu)s$/i' => '\\1\\2', '/(quiz)zes$/i' => '\\1', '/(matr)ices$/i' => '\\1ix', '/(vert|ind)ices$/i' => '\\1ex', '/^(ox)en/i' => '\\1', '/(alias)(es)*$/i' => '\\1', '/(alumn|bacill|cact|foc|fung|nucle|radi|stimul|syllab|termin|viri?)i$/i' => '\\1us', '/(cris|ax|test)es$/i' => '\\1is', '/(shoe)s$/i' => '\\1', '/(o)es$/i' => '\\1', '/ouses$/' => 'ouse', '/uses$/' => 'us', '/([m|l])ice$/i' => '\\1ouse', '/(x|ch|ss|sh)es$/i' => '\\1', '/(m)ovies$/i' => '\\1\\2ovie', '/(s)eries$/i' => '\\1\\2eries', '/([^aeiouy]|qu)ies$/i' => '\\1y', '/([lr])ves$/i' => '\\1f', '/(tive)s$/i' => '\\1', '/(hive)s$/i' => '\\1', '/(drive)s$/i' => '\\1', '/([^fo])ves$/i' => '\\1fe', '/(^analy)ses$/i' => '\\1sis', '/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i' => '\\1\\2sis', '/([ti])a$/i' => '\\1um', '/(p)eople$/i' => '\\1\\2erson', '/(m)en$/i' => '\\1an', '/(c)hildren$/i' => '\\1\\2hild', '/(n)ews$/i' => '\\1\\2ews', '/^(.*us)$/' => '\\1', '/s$/i' => '');
     $coreUninflectedSingular = array('.*[nrlm]ese', '.*deer', '.*fish', '.*measles', '.*ois', '.*pox', '.*sheep', '.*ss', 'Amoyese', 'bison', 'Borghese', 'bream', 'breeches', 'britches', 'buffalo', 'cantus', 'carp', 'chassis', 'clippers', 'cod', 'coitus', 'Congoese', 'contretemps', 'corps', 'debris', 'diabetes', 'djinn', 'eland', 'elk', 'equipment', 'Faroese', 'flounder', 'Foochowese', 'gallows', 'Genevese', 'Genoese', 'Gilbertese', 'graffiti', 'headquarters', 'herpes', 'hijinks', 'Hottentotese', 'information', 'innings', 'jackanapes', 'Kiplingese', 'Kongoese', 'Lucchese', 'mackerel', 'Maltese', 'media', 'mews', 'moose', 'mumps', 'Nankingese', 'news', 'nexus', 'Niasese', 'Pekingese', 'Piedmontese', 'pincers', 'Pistoiese', 'pliers', 'Portuguese', 'proceedings', 'rabies', 'rice', 'rhinoceros', 'salmon', 'Sarawakese', 'scissors', 'sea[- ]bass', 'series', 'Shavese', 'shears', 'siemens', 'species', 'swine', 'testes', 'trousers', 'trout', 'tuna', 'Vermontese', 'Wenchowese', 'whiting', 'wildebeest', 'Yengeese');
     $coreIrregularSingular = array('atlases' => 'atlas', 'beefs' => 'beef', 'brothers' => 'brother', 'children' => 'child', 'corpuses' => 'corpus', 'cows' => 'cow', 'ganglions' => 'ganglion', 'genies' => 'genie', 'genera' => 'genus', 'graffiti' => 'graffito', 'hoofs' => 'hoof', 'loaves' => 'loaf', 'men' => 'man', 'monies' => 'money', 'mongooses' => 'mongoose', 'moves' => 'move', 'mythoi' => 'mythos', 'numina' => 'numen', 'occiputs' => 'occiput', 'octopuses' => 'octopus', 'opuses' => 'opus', 'oxen' => 'ox', 'penises' => 'penis', 'people' => 'person', 'sexes' => 'sex', 'soliloquies' => 'soliloquy', 'testes' => 'testis', 'trilbys' => 'trilby', 'turfs' => 'turf');
     $singularRules = Set::pushDiff($this->__singularRules, $coreSingularRules);
     $uninflected = Set::pushDiff($this->__uninflectedSingular, $coreUninflectedSingular);
     $irregular = Set::pushDiff($this->__irregularSingular, $coreIrregularSingular);
     $this->singularRules = array('singularRules' => $singularRules, 'uninflected' => $uninflected, 'irregular' => $irregular);
     $this->singularized = array();
 }
Esempio n. 10
0
 function __mergeHasMany(&$resultSet, $merge, $association, &$model, &$linkModel)
 {
     foreach ($resultSet as $key => $value) {
         $merged[$association] = array();
         $count = 0;
         foreach ($merge as $assoc => $data) {
             if (isset($value[$model->name]) && $value[$model->name][$model->primaryKey] === $data[$association][$model->hasMany[$association]['foreignKey']]) {
                 if (count($data) > 1) {
                     $temp[] = Set::pushDiff($data[$association], $data);
                     unset($temp[$count][$association]);
                     $merged[$association] = $temp;
                 } else {
                     $merged[$association][] = $data[$association];
                 }
             }
             $count++;
         }
         if (isset($value[$model->name])) {
             $resultSet[$key] = Set::pushDiff($resultSet[$key], $merged);
             unset($merged);
             unset($temp);
         }
     }
 }
Esempio n. 11
0
 /**
  * testPushDiff method
  *
  * @access public
  * @return void
  */
 function testPushDiff()
 {
     $array1 = array('ModelOne' => array('id' => 1001, 'field_one' => 'a1.m1.f1', 'field_two' => 'a1.m1.f2'));
     $array2 = array('ModelTwo' => array('id' => 1002, 'field_one' => 'a2.m2.f1', 'field_two' => 'a2.m2.f2'));
     $result = Set::pushDiff($array1, $array2);
     $this->assertIdentical($result, $array1 + $array2);
     $array3 = array('ModelOne' => array('id' => 1003, 'field_one' => 'a3.m1.f1', 'field_two' => 'a3.m1.f2', 'field_three' => 'a3.m1.f3'));
     $result = Set::pushDiff($array1, $array3);
     $expected = array('ModelOne' => array('id' => 1001, 'field_one' => 'a1.m1.f1', 'field_two' => 'a1.m1.f2', 'field_three' => 'a3.m1.f3'));
     $this->assertIdentical($result, $expected);
     $array1 = array(0 => array('ModelOne' => array('id' => 1001, 'field_one' => 's1.0.m1.f1', 'field_two' => 's1.0.m1.f2')), 1 => array('ModelTwo' => array('id' => 1002, 'field_one' => 's1.1.m2.f2', 'field_two' => 's1.1.m2.f2')));
     $array2 = array(0 => array('ModelOne' => array('id' => 1001, 'field_one' => 's2.0.m1.f1', 'field_two' => 's2.0.m1.f2')), 1 => array('ModelTwo' => array('id' => 1002, 'field_one' => 's2.1.m2.f2', 'field_two' => 's2.1.m2.f2')));
     $result = Set::pushDiff($array1, $array2);
     $this->assertIdentical($result, $array1);
     $array3 = array(0 => array('ModelThree' => array('id' => 1003, 'field_one' => 's3.0.m3.f1', 'field_two' => 's3.0.m3.f2')));
     $result = Set::pushDiff($array1, $array3);
     $expected = array(0 => array('ModelOne' => array('id' => 1001, 'field_one' => 's1.0.m1.f1', 'field_two' => 's1.0.m1.f2'), 'ModelThree' => array('id' => 1003, 'field_one' => 's3.0.m3.f1', 'field_two' => 's3.0.m3.f2')), 1 => array('ModelTwo' => array('id' => 1002, 'field_one' => 's1.1.m2.f2', 'field_two' => 's1.1.m2.f2')));
     $this->assertIdentical($result, $expected);
     $result = Set::pushDiff($array1, null);
     $this->assertIdentical($result, $array1);
     $result = Set::pushDiff($array1, $array2);
     $this->assertIdentical($result, $array1 + $array2);
 }
Esempio n. 12
0
 /**
  * undocumented function
  *
  * @param string $state
  * @param string $query
  * @param string $results
  * @return void
  */
 function _findEvents($state, $query, $results = array())
 {
     if ($state == 'before') {
         $defaults = array('order' => array('Timeline.created' => 'DESC', 'Timeline.id' => 'DESC'));
         $query = Set::pushDiff($defaults, $query);
         return $query;
     }
     $data = array();
     foreach ((array) $results as $key => $timeline) {
         $type = $timeline['Timeline']['model'];
         if (!isset($this->{$type})) {
             continue;
         }
         $this->{$type}->recursive = 0;
         $related = $this->{$type}->findById($timeline['Timeline']['foreign_key']);
         if (!empty($related)) {
             $data[] = array_merge($timeline, (array) $related);
         }
     }
     return $data;
 }
Esempio n. 13
0
 /**
  * Get students and tutors not in a group
  *
  * @param int    $group_id group id
  * @param string $type     type of user
  *
  * @return array students and tutors not in the group
  */
 function getStudentsNotInGroup($group_id, $type = 'list')
 {
     // $people includes id of both students and tutors/TAs in group
     $people = $this->getMembersByGroupId($group_id, 'all');
     $people = Set::extract('/Member/id', $people);
     $peopleInGroups = array();
     $course = $this->Course->getCourseByGroupId($group_id);
     if (empty($course)) {
         return array();
     }
     $peopleListinGroups = $this->Member->find($type, array('conditions' => array('NOT' => array('Member.id' => $people), 'Group.course_id' => $course['Course']['id']), 'recursive' => 1, 'fields' => array('Member.student_no_with_full_name'), 'contain' => array('Group'), 'order' => 'Member.student_no'));
     foreach ($peopleListinGroups as $key => $student) {
         $peopleListinGroups[$key] = $student . ' *';
         $peopleInGroups[] = $key;
     }
     $excludedPeople = array_merge($people, $peopleInGroups);
     $studentsListNotinGroups = $this->Member->find($type, array('conditions' => array('NOT' => array('Member.id' => $excludedPeople), 'Enrolment.id' => $course['Course']['id']), 'recursive' => 1, 'fields' => array('Member.student_no_with_full_name'), 'order' => 'Member.student_no'));
     $tutorsListNotinGroups = $this->Member->find($type, array('conditions' => array('NOT' => array('Member.id' => $excludedPeople), 'Tutor.id' => $course['Course']['id'], 'Role.id' => 4), 'recursive' => 1, 'fields' => array('Member.full_name'), 'order' => 'Member.last_name'));
     $peopleList = Set::pushDiff($studentsListNotinGroups, $peopleListinGroups);
     $sorted_list = Set::pushDiff($tutorsListNotinGroups, $peopleList);
     return $sorted_list;
 }
Esempio n. 14
0
 /**
  * Binds the given domain to a file in the specified directory.
  *
  * @param string $domain Domain to bind
  * @return string Domain binded
  * @access private
  */
 function __bindTextDomain($domain)
 {
     $this->__noLocale = true;
     $core = true;
     $merge = array();
     $searchPaths[] = S2Paths::get($this->app, 'S2_APP_OVERRIDES') . 'locale';
     $searchPaths[] = S2Paths::get($this->app, 'S2_APP') . 'locale';
     //		$plugins = Configure::listObjects('plugin');
     if (!empty($plugins)) {
         $pluginPaths = Configure::read('pluginPaths');
         foreach ($plugins as $plugin) {
             $plugin = Inflector::underscore($plugin);
             if ($plugin === $domain) {
                 foreach ($pluginPaths as $pluginPath) {
                     $searchPaths[] = $pluginPath . DS . $plugin . DS . 'locale';
                 }
                 $searchPaths = array_reverse($searchPaths);
                 break;
             }
         }
     }
     foreach ($searchPaths as $directory) {
         foreach ($this->l10n->languagePath as $lang) {
             $file = $directory . DS . $lang . DS . $this->category . DS . $domain;
             if ($core) {
                 $app = $directory . DS . $lang . DS . $this->category . DS . 'core';
                 if (file_exists($fn = "{$app}.mo")) {
                     $this->__loadMo($fn, $domain);
                     $this->__noLocale = false;
                     $merge[$this->category][$this->__lang][$domain] = $this->__domains[$this->category][$this->__lang][$domain];
                     $core = null;
                 } elseif (file_exists($fn = "{$app}.po") && ($f = fopen($fn, "r"))) {
                     $this->__loadPo($f, $domain);
                     $this->__noLocale = false;
                     $merge[$this->category][$this->__lang][$domain] = $this->__domains[$this->category][$this->__lang][$domain];
                     $core = null;
                 }
             }
             if (file_exists($fn = "{$file}.mo")) {
                 $this->__loadMo($fn, $domain);
                 $this->__noLocale = false;
                 break 2;
             } elseif (file_exists($fn = "{$file}.po") && ($f = fopen($fn, "r"))) {
                 $this->__loadPo($f, $domain);
                 $this->__noLocale = false;
                 break 2;
             }
         }
     }
     if (empty($this->__domains[$this->category][$this->__lang][$domain])) {
         $this->__domains[$this->category][$this->__lang][$domain] = array();
         return $domain;
     }
     if ($head = $this->__domains[$this->category][$this->__lang][$domain][""]) {
         foreach (explode("\n", $head) as $line) {
             $header = strtok($line, ":");
             $line = trim(strtok("\n"));
             $this->__domains[$this->category][$this->__lang][$domain]["%po-header"][strtolower($header)] = $line;
         }
         if (isset($this->__domains[$this->category][$this->__lang][$domain]["%po-header"]["plural-forms"])) {
             $switch = preg_replace("/(?:[() {}\\[\\]^\\s*\\]]+)/", "", $this->__domains[$this->category][$this->__lang][$domain]["%po-header"]["plural-forms"]);
             $this->__domains[$this->category][$this->__lang][$domain]["%plural-c"] = $switch;
             unset($this->__domains[$this->category][$this->__lang][$domain]["%po-header"]);
         }
         $this->__domains = Set::pushDiff($this->__domains, $merge);
         if (isset($this->__domains[$this->category][$this->__lang][$domain][null])) {
             unset($this->__domains[$this->category][$this->__lang][$domain][null]);
         }
     }
     return $domain;
 }
Esempio n. 15
0
 /**
  * testPushDiff method
  *
  * @return void
  */
 public function testPushDiff()
 {
     $array1 = array('ModelOne' => array('id' => 1001, 'field_one' => 'a1.m1.f1', 'field_two' => 'a1.m1.f2'));
     $array2 = array('ModelTwo' => array('id' => 1002, 'field_one' => 'a2.m2.f1', 'field_two' => 'a2.m2.f2'));
     $result = Set::pushDiff($array1, $array2);
     $this->assertEquals($array1 + $array2, $result);
     $array3 = array('ModelOne' => array('id' => 1003, 'field_one' => 'a3.m1.f1', 'field_two' => 'a3.m1.f2', 'field_three' => 'a3.m1.f3'));
     $result = Set::pushDiff($array1, $array3);
     $expected = array('ModelOne' => array('id' => 1001, 'field_one' => 'a1.m1.f1', 'field_two' => 'a1.m1.f2', 'field_three' => 'a3.m1.f3'));
     $this->assertEquals($expected, $result);
     $array1 = array(0 => array('ModelOne' => array('id' => 1001, 'field_one' => 's1.0.m1.f1', 'field_two' => 's1.0.m1.f2')), 1 => array('ModelTwo' => array('id' => 1002, 'field_one' => 's1.1.m2.f2', 'field_two' => 's1.1.m2.f2')));
     $array2 = array(0 => array('ModelOne' => array('id' => 1001, 'field_one' => 's2.0.m1.f1', 'field_two' => 's2.0.m1.f2')), 1 => array('ModelTwo' => array('id' => 1002, 'field_one' => 's2.1.m2.f2', 'field_two' => 's2.1.m2.f2')));
     $result = Set::pushDiff($array1, $array2);
     $this->assertEquals($array1, $result);
     $array3 = array(0 => array('ModelThree' => array('id' => 1003, 'field_one' => 's3.0.m3.f1', 'field_two' => 's3.0.m3.f2')));
     $result = Set::pushDiff($array1, $array3);
     $expected = array(0 => array('ModelOne' => array('id' => 1001, 'field_one' => 's1.0.m1.f1', 'field_two' => 's1.0.m1.f2'), 'ModelThree' => array('id' => 1003, 'field_one' => 's3.0.m3.f1', 'field_two' => 's3.0.m3.f2')), 1 => array('ModelTwo' => array('id' => 1002, 'field_one' => 's1.1.m2.f2', 'field_two' => 's1.1.m2.f2')));
     $this->assertEquals($expected, $result);
     $result = Set::pushDiff($array1, NULL);
     $this->assertEquals($array1, $result);
     $result = Set::pushDiff($array1, $array2);
     $this->assertEquals($array1 + $array2, $result);
 }
Esempio n. 16
0
 /**
  * Binds the given domain to a file in the specified directory.
  *
  * @param string $domain Domain to bind
  * @return string Domain binded
  * @access private
  */
 function __bindTextDomain($domain)
 {
     $_this =& I18n::getInstance();
     $_this->__noLocale = true;
     $core = true;
     $merge = array();
     $searchPath[] = APP . 'locale';
     $plugins = Configure::listObjects('plugin');
     if (!empty($plugins)) {
     }
     foreach ($searchPath as $directory) {
         foreach ($_this->l10n->languagePath as $lang) {
             $file = $directory . DS . $lang . DS . $_this->category . DS . $domain;
             if ($core) {
                 $app = $directory . DS . $lang . DS . $_this->category . DS . 'core';
                 if (file_exists($fn = "{$app}.mo")) {
                     $_this->__loadMo($fn, $domain);
                     $_this->__noLocale = false;
                     $merge = $_this->__domains;
                     $core = null;
                 } elseif (file_exists($fn = "{$app}.po") && ($f = fopen($fn, "r"))) {
                     $_this->__loadPo($f, $domain);
                     $_this->__noLocale = false;
                     $merge = $_this->__domains;
                     $core = null;
                 }
             }
             if (file_exists($fn = "{$file}.mo")) {
                 $_this->__loadMo($fn, $domain);
                 $_this->__noLocale = false;
                 break 2;
             } elseif (file_exists($fn = "{$file}.po") && ($f = fopen($fn, "r"))) {
                 $_this->__loadPo($f, $domain);
                 $_this->__noLocale = false;
                 break 2;
             }
         }
     }
     if (empty($_this->__domains[$_this->category][$domain])) {
         $_this->__domains[$_this->category][$domain] = array();
         return $domain;
     }
     if ($head = $_this->__domains[$_this->category][$domain][""]) {
         foreach (explode("\n", $head) as $line) {
             $header = strtok($line, ":");
             $line = trim(strtok("\n"));
             $_this->__domains[$_this->category][$domain]["%po-header"][strtolower($header)] = $line;
         }
         if (isset($_this->__domains[$_this->category][$domain]["%po-header"]["plural-forms"])) {
             $switch = preg_replace("/[() {}\\[\\]^\\s*\\]]+/", "", $_this->__domains[$_this->category][$domain]["%po-header"]["plural-forms"]);
             $_this->__domains[$_this->category][$domain]["%plural-c"] = $switch;
         }
         $_this->__domains = Set::pushDiff($_this->__domains, $merge);
         if (isset($_this->__domains[$_this->category][$domain][null])) {
             unset($_this->__domains[$_this->category][$domain][null]);
         }
     }
     return $domain;
 }
Esempio n. 17
0
 /**
  * Binds the given domain to a file in the specified directory.
  *
  * @param string $domain Domain to bind
  * @return string Domain binded
  * @access private
  */
 private static function __bindTextDomain($domain)
 {
     self::$__noLocale = true;
     $core = true;
     $merge = array();
     $searchPaths = App::path('locales');
     $plugins = App::objects('plugin');
     if (!empty($plugins)) {
         foreach ($plugins as $plugin) {
             $plugin = Inflector::underscore($plugin);
             if ($plugin === $domain) {
                 $searchPaths[] = App::pluginPath($plugin) . DS . 'locale' . DS;
                 $searchPaths = array_reverse($searchPaths);
                 break;
             }
         }
     }
     foreach ($searchPaths as $directory) {
         foreach (self::$L10n->languagePath as $lang) {
             $file = $directory . DS . $lang . DS . self::$category . DS . $domain;
             if ($core) {
                 $app = $directory . $lang . DS . self::$category . DS . 'core';
                 if (file_exists($fn = "{$app}.mo")) {
                     self::__loadMo($fn, $domain);
                     self::$__noLocale = false;
                     $merge[self::$category][self::$__lang][$domain] = self::$__domains[self::$category][self::$__lang][$domain];
                     $core = null;
                 } elseif (file_exists($fn = "{$app}.po") && ($f = fopen($fn, "r"))) {
                     self::__loadPo($f, $domain);
                     self::$__noLocale = false;
                     $merge[self::$category][self::$__lang][$domain] = self::$__domains[self::$category][self::$__lang][$domain];
                     $core = null;
                 }
             }
             if (file_exists($fn = "{$file}.mo")) {
                 self::__loadMo($fn, $domain);
                 self::$__noLocale = false;
                 break 2;
             } elseif (file_exists($fn = "{$file}.po") && ($f = fopen($fn, "r"))) {
                 self::__loadPo($f, $domain);
                 self::$__noLocale = false;
                 break 2;
             }
         }
     }
     if (empty(self::$__domains[self::$category][self::$__lang][$domain])) {
         self::$__domains[self::$category][self::$__lang][$domain] = array();
         return $domain;
     }
     if ($head = self::$__domains[self::$category][self::$__lang][$domain][""]) {
         foreach (explode("\n", $head) as $line) {
             $header = strtok($line, ":");
             $line = trim(strtok("\n"));
             self::$__domains[self::$category][self::$__lang][$domain]["%po-header"][strtolower($header)] = $line;
         }
         if (isset(self::$__domains[self::$category][self::$__lang][$domain]["%po-header"]["plural-forms"])) {
             $switch = preg_replace("/(?:[() {}\\[\\]^\\s*\\]]+)/", "", self::$__domains[self::$category][self::$__lang][$domain]["%po-header"]["plural-forms"]);
             self::$__domains[self::$category][self::$__lang][$domain]["%plural-c"] = $switch;
             unset(self::$__domains[self::$category][self::$__lang][$domain]["%po-header"]);
         }
         self::$__domains = Set::pushDiff(self::$__domains, $merge);
         if (isset(self::$__domains[self::$category][self::$__lang][$domain][null])) {
             unset(self::$__domains[self::$category][self::$__lang][$domain][null]);
         }
     }
     return $domain;
 }
Esempio n. 18
0
 /**
  * Saves model data to the database. By default, validation occurs before save.
  *
  * @param array $data Data to save.
  * @param boolean $validate If set, validation will be done before the save
  * @param array $fieldList List of fields to allow to be written
  * @return mixed On success Model::$data if its not empty or true, false on failure
  * @access public
  */
 function save($data = null, $validate = true, $fieldList = array())
 {
     $db =& ConnectionManager::getDataSource($this->useDbConfig);
     $_whitelist = $this->whitelist;
     $fields = array();
     if (!empty($fieldList)) {
         $this->whitelist = $fieldList;
     } elseif ($fieldList === null) {
         $this->whitelist = array();
     }
     $this->set($data);
     if (empty($this->data) && !$this->hasField(array('created', 'updated', 'modified'))) {
         return false;
     }
     foreach (array('created', 'updated', 'modified') as $field) {
         if (isset($this->data[$this->alias]) && array_key_exists($field, $this->data[$this->alias]) && $this->data[$this->alias][$field] === null) {
             unset($this->data[$this->alias][$field]);
         }
     }
     $exists = $this->exists();
     $dateFields = array('modified', 'updated');
     if (!$exists) {
         $dateFields[] = 'created';
     }
     if (isset($this->data[$this->alias])) {
         $fields = array_keys($this->data[$this->alias]);
     }
     if ($validate && !$this->validates()) {
         $this->whitelist = $_whitelist;
         return false;
     }
     foreach ($dateFields as $updateCol) {
         if ($this->hasField($updateCol) && !in_array($updateCol, $fields)) {
             $colType = array_merge(array('formatter' => 'date'), $db->columns[$this->getColumnType($updateCol)]);
             if (!array_key_exists('formatter', $colType) || !array_key_exists('format', $colType)) {
                 $time = strtotime('now');
             } else {
                 $time = $colType['formatter']($colType['format']);
             }
             if (!empty($this->whitelist)) {
                 $this->whitelist[] = $updateCol;
             }
             $this->set($updateCol, $time);
         }
     }
     if (!empty($this->behaviors)) {
         $behaviors = array_keys($this->behaviors);
         $ct = count($behaviors);
         for ($i = 0; $i < $ct; $i++) {
             if ($this->behaviors[$behaviors[$i]]->beforeSave($this) === false) {
                 $this->whitelist = $_whitelist;
                 return false;
             }
         }
     }
     if (!$this->beforeSave()) {
         $this->whitelist = $_whitelist;
         return false;
     }
     $fields = $values = array();
     foreach ($this->data as $n => $v) {
         if (isset($this->hasAndBelongsToMany[$n])) {
             if (isset($v[$n])) {
                 $v = $v[$n];
             }
             $joined[$n] = $v;
         } else {
             if ($n === $this->alias) {
                 foreach (array('created', 'updated', 'modified') as $field) {
                     if (array_key_exists($field, $v) && empty($v[$field])) {
                         unset($v[$field]);
                     }
                 }
                 foreach ($v as $x => $y) {
                     if ($this->hasField($x) && (empty($this->whitelist) || in_array($x, $this->whitelist))) {
                         list($fields[], $values[]) = array($x, $y);
                     }
                 }
             }
         }
     }
     $count = count($fields);
     if (!$exists && $count > 0) {
         $this->id = false;
     }
     $success = true;
     $created = false;
     if ($count > 0) {
         if (!empty($this->id)) {
             if (!$db->update($this, $fields, $values)) {
                 $success = false;
             }
         } else {
             foreach ($this->_schema as $field => $properties) {
                 if ($this->primaryKey === $field) {
                     if (empty($this->data[$this->alias][$this->primaryKey]) && $this->_schema[$field]['type'] === 'string' && $this->_schema[$field]['length'] === 36) {
                         list($fields[], $values[]) = array($this->primaryKey, String::uuid());
                     }
                     break;
                 }
             }
             if (!$db->create($this, $fields, $values)) {
                 $success = $created = false;
             } else {
                 $created = true;
                 if (!empty($this->belongsTo)) {
                     $this->updateCounterCache();
                 }
             }
         }
     }
     if (!empty($joined) && $success === true) {
         $this->__saveMulti($joined, $this->id);
     }
     if ($success && $count > 0) {
         if (!empty($this->data)) {
             $success = $this->data;
         }
         if (!empty($this->behaviors)) {
             $behaviors = array_keys($this->behaviors);
             $ct = count($behaviors);
             for ($i = 0; $i < $ct; $i++) {
                 $this->behaviors[$behaviors[$i]]->afterSave($this, $created);
             }
         }
         $this->afterSave($created);
         if (!empty($this->data)) {
             $success = Set::pushDiff($success, $this->data);
         }
         $this->data = false;
         $this->__exists = null;
         $this->_clearCache();
         $this->validationErrors = array();
     }
     $this->whitelist = $_whitelist;
     return $success;
 }