public function testCamelize() { $this->assertThat(StringUtil::camelize('word'), $this->equalTo('Word')); $this->assertThat(StringUtil::camelize('main-controller'), $this->equalTo('MainController')); $this->assertThat(StringUtil::camelize('main_controller_class'), $this->equalTo('MainControllerClass')); $this->assertThat(StringUtil::camelize('some undefined words'), $this->equalTo('SomeUndefinedWords')); }
public function renderFile() { if ($this->oJournalComment === null) { throw new Exception('Hash invalid'); } JournalCommentPeer::ignoreRights(true); $sAction = StringUtil::camelize("comment_{$this->sAction}"); $this->{$sAction}(); echo TranslationPeer::getString("journal_comment.executed_{$this->sAction}", null, 'done'); }
/** * render plugin for fetching a particular module object * * Examples * {selectmodobject module="AutoCustomer" objecttype="customer" id=4 assign="myCustomer"} * {selectmodobject module="AutoCocktails" objecttype="recipe" id=12 assign="myRecipe"} * {selectmodobject recordClass="AutoCocktails_Model_Recipe" id=12 assign="myRecipe"} * * Parameters: * module Name of the module storing the desired object (in DBObject mode) * objecttype Name of object type (in DBObject mode) * recordClass Class name of an doctrine record. (in Doctrine mode) * id Identifier of desired object * prefix Optional prefix for class names (defaults to PN) (in DBObject mode) * assign Name of the returned object * * @param array $params All attributes passed to this function from the template. * @param Zikula_View $view Reference to the Zikula_View object. * * @return void */ function smarty_function_selectmodobject($params, Zikula_View $view) { if (isset($params['recordClass']) && !empty($params['recordClass'])) { $doctrineMode = true; } else { // DBObject checks if (!isset($params['module']) || empty($params['module'])) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('selectmodobject', 'module'))); } if (!isset($params['objecttype']) || empty($params['objecttype'])) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('selectmodobject', 'objecttype'))); } if (!isset($params['prefix'])) { $params['prefix'] = 'PN'; } $doctrineMode = false; } if (!isset($params['id']) || empty($params['id']) || !is_numeric($params['id'])) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('selectmodobject', 'id'))); } if (!isset($params['assign']) || empty($params['assign'])) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('selectmodobject', 'assign'))); } // load object depending on mode: doctrine or dbobject if (!$doctrineMode) { if (!ModUtil::available($params['module'])) { $view->trigger_error(__f('Invalid %1$s passed to %2$s.', array('module', 'selectmodobject'))); } ModUtil::dbInfoLoad($params['module']); $class = "{$params['module']}_DBObject_" . StringUtil::camelize($params['objecttype']); // intantiate object model $object = new $class(); $idField = $object->getIDField(); // assign object data // this performs a new database select operation // while the result will be saved within the object, we assign it to a local variable for convenience $objectData = $object->get(intval($params['id']), $idField); if (!is_array($objectData) || !isset($objectData[$idField]) || !is_numeric($objectData[$idField])) { $view->trigger_error(__('Sorry! No such item found.')); } } else { if ($params['recordClass'] instanceof \Doctrine_Record) { $objectData = Doctrine_Core::getTable($params['recordClass'])->find($params['id']); if ($objectData === false) { $view->trigger_error(__('Sorry! No such item found.')); } } else { /** @var $em Doctrine\ORM\EntityManager */ $em = \ServiceUtil::get('doctrine.entitymanager'); $result = $em->getRepository($params['recordClass'])->find($params['id']); $objectData = $result->toArray(); } } $view->assign($params['assign'], $objectData); }
/** * render plugin for fetching a particular module object * * Examples * {selectmodobject module="AutoCustomer" objecttype="customer" id=4 assign="myCustomer"} * {selectmodobject module="AutoCocktails" objecttype="recipe" id=12 assign="myRecipe"} * {selectmodobject recordClass="AutoCocktails_Model_Recipe" id=12 assign="myRecipe"} * * Parameters: * module Name of the module storing the desired object (in DBObject mode) * objecttype Name of object type (in DBObject mode) * recordClass Class name of an doctrine record. (in Doctrine mode) * id Identifier of desired object * prefix Optional prefix for class names (defaults to PN) (in DBObject mode) * assign Name of the returned object * * @param array $params All attributes passed to this function from the template. * @param Zikula_View $view Reference to the Zikula_View object. * * @return void */ function smarty_function_selectmodobject($params, Zikula_View $view) { if (isset($params['recordClass']) && !empty($params['recordClass'])) { $doctrineMode = true; } else { // DBObject checks if (!isset($params['module']) || empty($params['module'])) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('selectmodobject', 'module'))); } if (!isset($params['objecttype']) || empty($params['objecttype'])) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('selectmodobject', 'objecttype'))); } if (!isset($params['prefix'])) { $params['prefix'] = 'PN'; } $doctrineMode = false; } if (!isset($params['id']) || empty($params['id']) || !is_numeric($params['id'])) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('selectmodobject', 'id'))); } if (!isset($params['assign']) || empty($params['assign'])) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('selectmodobject', 'assign'))); } // load object depending on mode: doctrine or dbobject if (!$doctrineMode) { if (!ModUtil::available($params['module'])) { $view->trigger_error(__f('Invalid %1$s passed to %2$s.', array('module', 'selectmodobject'))); } ModUtil::dbInfoLoad($params['module']); $classname = "{$params['module']}_DBObject_" . StringUtil::camelize($params['objecttype']); if (!class_exists($classname) && System::isLegacyMode()) { // BC check for PNObject old style. // load the object class corresponding to $params['objecttype'] if (!($class = Loader::loadClassFromModule($params['module'], $params['objecttype'], false, false, $params['prefix']))) { z_exit(__f('Unable to load class [%s] for module [%s]', array(DataUtil::formatForDisplay($params['objecttype']), DataUtil::formatForDisplay($params['module'])))); } } // intantiate object model $object = new $class(); $idField = $object->getIDField(); // assign object data // this performs a new database select operation // while the result will be saved within the object, we assign it to a local variable for convenience $objectData = $object->get(intval($params['id']), $idField); if (!is_array($objectData) || !isset($objectData[$idField]) || !is_numeric($objectData[$idField])) { $view->trigger_error(__('Sorry! No such item found.')); } } else { $objectData = Doctrine_Core::getTable($params['recordClass'])->find($params['id']); if ($objectData === false) { $view->trigger_error(__('Sorry! No such item found.')); } } $view->assign($params['assign'], $objectData); }
public function may($mPage, $sRightName, $bInheritedOnly = false) { $sRightName = "getMay" . StringUtil::camelize($sRightName, true); $aRights = $this->getRights(); foreach ($aRights as $oRight) { if ($bInheritedOnly && !$oRight->getIsInherited()) { continue; } if ($oRight->rightFits($mPage, $sRightName)) { return true; } } return false; }
public function getFileName($name) { return StringUtil::camelize($name); }
public static function isValidModuleClassName($sName) { return StringUtil::endsWith($sName, StringUtil::camelize(self::getType(), true) . "Module"); }
/** * render plugin for fetching a list of module objects * * Examples * {selectmodobjectarray module="AutoCustomer" objecttype="customer" assign="myCustomers"} * {selectmodobjectarray module="AutoCocktails" objecttype="recipe" orderby="name desc" assign="myRecipes"} * {selectmodobjectarray recordClass="AutoCocktails_Model_Recipe" orderby="name desc" assign="myRecipes"} * * Parameters: * module Name of the module storing the desired object (in DBObject mode) * objecttype Name of object type (in DBObject mode) * recordClass Class name of an doctrine record. (in Doctrine mode) * useArrays true to fetch arrays and false to fetch objects (default is true) (in Doctrine mode) * where Filter value * orderby Sorting field and direction * pos Start offset * num Amount of selected objects * prefix Optional prefix for class names (defaults to PN) (in DBObject mode) * assign Name of the returned object * * @param array $params All attributes passed to this function from the template. * @param Zikula_View $view Reference to the Zikula_View object. * * @return void */ function smarty_function_selectmodobjectarray($params, Zikula_View $view) { if (isset($params['recordClass']) && !empty($params['recordClass'])) { $doctrineMode = true; } else { // DBObject checks if (!isset($params['module']) || empty($params['module'])) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('selectmodobjectarray', 'module'))); } if (!isset($params['objecttype']) || empty($params['objecttype'])) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('selectmodobjectarray', 'objecttype'))); } if (!isset($params['prefix'])) { $params['prefix'] = 'PN'; } $doctrineMode = false; } if (!isset($params['assign'])) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('selectmodobjectarray', 'assign'))); } // load object depending on mode: doctrine or dbobject if (!$doctrineMode) { if (!ModUtil::available($params['module'])) { $view->trigger_error(__f('Invalid %1$s passed to %2$s.', array('module', 'selectmodobjectarray'))); } $classname = "{$params['module']}\\DBObject\\" . StringUtil::camelize($params['objecttype']) . 'Array'; // instantiate the object-array $objectArray = new $classname(); // convenience vars to make code clearer $where = $sort = ''; if (isset($params['where']) && !empty($params['where'])) { $where = $params['where']; } // TODO: add FilterUtil support here in 2.0 if (isset($params['orderby']) && !empty($params['orderby'])) { $sort = $params['orderby']; } $pos = 1; if (isset($params['pos']) && !empty($params['pos']) && is_numeric($params['pos'])) { $pos = $params['pos']; } $num = 10; if (isset($params['num']) && !empty($params['num']) && is_numeric($params['num'])) { $num = $params['num']; } // get() returns the cached object fetched from the DB during object instantiation // get() with parameters always performs a new select // while the result will be saved in the object, we assign in to a local variable for convenience. $objectData = $objectArray->get($where, $sort, $pos - 1, $num); } else { $query = Doctrine_Core::getTable($params['recordClass'])->createQuery(); if (isset($params['where']) && !empty($params['where'])) { if (is_array($params['where'])) { $query->where($params['where'][0], $params['where'][1]); } else { $query->where($params['where']); } } if (isset($params['orderby']) && !empty($params['orderby'])) { $query->orderBy($params['orderby']); } $pos = 0; if (isset($params['pos']) && !empty($params['pos']) && is_numeric($params['pos'])) { $pos = $params['pos']; } $num = 10; if (isset($params['num']) && !empty($params['num']) && is_numeric($params['num'])) { $num = $params['num']; } $query->offset($pos); $query->limit($num); if (isset($params['useArrays']) && !$params['useArrays']) { $objectData = $query->execute(); } else { $objectData = $query->fetchArray(); } } $view->assign($params['assign'], $objectData); }
public function testCamelize() { $this->assertSame('HogeFuga', StringUtil::camelize('hoge_fuga')); }
public static function insertRow($aArrayOfValues) { $oDocumentType = new DocumentType(); foreach ($aArrayOfValues as $sFieldName => $mValue) { $sMethodName = 'set' . StringUtil::camelize($sFieldName, true); $mValue = $mValue === true ? 1 : $mValue; $oDocumentType->{$sMethodName}($mValue); } $oDocumentType->save(); }
public function getOption($sName) { $sName = 'get' . StringUtil::camelize($sName, true); $aArgs = func_get_args(); return call_user_func_array(array($this->oDelegate, $sName), array_splice($aArgs, 1)); }
protected function resolveFunctionNameFromTemplateName($name) { preg_match("~^(\\d+)~", $name, $columnCount); // Not Coding Standard if (isset($columnCount[1])) { $columnCount = NumberToWordsUtil::convert($columnCount[1]); $name = strtolower($columnCount . substr($name, strlen($columnCount[1]))); } $name = 'make ' . strtolower($name); $name = preg_replace('/[^a-z ]/', '', $name); $name = StringUtil::camelize($name, false, ' '); return $name; }
/** * Creates an object array selector. * * @param string $modname Module name. * @param string $objectType Object type. * @param string $name Select field name. * @param string $field Value field. * @param string $displayField Display field. * @param string $where Where clause. * @param string $sort Sort clause. * @param string $selectedValue Selected value. * @param string $defaultValue Value for "default" option. * @param string $defaultText Text for "default" option. * @param string $allValue Value for "all" option. * @param string $allText Text for "all" option. * @param string $displayField2 Second display field. * @param boolean $submit Submit on choose. * @param boolean $disabled Add Disabled attribute to select. * @param string $fieldSeparator Field seperator if $displayField2 is given. * @param integer $multipleSize Size for multiple selects. * * @return string The rendered output. */ public static function getSelector_ObjectArray($modname, $objectType, $name, $field = '', $displayField = 'name', $where = '', $sort = '', $selectedValue = '', $defaultValue = 0, $defaultText = '', $allValue = 0, $allText = '', $displayField2 = null, $submit = true, $disabled = false, $fieldSeparator = ', ', $multipleSize = 1) { if (!$modname) { return z_exit(__f('Invalid %1$s passed to %2$s.', array('modname', 'HtmlUtil::getSelector_ObjectArray'))); } if (!$objectType) { return z_exit(__f('Invalid %1$s passed to %2$s.', array('objectType', 'HtmlUtil::getSelector_ObjectArray'))); } if (!ModUtil::dbInfoLoad($modname)) { return __f('Unavailable/Invalid %1$s [%2$s] passed to %3$s.', array('modulename', $modname, 'HtmlUtil::getSelector_ObjectArray')); } if (!SecurityUtil::checkPermission("{$objectType}::", '::', ACCESS_OVERVIEW)) { return __f('Security check failed for %1$s [%2$s] passed to %3$s.', array('modulename', $modname, 'HtmlUtil::getSelector_ObjectArray')); } $cacheKey = md5("{$modname}|{$objectType}|{$where}|{$sort}"); if (isset($cache[$cacheKey])) { $dataArray = $cache[$cacheKey]; } else { $classname = "{$modname}\\DBObject\\" . StringUtil::camelize($objectType) . 'Array'; $class = new $classname(); //$dataArray = $class->get($where, $sort, -1, -1, '', false, $distinct); $dataArray = $class->get($where, $sort, -1, -1, '', false); $cache[$cacheKey] = $dataArray; if (!$field) { $field = $class->_objField; } } $data2 = array(); foreach ($dataArray as $object) { $val = $object[$field]; $disp = $object[$displayField]; if ($displayField2) { $disp .= $fieldSeparator . $object[$displayField2]; } $data2[$val] = $disp; } return self::getSelector_Generic($name, $data2, $selectedValue, $defaultValue, $defaultText, $allValue, $allText, $submit, $disabled, $multipleSize); }
public function getName($name) { $camelized = StringUtil::camelize($name); return lcfirst($camelized) . 'Action'; }
public static function doIndex($sPageType, NavigationItem $oNavigationItem) { $sPageType = StringUtil::camelize($sPageType . '_page_type_module', true); if (method_exists($sPageType, 'doIndex') && $sPageType::doIndex($oNavigationItem) === false) { return false; } return true; }
private function displayFilteredOverview($oTemplate) { $sMethodName = StringUtil::camelize("display_overview_{$this->sOverviewMode}"); $this->{$sMethodName}($oTemplate, $this->createQuery()->filterByDate($this->iYear, $this->iMonth, $this->iDay)); }
private static function findInPathByExpressions(&$aResult, $aExpressions, $sPath, $sInstancePrefix, $sParentName = null, $sRelativePath = null) { if (count($aExpressions) === 0) { return; } $sPathExpression = array_shift($aExpressions); $bAllowPathItemToBeSkipped = is_array($sPathExpression); if ($bAllowPathItemToBeSkipped) { if (count($aExpressions) === 0) { //Add the current path (parent recursive invocation added nothing because there were still items on the stack, next invocation would return empty since the stack is empty) $aResult[$sRelativePath] = new FileResource($sPath, $sInstancePrefix, $sRelativePath); } else { //call current function without the optional element self::findInPathByExpressions($aResult, $aExpressions, $sPath, $sInstancePrefix, $sParentName, $sRelativePath); } if (count($sPathExpression) === 0) { //emtpy array means look recursively in all subdirs => put the any-item-specifier (true) and the empty array on the local stack array_unshift($aExpressions, array()); $sPathExpression = null; } else { //array has a path element => put the optional argument(s) on the local stack $sNextItem = array_shift($sPathExpression); $aExpressions = array_merge($sPathExpression, $aExpressions); $sPathExpression = $sNextItem; } } if (!is_dir($sPath)) { return; } if ($sParentName !== null && is_string($sPathExpression)) { $sPathExpression = str_replace('${parent_name}', $sParentName, $sPathExpression); $sPathExpression = str_replace('${parent_name_camelized}', StringUtil::camelize($sParentName, true), $sPathExpression); } if (is_string($sPathExpression) && !StringUtil::startsWith($sPathExpression, "/")) { //Take the shortcut when only dealing with a static file name $sFilePath = "{$sPath}/{$sPathExpression}"; if ($sRelativePath === null) { $sNextRelativePath = $sPathExpression; } else { $sNextRelativePath = "{$sRelativePath}/{$sPathExpression}"; } if (file_exists($sFilePath)) { if (count($aExpressions) > 0) { self::findInPathByExpressions($aResult, $aExpressions, $sFilePath, $sInstancePrefix, $sPathExpression, $sNextRelativePath); } else { $aResult[$sNextRelativePath] = new FileResource($sFilePath, $sInstancePrefix, $sNextRelativePath); } } } else { foreach (ResourceFinder::getFolderContents($sPath) as $sFileName => $sFilePath) { if ($sPathExpression === self::WILDCARD_ANY || $sPathExpression === self::WILDCARD_FILE && is_file($sFilePath) || $sPathExpression === self::WILDCARD_DIR && is_dir($sFilePath) || is_string($sPathExpression) && preg_match($sPathExpression, $sFileName) !== 0) { $sNextRelativePath = $sFileName; if ($sRelativePath !== null) { $sNextRelativePath = "{$sRelativePath}/{$sFileName}"; } if (count($aExpressions) > 0) { self::findInPathByExpressions($aResult, $aExpressions, $sFilePath, $sInstancePrefix, $sFileName, $sNextRelativePath); } else { $aResult[$sNextRelativePath] = new FileResource($sFilePath, $sInstancePrefix, $sNextRelativePath); } } } } }
protected static function resolveStringToAttributeAccessor($string) { return StringUtil::camelize(str_replace(MergeTagsUtil::PROPERTY_DELIMITER, '->', strtolower($string)), false, MergeTagsUtil::CAPITAL_DELIMITER); }
public function getFileName($name) { return StringUtil::camelize($name) . 'Controller'; }
public static function jsonBaseObjects($aBaseObjects, $aOriginalColumnNames) { if ($aBaseObjects instanceof PropelCollection) { $aBaseObjects = $aBaseObjects->getArrayCopy(); } $aResult = array(); $aColumnNames = array(); foreach ($aOriginalColumnNames as $mIdentifier => $sColumnName) { if (is_numeric($mIdentifier)) { $mIdentifier = $sColumnName; } $aColumnNames[$mIdentifier] = 'get' . StringUtil::camelize($sColumnName, true); } foreach ($aBaseObjects as $oBaseObect) { if (!$oBaseObect instanceof BaseObject) { $aResult[] = $oBaseObect; continue; } $aResult[] = array(); foreach ($aColumnNames as $sColumnName => $sGetterName) { $aResult[count($aResult) - 1][$sColumnName] = $oBaseObect->{$sGetterName}(); } } return $aResult; }
public function getFileName($name) { return StringUtil::camelize(str_replace('/', '/ ', $name)) . 'Command'; }
/** * Load event handler. * * @param Zikula_Form_View $view Reference to Zikula_Form_View object. * @param array &$params Parameters passed from the Smarty plugin function. * * @return void */ public function load(Zikula_Form_View $view, &$params) { if ($this->showEmptyValue != 0) { $this->addItem('- - -', 0); } // switch between doctrine and dbobject mode if ($this->recordClass) { $q = Doctrine::getTable($this->recordClass)->createQuery(); if ($this->where) { if (is_array($this->where)) { $q->where($this->where[0], $this->where[1]); } else { $q->where($this->where); } } if ($this->orderby) { $q->orderBy($this->orderby); } if ($this->pos >= 0) { $q->offset($this->pos); } if ($this->num > 0) { $q->limit($this->num); } $rows = $q->execute(); foreach ($rows as $row) { $itemLabel = $row[$this->displayField]; if (!empty($this->displayFieldTwo)) { $itemLabel .= ' (' . $row[$this->displayFieldTwo] . ')'; } $this->addItem($itemLabel, $row[$this->idField]); } } else { ModUtil::dbInfoLoad($this->module); // load the object class corresponding to $this->objecttype $class = "{$this->module}_DBObject_" . StringUtil::camelize($this->objecttype) . 'Array'; // instantiate the object-array $objectArray = new $class(); // get() returns the cached object fetched from the DB during object instantiation // get() with parameters always performs a new select // while the result will be saved in the object, we assign in to a local variable for convenience. $objectData = $objectArray->get($this->where, $this->orderby, $this->pos, $this->num); foreach ($objectData as $obj) { $itemLabel = $obj[$this->displayField]; if (!empty($this->displayFieldTwo)) { $itemLabel .= ' (' . $obj[$this->displayFieldTwo] . ')'; } $this->addItem($itemLabel, $obj[$this->idField]); } } parent::load($view, $params); }
public function renderFile() { $sRequestType = StringUtil::camelize(Manager::usePath() . '_action'); header("Content-Type: application/json;charset=utf-8"); print json_encode($this->{$sRequestType}(), JSON_FORCE_OBJECT); }