OSDN Git Service

add ACS webapp, sql, htdocs
[acs/acs.git] / webapp / lib / class / ACSScheduleParticipant.class.php
diff --git a/webapp/lib/class/ACSScheduleParticipant.class.php b/webapp/lib/class/ACSScheduleParticipant.class.php
new file mode 100644 (file)
index 0000000..8c66d7f
--- /dev/null
@@ -0,0 +1,322 @@
+<?php
+require_once(ACS_CLASS_DIR . 'ACSDB.class.php');
+
+/**
+ * ACS ¥¹¥±¥¸¥å¡¼¥ë»²²Ã¼Ô¥¯¥é¥¹
+ *
+ * @author  z-satosi
+ * @version $Revision: 1.1 $
+ */
+class ACSScheduleParticipant
+{
+       /* ¥¹¥±¥¸¥å¡¼¥ëID */
+       var $schedule_id;
+
+       /* »²²Ã¼Ô¥æ¡¼¥¶¥³¥ß¥å¥Ë¥Æ¥£ID */
+       var $user_community_id;
+
+       /* »²²Ã¼Ô¥æ¡¼¥¶¥³¥ß¥å¥Ë¥Æ¥£Ì¾¡Ê¥Ë¥Ã¥¯¥Í¡¼¥à¡Ë */
+       var $user_community_name;
+
+       /* »²²Ã¥³¥á¥ó¥È */
+       var $participant_comment;
+
+       /* ºï½ü¥Õ¥é¥° */
+       var $participant_delete_flag;
+
+       /* £Ä£ÂÅÐÏ¿¾õÂÖ */
+       var $_is_new;
+
+       /* ²óÅúÇÛÎó array( [adjustment_date_id] => [answer_no] ) */
+       var $_schedule_answer_array;
+
+       /**
+        * ¥³¥ó¥¹¥È¥é¥¯¥¿
+        *
+        * @param integer $schedule_id ¥¹¥±¥¸¥å¡¼¥ëid
+        * @param integer $user_community_id ¥æ¡¼¥¶¥³¥ß¥å¥Ë¥Æ¥£id
+        */
+       function ACSScheduleParticipant ($schedule_id,$user_community_id) {
+               $this->schedule_id = $schedule_id;
+               $this->user_community_id = $user_community_id;
+               $this->participant_delete_flag = "f";
+               $this->_schedule_answer_array = array();
+               $this->_is_new = 't';
+       }
+
+       /**
+        * ½é´ü½èÍý
+        *
+        * @param array $schedule_participant_row ¥¹¥±¥¸¥å¡¼¥ë»²²Ã¤Î¥Æ¡¼¥Ö¥ë¹Ô
+        * @param array $schedule_answer_rows ¥¹¥±¥¸¥å¡¼¥ë²óÅú¤Î¥Æ¡¼¥Ö¥ë¹ÔÇÛÎó
+        */
+       function initialize (&$schedule_participant_row,&$schedule_answer_rows) {
+               if (is_array($schedule_participant_row)) {
+                       $this->participant_comment     = 
+                                       $schedule_participant_row['participant_comment'];
+                       $this->participant_delete_flag = 
+                                       $schedule_participant_row['participant_delete_flag'] == '' ?
+                                       'f' : $schedule_participant_row['participant_delete_flag'];
+                       $this->user_community_name     = 
+                                       $schedule_participant_row['user_community_name'];
+                       $this->_is_new = 'f';
+               }
+               $this->_schedule_answer_array = array();
+               if (is_array($schedule_answer_rows)) {
+                       foreach ($schedule_answer_rows as $answer_row) {
+                               $this->_schedule_answer_array[$answer_row['adjustment_date_id']]
+                                               = $answer_row['answer_no'];     
+                       }
+                       reset($schedule_answer_rows);
+               }
+       }
+
+       /**
+        * ¥¹¥±¥¸¥å¡¼¥ë»²²Ã¾ðÊó¤Î£Ä£Â¹¹¿·
+        * 
+        * ¥¹¥±¥¸¥å¡¼¥ë»²²Ã¾ðÊó¤Î£Ä£Â¹¹¿·¤ò¼Â»Ü¤·¤Þ¤¹¡£<br>
+        * ¹¹¿·¤µ¤ì¤ë¥Æ¡¼¥Ö¥ë¤Ï°Ê²¼¤ÎÄ̤ê<br>
+        *     schedule_paticipant<br>
+        *     schedule_answer<br>
+        *
+        * @param boolean $is_participant_only »²²ÃÅÐÏ¿¤Î¤ß¤Î¾ì¹çTRUE(̤»ØÄê»þ¤ÏFALSE)
+        */
+       function update_participant($is_participant_only=FALSE) {
+
+               // BEGIN
+               ACSDB::_do_query("BEGIN");
+
+               if ($this->is_new()) {
+
+                       $sql = "INSERT INTO schedule_participant (".
+                                       " schedule_id, ".
+                                       " user_community_id, ".
+                                       " participant_comment, ".
+                                       " participant_delete_flag ".
+                                       ") VALUES (" .
+                                       " ".pg_escape_string($this->schedule_id)."," .
+                                       " ".pg_escape_string($this->user_community_id)."," .
+                                       " '".pg_escape_string($this->participant_comment)."'," .
+                                       " '".pg_escape_string($this->participant_delete_flag)."' " .
+                                       ")";
+
+
+               // Update
+               } else {
+                       $sql = "UPDATE schedule_participant SET ".
+                                       " participant_comment = ".
+                                       " '".pg_escape_string($this->participant_comment)."'," .
+                                       " participant_delete_flag = ".
+                                       " '".pg_escape_string($this->participant_delete_flag)."' " .
+                                       "WHERE schedule_id ".
+                                                       "= ".pg_escape_string($this->schedule_id) .
+                                       " AND user_community_id ".
+                                                       "= ".pg_escape_string($this->user_community_id) ;
+               }
+
+               $ret = ACSDB::_do_query($sql);
+               if (!$ret) {
+                       ACSDB::_do_query("ROLLBACK");
+                       return $ret;
+               }
+               $this->_is_new = 'f';
+
+               // ²óÅú(schedule_answer)¤ÎÅÐÏ¿(Delete/Insert)
+               if ($is_participant_only === FALSE) {
+
+                       // °ìöDelete
+                       $sql = "DELETE FROM schedule_answer ".
+                                       "WHERE schedule_id ".
+                                                       "= ".pg_escape_string($this->schedule_id) .
+                                       " AND user_community_id ".
+                                                       "= ".pg_escape_string($this->user_community_id) ;
+
+                       $ret = ACSDB::_do_query($sql);
+                       if (!$ret) {
+                               ACSDB::_do_query("ROLLBACK");
+                               return $ret;
+                       }
+
+                       // ¤¹¤Ù¤ÆInsert
+                       foreach ($this->_schedule_answer_array as $adjustment_date_id => $answer_no) {
+       
+                               $sql = "INSERT INTO schedule_answer ( ".
+                                               " schedule_id, ".
+                                               " user_community_id, ".
+                                               " adjustment_date_id, ".
+                                               " answer_no ".
+                                               ") VALUES (".
+                                               " ".pg_escape_string($this->schedule_id)."," .
+                                               " ".pg_escape_string($this->user_community_id)."," .
+                                               " ".pg_escape_string($adjustment_date_id)."," .
+                                               " ".pg_escape_string($answer_no)." " .
+                                               ")";
+       
+                               $ret = ACSDB::_do_query($sql);
+                               if (!$ret) {
+                                       ACSDB::_do_query("ROLLBACK");
+                                       return $ret;
+                               }
+                       }
+               }
+
+               // COMMIT
+               $ret = ACSDB::_do_query("COMMIT");
+
+               return $ret;
+       }
+
+       /**
+        * »ØÄê¸õÊäÆü»þ¤Î²óÅú¤òÀßÄê
+        *
+        * @param array $answers_array ²óÅú¾ðÊóÇÛÎó array([adjustment_date_id]=>[answer_no])
+        */
+       function set_answer ($answers_array) {
+               if (is_array($answers_array)) {
+                       foreach ($answers_array as $adjustment_date_id => $answer_no) {
+                               $this->_schedule_answer_array[$adjustment_date_id] = $answer_no;
+                       }
+               }
+       }
+
+       /**
+        * »ØÄê¸õÊäÆü»þ¤Î²óÅú¤ò¼èÆÀ
+        *
+        * @param integer $adjustment_date_id ¸õÊäÆü»þid
+        * @return integer ²óÅúNo(answer_no)
+        */
+       function & get_answer ($adjustment_date_id) {
+               return $this->_schedule_answer_array[$adjustment_date_id];
+       }
+
+       /**
+        * »²²Ã¤«¤É¤¦¤«¤ÎȽÄê
+        *
+        * @return boolean TRUE...»²²Ã/FALSE...ÉÔ»²²Ã
+        */
+       function is_participate () {
+               return ((!$this->is_new() && $this->participant_delete_flag == 'f') ? TRUE : FALSE);
+       }
+
+       /**
+        * ¿·µ¬¥¤¥ó¥¹¥¿¥ó¥¹¤«¤É¤¦¤«¤ÎȽÄê
+        *
+        * ¿·µ¬¤Ç¤Ê¤¤¥±¡¼¥¹<br>
+        * ¡¦initialize½èÍý»þ¤Ë»²²Ã¾ðÊó¤¬Â¸ºß¤·¤¿¾ì¹ç<br>
+        * ¡¦update_participant¤ò¼Â¹Ô¤·¤¿¾ì¹ç
+        *
+        * @return boolean TRUE...¿·µ¬/FALSE...¹¹¿·
+        */
+       function is_new () {
+               return $this->_is_new == 'f' ? FALSE : TRUE;
+       }
+
+       /****************************
+        * ¥¹¥¿¥Æ¥£¥Ã¥¯¥Õ¥¡¥ó¥¯¥·¥ç¥ó
+        ****************************/
+
+       /**
+        * ¥¹¥±¥¸¥å¡¼¥ë»²²Ã¥¤¥ó¥¹¥¿¥ó¥¹À¸À®
+        *
+        * @param string $schedule_id ³ºÅö¤Î¥¹¥±¥¸¥å¡¼¥ëid
+        * @param string $user_community_id ³ºÅö¤Î¥æ¡¼¥¶¥³¥ß¥å¥Ë¥Æ¥£id
+        * @return object ACSScheduleParticipant¥ª¥Ö¥¸¥§¥¯¥È
+        */
+       function & get_schedule_participant_instance ($schedule_id,$user_community_id) {
+
+               $sql = "SELECT pa.*, cm.community_name AS user_community_name " .
+                               "FROM schedule_participant AS pa " .
+                               "LEFT JOIN community AS cm " .
+                               "    ON pa.user_community_id = cm.community_id " .
+                               "WHERE pa.schedule_id = " . pg_escape_string($schedule_id) .
+                               " AND pa.user_community_id = " . pg_escape_string($user_community_id);
+
+               $participant_row = ACSDB::_get_row($sql);
+
+               $sql = "SELECT * FROM schedule_answer " .
+                               "WHERE schedule_id = " . pg_escape_string($schedule_id) .
+                               " AND user_community_id = " . pg_escape_string($user_community_id) .
+                               " ORDER BY adjustment_date_id";
+
+               $answer_rows = ACSDB::_get_row_array($sql);
+
+               $schedule_participant =& 
+                               new ACSScheduleParticipant($schedule_id,$user_community_id);
+               $schedule_participant->initialize($participant_row,$answer_rows);
+
+               return $schedule_participant;
+       }
+
+       /**
+        * ¥¹¥±¥¸¥å¡¼¥ë°ìÍ÷¥¤¥ó¥¹¥¿¥ó¥¹À¸À®
+        *
+        *  Ìá¤êÃͤϡ¢array([user_community_id] => ACSScheduleParticipant¥¤¥ó¥¹¥¿¥ó¥¹)
+        *
+        * @param string $schedule_id ³ºÅö¤Î¥¹¥±¥¸¥å¡¼¥ëid
+        * @param boolean $is_target_kind_all Á´°÷»²²Ã¥â¡¼¥É¤Ç¼èÆÀ¤¹¤ë¤«¤É¤¦¤«
+        * @return array ACSScheduleParticipant¥¤¥ó¥¹¥¿¥ó¥¹¤ÎÇÛÎó
+        */
+       function & get_schedule_participant_instance_list ($schedule_id,$is_target_kind_all) {
+
+               if ($is_target_kind_all) {
+                       $sql = "SELECT " .
+                                       " sc.schedule_id, " .
+                                       " mmb.user_community_id, " .
+                                       " pa.participant_comment, ".
+                                       " pa.participant_delete_flag, ".
+                                       " cmm.community_name AS user_community_name " .
+                                       "FROM (((schedule AS sc " .
+                                       "LEFT JOIN community AS cm ".
+                                       "    ON sc.community_id = cm.community_id) " .
+                                       "LEFT JOIN community_member AS mmb ".
+                                       "    ON sc.community_id = mmb.community_id) " .
+                                       "LEFT JOIN community AS cmm  ".
+                                       "    ON mmb.user_community_id = cmm.community_id) " .
+                                       "LEFT JOIN schedule_participant AS pa ".
+                                       "    ON sc.schedule_id = pa.schedule_id " .
+                                       "    AND mmb.user_community_id = pa.user_community_id ".
+                                       "WHERE sc.schedule_id = " . pg_escape_string($schedule_id) .
+                                       "  AND cmm.delete_flag != 't'";
+                                       " ORDER BY mmb.user_community_id ";
+               } else {
+                       $sql = "SELECT ".
+                                       " pa.schedule_id, ".
+                                       " pa.user_community_id, ".
+                                       " pa.participant_comment, ".
+                                       " pa.participant_delete_flag, ".
+                                       " cm.community_name AS user_community_name " .
+                                       "FROM schedule_participant AS pa " .
+                                       "LEFT JOIN community AS cm " .
+                                       "    ON pa.user_community_id = cm.community_id " .
+                                       "WHERE pa.schedule_id = " . pg_escape_string($schedule_id) .
+                                       " AND pa.participant_delete_flag = FALSE " .
+                                       " AND cm.delete_flag != 't'";
+                                       " ORDER BY pa.user_community_id ";
+               }
+       
+               $participant_rows = ACSDB::_get_row_array($sql);
+
+               $sql = "SELECT * FROM schedule_answer " .
+                               "WHERE schedule_id = " . pg_escape_string($schedule_id) .
+                               " ORDER BY user_community_id, adjustment_date_id";
+
+               $answer_res = ACSDB::_get_res($sql);
+               $answer_all_rows = array();
+               while ($row = $answer_res->fetchRow(DB_FETCHMODE_ASSOC)) {
+                       $answer_all_rows[$row['user_community_id']][] = $row;
+               }
+               $answer_res->free();
+
+               $schedule_participant_array = array();
+               foreach ($participant_rows as $participant_row) {
+                       $user_community_id = $participant_row['user_community_id'];
+                       $schedule_participant =& 
+                                       new ACSScheduleParticipant($schedule_id,$user_community_id);
+                       $schedule_participant->initialize(
+                                       $participant_row,$answer_all_rows[$user_community_id]);
+                       $schedule_participant_array[$user_community_id] = $schedule_participant;
+               }
+               return $schedule_participant_array;
+       }
+}
+?>