function it_encodes(reference $reference)
 {
     $reference->getReferenceIdentifier()->willReturn('ref');
     $encoder = new JavascriptEncoder(new Output());
     $this->encode($encoder)->shouldReturn('ref.foo("bar")');
     $this->encode($encoder, Flags::CLOSE_STATEMENT)->shouldReturn('ref.foo("bar");');
 }
Esempio n. 2
0
 /**
  *	Method to update the record
  *
  *	@since 1.0.0
  *	@access public
  *
  *	@return int Number of updated rows
  **/
 public function update($data)
 {
     // Initialize PDO object
     $this->queryInit();
     // Extract the columns
     $columns = array_keys($data);
     $columns = implode('=?, ', $columns) . '=?';
     // Extract the values
     $values = array_values($data);
     // Build update query
     $query = sprintf("UPDATE %s SET %s %s", $this->table, $columns, $this->where ? 'WHERE ' . $this->where : '');
     // Reset SQL query
     $this->resetQuery();
     // Prepare and execute update query
     $update = $this->pdo->prepare($query);
     $update->execute($values);
     return $update->rowCount();
 }
Esempio n. 3
0
/**	Check for database access errors
 *	@param reference $target - pointer to db object
 *	@return none
 */
function catch_error(&$target)
{
    if (vartrue($target->getLastErrorText()) && E107_DEBUG_LEVEL != 0) {
        $tmp2 = debug_backtrace();
        $tmp = $target->getLastErrorText();
        echo $tmp . " [ " . basename(__FILE__) . " on line " . $tmp2[0]['line'] . "] <br />";
    }
    return;
}
 /**
  * Liest aus der DB die Maildaten aus.
  *
  * @param reference $mysql_link MySQL Objekt
  * @param string $hash Hash
  */
 private function _db2mail($mysql_link, $hash, $delete = false)
 {
     if ($delete == false) {
         $select_query = "SELECT * FROM mailto WHERE mailto_hash = '{$hash}'";
         $mysql_link->query($select_query);
         $mailto_data = $mysql_link->fetcharray();
         $this->_mail_reciver_name = $mailto_data["mailto_reciver_name"];
         $this->_mail_reciver = $mailto_data["mailto_reciver_email"];
         $this->_mail_sender_name = $mailto_data["mailto_sender_name"];
         $this->_mail_sender = $mailto_data["mailto_sender_email"];
         $this->_mail_titel = $mailto_data["mailto_subject"];
         $this->_mail_content = $mailto_data["mailto_content"];
     } else {
         $delete_query = "DELETE FROM mailto WHERE mailto_hash = '{$hash}'";
         $mysql_link->query($delete_query);
     }
 }
Esempio n. 5
0
 /**
  * modify item (submit)
  *
  * called on item update from (@see collection::modify)
  *
  * @return array data
  */
 function modify($data)
 {
     $this->modify_before(reference::make($data));
     $_data = $data;
     $this->format_fields($data, 'modify');
     unset($data[$this->get_key()]);
     // $this->filter_data($data);
     $keys = $this->get_fields_keys();
     foreach ($keys as $key) {
         if (isset($data[$key]) && $this->in_working_set($key)) {
             $this->data[$key] = $data[$key];
         }
     }
     // restore key
     $_data[$this->get_key()] = $data[$this->get_key()] = $this->data[$this->get_key()] = $this->get_id();
     core::dprint('modify ' . get_class($this) . ' #id ' . $data[$this->get_key()]);
     // save to db
     $this->save();
     // working fields set deny modifying extra data,
     // only with full update
     if (empty($this->working_fields)) {
         $this->modify_after($_data);
     } else {
         $this->modify_partial_after($_data, $this->working_fields);
     }
     // remove renderer and other cache
     $this->drop_internal_cache();
     // call onload
     $data = $this->get_data();
     $this->filter_data($data);
     $this->set_data($data);
     return $data;
 }
Esempio n. 6
0
/**
 * Get a count of elements in an array. Since Smarty doesn't have an integrated
 * array counting function, this serves as a wrapper for PHP's. $p is an array 
 * which has various values used for the produced output:
 * 
 * $p['array'] contains the array whose elements will be counted.
 * 
 * If $p['assign'] is set and true, the function will change $p['assign']
 * to be the array count
 * 
 * @param array $p The array containing the previously mentioned values.
 * @param reference $sm A reference to a Smarty object
 * 
 * @return mixed Nothing is returned if $p['assign'] is true- in all other instances,
 * however, the elements count is returned
 */
function smcount($p, &$sm)
{
    //Sweet mother, why didn't I think of this sooner?!
    //Smarty doesn't have an array counting function built in, so here's a wrapper for PHP's.
    if (isset($p['assign']) == true) {
        $sm->assign($p['assign'], count($p['array']));
    } else {
        return count($p['array']);
    }
}
Esempio n. 7
0
 /**
  * Фильтрует статьи из базы данных по автору, по категории
  * и по дате публикации
  *
  * @param reference $conn Соединение с БД
  * @param int $authId Идентификатор автора статьи
  * @param int $catId Идентификатор категории
  * @param datetime $pubDate Дата публикации статьи
  * @return object[]
  */
 public static function Find($conn, $authId = NULL, $catId = NULL, $pubDate = NULL)
 {
     // Формируем условия для фильтрации статей
     $q = "Select Articles.ID, Articles.Name, Articles.Content, Articles.PubDate,\n\t\t\t\t\tCategory.ID, Category.Name,\n\t\t\t\t\tAuthors.ID, Authors.Name\n\t\t\t\tFrom Category,\n\t\t\t\t\tArticles Left Outer Join ArtAuth On ArtAuth.ID_Article = Articles.ID\n\t\t\t\t\tLeft Outer Join ArtCat On ArtCat.ID_Article = Articles.ID\n\t\t\t\t\tLeft Outer Join Authors On Authors.ID = ArtAuth.ID_Author\n\t\t\t\tWhere ArtAuth.ID_Author = Authors.ID and ArtCat.ID_Category = Category.ID";
     if (isset($authId) && $authId >= 0) {
         $q = $q . " And Authors.ID = {$authId}";
     }
     if (isset($catId) && $catId >= 0) {
         $q = $q . " And Category.ID = {$catId}";
     }
     if (isset($pubDate)) {
         if ($pubDate == -2) {
             $q = $q . " And TO_DAYS(NOW()) - TO_DAYS(Articles.PubDate) <= 7";
         } elseif ($pubDate == -3) {
             $q = $q . " And TO_DAYS(NOW()) - TO_DAYS(Articles.PubDate) <= 365";
         }
     }
     /** @var reference Запрос в базу данных */
     $res = $conn->query($q);
     /** @var array[] Массив объектов класса Article */
     $articles = array();
     while ($article = $res->fetch()) {
         $id = $article[0];
         $auth = NULL;
         if (isset($article[6])) {
             $auth = new Author($article[6], $article[7]);
         }
         $id = $article[0];
         if (isset($articles[$id]) && isset($auth)) {
             $arr = $articles[$id]->authors;
             $arr[] = $auth;
             $articles[$id]->authors = $arr;
         } else {
             $articles[$id] = Article::Init($id, $article[1], $article[2], $article[3], new Category($article[4], $article[5]), new Author($article[6], $article[7]), $auth);
         }
     }
     return $articles;
 }
Esempio n. 8
0
/**
 * dbeHasPermission()
 * Wrapper for modx->hasPermission - custom permissions with fallback...
 * If the customPermissions plugin is installed and they are set (either 0 0r 1) for
 * the current user it will use those. Otherwise it will check the standard modx
 * permissions in the $modxPermissions table. For now this means that someone can have
 * access if they have sufficient module acces and have not had their custom permissions
 * set one way or the other.
 *
 * @param string $permission
 * @param reference $modx
 * @return boolean true or false
 **/
function dbeHasPermission($permission, &$modx)
{
    global $modxPermissions;
    $permission = isset($_SESSION['mgrPermissions'][$permission]) ? $permission : $modxPermissions[$permission];
    return $modx->hasPermission($permission);
}
Esempio n. 9
0
<?php

require '../loader.php';
$reftest = new referenceTest();
$dataA = ['param' => 1];
$dataO = new stdClass(['param' => 1]);
$reftest->testA(reference::make($dataA));
test_assert($dataA['param'] === 'helloA');
$reftest->testO(reference::make($dataO));
test_assert($dataO->param === 'helloO');
test_except('tf_exception', function () use($reftest, $dataO) {
    $reftest->testA(reference::make($dataO));
});
class referenceRunner
{
    function testA($data)
    {
        $data['param'] = 'helloA';
    }
    function testO($data)
    {
        $data->param = 'helloO';
    }
}
class referenceTest
{
    protected $rr;
    function __construct()
    {
        $this->rr = new referenceRunner();
    }