Completed
Pull Request — master (#6)
by Dima
12:13
created

Gallery.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: myslyvyi
5
 * Date: 05.01.2016
6
 * Time: 15:25
7
 */
8
9
namespace samsoncms\api;
10
11
class Gallery
12
{
13
    /** @var integer Table parent materialField identifier */
14
    protected $materialFieldId = null;
15
16
    /**
17
     * Constructor Gallery
18
     * @param integer $materialId material identifier
19
     * @param integer $fieldId field identifier
20
     */
21
    public function __construct($materialId, $fieldId)
22
    {
23
        $mf = null;
24
        if (is_int($materialId) && is_int($fieldId)) {
25
            if (dbQuery('materialfield')->cond('MaterialID', $materialId)->cond('FieldID', $fieldId)->first($mf)) {
0 ignored issues
show
Deprecated Code introduced by
The method samson\activerecord\dbQuery::cond() has been deprecated with message: @see self::where()

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
26
                $this->materialFieldId = $mf->id;
27
            }
28
        }
29
    }
30
31
    /**
32
     * Get all images in gallery
33
     * @return array
34
     */
35
    public function getImages()
36
    {
37
        if ($this->issetImages()) {
38
            // array images from gallery
39
            $images = null;
40
            if (dbQuery('gallery')->cond('MaterialFieldID', $this->materialFieldId)->exec($images)) {
0 ignored issues
show
Deprecated Code introduced by
The method samson\activerecord\dbQuery::cond() has been deprecated with message: @see self::where()

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
41
                return $images;
42
            }
43
        }
44
        return array();
45
    }
46
47
    /**
48
     * Check on empty gallery
49
     * @return boolean
50
     **/
51
    public function issetImages()
52
    {
53
        return (isset($this->materialFieldId)) ? true : false;
54
    }
55
}