コード例 #1
0
function Websites_0_8_4_Streams_mysql()
{
    $app = Q_Config::expect('Q', 'app');
    // allow inserting images in articles
    $r = new Streams_RelatedTo();
    $r->toPublisherId = $app;
    $r->toStreamName = 'Websites/article/';
    $r->type = 'images';
    $r->fromPublisherId = $app;
    $r->fromStreamName = 'Streams/image/';
    $r->save();
}
コード例 #2
0
function Streams_0_8_6_Streams_mysql()
{
    $app = Q_Config::expect('Q', 'app');
    // access for managing communities
    $access = new Streams_Access();
    $access->publisherId = $app;
    $access->streamName = 'Streams/community*';
    $access->ofUserId = '';
    $access->ofContactLabel = "{$app}/admins";
    $access->readLevel = Streams::$READ_LEVEL['messages'];
    $access->writeLevel = Streams::$WRITE_LEVEL['edit'];
    $access->adminLevel = Streams::$ADMIN_LEVEL['manage'];
    $access->save();
    // access for managing categories
    $access = new Streams_Access();
    $access->publisherId = $app;
    $access->streamName = 'Streams/category/';
    $access->ofUserId = '';
    $access->ofContactLabel = "{$app}/admins";
    $access->readLevel = Streams::$READ_LEVEL['messages'];
    $access->writeLevel = Streams::$WRITE_LEVEL['close'];
    $access->adminLevel = Streams::$ADMIN_LEVEL['manage'];
    $access->save();
    // template to help users relate things to Streams/category streams
    Streams_Stream::insert(array('publisherId' => '', 'name' => 'Streams/category/', 'type' => 'Streams/template', 'title' => 'Untitled Category', 'icon' => 'Streams/category', 'content' => '', 'attributes' => null, 'readLevel' => Streams::$READ_LEVEL['messages'], 'writeLevel' => Streams::$WRITE_LEVEL['relate'], 'adminLevel' => Streams::$ADMIN_LEVEL['invite']))->execute();
    // template to help users create subcategories for things
    Streams_RelatedTo::insert(array('toPublisherId' => '', 'toStreamName' => 'Streams/category/', 'type' => 'subcategories', 'fromPublisherId' => '', 'fromStreamName' => 'Streams/category/'))->execute();
}
コード例 #3
0
function Websites_0_9_1_Streams_mysql()
{
    $userId = Users::communityId();
    $ofUserId = '';
    $ofContactLabel = 'Websites/admins';
    $grantedByUserId = null;
    $streams = array("Websites/presentation/" => array('type' => "Streams/template", "title" => "Untitled Presentation", "icon" => "{{baseUrl}}/plugins/Websites/img/icons/Websites/presentation", "content" => "", "deletable" => true), "Websites/slide/" => array('type' => "Streams/template", "title" => "Untitled Slide", "icon" => "{{baseUrl}}/plugins/Websites/img/icons/Websites/presentation", "content" => "", "deletable" => true));
    $readLevel = Streams::$READ_LEVEL['messages'];
    $adminLevel = Streams::$ADMIN_LEVEL['own'];
    $rows = array();
    foreach ($streams as $streamName => $stream) {
        $publisherId = substr($streamName, -1) == '/' ? '' : $userId;
        $level = !empty($stream['deletable']) ? 'close' : 'edit';
        $writeLevel = Streams::$WRITE_LEVEL[!empty($stream['deletable']) ? 'close' : 'edit'];
        $rows[] = compact('publisherId', 'streamName', 'ofUserId', 'ofContactLabel', 'grantedByUserId', 'readLevel', 'writeLevel', 'adminLevel');
    }
    Streams_Access::insertManyAndExecute($rows);
    $attributes = null;
    $closedTime = null;
    $readLevel = Streams::$READ_LEVEL['messages'];
    $writeLevel = Streams::$WRITE_LEVEL['join'];
    $adminLevel = Streams::$ADMIN_LEVEL['invite'];
    $inheritAccess = null;
    $rows = array();
    foreach ($streams as $name => $s) {
        extract($s);
        $publisherId = substr($name, -1) == '/' ? '' : $userId;
        $rows[] = compact('publisherId', 'name', 'type', 'title', 'icon', 'content', 'attributes', 'readLevel', 'writeLevel', 'adminLevel', 'inheritAccess');
    }
    Streams_Stream::insertManyAndExecute($rows);
    Streams_RelatedTo::insert(array('toPublisherId' => '', 'toStreamName' => 'Websites/presentation/', 'type' => 'slides', 'fromPublisherId' => '', 'fromStreamName' => 'Websites/slide/'))->execute();
}
コード例 #4
0
function Streams_after_Streams_message_Streams_relatedTo($params)
{
    $message = $params['message'];
    $type = $message->getInstruction('type', null);
    $stream = $params['stream'];
    $rtypes = Q_Config::get('Streams', 'categorize', 'relationTypes', array());
    $stypes = Q_Config::get('Streams', 'categorize', 'streamTypes', array());
    if (!in_array($type, $rtypes) or !in_array($stream->type, $stypes)) {
        return;
    }
    $c = new Streams_Category();
    $c->publisherId = $stream->publisherId;
    $c->streamName = $stream->name;
    $fromPublisherId = $message->getInstruction('fromPublisherId', null);
    $fromStreamName = $message->getInstruction('fromStreamName', null);
    if (!isset($fromPublisherId) or !isset($fromStreamName)) {
        return;
    }
    // Begin database transaction
    $relatedTo = $c->retrieve(null, array('ignoreCache' => true, 'begin' => true)) ? json_decode($c->relatedTo, true) : array();
    $weight = (double) $message->getInstruction('weight', null);
    if (!isset($weight)) {
        $rt = new Streams_RelatedTo();
        $rt->toPublisherId = $stream->publisherId;
        $rt->toStreamName = $stream->name;
        $rt->type = $type;
        $rt->fromPublisherId = $fromPublisherId;
        $rt->fromStreamName = $fromStreamName;
        $rt->retrieve(null, null, array('ignoreCache' => true));
        $weight = $rt->weight;
    }
    $fs = Streams::fetchOne($message->byUserId, $fromPublisherId, $fromStreamName);
    $weight = floor($weight);
    $relatedTo[$type][$weight] = array($fromPublisherId, $fromStreamName, $fs->title, $fs->icon);
    $c->relatedTo = Q::json_encode($relatedTo);
    $c->save(false, true);
    // End database transaction
}
コード例 #5
0
function Websites_0_8_Streams_mysql()
{
    $userId = Q_Config::get("Websites", "user", "id", null);
    if (!$userId) {
        throw new Q_Exception('Websites: Please fill in the config field "Websites"/"user"/"id"');
    }
    // $now = Streams::db()->toDateTime(Streams::db()->getCurrentTimestamp());
    $ofUserId = '';
    $ofContactLabel = 'Websites/admins';
    $grantedByUserId = null;
    $streams = array("Streams/images/" => array('type' => "Streams/template", "title" => "Images", "icon" => "default", "content" => "", "deletable" => true), "Streams/image/" => array('type' => "Streams/template", "title" => "Untitled Image", "icon" => "Streams/image", "content" => "", "deletable" => true), "Streams/file/" => array('type' => "Streams/template", "title" => "Untitled File", "icon" => "files/_blank", "content" => "", "deletable" => true), "Websites/article/" => array('type' => "Streams/template", "title" => "Untitled Article", "icon" => "default", "content" => "", "deletable" => true), "Websites/seo/" => array('type' => "Streams/template", "title" => "Website SEO", "icon" => Q_Html::themedUrl("plugins/Websites/img/seo"), "content" => "", "deletable" => true), "Websites/header" => array('type' => "Streams/image/icon", "title" => "Header image", "icon" => Q_Html::themedUrl("plugins/Websites/img/header"), "content" => ""), "Websites/slogan" => array('type' => "Streams/text/small", "title" => "Website slogan", "icon" => "default", "content" => "The coolest website"), "Websites/title" => array('type' => "Streams/text/small", "title" => "Website title", "icon" => "default", "content" => "Website Title"), "Websites/menu" => array('type' => "Streams/category", "title" => "Website Menu", "icon" => "default", "content" => ""), "Websites/articles" => array('type' => "Streams/category", "title" => "Articles", "icon" => "default", "content" => "Articles"), "Websites/images" => array('type' => "Streams/category", "title" => "Images", "icon" => "default", "content" => "Articles"));
    $readLevel = Streams::$READ_LEVEL['messages'];
    $writeLevel = Streams::$WRITE_LEVEL['edit'];
    $adminLevel = Streams::$ADMIN_LEVEL['own'];
    $rows = array();
    foreach ($streams as $streamName => $stream) {
        $publisherId = substr($streamName, -1) == '/' ? '' : $userId;
        $writeLevel = !empty($stream['deletable']) ? 40 : 30;
        $rows[] = compact('publisherId', 'streamName', 'ofUserId', 'ofContactLabel', 'grantedByUserId', 'readLevel', 'writeLevel', 'adminLevel');
    }
    Streams_Access::insertManyAndExecute($rows);
    $attributes = null;
    $closedTime = null;
    $readLevel = Streams::$READ_LEVEL['messages'];
    $writeLevel = Streams::$WRITE_LEVEL['join'];
    $adminLevel = Streams::$ADMIN_LEVEL['invite'];
    $inheritAccess = null;
    $rows = array();
    foreach ($streams as $name => $s) {
        extract($s);
        if (substr($name, 0, 9) != 'Websites/') {
            continue;
            // this tempate was already added by Streams install script
        }
        $publisherId = substr($name, -1) == '/' ? '' : $userId;
        $rows[] = compact('publisherId', 'name', 'type', 'title', 'icon', 'content', 'attributes', 'readLevel', 'writeLevel', 'adminLevel', 'inheritAccess');
    }
    Streams_Stream::insertManyAndExecute($rows);
    Streams_RelatedTo::insert(array('toPublisherId' => '', 'toStreamName' => 'Streams/images/', 'type' => 'images', 'fromPublisherId' => '', 'fromStreamName' => 'Streams/image/'))->execute();
    Streams_RelatedTo::insert(array('toPublisherId' => '', 'toStreamName' => 'Streams/category/', 'type' => 'articles', 'fromPublisherId' => '', 'fromStreamName' => 'Websites/article/'))->execute();
    Streams_RelatedTo::insert(array('toPublisherId' => '', 'toStreamName' => 'Streams/category/', 'type' => 'announcements', 'fromPublisherId' => '', 'fromStreamName' => 'Websites/article/'))->execute();
}
コード例 #6
0
ファイル: Streams.php プロジェクト: atirjavid/Platform
 /**
  * Updates the weight on a relation
  * @param {string} $asUserId
  *  The id of the user on whose behalf the app will be updating the relation
  * @param {string} $toPublisherId
  *  The publisher of the stream on the 'to' end of the reltion
  * @param {string} $toStreamName
  *  The name of the stream on the 'to' end of the relation
  * @param {string} $type
  *  The type of the relation
  * @param {string} $fromPublisherId
  *  The publisher of the stream on the 'from' end of the reltion
  * @param {string} $fromStreamName
  *  The name of the stream on the 'from' end of the reltion
  * @param {double} $weight
  *  The new weight
  * @param {double} $adjustWeights=null
  *  The amount to move the other weights by, to make room for this one
  * @param {array} $options=array()
  *  An array of options that can include:
  *  "skipAccess" => Defaults to false. If true, skips the access checks and just updates the weight on the relation
  * @return {array|boolean}
  *  Returns false if the operation was canceled by a hook
  *  Otherwise returns array with key "to" and value of type Streams_Message
  */
 static function updateRelation($asUserId, $toPublisherId, $toStreamName, $type, $fromPublisherId, $fromStreamName, $weight, $adjustWeights = null, $options = array())
 {
     self::getRelation($asUserId, $toPublisherId, $toStreamName, $type, $fromPublisherId, $fromStreamName, $relatedTo, $relatedFrom, $category, $stream, $options);
     if (!$relatedTo->retrieve()) {
         throw new Q_Exception_MissingRow(array('table' => 'relatedTo', 'criteria' => 'with those fields'), array('publisherId', 'name', 'type', 'toPublisherId', 'to_name'));
     }
     //		if (!$relatedFrom->retrieve()) {
     //			throw new Q_Exception_MissingRow(
     //				array('table' => 'relatedFrom', 'criteria' => 'those fields'),
     //				array('publisherId', 'name', 'type', 'fromPublisherId', 'from_name')
     //			);
     //		}
     if (empty($options['skipAccess'])) {
         if (!$category->testWriteLevel('relations')) {
             throw new Users_Exception_NotAuthorized();
         }
     }
     /**
      * @event Streams/updateRelation/$streamType {before}
      * @param {string} relatedTo
      * @param {string} relatedFrom
      * @param {string} asUserId
      * @param {double} weight
      * @param {double} previousWeight
      */
     $previousWeight = $relatedTo->weight;
     $adjustWeightsBy = $weight < $previousWeight ? $adjustWeights : -$adjustWeights;
     if (Q::event("Streams/updateRelation/{$stream->type}", compact('relatedTo', 'relatedFrom', 'type', 'weight', 'previousWeight', 'adjustWeightsBy', 'asUserId'), 'before') === false) {
         return false;
     }
     if (!empty($adjustWeights) and is_numeric($adjustWeights) and $weight !== $previousWeight) {
         $criteria = array('toPublisherId' => $toPublisherId, 'toStreamName' => $toStreamName, 'type' => $type, 'weight' => $weight < $previousWeight ? new Db_Range($weight, true, false, $previousWeight) : new Db_Range($previousWeight, false, true, $weight));
         Streams_RelatedTo::update()->set(array('weight' => new Db_Expression("weight + " . $adjustWeightsBy)))->where($criteria)->execute();
     }
     $relatedTo->weight = $weight;
     $relatedTo->save();
     // Send Streams/updatedRelateTo message to the category stream
     // node server will be notified by Streams_Message::post
     $message = Streams_Message::post($asUserId, $toPublisherId, $toStreamName, array('type' => 'Streams/updatedRelateTo', 'instructions' => Q::json_encode(compact('fromPublisherId', 'fromStreamName', 'type', 'weight', 'previousWeight', 'adjustWeightsBy', 'asUserId'))), true);
     // TODO: We are not yet sending Streams/updatedRelateFrom message to the other stream
     // because we might be changing a lot of weights, and we'd have to message a lot of streams.
     // This is better done in the background using Node.js after selecting using $criteria
     // When we implement this, we can introduce weight again in the relatedFrom table.
     /**
      * @event Streams/updateRelation/$streamType {after}
      * @param {string} relatedTo
      * @param {string} relatedFrom
      * @param {string} asUserId
      * @param {double} weight
      * @param {double} previousWeight
      */
     Q::event("Streams/updateRelation/{$stream->type}", compact('relatedTo', 'relatedFrom', 'type', 'weight', 'previousWeight', 'adjustWeightsBy', 'asUserId'), 'after');
     return $message;
 }
コード例 #7
0
ファイル: Streams.php プロジェクト: AndreyTepaykin/Platform
 /**
  * Updates the weight on a relation
  * @param {string} $asUserId
  *  The id of the user on whose behalf the app will be updating the relation
  * @param {string} $toPublisherId
  *  The publisher of the stream on the 'to' end of the reltion
  * @param {string} $toStreamName
  *  The name of the stream on the 'to' end of the relation
  * @param {string} $type
  *  The type of the relation
  * @param {string} $fromPublisherId
  *  The publisher of the stream on the 'from' end of the reltion
  * @param {string} $fromStreamName
  *  The name of the stream on the 'from' end of the reltion
  * @param {double} $weight
  *  The new weight
  * @param {double} [$adjustWeights=1]
  *  The amount to move the other weights by, to make room for this one.
  *  This should be a positive number - the direction of the shift is determined automatically.
  *  Or, set to 0 to prevent moving the other weights.
  * @param {array} $options=array()
  * @param {boolean} [$options.skipAccess=false] If true, skips the access checks and just unrelates the stream from the category
  * @return {array|boolean}
  *  Returns false if the operation was canceled by a hook
  *  Otherwise returns array with key "to" and value of type Streams_Message
  */
 static function updateRelation($asUserId, $toPublisherId, $toStreamName, $type, $fromPublisherId, $fromStreamName, $weight, $adjustWeights = 1, $options = array())
 {
     self::getRelations($asUserId, $toPublisherId, $toStreamName, $type, $fromPublisherId, $fromStreamName, $relatedTo, $relatedFrom, $categories, $streams, $arrayField, $options);
     $relatedTo = reset($relatedTo);
     $relatedFrom = reset($relatedFrom);
     $category = reset($categories);
     $stream = reset($streams);
     if (!$relatedTo) {
         throw new Q_Exception_MissingRow(array('table' => 'relatedTo', 'criteria' => 'with those fields'), array('publisherId', 'name', 'type', 'toPublisherId', 'to_name'));
     }
     //		if (!$relatedFrom->retrieve()) {
     //			throw new Q_Exception_MissingRow(
     //				array('table' => 'relatedFrom', 'criteria' => 'those fields'),
     //				array('publisherId', 'name', 'type', 'fromPublisherId', 'from_name')
     //			);
     //		}
     if (empty($options['skipAccess'])) {
         if (!$category->testWriteLevel('relations')) {
             throw new Users_Exception_NotAuthorized();
         }
     }
     /**
      * @event Streams/updateRelation/$streamType {before}
      * @param {string} relatedTo
      * @param {string} relatedFrom
      * @param {string} asUserId
      * @param {double} weight
      * @param {double} previousWeight
      */
     $previousWeight = $relatedTo->weight;
     if (empty($adjustWeights)) {
         $adjustWeights = 0;
     }
     if (!is_numeric($adjustWeights) or $adjustWeights < 0) {
         throw new Q_Exception_WrongType(array('fields' => 'adjustWeights', 'type' => 'a non-negative number'));
     }
     $adjustWeightsBy = $weight < $previousWeight ? $adjustWeights : -$adjustWeights;
     if (Q::event("Streams/updateRelation/{$stream->type}", compact('relatedTo', 'relatedFrom', 'type', 'weight', 'previousWeight', 'adjustWeightsBy', 'asUserId'), 'before') === false) {
         return false;
     }
     if ($adjustWeights and $weight !== $previousWeight) {
         $criteria = array('toPublisherId' => $toPublisherId, 'toStreamName' => $toStreamName, 'type' => $type, 'weight' => $weight < $previousWeight ? new Db_Range($weight, true, false, $previousWeight) : new Db_Range($previousWeight, false, true, $weight));
         Streams_RelatedTo::update()->set(array('weight' => new Db_Expression("weight + " . $adjustWeightsBy)))->where($criteria)->execute();
     }
     $relatedTo->weight = $weight;
     $relatedTo->save();
     // Send Streams/updatedRelateTo message to the category stream
     // node server will be notified by Streams_Message::post
     $message = Streams_Message::post($asUserId, $toPublisherId, $toStreamName, array('type' => 'Streams/updatedRelateTo', 'instructions' => compact('fromPublisherId', 'fromStreamName', 'type', 'weight', 'previousWeight', 'adjustWeightsBy', 'asUserId')), true);
     /**
      * @event Streams/updateRelation/$categoryType {after}
      * @param {string} relatedTo
      * @param {string} relatedFrom
      * @param {string} asUserId
      * @param {double} weight
      * @param {double} previousWeight
      */
     Q::event("Streams/updateRelation/{$category->type}", compact('relatedTo', 'relatedFrom', 'type', 'weight', 'previousWeight', 'adjustWeightsBy', 'asUserId'), 'after');
     return $message;
 }
コード例 #8
0
ファイル: Shipping.php プロジェクト: AndreyTepaykin/Platform
 /**
  * Get current relation of shipment stream to Shipping/shipments category stream
  * @method getShipmentRelation
  * @static
  * @param object $stream shipment stream object
  * @param boolean $returnTitle flag which define what to return, if true - return relation title from config, else - return value from DB
  * @return string
  */
 static function getShipmentRelation($stream, $returnTitle = false)
 {
     $env = self::getVars();
     $type = Streams_RelatedTo::select(array("type"))->where(array('toPublisherId' => $env->communityId, 'toStreamName' => $env->shipmentsStreamName, 'fromPublisherId' => $stream->publisherId, 'fromStreamName' => $stream->name))->execute()->fetchAll(PDO::FETCH_ASSOC)[0]["type"];
     if (!$returnTitle) {
         return $type;
     }
     $states = Q_Config::expect('Shipping', 'states');
     foreach ($states as $state) {
         if ($state["type"] == $type) {
             return $state["title"];
         }
     }
 }