17
SugarCRMCMSとして活用 CogniTom Academic Design 河村 [email protected] 2009930日水曜日

SugarCRM勉強会#001 SugarCRMをCMSとして活用

Embed Size (px)

Citation preview

Page 1: SugarCRM勉強会#001 SugarCRMをCMSとして活用

SugarCRMをCMSとして活用CogniTom Academic Design

河村 奨[email protected]

2009年9月30日水曜日

Page 2: SugarCRM勉強会#001 SugarCRMをCMSとして活用

Why?

• 日常業務と同じ画面で作業できる• 申込フォームなどの直接連携• 業務DBを必要に応じて参照

• 比較的鍛えられた(?) セキュリティ

• WEB → 業務システムへ 事業戦略として

2009年9月30日水曜日

Page 3: SugarCRM勉強会#001 SugarCRMをCMSとして活用

ただし...

• Sugarをセキュリティ上のリスクにさらすことにも

• 負荷対策・一般業務システムとの分離などが、必要な場合も

不必要な場合も多い

2009年9月30日水曜日

Page 4: SugarCRM勉強会#001 SugarCRMをCMSとして活用

サイト構成

非SSL SSL

•トップページ•ニュース•製品ページ•通常ページ

•申込フォーム•購入ページ

•SugarCRM

2009年9月30日水曜日

Page 5: SugarCRM勉強会#001 SugarCRMをCMSとして活用

モジュール開発

• WebPages : 一般ページ

• WebNews : ニュース記事

• WebParts : ページ部品 (広告など)

• WebRegistries : 各種設定

• WebProducts : 製品詳細 ...etc.

2009年9月30日水曜日

Page 6: SugarCRM勉強会#001 SugarCRMをCMSとして活用

EditView• TinyMCEを活用 ← 元々Sugarに導入済み

31. $viewdefs['WebPages']['EditView'] = array(32. 'templateMeta' => array (33. 'form' => array (...省略...),

34. 'maxColumns' => '3',35. 'widths' => array (...省略...),

36. 'javascript' => '37. <script type="text/javascript" src="include/javascript/tiny_mce/tiny_mce.js"></script>38. <script type="text/javascript">39. {literal}40. tinyMCE.init({41. mode: "exact",42. elements: "contents",43. theme: "advanced",44. language: "ja_utf-8",45. relative_urls: false,46. plugins: "table",47. ...省略...48. });49. {/literal}50. </script>51. ',52. ),

2009年9月30日水曜日

Page 7: SugarCRM勉強会#001 SugarCRMをCMSとして活用

TinyMCE

2009年9月30日水曜日

Page 8: SugarCRM勉強会#001 SugarCRMをCMSとして活用

ディレクトリ構成• httpdocs/ 非SSLのページ

• .htaccess リクエストをindex.phpに転送

• index.php ルーティングとSugarの起動

• httpsdocs/ SSLのページ

• .htaccess リクエストをindex.phpに転送

• index.php ルーティングとSugarの起動

• sugar/  

• index.php Sugarの起動

• include/entryPoint.php 各種構成ファイルの読み込み• modules/  

• WebPages/  • entry_point_registry.php エントリーポイントの拡張• public/sample.php コントローラ• tpls/sample.html 表示テンプレート

2009年9月30日水曜日

Page 9: SugarCRM勉強会#001 SugarCRMをCMSとして活用

処理の流れ

• /.htaccess

• /index.php

• /sugar/include/entryPoint.php

• /sugar/modules/WebPages/entry_point_registry.php

• /sugar/modules/WebPages/public/home.php

• /sugar/modules/WebPages/tpls/public.home.html

mod_rewrite

ルーティング

entryPoint 拡張

Smarty テンプレート

2009年9月30日水曜日

Page 10: SugarCRM勉強会#001 SugarCRMをCMSとして活用

entryPoint

• entryPointをアップグレードセーフに拡張する/sugar/modules/WebPages/entry_point_registry.phpindex.php?module=WebNews&entryPoint=list&year=2009

37. $entry_point_registry['list'] = array('file' => 'modules/WebProducts/public/list.php', 'auth' => false);

38. $entry_point_registry['detail'] = array('file' => 'modules/WebProducts/public/detail.php', 'auth' => false);

2009年9月30日水曜日

Page 11: SugarCRM勉強会#001 SugarCRMをCMSとして活用

リクエストの処理 ❶

• .htaccess ですべてのページリクエストをindex.phpに転送

3. RewriteEngine On4. RewriteCond %{REQUEST_FILENAME} !-f5. RewriteCond %{REQUEST_FILENAME} !-d6. RewriteRule ^(.*)$ index.php [L,QSA]

2009年9月30日水曜日

Page 12: SugarCRM勉強会#001 SugarCRMをCMSとして活用

リクエストの処理 ❷

• PHPの作業ディレクトリを、Sugarのルートに移動/httpdocs/ → /httpsdocs/sugar/

2. chdir('../httpsdocs/sugar');//Sugarのディレクトリに移動

2009年9月30日水曜日

Page 13: SugarCRM勉強会#001 SugarCRMをCMSとして活用

リクエストの処理 ❸

• REQUEST_URIを正規表現で場合分けしてルーティング

9. if (preg_match('/^\/news\/(?<year>\d+)\/(?<month>\d+)\//', $path, $matches)) $route = array( 'module' => 'WebNews', 'entryPoint' => 'list', 'year' => $matches['year'], 'month' => $matches['month'] );

10. else { header("HTTP/1.0 404 Not Found"); die("ページが見つかりません"); }

11. $_REQUEST = array_merge($_REQUEST, $route);

2009年9月30日水曜日

Page 14: SugarCRM勉強会#001 SugarCRMをCMSとして活用

リクエストの処理 ❹

31. //アプリケーションの準備32. define('sugarEntry', true);33. $startTime = microtime(true);34. require_once('include/entryPoint.php');35. 36. //WEBユーザをセット37. require_once('modules/Users/User.php');38. global $current_user;39. $current_user = new User();40. $current_user->retrieve($current_user->retrieve_user_id('webuser'));41. 42. //アプリケーションの開始43. ob_start();44. require_once('include/MVC/SugarApplication.php');45. $app = new SugarApplication();46. $app->startSession();47. $app->execute();

2009年9月30日水曜日

Page 15: SugarCRM勉強会#001 SugarCRMをCMSとして活用

テンプレート

>> Espresso へ

31. //Smartyテンプレートの準備32. $ss = new Sugar_Smarty();33. $ss->assign('MOD', $GLOBALS['mod_strings']);34. $ss->assign('APL', $GLOBALS['app_list_strings']);35. $ss->assign('page', $page);36. $ss->assign('page_siblings', $page_siblings);37. $ss->assign('toppage_message', $toppage_message);38. $ss->assign('news', $news);39. $ss->assign('global_links', $global_links);

41. //画面出力42. echo $ss->fetch('modules/WebPages/tpls/public.home.html');

• Smartyテンプレートによる画面出力

2009年9月30日水曜日

Page 16: SugarCRM勉強会#001 SugarCRMをCMSとして活用

よく使うコード ❶

• 文字列をキーに、レコードを取り出す

8. $page = new WebPage();9. $page->retrieve_by_string_fields(array('search_key'=>'home', 'language'=>'ja'));

2009年9月30日水曜日

Page 17: SugarCRM勉強会#001 SugarCRMをCMSとして活用

よく使うコード ❷

• 検索条件を指定して、レコードのリストを取得する

31. $focus = new WebNewsArticle();32. $result = $focus->get_list('date desc', “YEAR(date) = {$year}”, 0, 20);33. $news = $result['list'];

2009年9月30日水曜日