/**
  * Process the modified NSDR definition together its NSDR definition methods
  */
 public function processEditAction()
 {
     $this->editAction();
     // NSDR Definition parameters
     $params = $this->_getParam('nsdrDefinition');
     $this->_nsdrDefinition->populateWithArray($params);
     $id = $params['uuid'];
     if (!strlen($id) > 0) {
         $this->_nsdrDefinition->uuid = NSDR::create_guid();
     }
     $message = __('Record Saved for NSDR Definition: ' . $this->_nsdrDefinition->namespace);
     $code = 200;
     // cannot add method if alias exists (alias must be canonical)
     if (strlen($this->_nsdrDefinition->aliasFor) > 0) {
         $nsdr = new NSDRDefinition();
         //$nsdr->uuid = $this->_nsdrDefinition->aliasFor;
         //$nsdr->populate();
         $nsdr->populateByNamespace($this->_nsdrDefinition->aliasFor);
         if (strlen($nsdr->namespace) > 0) {
             if (strlen($nsdr->aliasFor) > 0) {
                 $this->_nsdrDefinition->aliasFor = '';
                 $message = __('Alias must be canonical.');
                 $code = 400;
             }
         } else {
             $this->_nsdrDefinition->aliasFor = '';
             $message = __('Alias does not exists.');
             $code = 401;
         }
     }
     if (strlen($this->_nsdrDefinition->ORMClass) > 0) {
         if (!NSDRDefinition::isORMClassImplementsMethod($this->_nsdrDefinition->ORMClass)) {
             $this->_nsdrDefinition->ORMClass = '';
             $message = __('Invalid ORM Class');
             $code = 402;
         }
     }
     $this->_nsdrDefinition->persist();
     $this->view->message = $message;
     $this->view->code = $code;
     $this->render('edit');
 }
Example #2
0
 protected static function getNSDRORMMethod(NSDRBase $nsdrBase, $key, $context, $method, $data = null)
 {
     $memcache = Zend_Registry::get('memcache');
     // check to see if key exists in memcache
     $result = $memcache->get($key);
     preg_match("/(.*)\\((.*)\\)/", $method, $matches);
     $methodName = $matches[1];
     $contextArray[$context] = array('filters' => array());
     if ($result === false) {
         // key not found
         if (!strlen($method) > 0) {
             return array('error' => __('Invalid method'));
         }
         // extract the method context methodName($context)
         if (array_key_exists(2, $matches)) {
             // replace context with the one found on method call method(context)
             $methodArgs = $matches[2];
             if (strlen($methodArgs) > 0 && $methodArgs[0] == '@') {
                 $str = str_replace(',@', '&@', $methodArgs);
                 parse_str($str, $array);
                 foreach ($array as $k => $v) {
                     if (get_magic_quotes_gpc()) {
                         $v = stripslashes($v);
                     }
                     $key = trim(str_replace('@', '', $k));
                     $contextArray[$context]['filters'][$key] = trim($v);
                 }
             } else {
                 // retain the methodName(value)
                 $contextArray[$context]['filters'][$methodArgs] = '';
             }
         }
         if ($methodName == 'iterator') {
             $getIterMethods = array();
             $getIterMethods[] = 'getIterator';
             $getIterMethods[] = 'getIter';
             $setFilterMethods = array();
             $setFilterMethods[] = 'setFilter';
             $setFilterMethods[] = 'setFilters';
             foreach ($getIterMethods as $iterMethod) {
                 if (method_exists(self::$_ORMClass, $iterMethod)) {
                     $iter = self::$_ORMClass->{$iterMethod}();
                     foreach ($setFilterMethods as $filterMethod) {
                         if (method_exists($iter, $filterMethod)) {
                             if (!is_array($context)) {
                                 $context = array($context);
                             }
                             $iter->{$filterMethod}($context);
                             return $iter;
                         }
                     }
                     break;
                 }
             }
         }
         $methodName[0] = strtoupper($methodName[0]);
         $nsdrMethodName = 'nsdr' . $methodName;
         // check if method prefix with nsdr exists in ORMClass
         if (method_exists(self::$_ORMClass, $nsdrMethodName)) {
             $result = self::$_ORMClass->{$nsdrMethodName}($nsdrBase, $contextArray, $data);
         } else {
             // check if method exists in NSDRBase
             if (method_exists($nsdrBase, $methodName)) {
                 $result = $nsdrBase->{$methodName}($nsdrBase, $contextArray, $data);
             } else {
                 // otherwise, do the ordinary routine
                 $result = self::getNSDRMethod($nsdrBase, $key, $contextArray);
             }
         }
     } else {
         if (self::isORM($result)) {
             $nsdr = new NSDRDefinition();
             $nsdr->populateByNamespace($key);
             if (strlen($nsdr->aliasFor) > 0) {
                 self::$_ORMClass = new $result($contextArray, $key);
             } else {
                 self::$_ORMClass = new $result($contextArray);
             }
             $methodName[0] = strtoupper($methodName[0]);
             $nsdrMethodName = 'nsdr' . $methodName;
             if (method_exists(self::$_ORMClass, $nsdrMethodName)) {
                 $result = self::$_ORMClass->{$nsdrMethodName}($nsdrBase, $contextArray, $data);
             }
         }
     }
     return $result;
 }