ここの情報は古いです。ご理解頂いた上でお取り扱いください。

Changeset 9061


Ignore:
Timestamp:
Nov 10, 2008, 9:12:23 PM (11 years ago)
Author:
ShogoKawahara
Message:

#3119:changed Application model

Location:
OpenPNE3/plugins/opOpenSocialPlugin/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • OpenPNE3/plugins/opOpenSocialPlugin/trunk/config/schema.yml

    r9058 r9061  
    1818    height: { type: integer, required: true }
    1919    scrolling: { type: integer, required: true }
    20     modified: { type: integer, required: true }
     20    updated_at: ~
    2121
    2222  application_setting:
  • OpenPNE3/plugins/opOpenSocialPlugin/trunk/lib/form/base/BaseApplicationForm.class.php

    r9059 r9061  
    2828      'height'          => new sfWidgetFormInput(),
    2929      'scrolling'       => new sfWidgetFormInput(),
    30       'modified'        => new sfWidgetFormInput(),
     30      'updated_at'      => new sfWidgetFormDateTime(),
    3131    ));
    3232
     
    4747      'height'          => new sfValidatorInteger(),
    4848      'scrolling'       => new sfValidatorInteger(),
    49       'modified'        => new sfValidatorInteger(),
     49      'updated_at'      => new sfValidatorDateTime(array('required' => false)),
    5050    ));
    5151
  • OpenPNE3/plugins/opOpenSocialPlugin/trunk/lib/model/ApplicationPeer.php

    r9059 r9061  
    1010class ApplicationPeer extends BaseApplicationPeer
    1111{
     12  /**
     13   * cast object from array
     14   *
     15   * @param array $array
     16   * @return object
     17   */
     18  protected static function arrayToObject($array)
     19  {
     20    foreach ($array as &$a)
     21    {
     22      if(is_array($a))
     23      {
     24        $a = self::arrayToObject($a);
     25      }
     26    }
     27    return (object)$array;
     28  }
     29  /**
     30   * add application
     31   *
     32   * @param string $url     gadget url
     33   * @param string $culture culture
     34   * @param bool   $update 
     35   */
     36  public static function addApplication($url, $culture = 'en_US', $update = false)
     37  {
     38    $criteria = new Criteria(ApplicationPeer::DATABASE_NAME);
     39    $criteria->add(ApplicationPeer::URL, $url);
     40    $criteria->add(ApplicationPeer::CULTURE, $culture);
     41    $app = ApplicationPeer::doSelectOne($criteria);
     42    if (!empty($app) && !$update)
     43    {
     44      return $app->getId();
     45    }
     46    $cul = split('_',$culture);
     47    $req = self::arrayToObject(array(
     48      'context' => array(
     49        'country' => isset($cul[1]) ? $cul[1] : 'US',
     50        'language' => $cul[0],
     51        'view' => 'default',
     52        'container' => 'openpne3'
     53      ),
     54      'gadgets' => array(array('url' => $url,'moduleId' => 1))
     55    ));
     56    $handler = new MetadataHandler();
     57    $response = $handler->process($req);
     58    if (!is_array($response) || count($response) <= 0 || isset($response[0]['errors']))
     59    {
     60      return false;
     61    }
     62    $default_gadget = array(
     63      'url'             => '',
     64      'title'           => '',
     65      'directory_title' => '',
     66      'screenshot'      => '',
     67      'thumbnail'       => '',
     68      'author'          => '',
     69      'author_email'    => '',
     70      'description'     => ''
     71    );
     72    $gadget = $response[0];
     73    $gadget = array_merge($default_gadget,$gadget);
     74    if (empty($app))
     75    {
     76      $app = new Application();
     77    }
     78    $app->setUrl($gadget['url']);
     79    $app->setCulture($culture);
     80    $app->setTitle($gadget['title']);
     81    $app->setDirectoryTitle($gadget['directory_title']);
     82    $app->setScreenshot($gadget['screenshot']);
     83    $app->setThumbnail($gadget['thumbnail']);
     84    $app->setAuthor($gadget['author']);
     85    $app->setAuthorEmail($gadget['author_email']);
     86    $app->setDescription($gadget['description']);
     87    $app->setSettings(isset($gadget['userPrefs']) ? serialize($gadget['userPrefs']) : '');
     88    $app->setViews(isset($gadget['views']) ? serialize($gadget['views']) : '');
     89    if ($gadget['scrolling'] == 'true')
     90    {
     91      $gadget['scrolling'] = 1;
     92    }
     93    $app->setScrolling(! empty($gadget['scrolling']) ? $gadget['scrolling'] : '0');
     94    $app->setHeight(! empty($gadget['height']) ? $gadget['height'] : '0');
     95    $iframe_url = $gadget['iframeUrl'];
     96    $iframe_params = array();
     97    parse_str($iframe_url, $iframe_params);
     98    $app->setVersion(isset($iframe_params['v']) ? $iframe_params['v'] : '');
     99    $app->save();
     100    return $app->getId();
     101  }
    12102}
  • OpenPNE3/plugins/opOpenSocialPlugin/trunk/lib/model/map/ApplicationMapBuilder.php

    r9059 r9061  
    6363                $tMap->addColumn('SCROLLING', 'Scrolling', 'int', CreoleTypes::INTEGER, true, null);
    6464
    65                 $tMap->addColumn('MODIFIED', 'Modified', 'int', CreoleTypes::INTEGER, true, null);
     65                $tMap->addColumn('UPDATED_AT', 'UpdatedAt', 'int', CreoleTypes::TIMESTAMP, false, null);
    6666
    6767        }
  • OpenPNE3/plugins/opOpenSocialPlugin/trunk/lib/model/om/BaseApplication.php

    r9059 r9061  
    7070
    7171       
    72         protected $modified;
     72        protected $updated_at;
    7373
    7474       
     
    196196
    197197       
    198         public function getModified()
    199         {
    200 
    201                 return $this->modified;
     198        public function getUpdatedAt($format = 'Y-m-d H:i:s')
     199        {
     200
     201                if ($this->updated_at === null || $this->updated_at === '') {
     202                        return null;
     203                } elseif (!is_int($this->updated_at)) {
     204                                                $ts = strtotime($this->updated_at);
     205                        if ($ts === -1 || $ts === false) {                              throw new PropelException("Unable to parse value of [updated_at] as date/time value: " . var_export($this->updated_at, true));
     206                        }
     207                } else {
     208                        $ts = $this->updated_at;
     209                }
     210                if ($format === null) {
     211                        return $ts;
     212                } elseif (strpos($format, '%') !== false) {
     213                        return strftime($format, $ts);
     214                } else {
     215                        return date($format, $ts);
     216                }
    202217        }
    203218
     
    413428        }
    414429       
    415         public function setModified($v)
    416         {
    417 
    418                                                 if ($v !== null && !is_int($v) && is_numeric($v)) {
    419                         $v = (int) $v;
    420                 }
    421 
    422                 if ($this->modified !== $v) {
    423                         $this->modified = $v;
    424                         $this->modifiedColumns[] = ApplicationPeer::MODIFIED;
     430        public function setUpdatedAt($v)
     431        {
     432
     433                if ($v !== null && !is_int($v)) {
     434                        $ts = strtotime($v);
     435                        if ($ts === -1 || $ts === false) {                              throw new PropelException("Unable to parse date/time value for [updated_at] from input: " . var_export($v, true));
     436                        }
     437                } else {
     438                        $ts = $v;
     439                }
     440                if ($this->updated_at !== $ts) {
     441                        $this->updated_at = $ts;
     442                        $this->modifiedColumns[] = ApplicationPeer::UPDATED_AT;
    425443                }
    426444
     
    461479                        $this->scrolling = $rs->getInt($startcol + 14);
    462480
    463                         $this->modified = $rs->getInt($startcol + 15);
     481                        $this->updated_at = $rs->getTimestamp($startcol + 15, null);
    464482
    465483                        $this->resetModified();
     
    498516        public function save($con = null)
    499517        {
     518    if ($this->isModified() && !$this->isColumnModified(ApplicationPeer::UPDATED_AT))
     519    {
     520      $this->setUpdatedAt(time());
     521    }
     522
    500523                if ($this->isDeleted()) {
    501524                        throw new PropelException("You cannot save an object that has been deleted.");
     
    672695                                break;
    673696                        case 15:
    674                                 return $this->getModified();
     697                                return $this->getUpdatedAt();
    675698                                break;
    676699                        default:
     
    699722                        $keys[13] => $this->getHeight(),
    700723                        $keys[14] => $this->getScrolling(),
    701                         $keys[15] => $this->getModified(),
     724                        $keys[15] => $this->getUpdatedAt(),
    702725                );
    703726                return $result;
     
    761784                                break;
    762785                        case 15:
    763                                 $this->setModified($value);
     786                                $this->setUpdatedAt($value);
    764787                                break;
    765788                }       }
     
    785808                if (array_key_exists($keys[13], $arr)) $this->setHeight($arr[$keys[13]]);
    786809                if (array_key_exists($keys[14], $arr)) $this->setScrolling($arr[$keys[14]]);
    787                 if (array_key_exists($keys[15], $arr)) $this->setModified($arr[$keys[15]]);
     810                if (array_key_exists($keys[15], $arr)) $this->setUpdatedAt($arr[$keys[15]]);
    788811        }
    789812
     
    808831                if ($this->isColumnModified(ApplicationPeer::HEIGHT)) $criteria->add(ApplicationPeer::HEIGHT, $this->height);
    809832                if ($this->isColumnModified(ApplicationPeer::SCROLLING)) $criteria->add(ApplicationPeer::SCROLLING, $this->scrolling);
    810                 if ($this->isColumnModified(ApplicationPeer::MODIFIED)) $criteria->add(ApplicationPeer::MODIFIED, $this->modified);
     833                if ($this->isColumnModified(ApplicationPeer::UPDATED_AT)) $criteria->add(ApplicationPeer::UPDATED_AT, $this->updated_at);
    811834
    812835                return $criteria;
     
    867890                $copyObj->setScrolling($this->scrolling);
    868891
    869                 $copyObj->setModified($this->modified);
     892                $copyObj->setUpdatedAt($this->updated_at);
    870893
    871894
  • OpenPNE3/plugins/opOpenSocialPlugin/trunk/lib/model/om/BaseApplicationPeer.php

    r9059 r9061  
    6666
    6767       
    68         const MODIFIED = 'application.MODIFIED';
     68        const UPDATED_AT = 'application.UPDATED_AT';
    6969
    7070       
     
    7474       
    7575        private static $fieldNames = array (
    76                 BasePeer::TYPE_PHPNAME => array ('Id', 'Url', 'Culture', 'Title', 'DirectoryTitle', 'Screenshot', 'Thumbnail', 'Author', 'AuthorEmail', 'Description', 'Settings', 'Views', 'Version', 'Height', 'Scrolling', 'Modified', ),
    77                 BasePeer::TYPE_COLNAME => array (ApplicationPeer::ID, ApplicationPeer::URL, ApplicationPeer::CULTURE, ApplicationPeer::TITLE, ApplicationPeer::DIRECTORY_TITLE, ApplicationPeer::SCREENSHOT, ApplicationPeer::THUMBNAIL, ApplicationPeer::AUTHOR, ApplicationPeer::AUTHOR_EMAIL, ApplicationPeer::DESCRIPTION, ApplicationPeer::SETTINGS, ApplicationPeer::VIEWS, ApplicationPeer::VERSION, ApplicationPeer::HEIGHT, ApplicationPeer::SCROLLING, ApplicationPeer::MODIFIED, ),
    78                 BasePeer::TYPE_FIELDNAME => array ('id', 'url', 'culture', 'title', 'directory_title', 'screenshot', 'thumbnail', 'author', 'author_email', 'description', 'settings', 'views', 'version', 'height', 'scrolling', 'modified', ),
     76                BasePeer::TYPE_PHPNAME => array ('Id', 'Url', 'Culture', 'Title', 'DirectoryTitle', 'Screenshot', 'Thumbnail', 'Author', 'AuthorEmail', 'Description', 'Settings', 'Views', 'Version', 'Height', 'Scrolling', 'UpdatedAt', ),
     77                BasePeer::TYPE_COLNAME => array (ApplicationPeer::ID, ApplicationPeer::URL, ApplicationPeer::CULTURE, ApplicationPeer::TITLE, ApplicationPeer::DIRECTORY_TITLE, ApplicationPeer::SCREENSHOT, ApplicationPeer::THUMBNAIL, ApplicationPeer::AUTHOR, ApplicationPeer::AUTHOR_EMAIL, ApplicationPeer::DESCRIPTION, ApplicationPeer::SETTINGS, ApplicationPeer::VIEWS, ApplicationPeer::VERSION, ApplicationPeer::HEIGHT, ApplicationPeer::SCROLLING, ApplicationPeer::UPDATED_AT, ),
     78                BasePeer::TYPE_FIELDNAME => array ('id', 'url', 'culture', 'title', 'directory_title', 'screenshot', 'thumbnail', 'author', 'author_email', 'description', 'settings', 'views', 'version', 'height', 'scrolling', 'updated_at', ),
    7979                BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, )
    8080        );
     
    8282       
    8383        private static $fieldKeys = array (
    84                 BasePeer::TYPE_PHPNAME => array ('Id' => 0, 'Url' => 1, 'Culture' => 2, 'Title' => 3, 'DirectoryTitle' => 4, 'Screenshot' => 5, 'Thumbnail' => 6, 'Author' => 7, 'AuthorEmail' => 8, 'Description' => 9, 'Settings' => 10, 'Views' => 11, 'Version' => 12, 'Height' => 13, 'Scrolling' => 14, 'Modified' => 15, ),
    85                 BasePeer::TYPE_COLNAME => array (ApplicationPeer::ID => 0, ApplicationPeer::URL => 1, ApplicationPeer::CULTURE => 2, ApplicationPeer::TITLE => 3, ApplicationPeer::DIRECTORY_TITLE => 4, ApplicationPeer::SCREENSHOT => 5, ApplicationPeer::THUMBNAIL => 6, ApplicationPeer::AUTHOR => 7, ApplicationPeer::AUTHOR_EMAIL => 8, ApplicationPeer::DESCRIPTION => 9, ApplicationPeer::SETTINGS => 10, ApplicationPeer::VIEWS => 11, ApplicationPeer::VERSION => 12, ApplicationPeer::HEIGHT => 13, ApplicationPeer::SCROLLING => 14, ApplicationPeer::MODIFIED => 15, ),
    86                 BasePeer::TYPE_FIELDNAME => array ('id' => 0, 'url' => 1, 'culture' => 2, 'title' => 3, 'directory_title' => 4, 'screenshot' => 5, 'thumbnail' => 6, 'author' => 7, 'author_email' => 8, 'description' => 9, 'settings' => 10, 'views' => 11, 'version' => 12, 'height' => 13, 'scrolling' => 14, 'modified' => 15, ),
     84                BasePeer::TYPE_PHPNAME => array ('Id' => 0, 'Url' => 1, 'Culture' => 2, 'Title' => 3, 'DirectoryTitle' => 4, 'Screenshot' => 5, 'Thumbnail' => 6, 'Author' => 7, 'AuthorEmail' => 8, 'Description' => 9, 'Settings' => 10, 'Views' => 11, 'Version' => 12, 'Height' => 13, 'Scrolling' => 14, 'UpdatedAt' => 15, ),
     85                BasePeer::TYPE_COLNAME => array (ApplicationPeer::ID => 0, ApplicationPeer::URL => 1, ApplicationPeer::CULTURE => 2, ApplicationPeer::TITLE => 3, ApplicationPeer::DIRECTORY_TITLE => 4, ApplicationPeer::SCREENSHOT => 5, ApplicationPeer::THUMBNAIL => 6, ApplicationPeer::AUTHOR => 7, ApplicationPeer::AUTHOR_EMAIL => 8, ApplicationPeer::DESCRIPTION => 9, ApplicationPeer::SETTINGS => 10, ApplicationPeer::VIEWS => 11, ApplicationPeer::VERSION => 12, ApplicationPeer::HEIGHT => 13, ApplicationPeer::SCROLLING => 14, ApplicationPeer::UPDATED_AT => 15, ),
     86                BasePeer::TYPE_FIELDNAME => array ('id' => 0, 'url' => 1, 'culture' => 2, 'title' => 3, 'directory_title' => 4, 'screenshot' => 5, 'thumbnail' => 6, 'author' => 7, 'author_email' => 8, 'description' => 9, 'settings' => 10, 'views' => 11, 'version' => 12, 'height' => 13, 'scrolling' => 14, 'updated_at' => 15, ),
    8787                BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, )
    8888        );
     
    168168                $criteria->addSelectColumn(ApplicationPeer::SCROLLING);
    169169
    170                 $criteria->addSelectColumn(ApplicationPeer::MODIFIED);
     170                $criteria->addSelectColumn(ApplicationPeer::UPDATED_AT);
    171171
    172172        }
Note: See TracChangeset for help on using the changeset viewer.