示例#1
0
 public static function enum($value, $options, $default = '')
 {
     if ($value !== null) {
         if (array_key_Exists($value, $options)) {
             return $options[$value];
         }
         return $default;
     }
     return $options;
 }
示例#2
0
 public function AddTableName($tableName, $modelName)
 {
     if (!array_key_Exists($tableName, $this->TableNames)) {
         $this->TableNames[$tableName] = $modelName;
     }
 }
 /**
  *
  * @param unknown_type $columns
  */
 function table_headers($columns)
 {
     if (empty($this->_columns)) {
         return $columns;
     }
     print_r($columns);
     $newColumns = array();
     foreach ((array) $this->_columns as $params) {
         if (!array_key_Exists('id', $params)) {
             continue;
         }
         if (!array_key_Exists('title', $params)) {
             continue;
         }
         $newColumns[$params['id']] = $params['title'];
     }
     return $newColumns;
 }
示例#4
0
 /**
  * @param string $name
  * @return bool
  */
 public function hasField($name)
 {
     return array_key_Exists($name, $this->fields);
 }
示例#5
0
 /**
  * Get the role of the currently set user
  *
  * @return string
  */
 public function getRole()
 {
     if (!$this->user->isAuthenticated()) {
         return $this->defaultRole;
     }
     if (!array_key_Exists($this->user->getService(), $this->admins)) {
         return $this->loggedInRole;
     }
     if (!in_array($this->user->getDisplayName(), $this->admins[$this->user->getService()])) {
         return $this->loggedInRole;
     }
     return $this->adminRole;
 }
 /**
  * Runs a single named setup resource
  *
  * This method nukes the global/resources node in the global config
  * and then repopulates it with **only** the $name resource. Then it
  * calls the standard Contao `applyAllUpdates` method.
  *
  * The benefit of this approach is we don't need to recreate the entire
  * setup resource running logic ourselves.  Yay for code reuse
  *
  * The downside is we should probably exit quickly, as anything else that
  * uses the global/resources node is going to behave weird.
  *
  * @todo Repopulate global config after running?  Non trivial since setNode escapes strings
  *
  * @param string $name
  * @param bool $needsUpdate
  * @param string $type
  * @throws \Exception
  * @internal param $string
  */
 protected function _runNamedSetupResource($name, $needsUpdate, $type)
 {
     $output = $this->_output;
     if (!in_array($type, array(self::TYPE_MIGRATION_STRUCTURE, self::TYPE_MIGRATION_DATA))) {
         throw new \Exception('Invalid Type [' . $type . ']: structure, data are valid');
     }
     if (!array_key_Exists($name, $needsUpdate)) {
         $output->writeln('<error>No updates to run for ' . $name . ', skipping </error>');
         return;
     }
     //remove all other setup resources from configuration
     //(in memory, do not persist this to cache)
     $realConfig = \Mage::getConfig();
     $resources = $realConfig->getNode('global/resources');
     foreach ($resources->children() as $resource) {
         if (!$resource->setup) {
             continue;
         }
         unset($resource->setup);
     }
     //recreate our specific node in <global><resources></resource></global>
     //allows for theoretical multiple runs
     $setupResource = $needsUpdate[$name];
     $setupResourceConfig = $this->_secondConfig->getNode('global/resources/' . $name);
     $moduleName = $setupResourceConfig->setup->module;
     $className = $setupResourceConfig->setup->class;
     $specificResource = $realConfig->getNode('global/resources/' . $name);
     $setup = $specificResource->addChild('setup');
     if ($moduleName) {
         $setup->addChild('module', $moduleName);
     } else {
         $output->writeln('<error>No module node configured for ' . $name . ', possible configuration error </error>');
     }
     if ($className) {
         $setup->addChild('class', $className);
     }
     //and finally, RUN THE UPDATES
     try {
         ob_start();
         if ($type == self::TYPE_MIGRATION_STRUCTURE) {
             $this->_stashEventContext();
             \Mage_Core_Model_Resource_Setup::applyAllUpdates();
             $this->_restoreEventContext();
         } else {
             if ($type == self::TYPE_MIGRATION_DATA) {
                 \Mage_Core_Model_Resource_Setup::applyAllDataUpdates();
             }
         }
         $exceptionOutput = ob_get_clean();
         $this->_output->writeln($exceptionOutput);
     } catch (\Exception $e) {
         $exceptionOutput = ob_get_clean();
         $this->_processExceptionDuringUpdate($e, $name, $setupResource, $exceptionOutput);
         if ($this->_input->getOption('stop-on-error')) {
             throw new \RuntimeException('Setup stopped with errors');
         }
     }
 }
 public function hasExtension($nameOrInstance)
 {
     return array_key_Exists($nameOrInstance instanceof AbstractExtension ? $nameOrInstance->getName() : (string) $nameOrInstance, $this->extensions);
 }
 /**
  * 用 $upload_id 的內容覆蓋 SheetHub 線上的內容,採用 update_type=1, 當新檔案沒有的東西在 SheetHub 上也會刪除
  * 
  * @param string $user
  * @param string $sheet
  * type 
  * @param string $upload_id 
  * @access public
  * @return Object result 
  */
 public function updateFile($user, $sheet, $upload_id, $config = array())
 {
     $sheethub_domain = getenv('SHEETHUB_DOMAIN') ?: 'sheethub.com';
     $sheethub_key = getenv('SHEETHUB_KEY');
     $info = self::getFileInfoFromUpload($upload_id, $config['encode']);
     if (array_key_exists('tab_id', $config)) {
         $tab_id = $config['tab_id'];
         $tab_no = array_search($tab_id, $info->tab_ids);
         if (false === $tab_no) {
             throw new Exception("找不到 {$tab_id} 這個 tab");
         }
     } else {
         if (count($info->tab_ids) != 1) {
             throw new Exception("超過一個檔案或 tab 可選");
         }
         $tab_id = $info->tab_ids[0];
         $tab_no = 0;
     }
     $row_begin = array_key_exists('row_begin', $config) ? $config['row_begin'] : self::guessRowBegin($info->tables[0]);
     $columns = $info->tables[$tab_no][max(0, $row_begin - 1)];
     if ($config['columns'] and count($config['columns']) == count($columns)) {
         $columns = $config['columns'];
     }
     $columns = array_map(function ($s) {
         return str_replace("\n", "", $s);
     }, $columns);
     $params = array();
     $params[] = 'upload_id=' . urlencode($upload_id);
     $params[] = 'tab-select=' . urlencode($tab_id);
     $params[] = 'row_begin=' . intval($row_begin);
     $params[] = 'update_type=' . array_key_exists('update_type', $config) ? $config['update_type'] : 0;
     $params[] = 'clean_uploaded_file=1';
     $params[] = 'cols=' . urlencode(json_encode($columns));
     if ($config['encode']) {
         $params[] = 'encode=' . urlencode($config['encode']);
     }
     if (array_key_Exists('srs', $config)) {
         $params[] = 'srs=' . urlencode($config['srs']);
     }
     $user = urlencode($user);
     $sheet = urlencode($sheet);
     $curl = curl_init("https://{$sheethub_domain}/{$user}/{$sheet}/updatefile?access_token={$sheethub_key}");
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($curl, CURLOPT_POSTFIELDS, implode('&', $params));
     $content = curl_exec($curl);
     $ret = json_decode($content);
     if ($ret->error) {
         error_log('table=' . json_encode($info->tables[$tab_no], JSON_UNESCAPED_UNICODE));
         error_log('column=' . json_encode($columns, JSON_UNESCAPED_UNICODE));
         throw new Exception($ret->message);
     }
     return $ret->data;
 }