function auto_complete()
 {
     $this->loadModel('Product');
     $terms = $this->Product->find('all', array('conditions' => array('Product.productname LIKE' => $this->params['url']['autoCompleteText'] . '%'), 'fields' => array('id', 'productname'), 'limit' => 3, 'recursive' => -1));
     $terms = Set::Extract($terms, '{n}.Product.productname');
     $this->set('terms', $terms);
     $this->layout = 'ajax';
 }
Exemplo n.º 2
0
 /**
  * Get a list of authorized methods for a particular user/role to a resource
  *
  * @param string $resourceName
  * @return array $permittedMethods
  * @access public
  */
 public function getPermissions($resourceName = null)
 {
     $permissionNames = array();
     $permittedMethods = array();
     $Resource = ClassRegistry::init('Nssrbac.Resource');
     $Permission = ClassRegistry::init('Nssrbac.Permission');
     $roles = $this->Session->read('Auth');
     $myRoleIds = Set::Extract('/Role/id', $roles);
     $permissions = $Permission->find('all', array('conditions' => array('Resource.name' => Inflector::singularize($resourceName)), 'contain' => array('Role' => array('conditions' => array('Role.id' => $myRoleIds)), 'Resource'), 'fields' => array('Permission.name')));
     foreach ($permissions as $p => $permission) {
         if (!empty($permission['Role'])) {
             $permissionNames[] = $permission['Permission']['name'];
         }
     }
     if (is_array($permissionNames)) {
         foreach ($permissionNames as $name) {
             $methods = $this->permissionsMap[$name];
             foreach ($methods as $method) {
                 $permittedMethods[] = $method;
             }
         }
         return $permittedMethods;
     }
 }
Exemplo n.º 3
0
 function testCond($cond, $data, $or = false, $empty = false)
 {
     $valid = true;
     $def = $empty;
     $modifKeys = array('and', 'or');
     App::import('Lib', 'Operations');
     foreach ($cond as $key => $cnd) {
         $op = false;
         $path = $key;
         if (is_numeric($path)) {
             $val = $data;
         } elseif (in_array($path, $modifKeys)) {
             $val = $data;
         } elseif (array_key_exists($path, $data)) {
             $val = $data[$path];
         } else {
             $op = Operations::parseStringOperation($path, array('mode' => 'left', 'type' => 'bool', 'sepPattern' => '\\h+'));
             if ($op) {
                 $path = $op['subject'];
             }
             $val = Set::Extract($path, $data);
         }
         if ($op) {
             $op['subject'] = $val;
             $op['val'] = $cnd;
             $valid = Operations::applyOperation($op);
         } elseif (is_null($cnd)) {
             $valid = is_null($val);
         } elseif (is_array($cnd)) {
             $or = $path == 'or';
             $valid = SetMulti::testCond($cnd, $val, $or);
         } elseif (!is_null($data)) {
             $valid = $val == $cnd;
         } else {
             $valid = false;
         }
         if ($valid == $or) {
             return $or;
         }
         $def = $valid;
     }
     return $def;
 }
Exemplo n.º 4
0
 /**
  * afterFind function
  *
  * When looking for English content, if there isn't a current revision, populate with default text
  * When looking for none English content, if there isn't a current revision populate with the English text
  * 	Auto correct any links in content to point at same-language pages
  *
  * @param mixed $results
  * @access public
  * @return void
  */
 function afterFind($results)
 {
     $before = $results;
     $defaultLang = Configure::read('Languages.default');
     if ($this->language == $defaultLang) {
         if (isset($results[0]['Revision'])) {
             foreach ($results as $i => $result) {
                 if (array_key_exists('title', $result['Revision']) && !$result['Revision']['title']) {
                     $results[$i]['Revision']['title'] = __('Default Title', true);
                 }
                 if (array_key_exists('slug', $result['Revision']) && !$result['Revision']['slug']) {
                     $results[$i]['Revision']['slug'] = __('default_slug', true);
                 }
                 if (array_key_exists('content', $result['Revision']) && !$result['Revision']['content']) {
                     $results[$i]['Revision']['content'] = __('Default Content', true);
                 }
                 if (array_key_exists('lang', $result['Revision']) && !$result['Revision']['lang']) {
                     $results[$i]['Revision']['lang'] = $defaultLang;
                 }
             }
         }
         return $results;
     }
     if (isset($results[0]['Revision'])) {
         $missing = false;
         foreach ($results as $result) {
             if (array_key_exists('title', $result['Revision']) && !$result['Revision']['title']) {
                 $missing = true;
                 break;
             }
             if (array_key_exists('slug', $result['Revision']) && !$result['Revision']['slug']) {
                 $missing = true;
                 break;
             }
             if (array_key_exists('content', $result['Revision']) && !$result['Revision']['content']) {
                 $missing = true;
                 break;
             }
         }
         $language = $this->language;
         if ($missing) {
             $this->setLanguage($defaultLang);
             if ($this->__queryData['order'] == array(null)) {
                 unset($this->__queryData['order']);
             }
             $ids = Set::Extract($results, '/Node/id');
             $engResults = $this->find('all', am($this->__queryData, array('conditions' => array('Node.id' => $ids))));
             $this->setLanguage($language);
         }
         $root = trim(Router::url('/'), '/');
         if ($root) {
             $root .= '/';
         }
         $find = '@href="/' . $root . '(?!' . $language . '/)@';
         $replace = 'href="/' . $root . $language . '/';
         foreach ($results as $i => &$result) {
             if (isset($engResults[$i])) {
                 if (array_key_exists('title', $result['Revision']) && !$result['Revision']['title']) {
                     $result['Revision']['title'] = $engResults[$i]['Revision']['title'];
                 }
                 if (array_key_exists('slug', $result['Revision']) && !$result['Revision']['slug']) {
                     $result['Revision']['slug'] = $engResults[$i]['Revision']['slug'];
                 }
                 if (array_key_exists('content', $result['Revision']) && !$result['Revision']['content']) {
                     $result['Revision']['content'] = $engResults[$i]['Revision']['content'];
                 }
                 if (array_key_exists('lang', $result['Revision']) && !$result['Revision']['lang']) {
                     $result['Revision']['lang'] = $defaultLang;
                 }
             }
             //if (isset($result['Revision']['content']) && strpos('href="/', $result['Revision']['content'])) {
             if (isset($result['Revision']['content'])) {
                 $result['Revision']['content'] = preg_replace($find, $replace, $result['Revision']['content']);
             }
         }
     }
     return $results;
 }
Exemplo n.º 5
0
 function testDeleteInstructor()
 {
     $empty = null;
     /*
      * Try to delete an valid instructor from a valid assigned course
      * Inputs: Course_id==2 : "Mth321"	(Valid)
      *		   User_id==6 : "INSTRUCTOR2"	(Valid)
      */
     //Run tests
     $this->Course->addInstructor(2, 6);
     $this->Course->deleteInstructor(2, 6);
     $deletedInstructor = $this->Course->getCourseByInstructor(6);
     $this->assertEqual($empty, $deletedInstructor);
     /*
      * Test deleteInstructor() using invalid "course_id" input:
      * Inputs: Course_id==999999 : (Invalid)
      * 		   Course_id==2 : "Math321"	(Valid)
      * 		   User_id==2 : "Peterson"	(Valid)
      */
     //Run tests
     $this->Course->deleteInstructor(999999, 2);
     $invalidCourseInstructor = $this->Course->getCourseByInstructor(999999);
     $this->assertEqual($invalidCourseInstructor, $empty);
     /*
      * Test deleteInstructor() invalid "user_id" input:
      * Inputs: Course_id==2 : "Math321"	(Valid)
      * 		   User_id==13 : 	(inValid)
      */
     //Reused data from previous setup
     $this->Course->deleteInstructor(2, 13);
     $invalidCourseInstructor = $this->Course->getCourseByInstructor(13);
     $this->assertEqual($invalidCourseInstructor, $empty);
     /*
      * Test deleteInstructor on course without instructor
      * Inputs: Course_id==1 : "Math303" (Valid)
      * 		   User_id==4 : "INSTRUCTOR1" 	(Valid)
      */
     //Reused data from previous setup
     $this->Course->addInstructor(1, 5);
     $this->Course->deleteInstructor(1, 5);
     $this->Course->deleteInstructor(1, 5);
     $course = $this->Course->getCourseByInstructor(5);
     $this->assertEqual($course, $empty);
     //Test null inputs;
     //Set up data
     $this->Course->addInstructor(1, 1);
     //Run tests, should have no effects whatsoever
     $this->Course->deleteInstructor(null, 1);
     $this->Course->deleteInstructor(1, null);
     $course = $this->Course->getCourseByInstructor(1);
     $this->assertTrue(in_array('MECH 328', Set::Extract('/Course/course', $course)));
 }