Beispiel #1
0
 public function testClassifyAndTableizeFunction()
 {
     $start = 'auth_user';
     $middle = 'AuthUser';
     $this->assertEquals($middle, Centurion_Inflector::classify($start));
     $this->assertEquals($start, Centurion_Inflector::tableize($middle));
 }
 /**
  * This action list all admin controller in all active modules.
  * It can help to build navigation.
  */
 public function listAdminAction()
 {
     $front = $this->getFrontController();
     $modules = $front->getControllerDirectory();
     $moduleEnabled = Centurion_Config_Manager::get('resources.modules');
     $this->view->modules = array();
     foreach ($modules as $moduleName => $module) {
         $this->view->modules[$moduleName] = array();
         if (!in_array($moduleName, $moduleEnabled)) {
             continue;
         }
         $dbTableDir = realpath($module);
         if (!file_exists($dbTableDir)) {
             continue;
         }
         $dir = new Centurion_Iterator_DbTableFilter($dbTableDir);
         foreach ($dir as $fileInfo) {
             if (substr($fileInfo, 0, 5) == 'Admin') {
                 if (substr($fileInfo, -14) == 'Controller.php') {
                     $controllerName = Centurion_Inflector::tableize(substr($fileInfo, 0, -14), '-');
                     $this->view->modules[$moduleName][] = $controllerName;
                 }
             }
         }
     }
     ksort($this->view->modules);
 }
 public function __construct($name = NULL, array $data = array(), $dataName = '')
 {
     if ($this->_moduleName == null && $this->_objectName == null) {
         $class = get_class($this);
         preg_match('`([a-z]*)_.*_Admin([a-z]*)ControllerTest`i', $class, $matches);
         $this->_moduleName = strtolower($matches[1]);
         $this->_objectName = Centurion_Inflector::tableize($matches[2], '-');
     }
     parent::__construct($name, $data, $dataName);
 }
 /**
  * This function list all action available for current controller (so all available static html integration)
  *
  */
 public function indexAction()
 {
     $reflection = new ReflectionClass('HtmlController');
     $methods = $reflection->getMethods();
     $htmlMethod = array();
     foreach ($methods as $methodClass) {
         $method = $methodClass->name;
         if ('_' !== $method[0] && 'indexAction' !== $method && 'Action' === substr($method, -6)) {
             $htmlMethod[] = Centurion_Inflector::tableize(substr($method, 0, -6), '-');
         }
     }
     $this->view->methods = $htmlMethod;
 }
Beispiel #5
0
 /**
  * Check if a field name belongs to the table.
  *
  * @param   string          $fieldName
  * @return  boolean|string  False if the field doesn't belong to the table, otherwise, tableized field
  */
 protected function _isFieldNameBelongToTable($fieldName)
 {
     $fieldName = Centurion_Inflector::tableize($fieldName);
     if (in_array($fieldName, $this->_getCols())) {
         return $fieldName;
     }
     return false;
 }
Beispiel #6
0
 /**
  * Retrieve the next or previous row count.
  *
  * @param string $by                        Column name
  * @param boolean $isNext                   Next row if true, previous instead
  * @param array $kwargs                     Arguments passed to the table
  * @param Centurion_Db_Table_Select $select The select used to process the query
  * @return int
  */
 protected function _getNextOrPreviousCountByField($by, $isNext = true, $kwargs = null, $select = null)
 {
     if (is_string($by)) {
         $by = Centurion_Inflector::tableize($by);
     }
     if (null === $select) {
         $select = $this->getTable()->select(true);
     }
     return $this->_getNextOrPreviousSelectByField($by, $isNext, $kwargs, $select)->count();
 }
Beispiel #7
0
 /**
  * Adds a JOIN table and columns to the query with the referenceMap.
  *
  * @param  string $key                 The referenceMap key
  * @param  array|string $cols          The columns to select from the joined table.
  * @param  string $schema              The database name to specify, if any.
  * @return Centurion_Db_Table_Select   This Centurion_Db_Table_Select object.
  */
 protected function _joinUsingVia($key, $type, $cols = '*', $schema = null)
 {
     if (empty($this->_parts[self::FROM])) {
         require_once 'Zend/Db/Select/Exception.php';
         throw new Zend_Db_Select_Exception("You can only perform a joinUsing after specifying a FROM table");
     }
     $referenceMap = $this->getTable()->getReferenceMap(Centurion_Inflector::tableize($key));
     $refTable = Centurion_Db::getSingletonByClassName($referenceMap['refTableClass']);
     $name = $refTable->info('name');
     $join = $this->_adapter->quoteIdentifier(key($this->_parts[self::FROM]), true);
     $from = $this->_adapter->quoteIdentifier($name);
     $primary = $refTable->info('primary');
     $cond1 = $join . '.' . $referenceMap['columns'];
     $cond2 = $from . '.' . $primary[1];
     $cond = $cond1 . ' = ' . $cond2;
     return $this->_join($type, $name, $cond, $cols, $schema);
 }
Beispiel #8
0
 public function acl($env)
 {
     $this->bootstrap($env);
     $application = $this->_application;
     $bootstrap = $application->getBootstrap();
     $front = $bootstrap->getResource('FrontController');
     $modules = $front->getControllerDirectory();
     $default = $front->getDefaultModule();
     $curBootstrapClass = get_class($bootstrap);
     $options = $bootstrap->getOption('resources');
     $options = $options['modules'];
     if (is_array($options) && !empty($options[0])) {
         $diffs = array_diff($options, array_keys($modules));
         if (count($diffs)) {
             throw new Centurion_Application_Resource_Exception(sprintf("The modules %s is not found in your registry (%s)", implode(', ', $diffs), implode(PATH_SEPARATOR, $modules)));
         }
         foreach ($modules as $key => $module) {
             if (!in_array($key, $options) && $key !== $default) {
                 unset($modules[$key]);
                 $front->removeControllerDirectory($key);
             }
         }
         $modules = Centurion_Inflector::sortArrayByArray($modules, array_values($options));
     }
     require_once APPLICATION_PATH . '/../library/Centurion/Contrib/auth/models/DbTable/Permission.php';
     require_once APPLICATION_PATH . '/../library/Centurion/Contrib/auth/models/DbTable/Row/Permission.php';
     $permissionTable = Centurion_Db::getSingleton('auth/permission');
     foreach ($modules as $module => $moduleDirectory) {
         echo "\n\n" . 'Scan new module: ' . $module . "\n";
         $bootstrapClass = $this->_formatModuleName($module) . '_Bootstrap';
         $modulePath = dirname($moduleDirectory);
         $dataPath = $modulePath . '/controllers/';
         if (is_dir($dataPath)) {
             $db = Zend_Db_Table::getDefaultAdapter();
             foreach (new DirectoryIterator($dataPath) as $file) {
                 if ($file->isDot() || !$file->isFile()) {
                     continue;
                 }
                 if (substr($file, 0, 5) !== 'Admin') {
                     continue;
                 }
                 $controllerName = substr($file, 5, -14);
                 $object = Centurion_Inflector::tableize($controllerName, '-');
                 $tab = array('index' => 'View %s %s index', 'list' => 'View %s %s list', 'get' => 'View an %s %s', 'post' => 'Create an %s %s', 'new' => 'Access to creation of an %s %s', 'delete' => 'Delete an %s %s', 'put' => 'Update an %s %s', 'batch' => 'Batch an %s %s', 'switch' => 'Switch an %s %s');
                 foreach ($tab as $key => $description) {
                     list($row, $created) = $permissionTable->getOrCreate(array('name' => $module . '_' . $object . '_' . $key));
                     if ($created) {
                         echo 'Create permission: ' . $module . '_' . $object . '_' . $key . "\n";
                         $row->description = sprintf($description, $module, $object);
                         $row->save();
                     }
                 }
             }
         }
     }
     Centurion_Loader_PluginLoader::clean();
     Centurion_Signal::factory('clean_cache')->send($this);
 }