/**
  * Executes this filter.
  *
  * @param sfFilterChain $filterChain A sfFilterChain instance
  */
 public function execute($filterChain)
 {
     // disable stateful security checking on signin and secure actions
     if (sfConfig::get('sf_login_module') == $this->context->getModuleName() && sfConfig::get('sf_login_action') == $this->context->getActionName() || sfConfig::get('sf_secure_module') == $this->context->getModuleName() && sfConfig::get('sf_secure_action') == $this->context->getActionName()) {
         $filterChain->execute();
         return;
     }
     $sf_user = $this->context->getUser();
     // retrieve the current action
     $action = $this->context->getController()->getActionStack()->getLastEntry()->getActionInstance();
     // get the current module and action names
     $module_name = sfInflector::camelize($action->getModuleName());
     $action_name = sfInflector::camelize($action->getActionName());
     // get the object for the current route
     $object = $this->getObjectForRoute($action->getRoute());
     // i.e.: canIndexDefault
     $method = "can{$action_name}{$module_name}";
     // if the method exist
     if (method_exists($sf_user, $method)) {
         // execute it
         if (!$sf_user->{$method}($object)) {
             $this->forwardToSecureAction();
         }
     } else {
         // get the default policy
         $default_policy = $this->getParameter('default_policy', 'allow');
         // if the default policy is not 'allow'
         if ($default_policy != 'allow') {
             $this->forwardToSecureAction();
         }
     }
     $filterChain->execute();
     return;
 }
Ejemplo n.º 2
0
 protected function getObjectsForParameters($parameters)
 {
     $this->options['model'] = Doctrine::getTable($this->options['model']);
     if (!isset($this->options['method'])) {
         $variables = $this->getRealVariables();
         switch (count($variables)) {
             case 0:
                 $this->options['method'] = 'findAll';
                 break;
             case 1:
                 $this->options['method'] = 'findOneBy' . sfInflector::camelize($variables[0]);
                 $parameters = $parameters[$variables[0]];
                 break;
             default:
                 $this->options['method'] = 'findByDQL';
                 $wheres = array();
                 foreach ($variables as $variable) {
                     $variable = $this->options['model']->getFieldName($variable);
                     $wheres[] = $variable . " = '" . $parameters[$variable] . "'";
                 }
                 $parameters = implode(' AND ', $wheres);
         }
     }
     return parent::getObjectsForParameters($parameters);
 }
 public function populateWithFacebook(m14tFacebook $fb, $force = true)
 {
     $sfGuardUser = $this->getInvoker();
     foreach ($this->_options['fields'] as $fb_key => $sfg_key) {
         $func = 'get' . sfInflector::camelize($fb_key);
         switch ($fb_key) {
             case 'location':
             case 'hometown':
             case 'languages':
             case 'education':
                 $sfGuardUser->{$sfg_key}($fb->{$func}(), $force);
                 break;
             case 'birthday':
                 if ($force || "" == $sfGuardUser[$sfg_key]) {
                     $sfGuardUser[$sfg_key] = date('Y-m-d', strtotime($fb->{$func}()));
                 }
                 break;
             default:
                 if ($force || "" == $sfGuardUser[$sfg_key]) {
                     $sfGuardUser[$sfg_key] = $fb->{$func}();
                 }
                 break;
         }
     }
 }
Ejemplo n.º 4
0
 public static function retrieveOrCreateByObject(BaseObject $object)
 {
     if ($object->isNew() === true || $object->isModified() === true || $object->isDeleted() === true) {
         throw new Exception('You can only approve an object which has already been saved');
     }
     $columnName = sfConfig::get('propel_behavior_sfPropelApprovableBehavior_' . get_class($object) . '_column', 'is_approved');
     $approvedValue = sfConfig::get('propel_behavior_sfPropelApprovableBehavior_' . get_class($object) . '_approved_value', true);
     $disabledApplications = sfConfig::get('propel_behavior_sfPropelApprovableBehavior_' . get_class($object) . '_disabled_applications');
     // Test if we should crated an approval - is the column value different to out required value?
     // If our object is already approved then we can delete other
     $columnGetter = 'get' . sfInflector::camelize($columnName);
     if ($approvedValue != $object->{$columnGetter}()) {
         $c = new Criteria();
         $c->add(sfApprovalPeer::APPROVABLE_ID, $object->getPrimaryKey());
         $c->add(sfApprovalPeer::APPROVABLE_MODEL, get_class($object));
         $approval = sfApprovalPeer::doSelectOne($c);
         if (!$approval) {
             $approval = new sfApproval();
             $approval->setApprovableModel(get_class($object));
             $approval->setApprovableId($object->getPrimaryKey());
             $approval->setUuid(sfPropelApprovableToolkit::generateUuid());
             $approval->save();
         }
         return $approval;
     } else {
         sfApprovalPeer::deleteByObject($object);
         return null;
     }
     return $approval;
 }
 /**
  * @see sfTask
  */
 protected function execute($arguments = array(), $options = array())
 {
     /**
      * include path to propel generator
      */
     sfToolkit::addIncludePath(array(sfConfig::get('sf_propel_path') . '/generator/lib'));
     /**
      * first check the db connectivity for all connections
      */
     $this->logBlock('Checking Db Connectivity', "QUESTION");
     if (!$this->createTask('afs:db-connectivity')->run()) {
         return;
     }
     $this->logBlock('Creating specific AppFlower folders', "QUESTION");
     $this->createFolders();
     $this->logBlock('Setting Symfony project permissions', "QUESTION");
     $this->createTask('project:permissions')->run();
     $type_method = 'execute' . sfInflector::camelize($options['type']);
     if (!method_exists($this, $type_method)) {
         throw new sfCommandException("Type method '{$type_method}' not defined.");
     }
     call_user_func(array($this, $type_method), $arguments, $options);
     $this->logBlock('Creating models from current schema', "QUESTION");
     $this->createTask('propel:build-model')->run();
     $this->logBlock('Creating forms from current schema', "QUESTION");
     $this->createTask('propel:build-forms')->run();
     $this->logBlock('Setting AppFlower project permissions', "QUESTION");
     $this->createTask('afs:fix-perms')->run();
     $this->logBlock('Creating AppFlower validator cache', "QUESTION");
     $this->createTask('appflower:validator-cache')->run(array('frontend', 'cache', 'yes'));
     $this->logBlock('Clearing Symfony cache', "QUESTION");
     $this->createTask('cc')->run();
 }
 public function __construct($feed_array = array(), $extensions = array())
 {
     $version = '1.0';
     parent::__construct();
     /// we call initialize() later so we don't need to pass feed_array in yet
     $encoding = 'UTF-8';
     // sensible default
     $dom = $this->dom = new DOMDocument($version, $encoding);
     $this->setEncoding($encoding);
     // needed to avoid trying to set encoding to ''
     $this->context = sfContext::getInstance();
     $this->plugin_path = realpath(dirname(__FILE__) . '/../');
     $prefix = 'sfDomFeedExtension';
     $this->extensions = array();
     foreach ($extensions as $extension) {
         $class_name = $prefix . sfInflector::camelize($extension);
         $extension = new $class_name();
         if (!$extension instanceof sfDomFeedExtension) {
             throw new sfException("{$class_name} is not a sfDomFeedExtension");
         }
         // unfortunately ^ class_exists() is useless here; it will error instead of exception.
         $this->extensions[] = $extension;
     }
     if ($feed_array) {
         $this->initialize($feed_array);
     }
     if (!$dom->load($this->genTemplatePath(), LIBXML_NOERROR)) {
         throw new sfDomFeedException("DOMDocument::load failed");
     }
 }
 public function getLinkToAction($actionName, $params, $pk_link = false)
 {
     $options = isset($params['params']) && !is_array($params['params']) ? sfToolkit::stringToArray($params['params']) : array();
     // default values
     if ($actionName[0] == '_') {
         $actionName = substr($actionName, 1);
         $name = $actionName;
         //$icon       = sfConfig::get('sf_admin_web_dir').'/images/'.$actionName.'_icon.png';
         $action = $actionName;
         if ($actionName == 'delete') {
             $options['post'] = true;
             if (!isset($options['confirm'])) {
                 $options['confirm'] = 'Are you sure?';
             }
         }
     } else {
         $name = isset($params['name']) ? $params['name'] : $actionName;
         //$icon   = isset($params['icon']) ? sfToolkit::replaceConstants($params['icon']) : sfConfig::get('sf_admin_web_dir').'/images/default_icon.png';
         $action = isset($params['action']) ? $params['action'] : 'List' . sfInflector::camelize($actionName);
     }
     $url_params = $pk_link ? '?' . $this->getPrimaryKeyUrlParams() : '\'';
     $phpOptions = var_export($options, true);
     // little hack
     $phpOptions = preg_replace("/'confirm' => '(.+?)(?<!\\\\)'/", '\'confirm\' => __(\'$1\')', $phpOptions);
     return '<li class="sf_admin_action_' . sfInflector::underscore($name) . '">[?php echo link_to(__(\'' . $params['label'] . '\'), \'' . $this->getModuleName() . '/' . $action . $url_params . ($options ? ', ' . $phpOptions : '') . ') ?]</li>' . "\n";
 }
 public static function create($class, $title = null, $multisheet = false)
 {
     $managerClass = sprintf('sfExportManager%s', sfInflector::camelize($class));
     if (class_exists($managerClass)) {
         return new $managerClass($class, $title, $multisheet);
     }
     return new self($class, $title, $multisheet);
 }
Ejemplo n.º 9
0
 public function __get($name)
 {
     if (in_array($name, array('base_amount', 'discount_amount', 'net_amount', 'tax_amount', 'gross_amount'))) {
         $m = sfInflector::camelize("get_{$name}");
         return $this->{$m}();
     }
     return parent::__get($name);
 }
 public function initialize($context, $moduleName, $actionName, $viewName)
 {
     $this->nameSuffix = sfSmartphoneViewToolKit::getViewNameSuffixFromUA($this, $context, $moduleName, $actionName, $viewName, false);
     if ($this->nameSuffix) {
         $this->enableNameSuffix = sfSmartphoneViewToolKit::getViewNameSuffixFromUA($this, $context, $moduleName, $actionName, $viewName);
     }
     parent::initialize($context, $moduleName, $actionName, $viewName . sfInflector::camelize($this->enableNameSuffix));
 }
 /**
  * Returns the getter either non-developped: 'getFoo' or developped: '$class->getFoo()'.
  *
  * @param string  $column     The column name
  * @param boolean $developed  true if you want developped method names, false otherwise
  * @param string  $prefix     The prefix value
  *
  * @return string PHP code
  */
 public function getColumnGetter($column, $developed = false, $prefix = '')
 {
     $getter = 'get' . sfInflector::camelize($column);
     if ($developed) {
         $getter = sprintf('$%s%s->%s()', $prefix, $this->getSingularName(), $getter);
     }
     return $getter;
 }
Ejemplo n.º 12
0
 public function executeFeed()
 {
     /** @var sfWebRequest **/
     $request = $this->getContext()->getRequest();
     $IdType = $this->getRequestParameter('IdType', null);
     $id = $this->getRequestParameter('id', null);
     //Build the title
     $title = "Metadata Registry Change History";
     $filter = false;
     switch ($IdType) {
         //ElementSet :: (Schema)Element  :: (Schema)ElementProperty
         //Schema     :: SchemaProperty :: SchemaPropertyElement
         case "schema_property_element_id":
             /** @var SchemaPropertyElement **/
             $element = DbFinder::from('SchemaPropertyElement')->findPk($id);
             if ($element) {
                 /** @var SchemaProperty **/
                 $property = $element->getSchemaPropertyRelatedBySchemaPropertyId();
                 $title .= " for Property: '" . $element->getProfileProperty()->getLabel();
                 if ($property) {
                     $title .= "' of Element: '" . $property->getLabel() . "' in Element Set: '" . $property->getSchema()->getName() . "'";
                 }
             }
             $filter = true;
             break;
         case "schema_property_id":
             /** @var SchemaProperty **/
             $property = DbFinder::from('SchemaProperty')->findPk($id);
             if ($property) {
                 $title .= " for Element: '" . $property->getLabel() . "' in Element Set: '" . $property->getSchema()->getName() . "'";
             }
             $filter = true;
             break;
         case "schema_id":
             /** @var Schema **/
             $schema = DbFinder::from('Schema')->findPk($id);
             if ($schema) {
                 $title .= " for Element Set: '" . $schema->getName() . "'";
             }
             $filter = true;
             break;
         default:
             //the whole shebang
             $title .= " for all Element Sets";
             break;
     }
     $column = sfInflector::camelize($IdType);
     //default limit to 100 if not set in config
     $limit = $request->getParameter('nb', sfConfig::get('app_frontend_feed_count', 100));
     $finder = DbFinder::from('SchemaPropertyElementHistory')->orderBy('SchemaPropertyElementHistory.CreatedAt', 'desc')->join('SchemaPropertyElementHistory.SchemaPropertyElementId', 'SchemaPropertyElement.Id', 'left join')->join('SchemaProperty', 'left join')->join('Schema', 'left join')->join('Status', 'left join')->join('User', 'left join')->join('ProfileProperty', 'left join')->with('Schema', 'ProfileProperty', 'User', 'Status', 'SchemaProperty');
     if ($filter) {
         $finder = $finder->where('SchemaPropertyElementHistory.' . $column, $id);
     }
     $finder = $finder->find($limit);
     $this->setTemplate('feed');
     $this->feed = sfFeedPeer::createFromObjects($finder, array('format' => $request->getParameter('format', 'atom1'), 'link' => $request->getUriPrefix() . $request->getPathInfo(), 'feedUrl' => $request->getUriPrefix() . $request->getPathInfo(), 'title' => htmlentities($title), 'methods' => array('authorEmail' => '', 'link' => 'getFeedUniqueId')));
     return;
 }
 public function filterGet(Doctrine_Record $record, $name)
 {
     $method = 'get' . sfInflector::camelize($name);
     $event = sfProjectConfiguration::getActive()->getEventDispatcher()->notifyUntil(new sfEvent($record, 'sympal.' . $this->_eventName . '.method_not_found', array('method' => $method)));
     if ($event->isProcessed()) {
         return $event->getReturnValue();
     }
     throw new Doctrine_Record_UnknownPropertyException(sprintf('Unknown record property / related component "%s" on "%s"', $name, get_class($record)));
 }
Ejemplo n.º 14
0
 /**
  * Updates the index for an object
  *
  * @param Doctrine_Record $object
  */
 public function updateIndex(Doctrine_Record $object, $delete = false)
 {
     /* error checking */
     if (!array_key_exists('models', $this->config) || empty($this->config['models'])) {
         throw new Exception(sprintf('No models set in search.yml', $name));
     }
     if (!array_key_exists($model = get_class($object), $this->config['models'])) {
         throw new Exception(sprintf('Model "%s" not defined in "%s" index in your search.yml', $model, $this->name));
     }
     $id = $this->generateId($object->getId(), $model);
     $config = $this->config['models'][$model];
     //delete existing entries
     foreach ($this->search('_id:"' . $id . '"') as $hit) {
         $this->getIndex()->delete($hit->id);
     }
     if ($delete) {
         return;
     }
     //only add to search if canSearch method on model returns true (search if no method exists)
     if (method_exists($object, 'canSearch')) {
         if (!call_user_func(array($object, 'canSearch'))) {
             return;
         }
     }
     $doc = new Zend_Search_Lucene_Document();
     // store a key for deleting in future
     $doc->addField(Zend_Search_Lucene_Field::Keyword('_id', $id));
     // store job primary key and model name to identify it in the search results
     $doc->addField(Zend_Search_Lucene_Field::Keyword('_pk', $object->getId()));
     $doc->addField(Zend_Search_Lucene_Field::Keyword('_model', $model));
     // store title - used for search result title
     if (!array_key_exists('title', $config)) {
         throw new Exception(sprintf('A title must be set for model "%s" in search.yml', $model));
     }
     $doc->addField(Zend_Search_Lucene_Field::unIndexed('_title', call_user_func(array($object, 'get' . sfInflector::camelize($config['title'])))));
     // store description - used for search result description
     if (!array_key_exists('description', $config)) {
         throw new Exception(sprintf('A description must be set for model "%s" in search.yml', $model));
     }
     $doc->addField(Zend_Search_Lucene_Field::unIndexed('_description', call_user_func(array($object, 'get' . sfInflector::camelize($config['description'])))));
     // store url - @todo add more routing options
     if (!array_key_exists('route', $config)) {
         throw new Exception(sprintf('A route must be set for model "%s" in search.yml', $model));
     }
     sfContext::getInstance()->getConfiguration()->loadHelpers('Url');
     $url = url_for($config['route'], $object);
     $doc->addField(Zend_Search_Lucene_Field::unIndexed('_url', $url));
     //store fields
     if (array_key_exists('fields', $config)) {
         foreach ($config['fields'] as $field => $config) {
             $doc->addField(Zend_Search_Lucene_Field::UnStored($field, call_user_func(array($object, 'get' . sfInflector::camelize($field))), 'utf-8'));
         }
     }
     //save index
     $this->getIndex()->addDocument($doc);
     $this->getIndex()->commit();
 }
 public function getLinkToAction($actionName, $params, $pk_link = false)
 {
     $action = isset($params['action']) ? $params['action'] : 'List' . sfInflector::camelize($actionName);
     $url_params = $pk_link ? '?' . $this->getPrimaryKeyUrlParams() : '\'';
     if (isset($params['extend_url'])) {
         $url_params .= '.(has_slot(\'sf_admin.extend_url\') ? \'' . $params['extend_url'] . '\'.get_slot(\'sf_admin.extend_url\') : \'\')';
     }
     return '[?php echo link_to(__(\'' . $params['label'] . '\', array(), \'' . $this->getI18nCatalogue() . '\'), \'' . (isset($params['module']) ? $params['module'] : $this->getModuleName()) . '/' . $action . $url_params . ', ' . $this->asPhp($params['params']) . ') ?]';
 }
Ejemplo n.º 16
0
 /**
  * Renders the presentation and send the email to the client.
  *
  * @return mixed Raw data of the mail
  */
 public function render()
 {
     $retval = null;
     // execute pre-render check
     $this->preRenderCheck();
     // get sfMail object from action
     $mail = $this->attributeHolder->get('mail');
     if (!$mail) {
         throw new sfActionException('You must define a sfMail object named $mail ($this->mail) in your action to be able to use a sfMailView.');
     }
     // render main template
     $template = $this->getDirectory() . '/' . $this->getTemplate();
     $retval = $this->renderFile($template);
     // render main and alternate templates
     $all_template_dir = dirname($template);
     $all_template_regex = preg_replace('/\\.php$/', '\\..+\\.php', basename($template));
     $all_templates = sfFinder::type('file')->name('/^' . $all_template_regex . '$/')->in($all_template_dir);
     $all_retvals = array();
     foreach ($all_templates as $templateFile) {
         if (preg_match('/\\.([^.]+?)\\.php$/', $templateFile, $matches)) {
             $all_retvals[$matches[1]] = $this->renderFile($templateFile);
         }
     }
     // send email
     if (sfConfig::get('sf_logging_enabled')) {
         $this->dispatcher->notify(new sfEvent($this, 'application.log', array('Send email to client')));
     }
     // configuration prefix
     $config_prefix = 'sf_mailer_' . strtolower($this->moduleName) . '_';
     $vars = array('mailer', 'priority', 'content_type', 'charset', 'encoding', 'wordwrap', 'hostname', 'port', 'domain', 'username', 'password');
     $defaultMail = new sfMail();
     foreach ($vars as $var) {
         $setter = 'set' . sfInflector::camelize($var);
         $getter = 'get' . sfInflector::camelize($var);
         $value = $mail->{$getter}() !== $defaultMail->{$getter}() ? $mail->{$getter}() : sfConfig::get($config_prefix . strtolower($var));
         $mail->{$setter}($value);
     }
     $mail->setBody($retval);
     // alternate bodies
     $i = 0;
     foreach ($all_retvals as $type => $retval) {
         if ($type == 'altbody' && !$mail->getAltBody()) {
             $mail->setAltBody($retval);
         } else {
             ++$i;
             $mail->addStringAttachment($retval, 'file' . $i, 'base64', 'text/' . $type);
         }
     }
     // preparing email to be sent
     $mail->prepare();
     // send e-mail
     if (sfConfig::get($config_prefix . 'deliver')) {
         $mail->send();
     }
     return $mail->getRawHeader() . $mail->getRawBody();
 }
Ejemplo n.º 17
0
 public function getServiceType()
 {
     $ret = strtoupper(sfInflector::camelize($this->getObjectType()));
     if ($this->getObjectType() == ClientServicePeer::CLASSKEY_CLASSROOM) {
         $ret .= ' (' . $this->getOffice() . ')';
     }
     if ($this->getObjectType() == ClientServicePeer::CLASSKEY_SEIT || $this->getObjectType() == ClientServicePeer::CLASSKEY_PRESCHOOL) {
         $ret .= $this->getClient() && $this->getClient()->getDistrict() ? ' (' . $this->getClient()->getDistrict() . ')' : '';
     }
     return $ret;
 }
Ejemplo n.º 18
0
 public function __get($name)
 {
     if ($name == 'due_amount') {
         $m = sfInflector::camelize("get_{$name}");
         return $this->{$m}();
     }
     if (strpos($name, 'tax_amount_') === 0) {
         return $this->calculate($name, true);
     }
     return parent::__get($name);
 }
 /**
  * @see sfTask
  */
 protected function execute($arguments = array(), $options = array())
 {
     $this->logSection('doctrine', 'generating model classes');
     $config = $this->getCliConfig();
     $builderOptions = $this->configuration->getPluginConfiguration('sfDoctrinePlugin')->getModelBuilderOptions();
     $stubFinder = sfFinder::type('file')->prune('base')->name('*' . $builderOptions['suffix']);
     $before = $stubFinder->in($config['models_path']);
     $schema = $this->prepareSchemaFile($config['yaml_schema_path']);
     $import = new Doctrine_Import_Schema();
     $import->setOptions($builderOptions);
     $import->importSchema($schema, 'yml', $config['models_path']);
     // markup base classes with magic methods
     foreach (sfYaml::load($schema) as $model => $definition) {
         // Start OrangeHRM Modified Section
         $subPackageName = $this->getSubPackageName($definition);
         // End OrangeHRM Modified Section
         $file = sprintf('%s%s/%s/Base%s%s', $config['models_path'], isset($definition['package']) ? '/' . substr($definition['package'], 0, strpos($definition['package'], '.')) : '', $builderOptions['baseClassesDirectory'], $model, $builderOptions['suffix']);
         $code = file_get_contents($file);
         // introspect the model without loading the class
         if (preg_match_all('/@property (\\w+) \\$(\\w+)/', $code, $matches, PREG_SET_ORDER)) {
             $properties = array();
             foreach ($matches as $match) {
                 $properties[$match[2]] = $match[1];
             }
             $typePad = max(array_map('strlen', array_merge(array_values($properties), array($model))));
             $namePad = max(array_map('strlen', array_keys(array_map(array('sfInflector', 'camelize'), $properties))));
             $setters = array();
             $getters = array();
             foreach ($properties as $name => $type) {
                 $camelized = sfInflector::camelize($name);
                 $collection = 'Doctrine_Collection' == $type;
                 $getters[] = sprintf('@method %-' . $typePad . 's %s%-' . ($namePad + 2) . 's Returns the current record\'s "%s" %s', $type, 'get', $camelized . '()', $name, $collection ? 'collection' : 'value');
                 $setters[] = sprintf('@method %-' . $typePad . 's %s%-' . ($namePad + 2) . 's Sets the current record\'s "%s" %s', $model, 'set', $camelized . '()', $name, $collection ? 'collection' : 'value');
             }
             // use the last match as a search string
             $code = str_replace($match[0], $match[0] . PHP_EOL . ' * ' . PHP_EOL . ' * ' . implode(PHP_EOL . ' * ', array_merge($getters, $setters)), $code);
             // Start OrangeHRM Modified Section
             $tokens = array('##SUBPACKAGE##' => $subPackageName);
             $code = str_replace(array_keys($tokens), array_values($tokens), $code);
             // End OrangeHRM Modified Section
             file_put_contents($file, $code);
         }
     }
     $properties = parse_ini_file(sfConfig::get('sf_config_dir') . '/properties.ini', true);
     $tokens = array('##PACKAGE##' => isset($properties['symfony']['name']) ? $properties['symfony']['name'] : 'symfony', '##SUBPACKAGE##' => 'model', '##NAME##' => isset($properties['symfony']['author']) ? $properties['symfony']['author'] : 'Your name here', ' <##EMAIL##>' => '', "{\n\n}" => "{\n}\n");
     // cleanup new stub classes
     $after = $stubFinder->in($config['models_path']);
     $this->getFilesystem()->replaceTokens(array_diff($after, $before), '', '', $tokens);
     // cleanup base classes
     $baseFinder = sfFinder::type('file')->name('Base*' . $builderOptions['suffix']);
     $baseDirFinder = sfFinder::type('dir')->name('base');
     $this->getFilesystem()->replaceTokens($baseFinder->in($baseDirFinder->in($config['models_path'])), '', '', $tokens);
     $this->reloadAutoload();
 }
Ejemplo n.º 20
0
 /**
  * rss and atom feeds
  *
  * @return return_type
  */
 public function executeFeed()
 {
     /** @var sfWebRequest **/
     $request = $this->getContext()->getRequest();
     $IdType = $this->getRequestParameter('IdType', null);
     $id = $this->getRequestParameter('id', null);
     //Build the title
     $title = "Metadata Registry Change History";
     $filter = false;
     switch ($IdType) {
         case "property_id":
             /** @var ConceptProperty **/
             $conceptProperty = ConceptPropertyPeer::retrieveByPK($id);
             if ($conceptProperty) {
                 $vocabularyname = $conceptProperty->getVocabulary() ? $conceptProperty->getVocabulary()->getName() : "?";
                 $title .= " for Property: '" . $conceptProperty->getProfileProperty()->getName() . "' of Concept: '" . $conceptProperty->getConceptRelatedByConceptId()->getPrefLabel() . "' in Vocabulary: '" . $vocabularyname . "'";
             }
             $filter = true;
             break;
         case "concept_id":
             /** @var Concept **/
             $concept = DbFinder::from('Concept')->findPk($id);
             if ($concept) {
                 $title .= " for Concept: '" . $concept->getPrefLabel() . "' in Vocabulary: '" . $concept->getVocabulary()->getName() . "'";
             }
             $filter = true;
             break;
         case "vocabulary_id":
             /** @var Vocabulary **/
             $vocab = DbFinder::from('Vocabulary')->findPk($id);
             if ($vocab) {
                 $title .= " for Vocabulary: '" . $vocab->getName() . "'";
             }
             $filter = true;
             break;
         default:
             //the whole shebang
             $title .= " for all Vocabularies";
             break;
     }
     //special rule for property_id
     $column = "property_id" == $IdType ? "ConceptPropertyId" : sfInflector::camelize($IdType);
     //default limit to 100 if not set in config
     $limit = $request->getParameter('nb', sfConfig::get('app_frontend_feed_count', 100));
     $finder = DbFinder::from('ConceptPropertyHistory')->orderBy('ConceptPropertyHistory.CreatedAt', 'desc')->join('ConceptProperty', 'left join')->join('Concept', 'left join')->join('Vocabulary', 'left join')->join('Status', 'left join')->join('User', 'left join')->join('SkosProperty', 'left join')->with('Vocabulary', 'SkosProperty', 'User', 'Status', 'ConceptProperty', 'Concept');
     if ($filter) {
         $finder = $finder->where('ConceptPropertyHistory.' . $column, $id);
     }
     $finder = $finder->find($limit);
     $this->setTemplate('feed');
     $this->feed = sfFeedPeer::createFromObjects($finder, array('format' => $request->getParameter('format', 'atom1'), 'link' => $request->getUriPrefix() . $request->getPathInfo(), 'feedUrl' => $request->getUriPrefix() . $request->getPathInfo(), 'title' => htmlentities($title), 'methods' => array('authorEmail' => '', 'link' => 'getFeedUniqueId')));
     return;
 }
Ejemplo n.º 21
0
 public static function _getPhpName($dbName, $tableName)
 {
     if (!isset(self::$dbschema)) {
         $root = sfConfig::get("sf_root_dir");
         self::$dbschema = sfYaml::load($root . '/config/schema.yml');
     }
     if (isset(self::$dbschema[$dbName][$tableName]['_attributes']['phpName'])) {
         $phpName = self::$dbschema[$dbName][$tableName]['_attributes']['phpName'];
     } else {
         $phpName = sfInflector::camelize($tableName);
     }
     return $phpName;
 }
Ejemplo n.º 22
0
 /**
  * Public method for rendering the changelog of an $object using a specific
  * $style ('list', 'tooltip').
  * By passing a value in $options['credentials'], this method will check
  * if the session user has the required credentials to see the changelog,
  * and if not will return an empty string.
  *
  * @param  mixed  $object  An object using ncPropelChangeLogBehavior.
  * @param  string $style   The name of the style for rendering. It can be 'list'
  *                         or 'tooltip'.
  * @param  array  $options An array of options.
  *
  * @return string The rendered changelog when possible, or an empty string.
  */
 public static function render($object, $style = 'list', $options = array())
 {
     try {
         if ($object->hasChangeLog() && self::checkCredentials($options)) {
             $method = 'renderAs' . sfInflector::camelize($style);
             $callable = array(__CLASS__, $method);
             if (is_callable($callable)) {
                 return call_user_func_array($callable, array($object));
             }
         }
     } catch (Exception $exception) {
         // do nothing - return an empty string
     }
 }
 protected function proxy_has($name, $set = false)
 {
     if (!$this->isWrapped()) {
         return null;
     }
     $method_name = ($set ? 'set' : 'get') . sfInflector::camelize($name);
     // todo work with Doctrine style gets/sets
     $cb = array($this->wrapped_object, $method_name);
     if (method_exists($this->wrapped_object, $method_name)) {
         return array($this->wrapped_object, $method_name);
     } else {
         return null;
     }
 }
 public function refreshGeocodes()
 {
     $obj = $this->getInvoker();
     $query = array();
     foreach ($this->_options['fields'] as $field) {
         $query[] = $obj->{$field};
     }
     $geocoder_class = $this->_options['geocoder_class'];
     $geocoder = new $geocoder_class(implode(', ', $query));
     foreach ($this->_options['columns'] as $key => $options) {
         $func = 'get' . sfInflector::camelize($options['name']);
         $obj[$options['name']] = $geocoder->{$func}();
     }
 }
 /**
  * Execute task
  * 
  * @param   array   $arguments  Task arguments [optional]
  * @param   array   $options    Task options [optional]
  * @return  void
  */
 protected function execute($arguments = array(), $options = array())
 {
     $this->logSection('doctrine', 'generating model classes');
     $config = $this->getCliConfig();
     $builderOptions = $this->configuration->getPluginConfiguration('sfDoctrinePlugin')->getModelBuilderOptions();
     $finder = sfFinder::type('file')->prune('base')->name('*' . $builderOptions['suffix']);
     $before = $finder->in($config['models_path']);
     $schema = $this->prepareSchemaFile($config['yaml_schema_path']);
     $import = new Doctrine_Import_Schema();
     $import->setOptions($builderOptions);
     $import->importSchema($schema, 'yml', $config['models_path']);
     $base = $builderOptions['baseClassesDirectory'];
     $suff = $builderOptions['suffix'];
     $src = array('##PACKAGE##', '##SUBPACKAGE##', '##NAME##', ' <##EMAIL##>');
     // markup base classes with magic methods
     foreach (sfYaml::load($schema) as $model => $definition) {
         $package = isset($definition['package']) ? substr($definition['package'], 0, strpos($definition['package'], '.')) : '';
         $basePath = $config['models_path'] . ($package ? '/' . $package : '') . '/';
         $file = $basePath . $base . '/Base' . $model . $suff;
         $code = file_get_contents($file);
         // introspect the model without loading the class
         if (preg_match_all('/@property (\\w+) \\$(\\w+)/', $code, $matches, PREG_SET_ORDER)) {
             $properties = array();
             foreach ($matches as $match) {
                 $properties[$match[2]] = $match[1];
             }
             $typePad = max(array_map('strlen', array_merge(array_values($properties), array($model))));
             $namePad = max(array_map('strlen', array_keys(array_map(array('sfInflector', 'camelize'), $properties))));
             $setters = array();
             $getters = array();
             foreach ($properties as $name => $type) {
                 $camelized = sfInflector::camelize($name);
                 $collection = 'Doctrine_Collection' == $type;
                 $getters[] = sprintf('@method %-' . $typePad . 's %s%-' . ($namePad + 2) . 's Returns the current record\'s "%s" %s', $type, 'get', $camelized . '()', $name, $collection ? 'collection' : 'value');
                 $setters[] = sprintf('@method %-' . $typePad . 's %s%-' . ($namePad + 2) . 's Sets the current record\'s "%s" %s', $model, 'set', $camelized . '()', $name, $collection ? 'collection' : 'value');
             }
             $dst = array(dinGeneratorSigner::getProjectName(), 'lib.model.doctrine' . ($package ? '.' . $package : '') . '.base', dinGeneratorSigner::getAuthor(), '');
             $code = str_replace($match[0], $match[0] . PHP_EOL . ' * ' . PHP_EOL . ' * ' . implode(PHP_EOL . ' * ', array_merge($getters, $setters)), $code);
             $code = str_replace($src, $dst, $code);
             file_put_contents($file, $code);
         }
         $this->replaceLibClasses($basePath, $model, $package, $suff);
         if ($package) {
             $basePath = $this->configuration->getPluginConfiguration($package)->getRootDir() . '/lib/model/doctrine/';
             $this->replaceLibClasses($basePath, $model, $package, $suff, true);
         }
     }
     $this->reloadAutoload();
 }
 public function mooJsonDataToAction($actionName, $params, $pk_link = false)
 {
     //return  (print_r($params));
     $dims = isset($params[dims]) ? ', dims: \'' . $params[dims] . '\'' : '';
     $action = isset($params['action']) ? $params['action'] : 'List' . sfInflector::camelize($actionName);
     $actionContent = $action . 'Content';
     $url_params = $pk_link ? '?' . $this->getPrimaryKeyUrlParams() : '\'';
     if (isset($params['inWinPopUp']) and $params['inWinPopUp'] == true) {
         // en $execute definimos la accion a ejecutar en el cliente
         $execute = isset($params['winType']) ? 'renderAjax' . ucfirst($params['winType']) : 'renderAjaxWin';
         return '{type: \'ajax_link\', link: \'[?php echo url_for(\'' . $this->getModuleName() . '/' . $action . $url_params . ', ' . $this->asPhp($params['params']) . ', \'' . $this->getI18nCatalogue() . '\') ?]\', link_content: \'[?php echo url_for(\'' . $this->getModuleName() . '/' . $actionContent . $url_params . ', ' . $this->asPhp($params['params']) . ', \'' . $this->getI18nCatalogue() . '\') ?]\', update: \'_new\', execute: \'' . $execute . '\'' . $dims . '},' . "\n";
     } else {
         return "{type: 'ajax_link'}";
     }
 }
Ejemplo n.º 27
0
 public function fillParams()
 {
     $routing = sfContext::getInstance()->getRouting()->getRoutes();
     if (!isset($routing[substr($this->getBaseRoute(), 1)])) {
         throw new sfException('Undefined Route: ' . $this->getBaseRoute());
     }
     $route = $routing[substr($this->getBaseRoute(), 1)];
     foreach ($route->getVariables() as $key => $value) {
         if ($param = $this->routeHasParameter($key)) {
             $this->addRouteParam($key, $param);
         } elseif (method_exists(new csNavigationMenu(), sfInflector::camelize('get_default_' . $key))) {
             $method = sfInflector::camelize('get_default_' . $key);
             $this->addRouteParam($key, csNavigationMenu::$method($this));
         }
     }
 }
Ejemplo n.º 28
0
 protected function getObjectsForParameters($parameters)
 {
     $this->options['model'] = Doctrine::getTable($this->options['model']);
     $variables = array();
     foreach ($this->getRealVariables() as $variable) {
         if ($this->options['model']->hasColumn($this->options['model']->getColumnName($variable))) {
             $variables[] = $variable;
         }
     }
     if (!isset($this->options['method'])) {
         switch (count($variables)) {
             case 0:
                 $this->options['method'] = 'findAll';
                 break;
             case 1:
                 $this->options['method'] = 'findOneBy' . sfInflector::camelize($variables[0]);
                 $parameters = $parameters[$variables[0]];
                 break;
             default:
                 $this->options['method'] = 'findByDQL';
                 $wheres = array();
                 $values = array();
                 foreach ($variables as $variable) {
                     $variable = $this->options['model']->getFieldName($variable);
                     $wheres[] = $variable . ' = ?';
                     $values[] = $parameters[$variable];
                 }
                 $parameters = array();
                 $parameters[] = implode(' AND ', $wheres);
                 $parameters[] = $values;
         }
         $className = $this->options['model'];
         return call_user_func_array(array($className, $this->options['method']), $parameters);
     } else {
         $q = $this->options['model']->createQuery('a');
         foreach ($variables as $variable) {
             $fieldName = $this->options['model']->getFieldName($variable);
             $q->andWhere('a.' . $fieldName . ' = ?', $parameters[$variable]);
         }
         $parameters = $q;
         $className = $this->options['model'];
         if (!isset($this->options['method'])) {
             throw new InvalidArgumentException(sprintf('You must pass a "method" option for a %s object.', get_class($this)));
         }
         return call_user_func(array($className, $this->options['method']), $parameters);
     }
 }
 public function getFrozen($key)
 {
     if (0 == count($this->frozen_data) and false == is_null(parent::getFrozenData())) {
         $this->frozen_data = json_decode(parent::getFrozenData(), true);
     }
     if (false == is_array($this->frozen_data)) {
         $this->frozen_data = array();
     }
     if (false == is_null($key)) {
         if (array_key_exists($key, $this->frozen_data)) {
             return $this->frozen_data[$key];
         } else {
             throw new Doctrine_Record_UnknownPropertyException(sprintf('Unknown method %s::%s', get_class($this), 'get' . sfInflector::camelize($key)));
         }
     }
     return $this->frozen_data;
 }
 /**
  * Runs the current application.
  *
  * @param mixed $options The command line options
  *
  * @return integer 0 if everything went fine, or an error code
  */
 public function run($options = null)
 {
     $this->handleOptions($options);
     $arguments = $this->commandManager->getArgumentValues();
     if (!isset($arguments['task'])) {
         $arguments['task'] = 'list';
         $this->commandOptions .= $arguments['task'];
     }
     $this->currentTask = $this->getTaskToExecute($arguments['task']);
     if ($this->currentTask instanceof sfCommandApplicationTask) {
         $this->currentTask->setCommandApplication($this);
     }
     sfInflector::camelize('/aaa_bbb');
     $ret = $this->currentTask->runFromCLI($this->commandManager, $this->commandOptions);
     $this->currentTask = null;
     return $ret;
 }